def runit(): # APN credentials (replace with yours) GSM_APN = 'wholesale' # Your APN GSM_USER = '' # Your User GSM_PASS = '' # Your Pass # Power on the GSM module GSM_PWR = machine.Pin(4, machine.Pin.OUT) GSM_RST = machine.Pin(5, machine.Pin.OUT) GSM_MODEM_PWR = machine.Pin(23, machine.Pin.OUT) GSM_PWR.value(0) GSM_RST.value(1) GSM_MODEM_PWR.value(1) print("Here we go!") # gsm.debug(True) # Uncomment this to see more logs, investigate issues, etc. gsm.start(tx=27, rx=26, apn=GSM_APN, user=GSM_USER, password=GSM_PASS) sys.stdout.write('Waiting for AT command response...') for retry in range(30): if gsm.atcmd('AT'): break else: sys.stdout.write('.') time.sleep_ms(5000) else: raise Exception("Modem not responding!") print() print("Connecting to GSM...") gsm.connect() while gsm.status()[0] != 1: pass print('IP:', gsm.ifconfig()[0]) print("Making get request...") response = urequests.get("https://bot.whatismyipaddress.com") print(response.text) gsm.disconnect() gsm.sendSMS("+1xxxx", "My public ip is: {}".format(response.text))
def getContacts(): """Makes a rest call to wiredzenith.tech that get a list of the users stored in the database Returns: json object -- array of object contaning users names and numbers """ usersList = [] gsm.connect() if gsm.status() == "98, 'Not started'": gsm.connect() r = req.get("http://wiredzenith.tech/contacts/list") usersList = r.json() gsm.disconnect() return usersList
gsm.start(tx=27, rx=26, apn=GSM_APN, user=GSM_USER, password=GSM_PASS) sys.stdout.write('Waiting for AT command response...') for retry in range(20): if gsm.atcmd('AT'): break else: sys.stdout.write('.') time.sleep_ms(5000) else: raise Exception("Modem not responding!") print() print("Connecting to GSM...") gsm.connect() while gsm.status()[0] != 1: pass print('IP:', gsm.ifconfig()[0]) print("Connected !") addr = socket.getaddrinfo('loboris.eu', 80)[0][-1] s = socket.socket() s.connect(addr) s.send(b'GET /ESP32/info.txt HTTP/1.1\r\nHost: loboris.eu\r\n\r\n') data = s.recv(1000) print('data=', end='') print(data) s.close()
def gsm_connect(self): import gsm gsm.connect() while gsm.status()[0] != 1: pass LOG.info('IP: %s' % gsm.ifconfig()[0])