Kazalo:

PInt@t10n: Pametni sistem za nadzor rastlin: 9 korakov
PInt@t10n: Pametni sistem za nadzor rastlin: 9 korakov

Video: PInt@t10n: Pametni sistem za nadzor rastlin: 9 korakov

Video: PInt@t10n: Pametni sistem za nadzor rastlin: 9 korakov
Video: 97% Owned: The Money System | Finance Documentary Film (Netflix) 2024, November
Anonim
PInt@t10n: Pametni sistem za nadzor rastlin
PInt@t10n: Pametni sistem za nadzor rastlin

Ta projekt je nastal kot test za oblak ibm iot. Za pošiljanje in sprejemanje podatkov v oblak ibm in iz njega uporabljamo esp-8266. Komunikacija med esp in oblakom ibm poteka prek MQTT.

Za obdelavo vseh podatkov in predstavitev uporabniku uporabniškega vmesnika uporabljamo node-red. Je zelo prijazen začetnikom.

Za začetek potrebujete:

  • Esp-8266
  • senzor temp./vlage dht 11/22
  • fotoobčutljiva dioda (merjenje svetlobe)
  • zvočni signal
  • senzor vlažnosti tal
  • ibm račun v oblaku

1. korak: Povežite svoje senzorje

Povežite svoje senzorje
Povežite svoje senzorje
Povežite svoje senzorje
Povežite svoje senzorje
Priključite svoje senzorje
Priključite svoje senzorje

Kot smo že omenili, bomo za branje in pošiljanje podatkov tipala uporabili esp8266. V tej vadnici bomo domnevali, da veste, kako povezati svoje senzorje z mikro krmilnikom. Prav tako morate že vedeti, kako naložiti kodo na esp8266.

Naš model esp ima samo ena analogna vrata, zato smo se odločili prejemati analogne informacije od našega svetlobnega senzorja, ker lahko potem spremljamo, koliko svetlobe rastlina dobi.

Vsi drugi senzorji so digitalno povezani. Naš senzor DHT11 podatke pošilja digitalno, za razlago podatkov senzorjev pa uporabljamo knjižnico dht.

Zgoraj najdete diagram vezja za senzorje, ki smo jih uporabili. Upoštevajte pa, da so senzorji, ki smo jih uporabljali, pogosto opremljeni z modulom, tako da ga lahko preprosto povežete z mikrokrmilnikom brez vseh dodatnih uporov, ki smo jih vključili v diagram.

2. korak: Koda

To je skica arduino, ki smo jo uporabili. O tem, kako deluje koda, lahko izveste, če preberete komentarje.

