def smscb(self, indexes): print("indexes = ", indexes) if (indexes): msg = gsm.readSMS(int(indexes[0]), True) if (self._is_register_phone_(msg[2])): #if(msg[2].find(self.registrPhoneNumbers)>=0): print("Phone Ok") ret = self._sms_cmd_exec_(msg[6]) gsm.sendSMS(msg[2], ret) else: print("Not register phone number - ", msg[2]) #На всякий случай удаляем все смс gsm.atcmd('AT+CMGDA="DEL ALL"', printable=True) return print("Errore indexes in smscb") pass
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 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()
GSM_PWR.value(1) time.sleep_ms(300) GSM_PWR.value(0) LED = machine.Pin(12, machine.Pin.OUT) LED.value(1) # Init PPPoS # 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(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])
def __init__(self): self._conf = {} conf = load_json('conf.json') if conf: for conf_item in ('wlan_enabled_switch', 'gsm_modem'): if conf_item in conf: self._conf[conf_item] = conf[conf_item] self._wlan = None self._wlan_enabled_switch = None self.gsm = False self._gsm_settings = {} enable_wlan = False if self._conf.get('wlan_enabled_switch'): self._wlan_enabled_switch = machine.Pin( self._conf['wlan_enabled_switch'], handler=wlan_enabled_switch_handler, trigger=machine.Pin.IRQ_FALLING) enable_wlan = self._wlan_enabled_switch.value() machine.RTC().wake_on_ext0(self._wlan_enabled_switch, 1) if not enable_wlan and self._conf.get('gsm_modem'): import gsm self._gsm_modem_on = None if self._conf['gsm_modem'].get('on'): self._gsm_modem_on = machine.Pin(self._conf['gsm_modem']['on'], machine.Pin.OUT, value=1) if self._conf['gsm_modem'].get('on_rev'): self._gsm_modem_on = machine.Pin( self._conf['gsm_modem']['on_rev'], machine.Pin.OUT, value=0) self.gsm = True self._gsm_settings = load_json('gsm_settings.json') or {} gsm_apns = load_json('gsm_apns.json') apn_settings = {} self._gsm_pwr = machine.Pin(self._conf['gsm_modem']['pwr'], machine.Pin.INOUT, value=0)\ if self._conf['gsm_modem'].get('pwr') else None if self._gsm_pwr: utime.sleep(2) self._gsm_rst = machine.Pin(self._conf['gsm_modem']['rst'], machine.Pin.OUT, value=1)\ if self._conf['gsm_modem'].get('rst') else None self._gsm_pwr_key = machine.Pin(self._conf['gsm_modem']['pwr_key'], machine.Pin.OUT)\ if self._conf['gsm_modem'].get('pwr_key') else None self.gsm_pwr_key_cycle() if not self._gsm_settings.get('network'): self.gsm_start({'apn': ''}) machine.resetWDT() network_cmd = gsm.atcmd('AT+COPS?', timeout=1000, response='OK') network_name = [ key for key in gsm_apns.keys() if key in network_cmd ] if network_name: self._gsm_settings['network'] = network_name[0] save_json(self._gsm_settings, 'gsm_settings.json') gsm.stop() else: LOG.info('Network apn data not found. Trying empty apn.') if self._gsm_settings.get('network'): apn_settings = gsm_apns[self._gsm_settings['network']] if apn_settings: self.gsm_start(apn_settings) machine.resetWDT() self.gsm_connect() machine.resetWDT() else: self._wlan = WlanController()
GSM_PWR = machine.Pin(4, machine.Pin.OUT) LED = machine.Pin(12, machine.Pin.INOUT) GSM_PWR.value(1) time.sleep_ms(300) GSM_PWR.value(0) LED.value(1) # Init PPPoS # 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(20): if gsm.atcmd('AT'): break else: sys.stdout.write('.') time.sleep_ms(5000) else: raise Exception("Modem not responding!") print() # Turn on GPS positioning gsm.atcmd('AT+CGNSPWR=1', printable=True) # Turn on GPS power control, it is controlled by module GPIO4 gsm.atcmd('AT+SGPIO=0,4,1,1', printable=True) while True: # Get positioning data