Cuprins:

PInt @ t10n: Sistem inteligent de monitorizare a plantelor: 9 pași
PInt @ t10n: Sistem inteligent de monitorizare a plantelor: 9 pași

Video: PInt @ t10n: Sistem inteligent de monitorizare a plantelor: 9 pași

Video: PInt @ t10n: Sistem inteligent de monitorizare a plantelor: 9 pași
Video: How To Fix Camera Photos Auto Rotate Problem Solve || Photo Apne Ap hi Ulte ho jate hai 2024, Iulie
Anonim
PInt @ t10n: Sistem inteligent de monitorizare a plantelor
PInt @ t10n: Sistem inteligent de monitorizare a plantelor

PI @ nt @ t10n

Acest proiect a fost creat ca un test pentru cloud-ul ibm iot. Folosim un esp-8266 pentru a trimite și primi date către și de la cloudul IBM. Comunicarea dintre cloud-ul esp și ibm are loc prin MQTT.

Pentru a gestiona toate datele și pentru a prezenta utilizatorului o interfață cu utilizatorul, utilizăm nod roșu. Este foarte prietenos pentru începători.

Pentru a începe, aveți nevoie de:

  • Esp-8266
  • dht 11/22 senzor de temperatură / umiditate
  • diodă fotosensibilă (măsurare lumină)
  • buzzer
  • senzor de umiditate la sol
  • cont cloud cloud

Pasul 1: Conectați-vă senzorii

Conectați-vă senzorii
Conectați-vă senzorii
Conectați-vă senzorii
Conectați-vă senzorii
Conectați-vă senzorii
Conectați-vă senzorii

După cum am menționat anterior, vom folosi esp8266 pentru a citi și a trimite datele senzorului. Pentru acest tutorial, vom presupune că știți cum să vă conectați senzorii la microcontrolerul dvs. De asemenea, trebuie să știți cum să încărcați codul pe un esp8266.

Modelul nostru esp are un singur port analogic, așa că am ales să primim informații analogice de la senzorul nostru de lumină, deoarece atunci putem monitoriza câtă lumină primește planta.

Toți ceilalți senzori sunt conectați digital. Senzorul nostru DHT11 trimite date digital și folosim biblioteca dht pentru a interpreta datele senzorilor.

Mai sus puteți găsi o schemă de circuit pentru senzorii pe care i-am folosit. Dar rețineți că senzorii pe care i-am folosit vin adesea cu un modul, astfel încât să îl puteți conecta cu ușurință la microcontrolerul dvs. fără toate rezistențele suplimentare pe care le-am inclus în diagramă.

Pasul 2: Cod

Aceasta este schița arduino pe care am folosit-o. Puteți afla cum funcționează codul dacă citiți comentariile.

#include ArduinoJson.h # include DHT_U.h #include DHT.h #include ESP8266WiFi.h #include ESP8266WiFiMulti.h #include PubSubClient.h

