Talaan ng mga Nilalaman:
- Hakbang 1: Ikonekta ang Iyong Mga Sensor
- Hakbang 2: Code
- Hakbang 3: Ibm Cloud
- Hakbang 4: Node-RED
- Hakbang 5: Pag-set up ng Node-RED: Magaang
- Hakbang 6: Pag-set up ng Node-RED: Temperatura
- Hakbang 7: Pag-set up ng Node-RED: Humidity
- Hakbang 8: Pag-set up ng Node-RED: Kahalumigmigan
- Hakbang 9: Tapos Na
Video: PInt @ t10n: Smart Plant Monitoring System: 9 Mga Hakbang
2024 May -akda: John Day | [email protected]. Huling binago: 2024-01-30 13:13
PI @ nt @ t10n
Ang proyektong ito ay nilikha bilang isang pagsubok para sa ibm iot cloud. Gumagamit kami ng isang esp-8266 upang magpadala at tumanggap ng data papunta at mula sa cloud ng ibm. Ang komunikasyon sa pagitan ng esp at cloud ng ibm ay nangyayari sa pamamagitan ng MQTT.
Upang hawakan ang lahat ng data at upang maipakita ang gumagamit sa isang interface ng gumagamit ginagamit namin ang node-red. Napaka-friendly ng baguhan.
Upang makapagsimula kailangan mo:
- Esp-8266
- dht 11/22 temp / kahalumigmigan sensor
- photosensitive diode (pagsukat ng ilaw)
- buzzer
- ground moisture sensor
- ibm cloud account
Hakbang 1: Ikonekta ang Iyong Mga Sensor
Tulad ng nabanggit namin bago gagamitin namin ang esp8266 upang mabasa at magpadala ng data ng sensor. Para sa tutorial na ito ay ipagpapalagay namin na alam mo kung paano ikonekta ang iyong mga sensor sa iyong micro controller. Kailangan mo ring malaman kung paano mag-upload ng code sa isang esp8266.
Ang aming modelo ng esp ay mayroon lamang isang analog port kaya pinili naming makatanggap ng impormasyon sa analog mula sa aming light sensor dahil maaari naming subaybayan kung gaano karaming ilaw ang nakukuha ng halaman.
Ang lahat ng iba pang mga sensor ay konektado sa digital. Ang aming sensor ng DHT11 ay nagpapadala ng data nang digital at ginagamit namin ang dht library upang bigyang kahulugan ang data ng mga sensor.
Sa itaas maaari kang makahanap ng isang circuit diagram para sa mga sensor na ginamit namin. Ngunit mangyaring tandaan na ang mga sensor na ginamit namin ay madalas na may isang module upang madali mong ikonekta ito sa iyong micro controller nang walang lahat ng labis na resistors na isinama namin sa diagram.
Hakbang 2: Code
Ito ang ginamit na sketch ng arduino. Maaari mong malaman ang tungkol sa kung paano gumagana ang code kung nabasa mo ang mga komento.
# isama ang ArduinoJson.h # isama ang DHT_U.h # isama ang DHT.h # isama ang ESP8266WiFi.h # isama ang ESP8266WiFiMulti.h # isama ang 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; float halumigmig = 0; boolean moisture = false; int light = 0; const char * ssid = STASSID; const char * password = STAPSK; const char * mqtt_server = "cmfwqk.messaging.internetofthings.ibmcloud.com"; WiFiClient espClient; PubSubClient client (espClient); mahaba lastMsg = 0; char msg [50]; int halaga = 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-authQ" TICT iot-2 / evt / status / fmt / json "#define MQTT_TOPIC_DISPLAY" iot-2 / cmd / update / fmt / json "#kasama ang" mga pitches.h "// tala sa himig: // durations ng tala: 4 = quarter tala, 8 = ikawalong tala, atbp.: int shortTone = 80; int longTone = 200; int standardDelay = 50; int delayBetweenBars = 50; walang bisa setup_wifi () {pagkaantala (10); // Nagsisimula kami sa pamamagitan ng pagkonekta sa isang WiFi network Serial.println (); Serial.print ("Kumokonekta sa"); Serial.println (ssid); WiFi.begin (ssid, password); habang (WiFi.status ()! = WL_CONNected) {pagkaantala (500); Serial.print ("."); } Serial.println (""); Serial.println ("Konektado sa WiFi"); Serial.println ("IP address:"); Serial.println (WiFi.localIP ()); } void callback (char * topic, byte * payload, unsigned int haba) {Serial.print ("Dumating ang mensahe ["); Serial.print (paksa); Serial.print ("]"); para sa (int i = 0; i <haba; i ++) {Serial.print ((char) payload ); } Serial.println (); StaticJsonDocument jsonBuffer; deserializeJson (jsonBuffer, payload); JsonObject root = jsonBuffer.as (); kung (root ["song"] == "darude") {darude (); } kung (root ["song"] == "starwars") {starwars (); } kung (root ["song"] == "jacques") {Serial.println ("jakakakakakkakaka"); jacques (); }} void reconnect () {// Loop hanggang sa kumonekta ulit kami habang (! client.connected ()) {Serial.print ("Pagtatangka sa koneksyon ng MQTT …"); // Subukang kumonekta kung (client.connect (MQTT_DEVICEID, MQTT_USER, MQTT_TOKEN)) {Serial.println ("konektado"); client.subscribe (MQTT_TOPIC_DISPLAY); } iba pa {Serial.print ("failed, rc ="); Serial.print (client.state ()); Serial.println ("subukang muli sa 5 segundo"); // Maghintay ng 5 segundo bago subukang muli ang pagkaantala (5000); }}} void setup () {Serial.begin (9600); pinMode (moisturePin, INPUT); dht.begin (); pinMode (0, OUTPUT); setup_wifi (); client.setServer (mqtt_server, MQTT_PORT); client.setCallback (callback); pagkaantala (20); } void loop () {if (! client.connected ()) {reconnect (); } client.loop (); kahalumigmigan = digitalRead (moisturePin); ilaw = analogRead (A0); temp = dht.readTemperature (); halumigmig = dht.readHumidity (); Serial.println ("Temperatura =" + String (temp, 1) + "\ nHumidity =" + String (halumigmig, 1) + "\ nMoisture:" + String (kahalumigmigan) + "\ nLight:" + String (light)); String payload = "{" ts / ": {" t / ":" + String (temp, 1) + ", \" h / ":" + String (halumigmig, 1) + "}, \" ms / ": {" m / ":" + String (kahalumigmigan) + "}, \" ls / ": {" l / ":" + String (light) + "}}"; Serial.println (payload); kung (client.publish (MQTT_TOPIC, (char *) payload.c_str ())) {Serial.println ("publish ok"); } iba pa {Serial.println ("Nabigo ang pag-publish"); } pagkaantala (2000); } void darude () {tone (0, NOTE_B3, shortTone); antala (shortTone); noTone (0); antala (standardDelay); tono (0, NOTE_B3, shortTone); antala (shortTone); noTone (0); antala (standardDelay); tono (0, NOTE_B3, shortTone); antala (shortTone); noTone (0); antala (standardDelay); tono (0, NOTE_B3, shortTone); antala (shortTone); noTone (0); antala (standardDelay); tono (0, NOTE_B3, longTone); antala (longTone); noTone (0); antala (delayBetweenBars); tono (0, NOTE_B3, shortTone); antala (shortTone); noTone (0); antala (standardDelay); tono (0, NOTE_B3, shortTone); antala (shortTone); noTone (0); antala (standardDelay); tono (0, NOTE_B3, shortTone); antala (shortTone); noTone (0); antala (standardDelay); tono (0, NOTE_B3, shortTone); antala (shortTone); noTone (0); antala (standardDelay); tono (0, NOTE_B3, shortTone); antala (shortTone); noTone (0); antala (standardDelay); tono (0, NOTE_B3, shortTone); antala (shortTone); noTone (0); antala (standardDelay); tono (0, NOTE_B3, longTone); antala (longTone); noTone (0); antala (standardDelay); tono (0, NOTE_E4, shortTone); antala (shortTone); noTone (0); antala (standardDelay); tono (0, NOTE_E4, shortTone); antala (shortTone); noTone (0); antala (standardDelay); tono (0, NOTE_E4, shortTone); antala (shortTone); noTone (0); antala (standardDelay); tono (0, NOTE_E4, shortTone); antala (shortTone); noTone (0); antala (standardDelay); tono (0, NOTE_E4, shortTone); antala (shortTone); noTone (0); antala (standardDelay); tono (0, NOTE_E4, shortTone); antala (shortTone); noTone (0); antala (standardDelay); tono (0, NOTE_E4, longTone); antala (longTone); noTone (0); antala (standardDelay); tono (0, NOTE_D4, shortTone); antala (shortTone); noTone (0); antala (standardDelay); tono (0, NOTE_D4, shortTone); antala (shortTone); noTone (0); antala (standardDelay); tono (0, NOTE_D4, shortTone); antala (shortTone); noTone (0); antala (standardDelay); tono (0, NOTE_D4, shortTone); antala (shortTone); noTone (0); antala (standardDelay); tono (0, NOTE_D4, shortTone); antala (shortTone); noTone (0); antala (standardDelay); tono (0, NOTE_D4, shortTone); antala (shortTone); noTone (0); antala (standardDelay); tono (0, NOTE_D4, longTone); antala (longTone); noTone (0); antala (standardDelay); tono (0, NOTE_A3, longTone); antala (longTone); noTone (0); antala (standardDelay); tono (0, NOTE_B3, shortTone); antala (shortTone); noTone (0); antala (standardDelay); tono (0, NOTE_B3, shortTone); antala (shortTone); noTone (0); antala (standardDelay); tono (0, NOTE_B3, shortTone); antala (shortTone); noTone (0); antala (standardDelay); tono (0, NOTE_B3, shortTone); antala (shortTone); noTone (0); antala (standardDelay); tono (0, NOTE_B3, longTone); antala (longTone); noTone (0); antala (delayBetweenBars); tono (0, NOTE_B3, shortTone); antala (shortTone); noTone (0); antala (standardDelay); tono (0, NOTE_B3, shortTone); antala (shortTone); noTone (0); antala (standardDelay); tono (0, NOTE_B3, shortTone); antala (shortTone); noTone (0); antala (standardDelay); tono (0, NOTE_B3, shortTone); antala (shortTone); noTone (0); antala (standardDelay); tono (0, NOTE_B3, shortTone); antala (shortTone); noTone (0); antala (standardDelay); tono (0, NOTE_B3, shortTone); antala (shortTone); noTone (0); antala (standardDelay); tono (0, NOTE_B3, longTone); antala (longTone); noTone (0); antala (standardDelay); tono (0, NOTE_E4, longTone); antala (longTone); noTone (0); antala (standardDelay); tono (0, NOTE_B3, shortTone); antala (shortTone); noTone (0); antala (standardDelay); tono (0, NOTE_B3, shortTone); antala (shortTone); noTone (0); antala (standardDelay); tono (0, NOTE_B3, shortTone); antala (shortTone); noTone (0); antala (standardDelay); tono (0, NOTE_B3, shortTone); antala (shortTone); noTone (0); antala (standardDelay); tono (0, NOTE_B3, longTone); antala (longTone); noTone (0); antala (delayBetweenBars); tono (0, NOTE_B3, shortTone); antala (shortTone); noTone (0); antala (standardDelay); tono (0, NOTE_B3, shortTone); antala (shortTone); noTone (0); antala (standardDelay); tono (0, NOTE_B3, shortTone); antala (shortTone); noTone (0); antala (standardDelay); tono (0, NOTE_B3, shortTone); antala (shortTone); noTone (0); antala (standardDelay); tono (0, NOTE_B3, shortTone); antala (shortTone); noTone (0); antala (standardDelay); tono (0, NOTE_B3, shortTone); antala (shortTone); noTone (0); antala (standardDelay); tono (0, NOTE_B3, longTone); antala (longTone); noTone (0); antala (standardDelay); tono (0, NOTE_E4, longTone); antala (longTone); noTone (0); antala (standardDelay); } walang bisa mga starwars () {beep (NOTE_A4, 500); beep (NOTE_A4, 500); beep (NOTE_A4, 500); beep (NOTE_F4, 350); beep (NOTE_C5, 150); beep (NOTE_A4, 500); beep (NOTE_F4, 350); beep (NOTE_C5, 150); beep (NOTE_A4, 650); pagkaantala (500); beep (TANDAAN_E5, 500); beep (TANDAAN_E5, 500); beep (TANDAAN_E5, 500); beep (NOTE_F5, 350); beep (NOTE_C5, 150); beep (NOTE_GS4, 500); beep (NOTE_F4, 350); beep (NOTE_C5, 150); beep (NOTE_A4, 650); } void beep (int note, int duration) {// Play tone on buzzerPin tone (0, tala, tagal); pagkaantala (tagal); noTone (0); antala (standardDelay); } void heartOfCourage () {} void jacques () {beep (NOTE_C4, 500); beep (NOTE_D4, 500); beep (NOTE_E4, 500); beep (NOTE_C4, 500); beep (NOTE_C4, 500); beep (NOTE_D4, 500); beep (NOTE_E4, 500); beep (NOTE_C4, 500); beep (NOTE_E4, 500); beep (NOTE_F4, 500); beep (NOTE_G4, 500); beep (NOTE_E4, 500); beep (NOTE_F4, 500); beep (NOTE_G4, 500); beep (NOTE_G4, 500); beep (NOTE_A4, 500); beep (NOTE_G4, 500); beep (NOTE_F4, 500); beep (NOTE_E4, 500); beep (NOTE_C4, 500); beep (NOTE_G4, 500); beep (NOTE_A4, 500); beep (NOTE_G4, 500); beep (NOTE_F4, 500); beep (NOTE_E4, 500); beep (NOTE_C4, 500); beep (NOTE_C4, 500); beep (NOTE_G4, 500); beep (NOTE_C4, 500); beep (NOTE_C4, 500); beep (NOTE_G4, 500); beep (NOTE_C4, 500); }
Hakbang 3: Ibm Cloud
Kailangan mong mag-set up ng isang halimbawa ng IBM-cloud. Maaari kang makahanap ng impormasyon tungkol dito sa pamamagitan ng link na ito: github.
Hakbang 4: Node-RED
Gumagamit kami ng node-red para sa paghawak ng aming pangkalahatang lohika sa negosyo at upang mailarawan ang data na ito sa isang madaling gamitin na interface ng gumagamit.
Hakbang 5: Pag-set up ng Node-RED: Magaang
I-import ang sumusunod na code sa iyong proyekto.
[{"id": "deb0d57.1c46528", "type": "tab", "label": "Light", "hindi pinagana": false, "info": ""}, {"id": "8a0fcaac. 4e54 "," type ":" ibmiot in "," z ":" deb0d57.1c46528 "," authentication ":" boundService "," apiKey ":" "," inputType ":" evt "," logicalInterface ":" "," rulesId ":" "," deviceId ":" ESP "," applicationId ":" "," deviceType ":" ESP8266 "," eventType ":" + "," commandType ":" "," format ": "json", "name": "Kumuha ng data mula sa ESP", "service": "rehistrado", "allDevices": false, "allApplications": "", "allDeviceTypes": false, "allLogicalInterfaces": "", "allEvents": true, "allCommands": "", "allFormats": "", "qos": 0, "x": 120, "y": 62, "wires":
Hakbang 6: Pag-set up ng Node-RED: Temperatura
I-import ang sumusunod na code sa iyong proyekto.
[{"id": "fbad3799.f0e0e", "type": "tab", "label": "Temperatura", "hindi pinagana": false, "info": ""}, {"id": "b8618eb9. 1c9288 "," type ":" ibmiot in "," z ":" fbad3799.f0e0e "," authentication ":" boundService "," apiKey ":" "," inputType ":" evt "," logicalInterface ":" "," rulesId ":" "," deviceId ":" ESP "," applicationId ":" "," deviceType ":" ESP8266 "," eventType ":" + "," commandType ":" "," format ": "json", "name": "Kumuha ng data mula sa ESP", "service": "rehistrado", "allDevices": false, "allApplications": "", "allDeviceTypes": false, "allLogicalInterfaces": "", "allEvents": totoo, "allCommands": "", "allFormats": "", "qos": 0, "x": 145.5, "y": 49, "wires":
Hakbang 7: Pag-set up ng Node-RED: Humidity
I-import ang sumusunod na code sa iyong proyekto.
[{"id": "144cd53b.c00473", "type": "tab", "label": "Humidity", "hindi pinagana": false, "info": ""}, {"id": "d958f58b. 2678e "," type ":" ibmiot in "," z ":" 144cd53b.c00473 "," authentication ":" boundService "," apiKey ":" "," inputType ":" evt "," logicalInterface ":" "," rulesId ":" "," deviceId ":" ESP "," applicationId ":" "," deviceType ":" ESP8266 "," eventType ":" + "," commandType ":" "," format ": "json", "name": "Kumuha ng data mula sa ESP", "service": "rehistrado", "allDevices": false, "allApplications": "", "allDeviceTypes": false, "allLogicalInterfaces": "", "allEvents": true, "allCommands": "", "allFormats": "", "qos": 0, "x": 142, "y": 87, "wires":
Hakbang 8: Pag-set up ng Node-RED: Kahalumigmigan
I-import ang sumusunod na code sa iyong proyekto.
[{"id": "4ee73536.ec6fc4", "type": "tab", "label": "Moisture", "hindi pinagana": 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 ":" Magpadala ng utos sa ESP "," service ":" rehistrado "," x ": 804.1944580078125," y ": 383.0000305175781," wires ": }, {" id ":" 4134fdb7.18e9b4 "," type ":" ibmiot in ", "z": "4ee73536.ec6fc4", "authentication": "boundService", "apiKey": "", "inputType": "evt", "logicalInterface": "", "ruleId": "", "deviceId": "ESP", "applicationId": "", "deviceType": "ESP8266", "eventType": "update", "commandType": "", "format": "json", "name": "Kumuha ng data mula sa ESP "," service ":" rehistrado "," allDevices ": false," allApplications ":" "," allDeviceTypes ": false," allLogicalInterfaces ":" "," allEvents ": true," allCommands ":" ", "allFormats": false, "qos": 0, "x": 115, "y": 76, "wires":
Hakbang 9: Tapos Na
Binabati kita! mayroon ka na ngayong gumaganang system ng pagmamasid ng halaman.
Kung mayroon kang anumang katanungan, huwag mag-atubiling makipag-ugnay sa amin!