i'm trying simple telit cc864 cellular module. module controlled at-commands through serial ports. modem control software such minicom, can input following sequence of commands:
input: @ output: ok input: at#sgact=1,1 output: ok input: at#sd=1,0,54321,"30.19.24.10",0,0,1 output: connected input: at#ssend=1 > hello world! > output: ok
what connects server have set , sends packet "hello world!". working in minicom. however, trying convert python script. here's have far:
import serial import time # modem config modem_port = serial.serial() modem_port.baudrate = 115200 modem_port.port = "/dev/tty.usbserial-00002114b" modem_port.parity = "n" modem_port.stopbits = 1 modem_port.xonxoff = 0 modem_port.timeout = 3 modem_port.open() def send_at_command(command): modem_port.write(bytes(command+"\r", encoding='ascii')) def read_command_response(): print(modem_port.read(100).decode('ascii').strip()) print("\n") if modem_port.isopen(): # check network status send_at_command("at+creg=1") read_command_response() # configure socket send_at_command("at#scfg=1,1,0,0,1200,0") read_command_response() # obtain ip network send_at_command("at#sgact=1,1") read_command_response() # connect aws server send_at_command("at#sd=1,0,54321,\"30.19.24.10\",0,0,1") read_command_response() # send packet aws server send_at_command("at#ssend=1") read_command_response() send_at_command("this sent python script.") read_command_response() modem_port.close()
however, script fails send packet. i'm thinking reason because in minicom, have press enter after hello world! in order send packet. i'm @ loss @ how simulate in python script. suggestions appreciated.
edit:
so reading module documentation more, , seems need send ctrl-z char (0x1a hex) through serial port. know how in python?
note documentation indicated execute command ctrl-z answer has been edited remove references \n
, \r
edit:
based on comments, try
def send_at_command(command): modem_port.write(bytes(command+"\1a", encoding='ascii'))
Comments
Post a Comment