Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    Lopy v1.0r and DeepSleep shield/library

    Scheduled Pinned Locked Moved LoPy
    3 Posts 2 Posters 270 Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H Offline
      hayesey
      last edited by

      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():
          time.sleep(2.5)
          print('Not yet joined...')
      #pycom.heartbeat(False)
      # 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)
      
      s.setblocking(True)
      s.bind(1)
      print(bytes(struct.pack('>4s', "ping")))
      s.send(bytes(struct.pack('>4s', "ping")))
      s.setblocking(False)
      data = s.recv(64)
      if data:
          print("recvd data: {}".format(data))
          if data == b'\x01':
              pycom.rgbled(0x007f00)
          elif data == b'\x00':
              pycom.rgbled(0x000000)
      
      print("going to sleep")
      ds.enable_pullups('G30')
      ds.enable_wake_on_fall('G30')
      ds.go_to_sleep(60)
      print("this should never happen")
      

      What I see in the REPL is:

      entry 0x400a059c
      Not yet joined...
      Not yet joined...
      Not yet joined...
      b'ping'
      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?

      1 Reply Last reply Reply Quote 0
      • H Offline
        hayesey
        last edited by

        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.

        R 1 Reply Last reply Reply Quote 0
        • R Offline
          rskoniec @hayesey
          last edited by rskoniec

          @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?

          os.uname()
          

          The machine is working as good as it's code.

          1 Reply Last reply Reply Quote 0

          Hello! It looks like you're interested in this conversation, but you don't have an account yet.

          Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

          With your input, this post could be even better 💗

          Register Login
          • 1 / 1
          • First post
            Last post

          Pycom on Twitter

          Pycom