def gsm_start(self, apn_settings): import gsm gsm.debug(True) # see more logs, investigate issues, etc. gsm.start(tx=self._conf['gsm_modem']['tx'], rx=self._conf['gsm_modem']['rx'], **apn_settings) sys.stdout.write('Waiting for AT command response...') for retry in range(20): machine.resetWDT() if gsm.atcmd('AT'): return True else: sys.stdout.write('.') utime.sleep(5) else: sys.stdout.write("Modem not responding!") machine.reset()
import gsm, json from network import mqtt gsm.debug(True) gsm.start(tx=17, rx=16, apn="TM", roaming=True, wait=True) gsm.connect() gsm.status() gsm.ifconfig() client = mqtt("test1", "calupietru.duckdns.org", port=1883, user="******", password="******") client.start() message = { "espid": "Prato", "timestamp": None, "temperatura": 23, "peso": 70.1 } client.publish("/maia/4", json.dumps(message)) client.publish("/maia/4", json.dumps(message)) client.stop() gsm.disconnect()
# 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) # create output GRN_LED = machine.Pin(12, machine.Pin.INOUT) #* Init PPPoS gsm.debug(True) # 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(20): if gsm.atcmd('AT'): break else: sys.stdout.write('.') time.sleep_ms(5000) else: raise Exception("Modem not responding!") print() #* end of Init PPPoS