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

    Pytrack and Gpy in deepsleep waking on gpio

    Scheduled Pinned Locked Moved Projects
    2 Posts 2 Posters 164 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.
    • J Offline
      jupiter8
      last edited by

      Hi,

      Can anyone can give me a good start on putting the Pytrack/Gpy combo in deepsleep and waking up from a gpio and returning to sleep?

      I want to use it as a flow detector where a simple float (switch) can be use as waking the module up and sending some ON/OFF status and return to sleep. I already have code to send messages on gpio triggering:

      Thanks.

      from network import LTE
      from machine import Pin
      from umqtt import MQTTClient
      import machine
      import time
      
      
      is_pressed = False
      button = Pin("P10", mode=Pin.IN, pull=Pin.PULL_UP)
      
      
      
      
      def settimeout(duration):
           pass
      lte = LTE()
      
       # Modem does not connect successfully without first being reset.
      print("Resetting LTE modem ... ", end='')
      lte.send_at_cmd('AT^RESET')
      print("OK")
      time.sleep(1)
      
      print("Configuring LTE ", end='')
      lte.send_at_cmd('AT+CGDCONT=1,"IP","yourAPN"')
      print(".", end='')
      lte.send_at_cmd('AT!="RRC::addscanfreq band=2, 4, 5 dl-earfcn=9410"')
      print(".", end='')
      lte.send_at_cmd('AT+CFUN=1')
      print(" OK")
      
      if not lte.isattached():
          print("Attaching to LTE network ", end='')
          lte.attach()
          while(True):
              if lte.isattached():
                  print(" OK")
                  break
              print('.', end='')
              time.sleep(1)
      
          # Once attached, connect() should succeed.
          if not lte.isconnected():
              print("Connecting on LTE network ", end='')
              lte.connect()
              while(True):
                  if lte.isconnected():
                      print(" OK")
                      break
                  print('.', end='')
                  time.sleep(1)
      lte.connect()
      while not lte.isconnected():
          machine.idle()
      
      print("Connected to LTE\n")
      #wlan = WLAN(mode=WLAN.STA)
      #wlan.antenna(WLAN.EXT_ANT)
      #wlan.connect("yourwifi", auth=(WLAN.WPA2, "yourpass"), timeout=5000)
      
      #while not wlan.isconnected():
      
      
      #print("Connected to Wifi\n")
      client = MQTTClient("joe", "yourMQTTbroker", port=1883)
      client.settimeout = settimeout
      client.connect()
      
      while True:
          if button() == 1 and not is_pressed:
              time.sleep(1)
          elif button() == 0 and not is_pressed:
              print("Button pressed")
              print("Sending ON")
              client.publish("/gpy", "ON")
              is_pressed = True
              time.sleep(1)
          elif button() == 1 and is_pressed:
              print("Button released")
              print("Sending OFF")
              client.publish("/gpy", "OFF")
              is_pressed = False
              time.sleep(1)
          else:
              pass
      
      1 Reply Last reply Reply Quote 0
      • P Offline
        Peter Ehses
        last edited by Peter Ehses

        Hi,
        I'm having the same problem right now. From what I've figured out so far, there's an interrupt on P#9 which can be configured through the py.setup_int_pin_wake_up(False) method. I haven't gotten it working so far, though. I have also created another topic asking a similar thing.

        Alternatively, you can sleep through the machine.deepsleep method and configure any GPIO as wakeup pin for that. YMMV though, as I am experiencing extremely high sleep current with the machine deepsleep.

        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