def get_device_id(self): #TODO For Wifi, change this to something like the mac address instead of SIM ICCID """Get an identifier for the device used in server requests In this case, we return the SHA256 hash of the SIM ICCID prefixed with 'ID:' and then prepend an 'IC' (for ICCID) so the result is e.g. devid = 'IC' + SHA256("ID:12345678901234567890") = IC27c6bb74efe9633181ae95bade7740969df13ef15bca1d72a92aa19fb66d24c9""" try: lte = LTE() iccid = lte.iccid() except Exception as e: print("Getting device ID failed:") print(e) return "ICERROR" hasher = None try: hasher = uhashlib.sha256("ID:" + iccid) hashvalue = hasher.digest() except Exception as e: if hasher is not None: hasher.digest( ) #make sure hasher is closed, as only one is allowed at a time by the hardware raise e devid = "IC" + ubinascii.hexlify(hashvalue).decode('utf-8') return devid
from network import LTE def send_at_cmd_pretty(cmd): response = lte.send_at_cmd(cmd).split('\r\n') for line in response: if (len(line) > 0): print(line) lte = LTE() print("imei", lte.imei()) print("is_connected", lte.isconnected()) print("ue_coverage", lte.ue_coverage()) print("iccid", lte.iccid()) print("time", lte.time()) send_at_cmd_pretty('AT+CGMI') # PYCOM send_at_cmd_pretty('AT+CGMM') # FiPy send_at_cmd_pretty('AT+CGMR') # UE5.0.0.0d send_at_cmd_pretty('AT+CGSN=0') send_at_cmd_pretty('AT+CGSN=1') send_at_cmd_pretty('AT+CGSN=2') send_at_cmd_pretty('AT+CGSN=3') # +CGSN: "00"
import time import socket # NOTE: test the code. Changed prints during loops #sqnsupgrade.info(verbose=False, debug=False) print("#####################") print("#####################") print("NB-IoT Test v0.2") wdt=WDT(timeout=20000000) lte = LTE() #lte.init() for i in range(4): ccid=lte.iccid() print (" ccid = " + str(ccid)) if ccid: break time.sleep(1) #Vodafone UK apn=nb.inetd.gdsp print("Attempting to attach...", end="") lte.attach(band=20,apn="ep.inetd.gdsp") for j in range(10): print(".", end ="") time.sleep(1) if lte.isattached(): print("\nAttached in attempt #"+str(j+1)) break lte.send_at_cmd('AT+CEREG?').replace('\r\n','') #NOTE: for Vodafone UK: AT+COPS=1,2,"23415"