lora.nvram example needed
I've searched for some functioning example of lora.nvram and found none. Can someone send one ?
It's absolutely needed for deepsleep function.
That's what I'm doing.
It's just a bit illogical for me, I've to try 5 or 6 different codes to find a working one. The place of the
lora.nvram_restore()isn't obvious ... If I place it just after the
lora = LoRa(mode=LoRa.LORAWAN, region=LoRa.EU868)then it's not working !
My working example :
print("deepsleep prog") from network import LoRa import socket import binascii import struct import time import utime #utime init_timer = time.time() # Initialize LoRa in LORAWAN mode. lora = LoRa(mode=LoRa.LORAWAN, region=LoRa.EU868) # create an ABP authentication params dev_addr = struct.unpack(">l", binascii.unhexlify('00 00 00 00'.replace(' ',''))) nwk_swkey = binascii.unhexlify('000000000000000000000000000000000') app_swkey = binascii.unhexlify('000000000000000000000000000000000') print("start join LoRa") print(utime.localtime())#utime print(utime.time())#utime # join a network using ABP (Activation By Personalization) lora.join(activation=LoRa.ABP, auth=(dev_addr, nwk_swkey, app_swkey)) # create a LoRa socket s = socket.socket(socket.AF_LORA, socket.SOCK_RAW) # set the LoRaWAN data rate s.setsockopt(socket.SOL_LORA, socket.SO_DR, 5) lora.nvram_restore() #strange place for the restore but working. # make the socket blocking # (waits for the data to be sent and for the 2 receive windows to expire) s.setblocking(True) while(True): print(".") # save the coordinates in a new variable coord = l76.coordinates() # verify the coordinates received if coord == (None, None) and time.time() < 200: print("Getting Location...") pycom.rgbled(0x7f7f00) #jaune print(utime.time())#utime continue # send the Coordinates to LoRA print("sending") pycom.rgbled(0x0000ff) #bleu s.send(struct.pack("<i", int(coord*100000))+struct.pack("<i", int(coord*100000))+struct.pack("<H", int(utime.time()))) time.sleep(1) lora.nvram_save() #nvram print("sent") print(time.time()) print(utime.localtime())#utime print(utime.time())#utime pycom.rgbled(0x000000) #sleep print("sleep") py.setup_sleep(600 - time.time()) py.go_to_sleep()
If someone has something smarter with an ABP connection, help me.
It's quite simple... When you boot,
lora.nvram_restore(). Before you go to sleep,
I read the documentation.
I need a full example.
I've a written a code and I tried to use those functions lora.nvram_save() and lora.nvram_restore() . But it doesn't seem to work. The "counter" of LoRaWan message reset.
@luc-hanneuse said in lora.nvram example needed:
alway look into official documentation. There is
if you need save some custom information use