Как анализировать выходные данные URL (пакеты JSON), как показано ниже:
{"result":"ok","db":[{"id":"2","createdate":"0000-00-00 00:00:00","modifydate":"0000-00-00 00:00:00","module":null,"serial":null,"company":"1","firstname":"An ","lastname":"","email1":"","email2":"","email3":"","phone":null,"mobile":null,"pincode":null,"username":null,"email4":""},{"id":"3","createdate":"0000-00-00 00:00:00","modifydate":"0000-00-00 00:00:00","module":"red","serial":null,"company":"2","firstname":"An ","lastname":"","email1":"","email2":"","email3":"","phone":null,"mobile":null,"pincode":null,"username":null,"email4":""},{"id":"4","createdate":"0000-00-00 00:00:00","modifydate":"0000-00-00 00:00:00","module":"red","serial":null,"company":"3","firstname":"An ","lastname":"","email1":"","email2":"","email3":"","phone":null,"mobile":null,"pincode":null,"username":null,"email4":""}
Из результатов URL читайте только значения идентификатора и модуля
module:null and id:2
module:red and id:3
module:red and id:4
если значение «красный», тогда выполнить digitalWrite(id_number, HIGH);
(в этом случае два исполнения должны произойти на контакте 3 и 4)
Код Arduino YUN:
#include <Bridge.h>
#include <HttpClient.h>
void setup() {
pinMode(13, OUTPUT);
Bridge.begin();
}
void loop() {
HttpClient client;
/* This returns JSON result */
client.get("http://example.com/ajax/pinoutput");
String result;
while (client.available()) {
char c = client.read();
result = result + c;
}
/* Check for the value RED from JSON result and read the ID which is to insert in digitalWrite(HERE); */
if(result.indexOf("red") < 0) {
digitalWrite(13, HIGH);
delay(1000);
} else {
digitalWrite(13, LOW);
delay(1000);
}
/* Delay the crawl interval */
delay(2000);
}
Вам нужен парсер. Простая библиотека, которая выполняет эту работу: