<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Code not moving past py.read_battery_voltage once every few thousand cycles]]></title><description><![CDATA[<p dir="auto">Hey everybody,</p>
<p dir="auto">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 &quot;Line 47.5&quot; and &quot;Line 48&quot;. It will print line 47.5, but never print the line 48.</p>
<p dir="auto">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.</p>
<p dir="auto">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.</p>
<p dir="auto">Has anyone else experienced this or do the battery voltage in a different way?</p>
<p dir="auto">My Code:</p>
<pre><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!=&quot;clearscanconfig&quot;')

print(&quot;Line 15&quot;)
lte.send_at_cmd('AT+CGDCONT=2,&quot;IP&quot;,&quot;telstra.internet&quot;')
print(&quot;Line 19&quot;)
lte.send_at_cmd(&quot;AT!=\&quot;RRC::addscanfreq band=28 dl-earfcn=9410\&quot;&quot;)
lte.send_at_cmd('AT!=&quot;RRC::addScanBand band=28&quot;')
print(&quot;Line 20&quot;)
lte.send_at_cmd('AT+CFUN=1')
print(&quot;Line 21&quot;)


while not lte.isattached():
    print(&quot;Attaching...&quot;)
    time.sleep(0.1)
print(lte.isattached())
print(&quot;Attached&quot;)

lte.connect()

while not lte.isconnected():
    print(&quot;Connecting...&quot;)
    time.sleep(0.1)
print(lte.isconnected())
print(&quot;Connected!&quot;)
time.sleep(2)
def settimeout(duration):
   pass
print(&quot;line41&quot;)
def sub_cb(topic, msg):
   print(msg)
print(&quot;line44&quot;)
while lte.isconnected():
    try:
        client = MQTTClient(&quot;Demo&quot;,&quot;io.adafruit.com&quot;,user=&quot;Dylan&quot;, password=&quot;password&quot;, port=1883)
        print(&quot;Line 38&quot;)
        client.set_callback(sub_cb)
        print(&quot;Line 41&quot;)
        client.connect()
        print(&quot;Line 43&quot;)
        time.sleep(1)
        client.subscribe(topic=&quot;Dylan/feeds/data&quot;)
        print(&quot;Line 46&quot;)

        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=&quot;Dylan/feeds/data&quot;, msg=data)
        print(data)
        # lora.nvram_save()
        time.sleep(3)
        print(&quot;Line 55&quot;)
        #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()
</code></pre>
]]></description><link>https://forum.pycom.io/topic/4035/code-not-moving-past-py-read_battery_voltage-once-every-few-thousand-cycles</link><generator>RSS for Node</generator><lastBuildDate>Thu, 10 Sep 2026 04:42:16 GMT</lastBuildDate><atom:link href="https://forum.pycom.io/topic/4035.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 25 Nov 2018 23:11:21 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Code not moving past py.read_battery_voltage once every few thousand cycles on Sun, 25 Nov 2018 23:11:21 GMT]]></title><description><![CDATA[<p dir="auto">Hey everybody,</p>
<p dir="auto">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 &quot;Line 47.5&quot; and &quot;Line 48&quot;. It will print line 47.5, but never print the line 48.</p>
<p dir="auto">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.</p>
<p dir="auto">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.</p>
<p dir="auto">Has anyone else experienced this or do the battery voltage in a different way?</p>
<p dir="auto">My Code:</p>
<pre><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!=&quot;clearscanconfig&quot;')

print(&quot;Line 15&quot;)
lte.send_at_cmd('AT+CGDCONT=2,&quot;IP&quot;,&quot;telstra.internet&quot;')
print(&quot;Line 19&quot;)
lte.send_at_cmd(&quot;AT!=\&quot;RRC::addscanfreq band=28 dl-earfcn=9410\&quot;&quot;)
lte.send_at_cmd('AT!=&quot;RRC::addScanBand band=28&quot;')
print(&quot;Line 20&quot;)
lte.send_at_cmd('AT+CFUN=1')
print(&quot;Line 21&quot;)


while not lte.isattached():
    print(&quot;Attaching...&quot;)
    time.sleep(0.1)
print(lte.isattached())
print(&quot;Attached&quot;)

lte.connect()

while not lte.isconnected():
    print(&quot;Connecting...&quot;)
    time.sleep(0.1)
print(lte.isconnected())
print(&quot;Connected!&quot;)
time.sleep(2)
def settimeout(duration):
   pass
print(&quot;line41&quot;)
def sub_cb(topic, msg):
   print(msg)
print(&quot;line44&quot;)
while lte.isconnected():
    try:
        client = MQTTClient(&quot;Demo&quot;,&quot;io.adafruit.com&quot;,user=&quot;Dylan&quot;, password=&quot;password&quot;, port=1883)
        print(&quot;Line 38&quot;)
        client.set_callback(sub_cb)
        print(&quot;Line 41&quot;)
        client.connect()
        print(&quot;Line 43&quot;)
        time.sleep(1)
        client.subscribe(topic=&quot;Dylan/feeds/data&quot;)
        print(&quot;Line 46&quot;)

        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=&quot;Dylan/feeds/data&quot;, msg=data)
        print(data)
        # lora.nvram_save()
        time.sleep(3)
        print(&quot;Line 55&quot;)
        #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()
</code></pre>
]]></description><link>https://forum.pycom.io/post/23754</link><guid isPermaLink="true">https://forum.pycom.io/post/23754</guid><dc:creator><![CDATA[Dylan]]></dc:creator><pubDate>Sun, 25 Nov 2018 23:11:21 GMT</pubDate></item></channel></rss>