0

Wanting to send data with different intervals
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Wanting to send data with different intervals

by themusicman on Fri Feb 22, 2019 1:40 pm

So I have the following code in my script, which uploads the data from a BME sensor to my Adafruit feed once a minute, however, for the 'pres' variable, I don't need to send that data up to my feed anywhere near as often.

I'm very new to Python, and am wondering how I would set up code to have the 'pres' feed to be uploaded once every 60 mins, rather than once every minute as is the case of 'temp'.

Any advice greatly appreciated.
Thanks

Code: Select all | TOGGLE FULL SIZE
while True:
    # Setup my MQTT connection to Adafruit
    c = MQTTClient(conf['deviceid'], server="io.adafruit.com", user=conf['user'], password=conf['apikey'], port=1883)
    c.connect()

    # Get the latest values from the BME sensor
    envi = bme.values
    print(envi)

    # Publish the values to Adafruit via MQTT
    c.publish(conf['user']+"/feeds/temp", envi[0])
    c.publish(conf['user']+"/feeds/pres", envi[1])
    #c.publish(conf['user']+"/feeds/humid", envi[2])
    #NOTE: humidity not being returned... maybe faulty sensor, hence commented out

    # Disconnect from MQTT, sleep for a minute
    c.disconnect()
    time.sleep_ms(60000) #60k mili = 60 seconds

themusicman
 
Posts: 7
Joined: Fri Feb 15, 2019 4:27 pm

Re: Wanting to send data with different intervals

by brubell on Fri Feb 22, 2019 5:48 pm

Instead of using time.sleep_ms, try using time.sleep which takes in seconds (instead of milliseconds)

brubell
 
Posts: 282
Joined: Fri Jul 17, 2015 10:33 pm

Please be positive and constructive with your questions and comments.