#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 moisPin 4 #define DHTType DHT11 DHT dht (DHTPin, DHTType); ESP8266WiFiMulti WiFiMulti; plavajoča temp = 0; vlažnost plovca = 0; logična vlaga = napačno; int svetloba = 0; const char* ssid = STASSID; const char* geslo = STAPSK; const char* mqtt_server = "cmfwqk.messaging.internetofthings.ibmcloud.com"; WiFiClient espClient; Odjemalec PubSubClient (espClient); dolga lastMsg = 0; char msg [50]; int vrednost = 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-autHQTTNKdekTKOP iot-2/evt/status/fmt/json "#define MQTT_TOPIC_DISPLAY" iot-2/cmd/update/fmt/json "#include" pitches.h "// not in melody: // trajanje not: 4 = četrtina opomba, 8 = osma opomba itd.: int shortTone = 80; int longTone = 200; int standardDelay = 50; int delayBetweenBars = 50; void setup_wifi () {zakasnitev (10); // Začnemo s povezavo z omrežjem WiFi Serial.println (); Serial.print ("Povezovanje z"); Serial.println (ssid); WiFi.begin (ssid, geslo); while (WiFi.status ()! = WL_CONNECTED) {zamuda (500); Serial.print ("."); } Serial.println (""); Serial.println ("WiFi povezan"); Serial.println ("naslov IP:"); Serial.println (WiFi.localIP ()); } void backback call (char* topic, byte* payload, unsigned int length) {Serial.print ("Sporočilo je prispelo ["); Serial.print (tema); Serial.print ("]"); za (int i = 0; i <dolžina; i ++) {Serial.print ((char) koristna obremenitev ); } Serial.println (); StaticJsonDocument jsonBuffer; deserializeJson (jsonBuffer, koristna obremenitev); Koren JsonObject = jsonBuffer.as (); if (root ["song"] == "darude") {darude (); } if (root ["song"] == "starwars") {starwars (); } if (root ["song"] == "jacques") {Serial.println ("jakakakakakkakaka"); jacques (); }} void reconnect () {// Zanka, dokler se znova ne povežemo while (! client.connected ()) {Serial.print ("Poskus povezave MQTT …"); // Poskus povezovanja if (client.connect (MQTT_DEVICEID, MQTT_USER, MQTT_TOKEN)) {Serial.println ("connected"); client.subscribe (MQTT_TOPIC_DISPLAY); } else {Serial.print ("ni uspelo, rc ="); Serial.print (client.state ()); Serial.println ("poskusite znova čez 5 sekund"); // Počakajte 5 sekund, preden zamudite ponovni poskus (5000); }}} void setup () {Serial.begin (9600); pinMode (moisPin, INPUT); dht.begin (); pinMode (0, OUTPUT); setup_wifi (); client.setServer (mqtt_server, MQTT_PORT); client.setCallback (povratni klic); zamuda (20); } void loop () {if (! client.connected ()) {reconnect (); } client.loop (); vlaga = digitalno branje (vlagaPin); svetloba = analogno branje (A0); temp = dht.readTemperature (); vlažnost = dht.readHumidity (); Serial.println ("Temperatura =" + Niz (temp, 1) + "\ nVlažnost =" + Niz (vlažnost, 1) + "\ nVlažnost:" + Niz (vlaga) + "\ nLuč:" + Niz (svetloba)); Niz koristnega tovora = "{" ts / ": {" t / ":"+Niz (temp, 1)+", \" h / ":"+Niz (vlažnost, 1)+"}, \" ms / ": {" m / ":"+niz (vlaga)+"}, \" ls / ": {" l / ":"+niz (svetloba)+"}}"; Serial.println (koristna obremenitev); if (client.publish (MQTT_TOPIC, (char*) payload.c_str ())) {Serial.println ("objavi v redu"); } else {Serial.println ("objava ni uspela"); } zamuda (2000); } void darude () {ton (0, NOTE_B3, shortTone); zakasnitev (shortTone); noTone (0); zamuda (standardna zamuda); ton (0, NOTE_B3, shortTone); zakasnitev (shortTone); noTone (0); zakasnitev (standardna zamuda); ton (0, NOTE_B3, shortTone); zakasnitev (shortTone); noTone (0); zamuda (standardna zamuda); ton (0, NOTE_B3, shortTone); zakasnitev (shortTone); noTone (0); zakasnitev (standardna zamuda); ton (0, NOTE_B3, longTone); zakasnitev (longTone); noTone (0); zakasnitev (delayBetweenBars); ton (0, NOTE_B3, shortTone); zakasnitev (shortTone); noTone (0); zamuda (standardna zamuda); ton (0, NOTE_B3, shortTone); zakasnitev (shortTone); noTone (0); zamuda (standardna zamuda); ton (0, NOTE_B3, shortTone); zakasnitev (shortTone); noTone (0); zakasnitev (standardna zamuda); ton (0, NOTE_B3, shortTone); zakasnitev (shortTone); noTone (0); zamuda (standardna zamuda); ton (0, NOTE_B3, shortTone); zakasnitev (shortTone); noTone (0); zamuda (standardna zamuda); ton (0, NOTE_B3, shortTone); zakasnitev (shortTone); noTone (0); zamuda (standardna zamuda); ton (0, NOTE_B3, longTone); zakasnitev (longTone); noTone (0); zamuda (standardna zamuda); ton (0, NOTE_E4, shortTone); zakasnitev (shortTone); noTone (0); zamuda (standardna zamuda); ton (0, NOTE_E4, shortTone); zakasnitev (shortTone); noTone (0); zamuda (standardna zamuda); ton (0, NOTE_E4, shortTone); zakasnitev (shortTone); noTone (0); zamuda (standardna zamuda); ton (0, NOTE_E4, shortTone); zakasnitev (shortTone); noTone (0); zamuda (standardna zamuda); ton (0, NOTE_E4, shortTone); zakasnitev (shortTone); noTone (0); zakasnitev (standardna zamuda); ton (0, NOTE_E4, shortTone); zakasnitev (shortTone); noTone (0); zakasnitev (standardna zamuda); ton (0, NOTE_E4, longTone); zakasnitev (longTone); noTone (0); zamuda (standardna zamuda); ton (0, NOTE_D4, shortTone); zakasnitev (shortTone); noTone (0); zakasnitev (standardna zamuda); ton (0, NOTE_D4, shortTone); zakasnitev (shortTone); noTone (0); zamuda (standardna zamuda); ton (0, NOTE_D4, shortTone); zakasnitev (shortTone); noTone (0); zakasnitev (standardna zamuda); ton (0, NOTE_D4, shortTone); zakasnitev (shortTone); noTone (0); zamuda (standardna zamuda); ton (0, NOTE_D4, shortTone); zakasnitev (shortTone); noTone (0); zamuda (standardna zamuda); ton (0, NOTE_D4, shortTone); zakasnitev (shortTone); noTone (0); zamuda (standardna zamuda); ton (0, NOTE_D4, longTone); zakasnitev (longTone); noTone (0); zamuda (standardna zamuda); ton (0, NOTE_A3, longTone); zakasnitev (longTone); noTone (0); zamuda (standardna zamuda); ton (0, NOTE_B3, shortTone); zakasnitev (shortTone); noTone (0); zakasnitev (standardna zamuda); ton (0, NOTE_B3, shortTone); zakasnitev (shortTone); noTone (0); zamuda (standardna zamuda); ton (0, NOTE_B3, shortTone); zakasnitev (shortTone); noTone (0); zamuda (standardna zamuda); ton (0, NOTE_B3, shortTone); zakasnitev (shortTone); noTone (0); zakasnitev (standardna zamuda); ton (0, NOTE_B3, longTone); zakasnitev (longTone); noTone (0); zakasnitev (delayBetweenBars); ton (0, NOTE_B3, shortTone); zakasnitev (shortTone); noTone (0); zamuda (standardna zamuda); ton (0, NOTE_B3, shortTone); zakasnitev (shortTone); noTone (0); zakasnitev (standardna zamuda); ton (0, NOTE_B3, shortTone); zakasnitev (shortTone); noTone (0); zamuda (standardna zamuda); ton (0, NOTE_B3, shortTone); zakasnitev (shortTone); noTone (0); zamuda (standardna zamuda); ton (0, NOTE_B3, shortTone); zakasnitev (shortTone); noTone (0); zakasnitev (standardna zamuda); ton (0, NOTE_B3, shortTone); zakasnitev (shortTone); noTone (0); zamuda (standardna zamuda); ton (0, NOTE_B3, longTone); zakasnitev (longTone); noTone (0); zamuda (standardna zamuda); ton (0, NOTE_E4, longTone); zakasnitev (longTone); noTone (0); zakasnitev (standardna zamuda); ton (0, NOTE_B3, shortTone); zakasnitev (shortTone); noTone (0); zamuda (standardna zamuda); ton (0, NOTE_B3, shortTone); zakasnitev (shortTone); noTone (0); zamuda (standardna zamuda); ton (0, NOTE_B3, shortTone); zakasnitev (shortTone); noTone (0); zamuda (standardna zamuda); ton (0, NOTE_B3, shortTone); zakasnitev (shortTone); noTone (0); zamuda (standardna zamuda); ton (0, NOTE_B3, longTone); zakasnitev (longTone); noTone (0); zakasnitev (delayBetweenBars); ton (0, NOTE_B3, shortTone); zakasnitev (shortTone); noTone (0); zamuda (standardna zamuda); ton (0, NOTE_B3, shortTone); zakasnitev (shortTone); noTone (0); zamuda (standardna zamuda); ton (0, NOTE_B3, shortTone); zakasnitev (shortTone); noTone (0); zamuda (standardna zamuda); ton (0, NOTE_B3, shortTone); zakasnitev (shortTone); noTone (0); zakasnitev (standardna zamuda); ton (0, NOTE_B3, shortTone); zakasnitev (shortTone); noTone (0); zamuda (standardna zamuda); ton (0, NOTE_B3, shortTone); zakasnitev (shortTone); noTone (0); zamuda (standardna zamuda); ton (0, NOTE_B3, longTone); zakasnitev (longTone); noTone (0); zakasnitev (standardna zamuda); ton (0, NOTE_E4, longTone); zakasnitev (longTone); noTone (0); zamuda (standardna zamuda); } void starwars () {pisk (NOTE_A4, 500); pisk (OPOMBA_A4, 500); pisk (OPOMBA_A4, 500); pisk (OPOMBA_F4, 350); pisk (OPOMBA_C5, 150); pisk (OPOMBA_A4, 500); pisk (OPOMBA_F4, 350); pisk (OPOMBA_C5, 150); pisk (OPOMBA_A4, 650); zamuda (500); pisk (OPOMBA_E5, 500); pisk (OPOMBA_E5, 500); pisk (OPOMBA_E5, 500); pisk (OPOMBA_F5, 350); pisk (OPOMBA_C5, 150); pisk (OPOMBA_GS4, 500); pisk (OPOMBA_F4, 350); pisk (OPOMBA_C5, 150); pisk (OPOMBA_A4, 650); } void beep (int note, int duration) {// Predvajaj ton na zvočnikuPin ton (0, opomba, trajanje); zamuda (trajanje); noTone (0); zamuda (standardna zamuda); } void heartOfCourage () {} void jacques () {pisk (NOTE_C4, 500); pisk (OPOMBA_D4, 500); pisk (OPOMBA_E4, 500); pisk (OPOMBA_C4, 500); pisk (OPOMBA_C4, 500); pisk (OPOMBA_D4, 500); pisk (OPOMBA_E4, 500); pisk (OPOMBA_C4, 500); pisk (OPOMBA_E4, 500); pisk (OPOMBA_F4, 500); pisk (OPOMBA_G4, 500); pisk (OPOMBA_E4, 500); pisk (OPOMBA_F4, 500); pisk (OPOMBA_G4, 500); pisk (OPOMBA_G4, 500); pisk (OPOMBA_A4, 500); pisk (OPOMBA_G4, 500); pisk (OPOMBA_F4, 500); pisk (OPOMBA_E4, 500); pisk (OPOMBA_C4, 500); pisk (OPOMBA_G4, 500); pisk (OPOMBA_A4, 500); pisk (OPOMBA_G4, 500); pisk (OPOMBA_F4, 500); pisk (OPOMBA_E4, 500); pisk (OPOMBA_C4, 500); pisk (OPOMBA_C4, 500); pisk (OPOMBA_G4, 500); pisk (OPOMBA_C4, 500); pisk (OPOMBA_C4, 500); pisk (OPOMBA_G4, 500); pisk (OPOMBA_C4, 500); }

