Skip to content
Snippets Groups Projects
Commit ecd1d3b0 authored by 13515029 - Finiko Kasula Novenda's avatar 13515029 - Finiko Kasula Novenda
Browse files

Fix strange character write bug

parent 6d35e848
No related merge requests found
......@@ -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);
......
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
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment