diff --git a/src/main_2/main_2.ino b/src/main_2/main_2.ino index 0baa12eb6871e71ba5273ab7aed6dfb060f074ca..dc90aea7c9868cbba6d869d959fadf3f5e8be605 100644 --- a/src/main_2/main_2.ino +++ b/src/main_2/main_2.ino @@ -87,7 +87,6 @@ void loop() { } // get the value to be displayed and update one digit - PythonCommunication(); lcd.setCursor(0,0); lcd.scrollDisplayLeft(); @@ -128,6 +127,7 @@ void loop() { Serial.println(lux0); lcd.print(GenerateSoilandLightText(readSoil(),lux0)); + PythonCommunication(); delay(1000); //​take a reading every second } @@ -135,6 +135,7 @@ void PythonCommunication() { if (Serial.available() > 0) { int test; char charRead= Serial.read(); + Serial.println(charRead + ":" + charRead); if(charRead >= '0' && charRead <= '9') { test = (10 * test) + (charRead - '0') ; // convert digits to a number update_one_digit(test); diff --git a/src/python/getSerial.py b/src/python/getSerial.py index 6accd3ef1a02490924a70f805507864811ab835b..b29f01bea0cfa78e805f4b7511116febfe3ea8e8 100644 --- a/src/python/getSerial.py +++ b/src/python/getSerial.py @@ -1,26 +1,27 @@ import serial, struct, time, urllib.request, json -with urllib.request.urlopen("https://tranquil-citadel-63668.herokuapp.com/api/status") as url: +with urllib.request.urlopen("http://localhost/api-greentyno/getStatus.php?id=1") as url: data = json.loads(url.read().decode()) -year = data['year'] +year = int(data['year']) ser = serial.Serial('COM8') # open serial port print(ser.name) # check which port was really used -ser.write(struct.pack('>B',year + 48)) while True : + ser.write(struct.pack('>B',year + 48)) line = ser.readline() raw = line.decode().split('\r\n')[0] + # print(raw) arr = raw.split(':') humidity = arr[0] light = arr[1] - - #postUrl = "http://localhost/api-greentyno/updateStatus?humidity=" + humidity + "&light=" + light - #print(postUrl) - # print(humidity) - # print(light) + + postUrl = "http://localhost/api-greentyno/updateStatus.php?humidity=" + humidity + "&light=" + light + print(postUrl) + print(humidity) + print(light) - # with urllib.request.urlopen(postUrl) as url: - # print()# data = json.loads(url.read().decode()) + with urllib.request.urlopen(postUrl) as url: + print()# data = json.loads(url.read().decode()) ser.close() # close port \ No newline at end of file