Has anyone successfully used lora.nvram_save() and restore?



  • Re: How to accomplish lora.nvram_restore() ?

    I have tried many variations, but no luck for me. If anyone has been successful, would you please post your code?



  • @jmarcelino

    Restoring the channel configuration did the trick. Setblocking(True) was not needed here.

    An anomaly that I have seen before showed up. The packets sent after nvram_restore all arrived with "payload not provided". But, if I first send a packet with a payload of a single character, it and all subsequent packets arrive successfully.

    May I suggest that the documentation be amended to detail what is and is not saved by lora.nvram_save().

    Thank you very much for your help.



  • @jalperin

    Try to restore your channel frequency configuration manually again after the nvram_restore, just use your existing code:

    for channel in range(0, 72):
        lora.remove_channel(channel)
    for chan in range(0, 8):
        lora.add_channel(chan, frequency=freq, dr_min=0, dr_max=3)
    

    The current nvram_save() may not save this...



  • @jalperin

    Umm so differences I see is I'm using OTAA and on EU868 region while you use ABP in the US915 region... also I do a few app related things before sending data and send several packets.

    Try s.setblocking(True) for your sends and also try more than one send, maybe a loop sending 10.



  • Thank you, jmarcellino. That is, I think, what I am doing, but without success. Below is my code. I get the first message, but not the second. I have check my gateway. It only sees the first message.

    from network import LoRa
    import struct
    import binascii
    import time
    import math
    import pycom
    import socket
    from pysense import Pysense

    py = Pysense()
    loraSaved = pycom.nvs_get('loraSaved')
    if not loraSaved:
    lora = LoRa(mode=LoRa.LORAWAN)
    freq = 902300000
    for channel in range(0, 72):
    lora.remove_channel(channel)
    for chan in range(0, 8):
    lora.add_channel(chan, frequency=freq, dr_min=0, dr_max=3)
    dev_addr = struct.unpack(">l", binascii.unhexlify('*****21E27'))[0]
    nwk_swkey = binascii.unhexlify('************4BD956A16FF3DADEB05608C1')
    app_swkey = binascii.unhexlify('*************738855C61661D0FF27')
    lora.join(activation=LoRa.ABP, auth=(dev_addr, nwk_swkey, app_swkey))
    while not lora.has_joined():
    machine.idle()
    s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
    s.setsockopt(socket.SOL_LORA, socket.SO_DR, 3)
    s.setblocking(False)
    s.send('LoRa Up')
    time.sleep(2)
    lora.nvram_save()
    pycom.nvs_set('loraSaved', 1)
    py.setup_sleep(60)
    py.go_to_sleep()
    else:
    lora = LoRa(mode=LoRa.LORAWAN)
    lora.nvram_restore()
    s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
    s.setsockopt(socket.SOL_LORA, socket.SO_DR, 3)
    s.setblocking(False)
    s.send('LoRa Restored')
    time.sleep(2)
    pycom.nvs_set('loraSaved', 0) # reset for next test



  • Yes it's working and really simple.

    First time you do your normal join (you do need to wait until it has actually joined!) then

    lora.nvram_save()
    

    Afterwards do

    lora = LoRa(mode=LoRa.LORAWAN)
    lora.nvram_restore()
    
    
    s.send(bytes([0x01, 0x02, 0x03]))
    

Log in to reply
 

Looks like your connection to Pycom Forum was lost, please wait while we try to reconnect.