Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import machine
- import utime
- sim800l = machine.UART(1, baudrate=115200, tx=8, rx=9, timeout=10000)
- import re
- resCodes = ['OK', 'ERROR']
- def resComplete(line):
- if any(element in line for element in resCodes):
- return True
- return False
- def getCommand(string):
- resPattern = re.compile(r'+(\w+)')
- cmd = resPattern.search(line).match
- return cmd
- def awaitResF(line, cmd):
- if cmd in line:
- return True
- return False
- def send_at_command(command, awaitRes=False):
- sim800l.write(command + b'\r\n')
- sim800l.flush() #wait until command is sent
- cmd = getCommand(command)
- response = b''
- newLine = ''
- while not resComplete(newLine) and (not awaitRes or awaitResF(newLine, cmd)):
- newLine = sim800l.readline()
- if newLine == None:
- #The machine took too long to respond
- #You can set the timeout time in the sim800 constructor - machine.uart(1, baudrate=..., tx=..., rx=..., timeout=...) in ms
- print("RESPONSE TIMED OUT")
- return
- response += newLine
- print('cmd :', command, 'res :', response.decode( 'utf-8').strip(), '\n----')
- send_at_command(b'AT+CMEE=2')
- send_at_command(b'AT+CFUN=1')
- send_at_command(b'AT+CPIN=7575', True)
- send_at_command(b'AT+CREG?')
- send_at_command(b'AT+CGATT?')
- send_at_command(b'AT+CGATT=1')
- send_at_command(b'AT+CSTT=?')
- send_at_command(b'AT+CSTT=internet.tele2.lv')
- send_at_command(b'AT+CIICR')
- send_at_command(b'AT+CSQ')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement