Code: Select all
#!/usr/bin/env python
import time
import serial
import sys
import urllib2
ser = serial.Serial(
port='/dev/ttyUSB0',
baudrate = 9600,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
timeout=1
)
counter=0
humavg=0
tem1avg=0
tem2avg=0
tem3avg=0
lightavg=0
while 1:
x=ser.readline()
values = x.split(" ")
if len(values) == 14:
counter=counter+1
humavg = float(values[1])/3 + humavg
tem1avg = float(values[3])/3 + tem1avg
tem2avg = float(values[6])/3 + tem2avg
tem3avg = float(values[9])/3 + tem3avg
lightavg = float(values[12])/3 + lightavg
if counter ==3:
f=urllib2.urlopen('http://192.168.1.132:8080/json.htm?type=command¶m=udevice&idx=27&nvalue=0&svalue='+str(lightavg))
f=urllib2.urlopen('http://192.168.1.132:8080/json.htm?type=command¶m=udevice&idx=25&nvalue=0&svalue='+str(tem2avg))
f=urllib2.urlopen('http://192.168.1.132:8080/json.htm?type=command¶m=udevice&idx=26&nvalue=0&svalue='+str(tem3avg))
f=urllib2.urlopen('http://192.168.1.132:8080/json.htm?type=command¶m=udevice&idx=24&nvalue=0&svalue='+str(tem1avg)+';'+str(humavg)+';1')
sys.exit()
Code: Select all
Sensors at nano
Humidity: 35.70 % Temperature: 20.10 *C T1: 33.56 *C T2: 18.06 *C Light: 87.30 %
Humidity: 35.60 % Temperature: 20.20 *C T1: 33.63 *C T2: 18.06 *C Light: 85.16 %