#define STASSID "ucll-projectweek-IoT" #define STAPSK "Foo4aiHa" #define DHTPin 5 #define moisturePin 4 #define DHTType DHT11 DHT dht (DHTPin, DHTType); ESP8266WiFiMulti WiFiMulti; float temp = 0; umiditatea plutitoare = 0; umiditate booleană = falsă; lumină int = 0; const char * ssid = STASSID; const char * parola = STAPSK; const char * mqtt_server = "cmfwqk.messaging.internetofthings.ibmcloud.com"; WiFiClient espClient; Clientul PubSubClient (espClient); long lastMsg = 0; char msg [50]; valoarea int = 0; #define MQTT_HOST "cmfwqk.messaging.internetofthings.ibmcloud.com" #define MQTT_PORT 1883 #define MQTT_DEVICEID "d: cmfwqk: ESP8266: ESP" #define MQTT_USER "use-token-auth" #define "MQTT_ iot-2 / evt / status / fmt / json "#define MQTT_TOPIC_DISPLAY" iot-2 / cmd / update / fmt / json "#include" pitches.h "// note în melodie: // duratele notei: 4 = sfert nota, 8 = nota a opta, etc: int shortTone = 80; int LongTone = 200; int standardDelay = 50; int delayBetweenBars = 50; void setup_wifi () {delay (10); // Începem prin conectarea la o rețea WiFi Serial.println (); Serial.print („Conectarea la”); Serial.println (ssid); WiFi.begin (ssid, parolă); while (WiFi.status ()! = WL_CONNECTED) {întârziere (500); Serial.print ("."); } Serial.println (""); Serial.println ("WiFi conectat"); Serial.println ("adresa IP:"); Serial.println (WiFi.localIP ()); } void callback (char * topic, octet * sarcină utilă, lungime int nesemnată) {Serial.print ("Mesajul a sosit ["); Serial.print (subiect); Serial.print ("]"); for (int i = 0; i <length; i ++) {Serial.print ((char) payload ); } Serial.println (); StaticJsonDocument jsonBuffer; deserializeJson (jsonBuffer, sarcină utilă); JsonObject root = jsonBuffer.as (); if (rădăcină ["cântec"] == "darude") {darude (); } if (rădăcină ["cântec"] == "starwars") {starwars (); } if (root ["song"] == "jacques") {Serial.println ("jakakakakakkakaka"); jacques (); }} void reconnect () {// Buclați până când suntem reconectați în timp ce (! client.connected ()) {Serial.print („Se încearcă conexiunea MQTT …”); // Încercați să vă conectați dacă (client.connect (MQTT_DEVICEID, MQTT_USER, MQTT_TOKEN)) {Serial.println ("conectat"); client.subscribe (MQTT_TOPIC_DISPLAY); } else {Serial.print ("nereușit, rc ="); Serial.print (client.state ()); Serial.println („încercați din nou în 5 secunde”); // Așteptați 5 secunde înainte de a reîncerca întârzierea (5000); }}} void setup () {Serial.begin (9600); pinMode (moistPin, INPUT); dht.begin (); pinMode (0, OUTPUT); setup_wifi (); client.setServer (mqtt_server, MQTT_PORT); client.setCallback (apel invers); întârziere (20); } void loop () {if (! client.connected ()) {reconnect (); } client.loop (); umiditate = citire digitală (umiditatePin); lumină = analogRead (A0); temp = dht.readTemperature (); umiditate = dht.readHumidity (); Serial.println ("Temperatura =" + String (temp, 1) + "\ nHumiditate =" + String (umiditate, 1) + "\ nMoisture:" + String (umiditate) + "\ nLumină:" + String (lumină)); String payload = "{" ts / ": {" t / ":" + String (temp, 1) + ", \" h / ":" + String (umiditate, 1) + "}, \" ms / ": {" m / ":" + Șir (umiditate) + "}, \" ls / ": {" l / ":" + Șir (luminos) + "}}"; Serial.println (sarcină utilă); if (client.publish (MQTT_TOPIC, (char *) payload.c_str ())) {Serial.println ("publish ok"); } else {Serial.println ("publicarea eșuată"); } întârziere (2000); } void darude () {tone (0, NOTE_B3, shortTone); întârziere (Ton scurt); noTone (0); întârziere (standardDelay); ton (0, NOTE_B3, shortTone); întârziere (Ton scurt); noTone (0); întârziere (standardDelay); ton (0, NOTE_B3, shortTone); întârziere (Ton scurt); noTone (0); întârziere (standardDelay); ton (0, NOTE_B3, shortTone); întârziere (Ton scurt); noTone (0); întârziere (standardDelay); ton (0, NOTE_B3, longTone); întârziere (ton lung); noTone (0); delay (delayBetweenBars); ton (0, NOTE_B3, shortTone); întârziere (Ton scurt); noTone (0); întârziere (standardDelay); ton (0, NOTE_B3, shortTone); întârziere (Ton scurt); noTone (0); întârziere (standardDelay); ton (0, NOTE_B3, shortTone); întârziere (Ton scurt); noTone (0); întârziere (standardDelay); ton (0, NOTE_B3, shortTone); întârziere (Ton scurt); noTone (0); întârziere (standardDelay); ton (0, NOTE_B3, shortTone); întârziere (Ton scurt); noTone (0); întârziere (standardDelay); ton (0, NOTE_B3, shortTone); întârziere (Ton scurt); noTone (0); întârziere (standardDelay); ton (0, NOTE_B3, longTone); întârziere (ton lung); noTone (0); întârziere (standardDelay); ton (0, NOTE_E4, shortTone); întârziere (Ton scurt); noTone (0); întârziere (standardDelay); ton (0, NOTE_E4, shortTone); întârziere (Ton scurt); noTone (0); întârziere (standardDelay); ton (0, NOTE_E4, shortTone); întârziere (Ton scurt); noTone (0); întârziere (standardDelay); ton (0, NOTE_E4, shortTone); întârziere (Ton scurt); noTone (0); întârziere (standardDelay); ton (0, NOTE_E4, shortTone); întârziere (Ton scurt); noTone (0); întârziere (standardDelay); ton (0, NOTE_E4, shortTone); întârziere (Ton scurt); noTone (0); întârziere (standardDelay); ton (0, NOTE_E4, longTone); întârziere (LongTone); noTone (0); întârziere (standardDelay); ton (0, NOTE_D4, shortTone); întârziere (Ton scurt); noTone (0); întârziere (standardDelay); ton (0, NOTE_D4, shortTone); întârziere (Ton scurt); noTone (0); întârziere (standardDelay); ton (0, NOTE_D4, shortTone); întârziere (Ton scurt); noTone (0); întârziere (standardDelay); ton (0, NOTE_D4, shortTone); întârziere (Ton scurt); noTone (0); întârziere (standardDelay); ton (0, NOTE_D4, shortTone); întârziere (Ton scurt); noTone (0); întârziere (standardDelay); ton (0, NOTE_D4, shortTone); întârziere (Ton scurt); noTone (0); întârziere (standardDelay); ton (0, NOTE_D4, longTone); întârziere (ton lung); noTone (0); întârziere (standardDelay); ton (0, NOTE_A3, longTone); întârziere (ton lung); noTone (0); întârziere (standardDelay); ton (0, NOTE_B3, shortTone); întârziere (Ton scurt); noTone (0); întârziere (standardDelay); ton (0, NOTE_B3, shortTone); întârziere (Ton scurt); noTone (0); întârziere (standardDelay); ton (0, NOTE_B3, shortTone); întârziere (Ton scurt); noTone (0); întârziere (standardDelay); ton (0, NOTE_B3, shortTone); întârziere (Ton scurt); noTone (0); întârziere (standardDelay); ton (0, NOTE_B3, longTone); întârziere (ton lung); noTone (0); delay (delayBetweenBars); ton (0, NOTE_B3, shortTone); întârziere (Ton scurt); noTone (0); întârziere (standardDelay); ton (0, NOTE_B3, shortTone); întârziere (Ton scurt); noTone (0); întârziere (standardDelay); ton (0, NOTE_B3, shortTone); întârziere (Ton scurt); noTone (0); întârziere (standardDelay); ton (0, NOTE_B3, shortTone); întârziere (Ton scurt); noTone (0); întârziere (standardDelay); ton (0, NOTE_B3, shortTone); întârziere (Ton scurt); noTone (0); întârziere (standardDelay); ton (0, NOTE_B3, shortTone); întârziere (Ton scurt); noTone (0); întârziere (standardDelay); ton (0, NOTE_B3, longTone); întârziere (ton lung); noTone (0); întârziere (standardDelay); ton (0, NOTE_E4, longTone); întârziere (ton lung); noTone (0); întârziere (standardDelay); ton (0, NOTE_B3, shortTone); întârziere (Ton scurt); noTone (0); întârziere (standardDelay); ton (0, NOTE_B3, shortTone); întârziere (Ton scurt); noTone (0); întârziere (standardDelay); ton (0, NOTE_B3, shortTone); întârziere (Ton scurt); noTone (0); întârziere (standardDelay); ton (0, NOTE_B3, shortTone); întârziere (Ton scurt); noTone (0); întârziere (standardDelay); ton (0, NOTE_B3, longTone); întârziere (LongTone); noTone (0); delay (delayBetweenBars); ton (0, NOTE_B3, shortTone); întârziere (Ton scurt); noTone (0); întârziere (standardDelay); ton (0, NOTE_B3, shortTone); întârziere (Ton scurt); noTone (0); întârziere (standardDelay); ton (0, NOTE_B3, shortTone); întârziere (Ton scurt); noTone (0); întârziere (standardDelay); ton (0, NOTE_B3, shortTone); întârziere (Ton scurt); noTone (0); întârziere (standardDelay); ton (0, NOTE_B3, shortTone); întârziere (Ton scurt); noTone (0); întârziere (standardDelay); ton (0, NOTE_B3, shortTone); întârziere (Ton scurt); noTone (0); întârziere (standardDelay); ton (0, NOTE_B3, longTone); întârziere (ton lung); noTone (0); întârziere (standardDelay); ton (0, NOTE_E4, longTone); întârziere (ton lung); noTone (0); întârziere (standardDelay); } void starwars () {beep (NOTE_A4, 500); bip (NOTE_A4, 500); bip (NOTE_A4, 500); bip (NOTE_F4, 350); bip (NOTE_C5, 150); bip (NOTE_A4, 500); bip (NOTE_F4, 350); bip (NOTE_C5, 150); bip (NOTE_A4, 650); întârziere (500); bip (NOTE_E5, 500); bip (NOTE_E5, 500); bip (NOTE_E5, 500); bip (NOTE_F5, 350); bip (NOTE_C5, 150); bip (NOTE_GS4, 500); bip (NOTE_F4, 350); bip (NOTE_C5, 150); bip (NOTE_A4, 650); } bip nul (notă int, durată int) {// Ton de redare pe buzzerPin ton (0, notă, durată); întârziere (durata); noTone (0); întârziere (standardDelay); } void heartOfCourage () {} void jacques () {beep (NOTE_C4, 500); bip (NOTE_D4, 500); bip (NOTE_E4, 500); bip (NOTE_C4, 500); bip (NOTE_C4, 500); bip (NOTE_D4, 500); bip (NOTE_E4, 500); bip (NOTE_C4, 500); bip (NOTE_E4, 500); bip (NOTE_F4, 500); bip (NOTE_G4, 500); bip (NOTE_E4, 500); bip (NOTE_F4, 500); bip (NOTE_G4, 500); bip (NOTE_G4, 500); bip (NOTE_A4, 500); bip (NOTE_G4, 500); bip (NOTE_F4, 500); bip (NOTE_E4, 500); bip (NOTE_C4, 500); bip (NOTE_G4, 500); bip (NOTE_A4, 500); bip (NOTE_G4, 500); bip (NOTE_F4, 500); bip (NOTE_E4, 500); bip (NOTE_C4, 500); bip (NOTE_C4, 500); bip (NOTE_G4, 500); bip (NOTE_C4, 500); bip (NOTE_C4, 500); bip (NOTE_G4, 500); bip (NOTE_C4, 500); }