Korak: Ibm Cloud

Ibm oblak
Ibm oblak

Nastaviti morate primerek IBM-cloud. Podatke o tem najdete na tej povezavi: github.

4. korak: Node-RED

Node-red uporabljamo za ravnanje s splošno poslovno logiko in za prikaz teh podatkov v intuitivnem uporabniškem vmesniku.

5. korak: Node-RED Setup: Svetloba

Node-RED Setup: Light
Node-RED Setup: Light

Naslednjo kodo uvozite v svoj projekt.

[{"id": "deb0d57.1c46528", "type": "tab", "label": "Light", "disabled": false, "info": ""}, {"id": "8a0fcaac. 4e54 "," type ":" ibmiot in "," z ":" deb0d57.1c46528 "," authentication ":" boundService "," apiKey ":" "," inputType ":" evt "," logični vmesnik ":" "," ruleId ":" "," deviceId ":" ESP "," applicationId ":" "," deviceType ":" ESP8266 "," eventType ":"+"," commandType ":" "," format ": "json", "name": "Pridobite podatke iz ESP", "service": "registriran", "allDevices": false, "allApplications": "", "allDeviceTypes": false, "allLogicalInterfaces": "", "allEvents": true, "allCommands": "", "allFormats": "", "qos": 0, "x": 120, "y": 62, "žice":

6. korak: Node-RED Setup: Temperatura

Node-RED Setup: Temperatura
Node-RED Setup: Temperatura

Naslednjo kodo uvozite v svoj projekt.

[{"id": "fbad3799.f0e0e", "type": "tab", "label": "Temperature", "disabled": false, "info": ""}, {"id": "b8618eb9. 1c9288 "," type ":" ibmiot in "," z ":" fbad3799.f0e0e "," authentication ":" boundService "," apiKey ":" "," inputType ":" evt "," logični vmesnik ":" "," ruleId ":" "," deviceId ":" ESP "," applicationId ":" "," deviceType ":" ESP8266 "," eventType ":"+"," commandType ":" "," format ": "json", "name": "Pridobite podatke iz ESP", "service": "registriran", "allDevices": false, "allApplications": "", "allDeviceTypes": false, "allLogicalInterfaces": "", "allEvents": true, "allCommands": "", "allFormats": "", "qos": 0, "x": 145,5, "y": 49, "žice":

7. korak: Node-RED Setup: Vlažnost

Node-RED Setup: Vlažnost
Node-RED Setup: Vlažnost

Naslednjo kodo uvozite v svoj projekt.

[{"id": "144cd53b.c00473", "type": "tab", "label": "Vlažnost", "onemogočeno": false, "info": ""}, {"id": "d958f58b. 2678e "," type ":" ibmiot in "," z ":" 144cd53b.c00473 "," authentication ":" boundService "," apiKey ":" "," inputType ":" evt "," logični vmesnik ":" "," ruleId ":" "," deviceId ":" ESP "," applicationId ":" "," deviceType ":" ESP8266 "," eventType ":"+"," commandType ":" "," format ": "json", "name": "Pridobite podatke iz ESP", "service": "registered", "allDevices": false, "allApplications": "", "allDeviceTypes": false, "allLogicalInterfaces": "", "allEvents": true, "allCommands": "", "allFormats": "", "qos": 0, "x": 142, "y": 87, "žice":

8. korak: Node-RED Setup: Vlaga

Node-RED Setup: Vlaga
Node-RED Setup: Vlaga

Naslednjo kodo uvozite v svoj projekt.

[{"id": "4ee73536.ec6fc4", "type": "tab", "label": "Vlaga", "onemogočeno": false, "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 ":" Pošlji ukaz ESP "," service ":" registered "," x ": 804.1944580078125," y ": 383.0000305175781," wires ": }, {" id ":" 4134fdb7.18e9b4 "," type ":" ibmiot in ", "z": "4ee73536.ec6fc4", "preverjanje pristnosti": "boundService", "apiKey": "", "inputType": "evt", "logični vmesnik": "", "praviloId": "", "deviceId": "ESP", "applicationId": "", "deviceType": "ESP8266", "eventType": "update", "commandType": "", "format": "json", "name": "Pridobite podatke iz ESP "," service ":" registered "," allDevices ": false," allApplications ":" "," allDeviceTypes ": false," allLogicalInterfaces ":" "," allEvents ": true," allCommands ":" ", "allFormats": false, "qos": 0, "x": 115, "y": 76, "žice":

9. korak: Končali ste

Čestitamo! zdaj imate delujoč sistem za opazovanje rastlin.

Če imate kakršno koli vprašanje, se obrnite na nas!