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

    Code not moving past py.read_battery_voltage once every few thousand cycles

    Scheduled Pinned Locked Moved FiPy
    batterylte
    1 Posts 1 Posters 310 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.
    • D Offline
      Dylan
      last edited by

      Hey everybody,

      I managed to catch this after a long time of searching, but for some reason on the rare occasion my nodes just stopped responding, I caught it after leaving my code run on a 20 second cycle (without deepsleep). There is no error, it just occurs between my code with "Line 47.5" and "Line 48". It will print line 47.5, but never print the line 48.

      My code ran for about 16 hours before it stopped, but has done longer and shorter intervals, at 16 hours its about 2500 cycles. I usually do 15minutes between cycles so during those tests sometimes the node will run for it's entire battery life but maybe one unit will fail, I've never been sure why this has been happening, hopefully this is the reason.

      I am making the assumption that this is happening while using deepsleep since as you can imagine it would be very difficult to refresh the REPL every time for a few thousand goes before it just stopped responding.

      Has anyone else experienced this or do the battery voltage in a different way?

      My Code:

      import machine
      from network import LTE
      from pytrack import Pytrack
      import os
      import time
      import socket
      import pycom
      from MQTT import MQTTClient
      from L76GNSS import L76GNSS
      
      
      def sub_cb(topic, msg):
          print(msg)
      
      lte = LTE()
      # lte.reset()
      lte.send_at_cmd('AT^RESET')
      lte.send_at_cmd('AT!="clearscanconfig"')
      
      print("Line 15")
      lte.send_at_cmd('AT+CGDCONT=2,"IP","telstra.internet"')
      print("Line 19")
      lte.send_at_cmd("AT!=\"RRC::addscanfreq band=28 dl-earfcn=9410\"")
      lte.send_at_cmd('AT!="RRC::addScanBand band=28"')
      print("Line 20")
      lte.send_at_cmd('AT+CFUN=1')
      print("Line 21")
      
      
      while not lte.isattached():
          print("Attaching...")
          time.sleep(0.1)
      print(lte.isattached())
      print("Attached")
      
      lte.connect()
      
      while not lte.isconnected():
          print("Connecting...")
          time.sleep(0.1)
      print(lte.isconnected())
      print("Connected!")
      time.sleep(2)
      def settimeout(duration):
         pass
      print("line41")
      def sub_cb(topic, msg):
         print(msg)
      print("line44")
      while lte.isconnected():
          try:
              client = MQTTClient("Demo","io.adafruit.com",user="Dylan", password="password", port=1883)
              print("Line 38")
              client.set_callback(sub_cb)
              print("Line 41")
              client.connect()
              print("Line 43")
              time.sleep(1)
              client.subscribe(topic="Dylan/feeds/data")
              print("Line 46")
      
              print(lte.isconnected())
              print('Line 47')
              py = Pytrack()
              print('47.5')
              battery = str(py.read_battery_voltage())
              print('Line 48')
              time.sleep(0.1)
              l76 = L76GNSS(py, timeout=90)
              coord = l76.coordinates()
              print('Line 49')
              lat = coord[0]
              lon = coord[1]
              utctime = coord[2]
              data = battery + ',' + str(utctime) + ',' +  str(lat) + ',' + str(lon) + '\n'
              client.publish(topic="Dylan/feeds/data", msg=data)
              print(data)
              # lora.nvram_save()
              time.sleep(3)
              print("Line 55")
              #client.check_msg()
              time.sleep(5)
              # py.setup_sleep(20)
              # py.go_to_sleep()
          except OSError:
              print('  OSERROR occured, retrying...')
              time.sleep(0.5)
              machine.reset()
      
      if not lte.isconnected():
          machine.reset()
      
      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