Stap 4: En uitleg van cloud en web toepassing
De code die de interfaces van de sensor van Intel Edison en de cloud (dat is voor nu emuleren door een andere PC) is:
#include
#include
char [ssid] = "LUISS_ENLABS"; uw netwerk-SSID (naam)
char doorgeven [] = "luissenlabs"; uw netwerkwachtwoord
float temperatuur;
float vochtigheid;
float gas;
int brand;
int B = 3975;
int. temp; String strURL = "";
int status = WL_IDLE_STATUS;
IP-adres server(172,16,37,156);
Initialiseren van de bibliotheek WiFiClient cliënt;
void setup {Serial.begin(9600); Serial.println ("probeert te verbinden met WPA netwerk...'); Serial.Print ("SSID:"); Serial.println(SSID);
Status = WiFi.begin (ssid, pass); Als (status! = WL_CONNECTED) {Serial.println ("niet kon krijgen een wifi-verbinding"); / / doe niets anders: while (true);}}
void loop {}
Serial.println ("Entro nel looop");
UpdateTemp();
Serial.println ("Esco da UpdateTemp");
while(client.available()) {char c = client.read(); Serial.Print(c); }
Als (! client.connected()) {Serial.println(); Serial.println("Disconnesso.");
client.stop(); } //esegui la richiesta ogni 10 secondi
delay(1000); }
VOID UpdateTemp() {}
Serial.println("Connessione...");
terwijl (client.connect (server, 80)) {}
Serial.println ("Connesso e sono in tijdje");
temperatuur = getTempValue();
Serial.Print ("\nTemp:--->");
Serial.println(Temperature);
vochtigheid = getHumidityValue();
Serial.Print ("Hum:--->");
Serial.println(Humidity);
gas = getGasValue();
Serial.Print ("Gas:--->");
Serial.println(gas);
brand = getFireValue();
Serial.Print ("brand:--->");
Serial.println(Fire);
Serial.Print ("String:--->"); Creo l'url ziet una stringa
strURL = getURLString();
Serial.println(strUrl); invio la richiesta al server
client.println(strUrl);
client.println ("Host: 172.16.37.156");
S erial.println ("Host: localhost");
client.println ("verbinding: sluiten");
client.println();
client.stop();
Serial.println("Stop");
delay(2500); }
Als (client.connect (server, 80)) {Serial.println ("Errore Connessione");}}
float getTempValue() {}
f loat temp = analogRead(A0);
zweven weerstand = (1023-temp) * 10000/temp; krijgen van de weerstand van de sensor;
zweven temperatuur = 1 / (log (weerstand/10000) /B+1/298.15)-273.15;//convert tot temperatuur via het gegevensblad; retourneren van de temperatuur; }
zweven getHumidityValue() {zweven vochtigheid = analogRead(A1); terugkeer vochtigheid;}
zweven getGasValue() {gas = analogRead(A3); gas gas/1024 = * 5.0; terugkeer gas;}
int getFireValue() {brand = digitalRead(4); terugkeer! brand;}
String getURLString() {}
strURL = "GET mypet/index.php?temperatura=";
strURL += (int) temperatuur;
strURL += "& gas =";
strURL += (int) gas; strURL += "& umidita =";
strURL += (int) vochtigheid; strURL += "& fuoco =";
strURL += (int) brand; retourneren van de strURL; }
Deze code Lees de waarde van alle sensoren op het bord, stuur ze dan in de cloud (wolk = 172.16.37.156).
Bovendien, de sensoren gegevens in de cloud kunnen worden gelezen in een webtoepassing en sturen We de waarde van de sensoren in Intel Dashboard Analytics.