From 5e692c8c4b4c06c9d62ea2667a77e750ad601fff Mon Sep 17 00:00:00 2001 From: jops Date: Sat, 5 Dec 2015 22:58:10 +0100 Subject: [PATCH] aggiornamenti control --- arduino/termostato/termostato.ino | 2 - cacControl.py | 79 +++++++++++++++++++------------ 2 files changed, 48 insertions(+), 33 deletions(-) diff --git a/arduino/termostato/termostato.ino b/arduino/termostato/termostato.ino index 9f8aba9..ad70e0d 100644 --- a/arduino/termostato/termostato.ino +++ b/arduino/termostato/termostato.ino @@ -138,8 +138,6 @@ void loop() { } delay(1000); - - } diff --git a/cacControl.py b/cacControl.py index 2b0f3d4..14b2330 100644 --- a/cacControl.py +++ b/cacControl.py @@ -2,49 +2,66 @@ import bluetooth import sys import time +import datetime + +bt_add = "98:D3:31:B2:35:33" #termostato +br_add = "30:14:06:26:04:18" #rele -bt_add = "98:D3:31:B2:35:33" #itade address - -port = 1 +#connessione ai dispositivi +portRele = 1 +portTerm = 1 sockTerm=bluetooth.BluetoothSocket( bluetooth.RFCOMM ) -sockTerm.connect((bt_add, port)) -print 'Connected' +sockTerm.connect((bt_add, portTerm)) +print 'Connesso al termostato' +sockRele=bluetooth.BluetoothSocket( bluetooth.RFCOMM ) +sockRele.connect((br_add, portRele)) +print 'Connesso al rele' + sockTerm.settimeout(1.0) -print sys.argv[1] -sockTerm.send(sys.argv[1]) -print 'Sent data' -time.sleep(5) # delays for 5 seconds -data = sockTerm.recv(1024) -print 'received [%s]' % data -sockTerm.close() -print 'socket chius' +sockRele.settimeout(1.0) -br_add = "30:14:06:26:04:18" #itade address +print 'parametro: ' + sys.argv[1] + +releValue = "s" + +#orario attuale +now = datetime.datetime.now() -port = 1 -sock=bluetooth.BluetoothSocket( bluetooth.RFCOMM ) -sock.connect((br_add, port)) -print 'Connected' -sock.settimeout(1.0) -print sys.argv[1] -sock.send(sys.argv[1]) -print 'Sent data' -data = "" while 1: try: - data += sock.recv(1024) - data_end = data.find('\n') - if data_end != -1: - rec = data[:data_end] - print data - data = data[data_end+1:] - break + data = "" + sockTerm.send(sys.argv[1]) + sockRele.send(releValue) + print 'Sent data: ' + releValue + time.sleep(5) # delays for 5 seconds + data = sockTerm.recv(1024) + if(len(data)==5): + temp = data.replace("t","") + temp = int(temp) + if (temp < 1570): + releValue = "f" + else: + releValue = "n" + print 'received t [%s]' % data + data = "" + time.sleep(5) # delays for 5 seconds + data += sockRele.recv(1024) + print 'received r: [%s]' % data +# data_end = data.find('\n') +# if data_end != -1: +# rec = data[:data_end] +# print data +# data = data[data_end+1:] +# break except KeyboardInterrupt: break except bluetooth.btcommon.BluetoothError as error: continue -sock.close() + +print 'socket chiuso' +sockRele.close() +sockTerm.close()