From ecd1d3b0e5803ca95d68b27814edc5e7db19bd1d Mon Sep 17 00:00:00 2001
From: finikokasulanovenda <13515029@std.stei.itb.ac.id>
Date: Wed, 11 Apr 2018 20:26:51 +0700
Subject: [PATCH] Fix strange character write bug

---
 src/main_2/main_2.ino   |  3 ++-
 src/python/getSerial.py | 21 +++++++++++----------
 2 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/src/main_2/main_2.ino b/src/main_2/main_2.ino
index 0baa12e..dc90aea 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 6accd3e..b29f01b 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
-- 
GitLab