diff --git a/arduino/itender/itender.ino b/arduino/itender/itender.ino index 7f19d5e..c1437d1 100644 --- a/arduino/itender/itender.ino +++ b/arduino/itender/itender.ino @@ -2,25 +2,38 @@ * Official proxy code for iTender GPIO Communication **/ -#include "HX711.h" #include -DynamicJsonDocument<200> doc; +const int BUFFER_SIZE = 256; +char buffer[BUFFER_SIZE]; +int bufferIndex = 0; void setup() { - Serial.begin(9600); - - while (!Serial) continue; - - + Serial.begin(115200); } - - void loop() { - if( Serial.available() > 0 ) - { - String data = Serial.readString(); - + if (Serial.available() > 0) { + char incomingByte = Serial.read(); + buffer[bufferIndex] = incomingByte; + bufferIndex++; + + if (incomingByte == '\n') { + buffer[bufferIndex] = '\0'; + bufferIndex = 0; + + StaticJsonDocument<200> doc; + DeserializationError error = deserializeJson(doc, buffer); + if (error) { + Serial.print(F("deserializeJson() failed: ")); + Serial.println(error.c_str()); + return; + } + + // Do something with the deserialized JSON object + int value = doc["value"]; + Serial.println(value); + } } } +