def online(self): if self.gsm: import gsm return gsm.status()[0] == 1 if self._wlan: return self._wlan.online() return False
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
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() # GSM connection is complete.
import t import gsm import machine t.modemOnOffNew() #gsm.start(tx=5, rx=35, apn='internet', connect=False) gsm.start(tx=5, rx=35, apn='internet', connect=False, user='******', password='******') gsm.connect() gsm.status() gsm.stop() uart = machine.UART(1, tx=5, rx=35) #uart.write('AT\r\n') recipient = "+393406440781" message = "Hello, F1neye!" try: time.sleep(0.5) #uart.write(b'ATZ\r\n') uart.write('ATZ\r\n') time.sleep(0.5) uart.write('AT+CMGF=1\r\n') time.sleep(0.5) uart.write('AT+CMGS="' + recipient + '"\r\n') time.sleep(0.5) uart.write(message + "\r\n") time.sleep(0.5) uart.write(bytes([26])) time.sleep(0.5) finally: uart.close()
def gsm_connect(self): import gsm gsm.connect() while gsm.status()[0] != 1: pass LOG.info('IP: %s' % gsm.ifconfig()[0])
def isConnect(self): state_int, state_str = gsm.status() if (state_int == 1): return True else: return False