Я работаю над проектом, включающим сбор информации из моего .json
файла в переменную в моем скриншоте Arduino, но у меня возникают проблемы, когда дело доходит до добавления значений в переменные, когда у меня более 1 значения , Если у меня есть более 1 значения, я не могу сохранить его в новой переменной.
Вот так выглядит мой JSON файл:
[{"AutoIncrement":"1","Aparelho":"LED","Status":"0"},
{"AutoIncrement":"2","Aparelho":"LED1","Status":"1"}]
Это мой эскиз Arduino:
char json[500];
payload.replace(" ", "");
payload.replace("\n", "");
payload.trim();
payload.remove(0,1);
payload.toCharArray(json, 500);
StaticJsonDocument<200> doc;
deserializeJson(doc, json);
//Isso nao depende do nome no banco de dados, depende do nome dentro de action.php
//LED 1
int id = doc["AutoIncrement"];
const char* nome = doc["Aparelho"];
int stat = doc["Status"];
//LED 2
int id1 = doc["AutoIncrement"];
const char* nome1 = doc["Aparelho"];
int stat1 = doc["Status"];
Serial.println(id);
Serial.println(nome);
Serial.println(stat);
Serial.println(id1);
Serial.println(nome1);
Serial.println(stat1);
if (stat == 1)
{
digitalWrite(led, HIGH);
digitalWrite(led1, HIGH);
}
else if (stat == 0)
{
digitalWrite(led, LOW);
digitalWrite(led1, LOW);
}
Это вывод:
Statuscode: 200
[{"AutoIncrement":"1","Aparelho":"LED","Status":"0"},
{"AutoIncrement":"2","Aparelho":"LED1","Status":"1"}]
1
LED
0
//This was suppose to be 2, LED1, 0:
1
LED
0