Demo entry 6781270

python

   

Submitted by anonymous on Jan 02, 2019 at 14:58
Language: Python 3. Code size: 954 Bytes.

import json
import time

def currentTEMP( temp ):
    tmp = float( temp )
    if tmp != 0:
        tmp = tmp / 1000
    return tmp

def currentHumidity( humidity ):
    tmp = float( humidity )
    if tmp != 0:
        tmp = tmp / 1000
    return tmp
        
def main():
    info = {}
    TEMP = 0
    HUMIDITY = 0
    while True:
        try:
            TEMP = open('/sys/bus/iio/devices/iio:device0/in_temp_input').read( )
            HUMIDITY = open('/sys/bus/iio/devices/iio:device0/in_humidityrelative_input').read( )
            TEMP = currentTEMP( TEMP )
            HUMIDITY = currentHumidity( HUMIDITY )
        except:
            TEMP = TEMP + 0.01
            HUMIDITY = HUMIDITY + 0.01
            
        info["TEMP"] = "%.2f" % TEMP
        info["HUMIDITY"] = "%.2f" % HUMIDITY

        jsonstr = json.dumps(info)
        print jsonstr
        time.sleep(1)
    
if __name__=='__main__':

    main()

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).