From 88e64184f805526aec2306ff60f101168c654e76 Mon Sep 17 00:00:00 2001
From: Tobias Hopp <tobi@gaminggeneration.de>
Date: Sat, 21 Jan 2023 15:11:53 +0100
Subject: [PATCH] update arduino code

---
 arduino/itender/itender.ino | 39 ++++++++++++++++++++++++-------------
 1 file changed, 26 insertions(+), 13 deletions(-)

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 <ArduinoJson.h>
 
-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);
+    }
   }
 }
+