Pasul 3: Ibm Cloud

Ibm Cloud
Ibm Cloud

Trebuie să configurați o instanță cloud IBM. Puteți găsi informații despre acest lucru prin intermediul acestui link: github.

Pasul 4: Nod-RED

Folosim roșu nod pentru a gestiona logica noastră generală de afaceri și pentru a vizualiza aceste date într-o interfață intuitivă cu utilizatorul.

Pasul 5: Configurare nod-roșu: lumină

Configurare nod-roșu: lumină
Configurare nod-roșu: lumină

Importați următorul cod în proiectul dvs.

[{"id": "deb0d57.1c46528", "type": "tab", "label": "Light", "disabled": false, "info": ""}, {"id": "8a0fcaac. 4e54 "," type ":" ibmiot in "," z ":" deb0d57.1c46528 "," authentication ":" boundService "," apiKey ":" "," inputType ":" evt "," logicInterface ":" "," ruleId ":" "," deviceId ":" ESP "," applicationId ":" "," deviceType ":" ESP8266 "," eventType ":" + "," commandType ":" "," format ": "json", "name": "Obțineți date de la ESP", "service": "înregistrat", "allDevices": false, "allApplications": "", "allDeviceTypes": false, "allLogicalInterfaces": "", "allEvents": adevărat, "allCommands": "", "allFormats": "", "qos": 0, "x": 120, "y": 62, "wires":

Pasul 6: Configurare nod-roșu: temperatură

Configurare nod-roșu: temperatură
Configurare nod-roșu: temperatură

Importați următorul cod în proiectul dvs.

[{"id": "fbad3799.f0e0e", "type": "tab", "label": "Temperature", "disabled": false, "info": ""}, {"id": "b8618eb9. 1c9288 "," type ":" ibmiot in "," z ":" fbad3799.f0e0e "," authentication ":" boundService "," apiKey ":" "," inputType ":" evt "," logicInterface ":" "," ruleId ":" "," deviceId ":" ESP "," applicationId ":" "," deviceType ":" ESP8266 "," eventType ":" + "," commandType ":" "," format ": "json", "name": "Obțineți date de la ESP", "service": "înregistrat", "allDevices": false, "allApplications": "", "allDeviceTypes": false, "allLogicalInterfaces": "", "allEvents": adevărat, "allCommands": "", "allFormats": "", "qos": 0, "x": 145.5, "y": 49, "wires":

Pasul 7: Configurare nod-RED: Umiditate

Configurare nod-roșu: umiditate
Configurare nod-roșu: umiditate

Importați următorul cod în proiectul dvs.

[{"id": "144cd53b.c00473", "type": "tab", "label": "Umiditate", "disabled": fals, "info": ""}, {"id": "d958f58b. 2678e "," type ":" ibmiot in "," z ":" 144cd53b.c00473 "," authentication ":" boundService "," apiKey ":" "," inputType ":" evt "," logicInterface ":" "," ruleId ":" "," deviceId ":" ESP "," applicationId ":" "," deviceType ":" ESP8266 "," eventType ":" + "," commandType ":" "," format ": "json", "name": "Obțineți date de la ESP", "service": "înregistrat", "allDevices": false, "allApplications": "", "allDeviceTypes": false, "allLogicalInterfaces": "", "allEvents": adevărat, "allCommands": "", "allFormats": "", "qos": 0, "x": 142, "y": 87, "wires":

Pasul 8: Configurare nod-RED: umiditate

Configurare nod-roșu: umiditate
Configurare nod-roșu: umiditate

Importați următorul cod în proiectul dvs.

[{"id": "4ee73536.ec6fc4", "type": "tab", "label": "Umiditate", "disabled": fals, "info": ""}, {"id": "a6daac3e. 2d5268 "," type ":" ibmiot out "," z ":" 4ee73536.ec6fc4 "," authentication ":" boundService "," apiKey ":" "," outputType ":" cmd "," deviceId ":" ESP "," deviceType ":" ESP8266 "," eventCommandType ":" update "," format ":" json "," data ":" msg "," qos ": 0," name ":" Trimite comanda către ESP "," service ":" înregistrat "," x ": 804.1944580078125," y ": 383.0000305175781," fire ": }, {" id ":" 4134fdb7.18e9b4 "," type ":" ibmiot in ", "z": "4ee73536.ec6fc4", "autentificare": "boundService", "apiKey": "", "inputType": "evt", "logicInterface": "", "ruleId": "", "deviceId": "ESP", "applicationId": "", "deviceType": "ESP8266", "eventType": "update", "commandType": "", "format": "json", "name": "Obțineți date din ESP "," service ":" înregistrat "," allDevices ": false," allApplications ":" "," allDeviceTypes ": false," allLogicalInterfaces ":" "," allEvents ": true," allCommands ":" ", "allFormats": false, "qos": 0, "x": 115, "y": 76, "wires":

Pasul 9: Ești gata

Felicitări! acum aveți un sistem de observare a plantelor de lucru.

Dacă aveți orice întrebare, nu ezitați să ne contactați!