lora.nvram example needed

  • Hi,
    I've searched for some functioning example of lora.nvram and found none. Can someone send one ?
    It's absolutely needed for deepsleep function.

  • I know this is an old post but for me this is still an issue.
    Any may of learning more about the specifics would be very much appreciated e.g what does


    Should I see somthing in the REPL?

    >>> lora.nvram_save()
    >>> l= pycom.nvs_get('lora')
    >>> print(l)

    Am I going about this in completely the wrong way?

  • @luc-hanneuse did you manage to solve this issue.
    I have a similar problem.
    I have place the lora.nvram_restore() after my lora = LoRa(mode=LoRa.LORAWAN, region=LoRa.AU915) command. This seems like the logical place to put it.
    However after waking from sleep a few times, it appears that restore does not work correctly.

    I am also having problems making the app_eui and app_key available for use between different functions (def) within the same file/module. I am using global app_eui, app_key in both functions but I get an error after waking with app_eui undefined!!!! Any ideas??


  • @livius I also appreciate it when there comes a working example for the using of the nvram and restore function.
    Everybody at the forum is from do this but by the most of us it isn`t working either.

  • @jcaron
    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(' ','')))[0]
    nwk_swkey = binascii.unhexlify('000000000000000000000000000000000')
    app_swkey = binascii.unhexlify('000000000000000000000000000000000')
    print("start join LoRa")
    # 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)
        # 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
        # send the Coordinates to LoRA
        pycom.rgbled(0x0000ff) #bleu
        s.send(struct.pack("<i",  int(coord[0]*100000))+struct.pack("<i",  int(coord[1]*100000))+struct.pack("<H",  int(utime.time())))
        lora.nvram_save() #nvram
        py.setup_sleep(600 - time.time())

    If someone has something smarter with an ABP connection, help me.

  • @luc-hanneuse

    It's quite simple... When you boot, lora.nvram_restore(). Before you go to sleep, lora.nvram_save().

  • @livius
    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.

Pycom on Twitter