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

    Wipy transmits data for 4 hours then stops

    Scheduled Pinned Locked Moved Comments & Feedback
    wipy
    12 Posts 3 Posters 2.9k Views 3 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.
    • B Offline
      bucknall
      last edited by

      Hi @robmarkcole,

      You could check for the memory usage by transmitting the gc.mem_free() value over MQTT along with your other messages.

      From your code, I would imagine the device memory is likely the problem! You can free this up by manually using the garbage collector or eliminating the point in your code that's forcing the memory issues.

      Thanks,

      Alex

      Developer Evangelist - Pycom

      R 2 Replies Last reply Reply Quote 0
      • R Offline
        robmarkcole @bucknall
        last edited by

        This post is deleted!
        1 Reply Last reply Reply Quote 0
        • R Offline
          robmarkcole @bucknall
          last edited by robmarkcole

          Thanks @bucknall have edited the code and after an initial reduction in memoryt the available memory plateaus with slight variations depending on the value of variables. cheers for the advice

          import pycom
          import time
          from machine import Pin
          import gc
          from dth import DTH
          from simple import MQTTClient
          
          gc.enable()  # enable auto garbage collection
          
          def settimeout(duration):
             pass
          
          client = MQTTClient(client_id="wipy_client", server='192.168.0.XX', port=1883)  #
          
          client.settimeout = settimeout
          client.connect()
          
          pycom.heartbeat(False)
          pycom.rgbled(0x000008) # blue
          th = DTH(Pin('P3', mode=Pin.OPEN_DRAIN),0)
          time.sleep(2)
          
          while True:
              result = th.read()
              if result.is_valid():
                  pycom.rgbled(0x001000) # green
                  gc.collect()   # perform garbage collection
                  print(gc.mem_free())
                  client.publish("wipy/Memory", str(gc.mem_free()))
                  print("Temperature: %d C" % result.temperature)
                  client.publish("wipy/Temperature", str(result.temperature))
                  print("Humidity: %d %%" % result.humidity)
                  client.publish("wipy/Humidity", str(result.humidity))
              time.sleep(5)
          P 1 Reply Last reply Reply Quote 0
          • P Offline
            pwest @robmarkcole
            last edited by

            @robmarkcole :
            Are you still experiencing your original problem? With a similar program, I generally get well over 4 hours, but rarely over 20 hours before my program fails. I'm pretty sure it's related to socket timeout problems that are not handled by the simple umqtt library.

            -Phil

            R 1 Reply Last reply Reply Quote 0
            • R Offline
              robmarkcole @pwest
              last edited by

              Hi Phil
              my script will run without any interruption indefinitely now. The wipy isn't connected to my computer but running off the mains.
              Hope that helps.
              Cheers

              P 1 Reply Last reply Reply Quote 0
              • P Offline
                pwest @robmarkcole
                last edited by

                @robmarkcole It looks like you are posting to a local broker. I've been publishing to either broker.hivemq.com or test.mosquitto.org and my sessions always terminate with some kind of a network error, usually after a few hours. I think I need to look into the robust mqtt library, but I'm having trouble getting started...

                R 1 Reply Last reply Reply Quote 0
                • R Offline
                  robmarkcole @pwest
                  last edited by

                  @pwest There are usually limitaitons with the free brokers, wrote a bit more about my experience on https://www.hackster.io/robin-cole/micropython-leak-detector-with-adafruit-and-home-assistant-a2fa9e

                  I am running a broker in Docker on my NAS, very easy to setup https://hub.docker.com/_/eclipse-mosquitto/

                  If you have a pi to dedicate you could install Hassio and run the MQTT broker
                  https://home-assistant.io/addons/

                  P 1 Reply Last reply Reply Quote 0
                  • P Offline
                    pwest @robmarkcole
                    last edited by

                    @robmarkcole Running a local broker would be easy for me, but my ultimate architecture requires that I publish from multiple locations to a remote commercial system (I had been planning to use AWS services). A reliable broker might largely solve my problem, but I'm thinking that I'd like my application to gracefully deal with lost connections, timeouts, etc.: hive and mosquitto seem to provide these issues for free!
                    The first error message associated with my current problem seems to be:

                    Traceback (most recent call last):
                    File "main.py", line 108, in new_adv_event
                    File "/flash/lib/umqtt.py", line 110, in publish
                    OSError: [Errno 104] ECONNRESET

                    So, it looks like the connection is getting reset, and I'm not handling that. Hopefully, this is one of the things that the robust mqtt code will help with.

                    P R 2 Replies Last reply Reply Quote 0
                    • P Offline
                      pwest @pwest
                      last edited by

                      @pwest I now have it running w/robust.py 79 mins so far.

                      1 Reply Last reply Reply Quote 0
                      • R Offline
                        robmarkcole @pwest
                        last edited by

                        @pwest I'm no expert on MQTT, but believe it an be configured to deal with lost connections etc.
                        The upcoming pybytes platform may also be of interested.
                        Keep us posted with your progress :)

                        P 1 Reply Last reply Reply Quote 0
                        • P Offline
                          pwest @robmarkcole
                          last edited by

                          @robmarkcole Using robust.py, I'm seeing the same problems, but now I'm getting a good error message back. Typically after a few hours I get (continuously repeated):
                          mqtt reconnect: OSError(105,)
                          So, I should be able to catch that and then kill and then restart the session.

                          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