diff --git a/main.py b/main.py index 8807fc8..31c4795 100755 --- a/main.py +++ b/main.py @@ -13,7 +13,7 @@ ser = serial.Serial('/dev/ttyACM0', baudrate = 9600, timeout = 1) while 1: - # { "command": "switch", "arg": "one", "state": "off"} + # { "command": "switch", "arg": "one", "state": "off", "ver":"1690931931"} userInput = input('> ') ser.write(str(userInput).encode('ascii')) arduinoData = ser.readline().decode('ascii') diff --git a/main/main.ino b/main/main.ino index 14802c9..2e686a8 100644 --- a/main/main.ino +++ b/main/main.ino @@ -4,6 +4,7 @@ int analogPin = 3; int data = 0; char userInput; +char* commandVer; void setup() { @@ -24,10 +25,10 @@ if(Serial.available()>0) { //userInput = Serial.read(); // String input; + //{ "command": "switch", "arg": "one", "state": "off", "ver":"1690931931"} + StaticJsonDocument<96> jsonin; - StaticJsonDocument<96> doc; - // { "command": "switch", "arg": "one", "state": "off"} - DeserializationError error = deserializeJson(doc, Serial); + DeserializationError error = deserializeJson(jsonin, Serial); if (error) { Serial.print(F("deserializeJson() failed: ")); @@ -35,20 +36,33 @@ if(Serial.available()>0) { return; } - const char* command = doc["command"]; // "switch" - const char* arg = doc["arg"]; // "one" - const char* state = doc["state"]; // "off" - + const char* command = jsonin["command"]; // "switch" + const char* arg = jsonin["arg"]; // "one" + const char* state = jsonin["state"]; // "off" + const char* ver = jsonin["ver"]; // "1690931931" + StaticJsonDocument<96> jsonout; + + jsonout["command"] = "lol"; + jsonout["arg"] = "rofl"; + jsonout["state"] = "on"; + jsonout["ver"] = "1690931337"; + + serializeJson(jsonout, Serial); + + /* Serial.print(command); Serial.print(" - "); Serial.print(arg); Serial.print(" - "); - Serial.println(state); + Serial.print(state); + Serial.print(" - "); + Serial.println(ver); if(userInput == 'g') { data = analogRead(analogPin); +*/ /* digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level) delay(200); // wait for a second @@ -63,10 +77,11 @@ if(Serial.available()>0) { digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW delay(200); - */ + //delay(2000); Serial.println(data); - } + */ + //} } }