Ejemplo n.º 1
0
def loop():
    while (1):
        value = analog_read(2)
        voltage = (value * 3.3) / 4096
        print("value =  %4d" % value)
        print("voltage =  %4.3f  V" % voltage)
        delay(100)
Ejemplo n.º 2
0
def loop():
    while(1):
        value = analog_read(2)
        voltage = (value * 3.3)/4096
        print ("value =  %4d"%value)
        print ("voltage =  %4.3f  V" %voltage)
        delay(100)
Ejemplo n.º 3
0
def main():
	while True:
		#get char from buffer
		count = ser.inWaiting()
		value = analog_read(2)
		try:
			tcpCliSock = socket(AF_INET, SOCK_STREAM)
			tcpCliSock.connect(ADDR)
			if count != 0:
				#read data
				recv = ser.read(count)
				str = recv[55:]
				pattern = re.compile(r"(?=UU).*(?=,\r)")
				res = pattern.match(str)
				if res:
					str_data = res.group()[2:]
					str_data = str_data + ","+"%i" %value
					str_data = str_data + ",79A14692-4481-4615-B6D8-27C07E13F514"
					str_data = str_data + ",7C399122-AA8C-4E2C-8792-89B51C0DD447"
					str_data = str_data + ",3BD4AA84-3E18-4C85-BF41-89179F8BC138"
					str_data = str_data + ",50949974-B3DD-484A-944F-58F30A19B6A2"
					print("res:",str_data)
					if str_data:
						try:
							if len(str_data) > 256 :
								continue
							tcpCliSock.send(('%s\r\n' % str_data).encode())
						except IOError:
							print("error happan in sending");
			#sleep
			time.sleep(SLTIME)
		except IOError:
			print("Can't connect to server");
			time.sleep(SLTIME)
	tcpCliSock.close()
Ejemplo n.º 4
0
def loop():

    while True:
        value = analog_read(5)
	temp = value*(3.3/4096*100)
        print ("value =  %4d"%value)
	print ("temperature =  %4.3f  V" %temp)
	
        now=datetime.datetime.utcnow()
        feed.datastreams=[ xively.Datastream(id='office_temp', current_value=temp, at=now)
        ]

        try:
              feed.update()
              print "Value pushed to Xively: " +  str(temp)
        except HTTPError as e:
                         print "Error connecting to Xively: " + str (e)

        time.sleep(20) 
Ejemplo n.º 5
0
def humi():
		humi = analog_read(4)
		return  "humi : %d " % humi
Ejemplo n.º 6
0
def brig():
		brig = analog_read(3)
		return  "Brightness : %d " % brig
Ejemplo n.º 7
0
def temp():
		temp = analog_read(2)
		return  "Temperature :%d " % temp
Ejemplo n.º 8
0
def tempread(pin):
    value = analog_read(pin)
    tempr = (value * 3.3)/4096*100
    return tempr
Ejemplo n.º 9
0
def tempread(pin):
    value = analog_read(pin)
    tempr = (value * 3.3) / 4096 * 100
    return tempr