update arduino code
This commit is contained in:
parent
10ffa1bf0e
commit
88e64184f8
@ -2,25 +2,38 @@
|
|||||||
* Official proxy code for iTender GPIO Communication
|
* Official proxy code for iTender GPIO Communication
|
||||||
**/
|
**/
|
||||||
|
|
||||||
#include "HX711.h"
|
|
||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
|
|
||||||
DynamicJsonDocument<200> doc;
|
const int BUFFER_SIZE = 256;
|
||||||
|
char buffer[BUFFER_SIZE];
|
||||||
|
int bufferIndex = 0;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(9600);
|
Serial.begin(115200);
|
||||||
|
|
||||||
while (!Serial) continue;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
if( Serial.available() > 0 )
|
if (Serial.available() > 0) {
|
||||||
{
|
char incomingByte = Serial.read();
|
||||||
String data = Serial.readString();
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user