Wipy transmits data for 4 hours then stops



  • My code below appears to work for only 4 hours, then the Wipy stops sending data over MQTT. Any ideas why it stops - runs out of memory?

    import pycom
    import time
    from machine import Pin
    from dth import DTH
    from simple import MQTTClient
    
    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
            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(1)
    


  • 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)


  • This post is deleted!

  • administrators

    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


Log in to reply
 

Looks like your connection to Pycom Forum was lost, please wait while we try to reconnect.