Lopy v1.0r and DeepSleep shield/library

  • I have an old Lopy v1.0r along with the Deepsleep shield, I can't seem to get the Deepsleep library working as I think it should. It is possible I've misunderstood how it's meant to work!

    My code is this:

    from network import LoRa
    import socket
    import time
    import binascii
    import struct
    import pycom
    from deepsleep import DeepSleep
    import deepsleep
    # Initialize LoRa in LORAWAN mode.
    lora = LoRa(mode=LoRa.LORAWAN)
    # create an OTAA authentication parameters
    app_eui = binascii.unhexlify('xxxx')
    app_key = binascii.unhexlify('xxxx')
    ds = DeepSleep()
    # join a network using OTAA (Over the Air Activation)
    lora.join(activation=LoRa.OTAA, auth=(app_eui, app_key), timeout=0)
    # wait until the module has joined the network
    while not lora.has_joined():
        print('Not yet joined...')
    # 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)
    print(bytes(struct.pack('>4s', "ping")))
    s.send(bytes(struct.pack('>4s', "ping")))
    data = s.recv(64)
    if data:
        print("recvd data: {}".format(data))
        if data == b'\x01':
        elif data == b'\x00':
    print("going to sleep")
    print("this should never happen")

    What I see in the REPL is:

    entry 0x400a059c
    Not yet joined...
    Not yet joined...
    Not yet joined...
    going to sleep

    And nothing else, I don't think it actually goes to sleep as the heartbeat LED still flashes.

    I have the board powered by USB, I've tried powering it just with a battery and it appears to do the same, it only ever sends a single LoraWAN message.

    Bridging pin G30 to ground doesn't do anything either.

    Is there something I've missed or misunderstood about how this should work?

  • @hayesey Deepsleep library at Pycom GitHub Repo is v.1.0.5, so it seems you've got the most recent version. What is the f/w version on your LoPy?


  • So I've just changed my code to use the built-in machine.deepsleep function instead of the DeepSleep library for the DeepSleep shield and it works. The Lopy does go to sleep and does wake up as expected.

    So it appears to be the DeepSleep library that's not working for me. I wonder if I've got an out of date version of it? It says version 1.0.5 in the code.

Log in to reply

Pycom on Twitter