Πίνακας περιεχομένων:

PInt@t10n: Smart Plant Monitoring System: 9 Βήματα
PInt@t10n: Smart Plant Monitoring System: 9 Βήματα

Βίντεο: PInt@t10n: Smart Plant Monitoring System: 9 Βήματα

Βίντεο: PInt@t10n: Smart Plant Monitoring System: 9 Βήματα
Βίντεο: 35 New Ways To Use Common Things 2024, Ιούλιος
Anonim
PInt@t10n: Smart Plant Monitoring System
PInt@t10n: Smart Plant Monitoring System

Αυτό το έργο δημιουργήθηκε ως δοκιμή για το ibm iot cloud. Χρησιμοποιούμε ένα esp-8266 για αποστολή και λήψη δεδομένων από και προς το ibm cloud. Η επικοινωνία μεταξύ του esp και του ibm cloud γίνεται μέσω MQTT.

Για να χειριστούμε όλα τα δεδομένα και να παρουσιάσουμε στο χρήστη μια διεπαφή χρήστη, χρησιμοποιούμε κόμβο-κόκκινο. Είναι πολύ φιλικό για αρχάριους.

Για να ξεκινήσετε χρειάζεστε:

  • Esp-8266
  • dht 11/22 αισθητήρας θερμοκρασίας/υγρασίας
  • φωτοευαίσθητη δίοδος (μέτρηση φωτός)
  • βομβητής
  • αισθητήρας υγρασίας εδάφους
  • ibm λογαριασμός cloud

Βήμα 1: Συνδέστε τους αισθητήρες σας

Συνδέστε τους αισθητήρες σας
Συνδέστε τους αισθητήρες σας
Συνδέστε τους αισθητήρες σας
Συνδέστε τους αισθητήρες σας
Συνδέστε τους αισθητήρες σας
Συνδέστε τους αισθητήρες σας

Όπως αναφέραμε πριν, θα χρησιμοποιήσουμε το esp8266 για να διαβάσουμε και να στείλουμε δεδομένα αισθητήρων. Για αυτό το σεμινάριο θα υποθέσουμε ότι γνωρίζετε πώς να συνδέσετε τους αισθητήρες σας στο μικροελεγκτή σας. Επίσης, πρέπει ήδη να γνωρίζετε πώς να ανεβάζετε κώδικα σε ένα esp8266.

Το μοντέλο esp μας έχει μόνο μία αναλογική θύρα, οπότε επιλέξαμε να λαμβάνουμε αναλογικές πληροφορίες από τον αισθητήρα φωτός γιατί τότε μπορούμε να παρακολουθούμε πόσο φως παίρνει το φυτό.

Όλοι οι άλλοι αισθητήρες συνδέονται ψηφιακά. Ο αισθητήρας DHT11 στέλνει δεδομένα ψηφιακά και χρησιμοποιούμε τη βιβλιοθήκη dht για να ερμηνεύσουμε τα δεδομένα των αισθητήρων.

Πάνω μπορείτε να βρείτε ένα διάγραμμα κυκλώματος για τους αισθητήρες που χρησιμοποιήσαμε. Αλλά λάβετε υπόψη ότι οι αισθητήρες που χρησιμοποιήσαμε συχνά συνοδεύονται από μια μονάδα, ώστε να μπορείτε εύκολα να τη συνδέσετε στο μικροελεγκτή σας χωρίς όλες τις επιπλέον αντιστάσεις που συμπεριλάβαμε στο διάγραμμα.

Βήμα 2: Κωδικός

Αυτό είναι το σκίτσο arduino που χρησιμοποιήσαμε. Μπορείτε να μάθετε πώς λειτουργεί ο κώδικας εάν διαβάσετε τα σχόλια.

#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 humidityPin 4 #define DHTType DHT11 DHT dht (DHTPin, DHTType); ESP8266WiFiMulti WiFiMulti; float temp = 0; υγρασία επίπλευσης = 0; boolean υγρασία = ψευδής? int φως = 0; const char* ssid = STASSID; const char* κωδικός πρόσβασης = STAPSK; const char* mqtt_server = "cmfwqk.messaging.internetofthings.ibmcloud.com"; WiFiClient espClient; Πελάτης PubSubClient (espClient). long lastMsg = 0; char msg [50]; int τιμή = 0; #define MQTT_HOST "cmfwqk.messaging.internetofthings.ibmcloud.com" #define MQTT_PORT 1883 #define MQTT_DEVICEID "d: cmfwqk: ESP8266: ESP" #define MQTT_USERT "MICT" #" iot-2/evt/status/fmt/json "#define MQTT_TOPIC_DISPLAY" iot-2/cmd/update/fmt/json "#include" pitches.h "// σημειώσεις στη μελωδία: // σημειώσεις διάρκειας: 4 = τέταρτο σημείωση, 8 = όγδοη νότα κ.λπ.: int shortTone = 80; int longTone = 200; int standardDelay = 50; int delayBetweenBars = 50; void setup_wifi () {καθυστέρηση (10); // Ξεκινάμε συνδέοντας ένα δίκτυο WiFi Serial.println (); Serial.print ("Σύνδεση σε"); Serial.println (ssid); WiFi.begin (ssid, κωδικός πρόσβασης); while (WiFi.status ()! = WL_CONNECTED) {καθυστέρηση (500); Serial.print ("."); } Serial.println (""); Serial.println ("WiFi συνδεδεμένο"); Serial.println ("Διεύθυνση IP:"); Serial.println (WiFi.localIP ()); } void callback (char* topic, byte* payload, unsigned int length) {Serial.print ("Το μήνυμα έφτασε ["); Serial.print (θέμα); Serial.print ("]"); για (int i = 0; i <μήκος; i ++) {Serial.print ((char) ωφέλιμο φορτίο ); } Serial.println (); StaticJsonDocument jsonBuffer; deserializeJson (jsonBuffer, ωφέλιμο φορτίο)? JsonObject root = jsonBuffer.as (); if (root ["τραγούδι"] == "darude") {darude (); } if (root ["song"] == "starwars") {starwars (); } if (root ["song"] == "jacques") {Serial.println ("jakakakakakkakaka"); ζακ (); }} void επανασύνδεση () {// Βρόχος μέχρι να επανασυνδεθούμε ενώ (! client.connected ()) {Serial.print ("Προσπάθεια σύνδεσης MQTT …"); // Προσπάθεια σύνδεσης if (client.connect (MQTT_DEVICEID, MQTT_USER, MQTT_TOKEN)) {Serial.println ("συνδεδεμένο"); client.subscribe (MQTT_TOPIC_DISPLAY); } else {Serial.print ("απέτυχε, rc ="); Serial.print (client.state ()); Serial.println ("δοκιμάστε ξανά σε 5 δευτερόλεπτα"); // Περιμένετε 5 δευτερόλεπτα πριν επαναλάβετε την καθυστέρηση (5000). }}} void setup () {Serial.begin (9600); pinMode (humidityPin, INPUT); dht.begin (); pinMode (0, OUTPUT); setup_wifi (); client.setServer (mqtt_server, MQTT_PORT); client.setCallback (επανάκληση); καθυστέρηση (20)? } void loop () {if (! client.connected ()) {επανασύνδεση (); } client.loop (); υγρασία = digitalRead (humidityPin); φως = analogRead (A0); temp = dht.readTemperature (); υγρασία = dht.readHumidity (); Serial.println ("Temperature =" + String (temp, 1) + "\ nHumidity =" + String (υγρασία, 1) + "\ n Υγρασία:" + String (υγρασία) + "\ nΦως:" + String (φως)); String payload = "{" ts / ": {" t / ":"+String (temp, 1)+", \" h / ":"+String (υγρασία, 1)+"}, \" ms / ": {" m / ":"+String (υγρασία)+"}, \" ls / ": {" l / ":"+String (light)+"}}"; Serial.println (ωφέλιμο φορτίο); if (client.publish (MQTT_TOPIC, (char*) payload.c_str ())) {Serial.println ("δημοσίευση εντάξει"); } else {Serial.println ("η δημοσίευση απέτυχε"); } καθυστέρηση (2000). } void darude () {tone (0, NOTE_B3, shortTone); καθυστέρηση (shortTone)? noTone (0); καθυστέρηση (standardDelay)? τόνος (0, NOTE_B3, shortTone); καθυστέρηση (shortTone)? noTone (0); καθυστέρηση (standardDelay)? τόνος (0, NOTE_B3, shortTone); καθυστέρηση (shortTone)? noTone (0); καθυστέρηση (standardDelay)? τόνος (0, NOTE_B3, shortTone); καθυστέρηση (shortTone)? noTone (0); καθυστέρηση (standardDelay)? τόνος (0, NOTE_B3, longTone); καθυστέρηση (longTone)? noTone (0); καθυστέρηση (delayBetweenBars)? τόνος (0, NOTE_B3, shortTone); καθυστέρηση (shortTone)? noTone (0); καθυστέρηση (standardDelay)? τόνος (0, NOTE_B3, shortTone); καθυστέρηση (shortTone)? noTone (0); καθυστέρηση (standardDelay)? τόνος (0, NOTE_B3, shortTone); καθυστέρηση (shortTone)? noTone (0); καθυστέρηση (standardDelay)? τόνος (0, NOTE_B3, shortTone); καθυστέρηση (shortTone)? noTone (0); καθυστέρηση (standardDelay)? τόνος (0, NOTE_B3, shortTone); καθυστέρηση (shortTone)? noTone (0); καθυστέρηση (standardDelay)? τόνος (0, NOTE_B3, shortTone); καθυστέρηση (shortTone)? noTone (0); καθυστέρηση (standardDelay)? τόνος (0, NOTE_B3, longTone); καθυστέρηση (longTone)? noTone (0); καθυστέρηση (standardDelay)? τόνος (0, NOTE_E4, shortTone); καθυστέρηση (shortTone)? noTone (0); καθυστέρηση (standardDelay)? τόνος (0, NOTE_E4, shortTone); καθυστέρηση (shortTone)? noTone (0); καθυστέρηση (standardDelay)? τόνος (0, NOTE_E4, shortTone); καθυστέρηση (shortTone)? noTone (0); καθυστέρηση (standardDelay)? τόνος (0, NOTE_E4, shortTone); καθυστέρηση (shortTone)? noTone (0); καθυστέρηση (standardDelay)? τόνος (0, NOTE_E4, shortTone); καθυστέρηση (shortTone)? noTone (0); καθυστέρηση (standardDelay)? τόνος (0, NOTE_E4, shortTone); καθυστέρηση (shortTone)? noTone (0); καθυστέρηση (standardDelay)? τόνος (0, NOTE_E4, longTone); καθυστέρηση (longTone)? noTone (0); καθυστέρηση (standardDelay)? τόνος (0, NOTE_D4, shortTone); καθυστέρηση (shortTone)? noTone (0); καθυστέρηση (standardDelay)? τόνος (0, NOTE_D4, shortTone); καθυστέρηση (shortTone)? noTone (0); καθυστέρηση (standardDelay)? τόνος (0, NOTE_D4, shortTone); καθυστέρηση (shortTone)? noTone (0); καθυστέρηση (standardDelay)? τόνος (0, NOTE_D4, shortTone); καθυστέρηση (shortTone)? noTone (0); καθυστέρηση (standardDelay)? τόνος (0, NOTE_D4, shortTone); καθυστέρηση (shortTone)? noTone (0); καθυστέρηση (standardDelay)? τόνος (0, NOTE_D4, shortTone); καθυστέρηση (shortTone)? noTone (0); καθυστέρηση (standardDelay)? τόνος (0, NOTE_D4, longTone); καθυστέρηση (longTone)? noTone (0); καθυστέρηση (standardDelay)? τόνος (0, NOTE_A3, longTone); καθυστέρηση (longTone)? noTone (0); καθυστέρηση (standardDelay)? τόνος (0, NOTE_B3, shortTone); καθυστέρηση (shortTone)? noTone (0); καθυστέρηση (standardDelay)? τόνος (0, NOTE_B3, shortTone); καθυστέρηση (shortTone)? noTone (0); καθυστέρηση (standardDelay)? τόνος (0, NOTE_B3, shortTone); καθυστέρηση (shortTone)? noTone (0); καθυστέρηση (standardDelay)? τόνος (0, NOTE_B3, shortTone); καθυστέρηση (shortTone)? noTone (0); καθυστέρηση (standardDelay)? τόνος (0, NOTE_B3, longTone); καθυστέρηση (longTone)? noTone (0); καθυστέρηση (delayBetweenBars)? τόνος (0, NOTE_B3, shortTone); καθυστέρηση (shortTone)? noTone (0); καθυστέρηση (standardDelay)? τόνος (0, NOTE_B3, shortTone); καθυστέρηση (shortTone)? noTone (0); καθυστέρηση (standardDelay)? τόνος (0, NOTE_B3, shortTone); καθυστέρηση (shortTone)? noTone (0); καθυστέρηση (standardDelay)? τόνος (0, NOTE_B3, shortTone); καθυστέρηση (shortTone)? noTone (0); καθυστέρηση (standardDelay)? τόνος (0, NOTE_B3, shortTone); καθυστέρηση (shortTone)? noTone (0); καθυστέρηση (standardDelay)? τόνος (0, NOTE_B3, shortTone); καθυστέρηση (shortTone)? noTone (0); καθυστέρηση (standardDelay)? τόνος (0, NOTE_B3, longTone); καθυστέρηση (longTone)? noTone (0); καθυστέρηση (standardDelay)? τόνος (0, NOTE_E4, longTone); καθυστέρηση (longTone)? noTone (0); καθυστέρηση (standardDelay)? τόνος (0, NOTE_B3, shortTone); καθυστέρηση (shortTone)? noTone (0); καθυστέρηση (standardDelay)? τόνος (0, NOTE_B3, shortTone); καθυστέρηση (shortTone)? noTone (0); καθυστέρηση (standardDelay)? τόνος (0, NOTE_B3, shortTone); καθυστέρηση (shortTone)? noTone (0); καθυστέρηση (standardDelay)? τόνος (0, NOTE_B3, shortTone); καθυστέρηση (shortTone)? noTone (0); καθυστέρηση (standardDelay)? τόνος (0, NOTE_B3, longTone); καθυστέρηση (longTone)? noTone (0); καθυστέρηση (delayBetweenBars)? τόνος (0, NOTE_B3, shortTone); καθυστέρηση (shortTone)? noTone (0); καθυστέρηση (standardDelay)? τόνος (0, NOTE_B3, shortTone); καθυστέρηση (shortTone)? noTone (0); καθυστέρηση (standardDelay)? τόνος (0, NOTE_B3, shortTone); καθυστέρηση (shortTone)? noTone (0); καθυστέρηση (standardDelay)? τόνος (0, NOTE_B3, shortTone); καθυστέρηση (shortTone)? noTone (0); καθυστέρηση (standardDelay)? τόνος (0, NOTE_B3, shortTone); καθυστέρηση (shortTone)? noTone (0); καθυστέρηση (standardDelay)? τόνος (0, NOTE_B3, shortTone); καθυστέρηση (shortTone)? noTone (0); καθυστέρηση (standardDelay)? τόνος (0, NOTE_B3, longTone); καθυστέρηση (longTone)? noTone (0); καθυστέρηση (standardDelay)? τόνος (0, NOTE_E4, longTone); καθυστέρηση (longTone)? noTone (0); καθυστέρηση (standardDelay)? } void starwars () {μπιπ (NOTE_A4, 500); μπιπ (NOTE_A4, 500); μπιπ (NOTE_A4, 500); μπιπ (NOTE_F4, 350); μπιπ (NOTE_C5, 150); μπιπ (NOTE_A4, 500); μπιπ (NOTE_F4, 350); μπιπ (NOTE_C5, 150); μπιπ (NOTE_A4, 650); καθυστέρηση (500)? μπιπ (NOTE_E5, 500); μπιπ (NOTE_E5, 500); μπιπ (NOTE_E5, 500); μπιπ (NOTE_F5, 350); μπιπ (NOTE_C5, 150); μπιπ (NOTE_GS4, 500); μπιπ (NOTE_F4, 350); μπιπ (NOTE_C5, 150); μπιπ (NOTE_A4, 650); } void beep (int note, int duration) {// Αναπαραγωγή τόνου στον ήχο buzzerPin (0, σημείωση, διάρκεια). καθυστέρηση (διάρκεια)? noTone (0); καθυστέρηση (standardDelay)? } void heartOfCourage () {} void jacques () {μπιπ (NOTE_C4, 500); μπιπ (NOTE_D4, 500); μπιπ (NOTE_E4, 500); μπιπ (NOTE_C4, 500); μπιπ (NOTE_C4, 500); μπιπ (NOTE_D4, 500); μπιπ (NOTE_E4, 500); μπιπ (NOTE_C4, 500); μπιπ (NOTE_E4, 500); μπιπ (NOTE_F4, 500); μπιπ (NOTE_G4, 500); μπιπ (NOTE_E4, 500); μπιπ (NOTE_F4, 500); μπιπ (NOTE_G4, 500); μπιπ (NOTE_G4, 500); μπιπ (NOTE_A4, 500); μπιπ (NOTE_G4, 500); μπιπ (NOTE_F4, 500); μπιπ (NOTE_E4, 500); μπιπ (NOTE_C4, 500); μπιπ (NOTE_G4, 500); μπιπ (NOTE_A4, 500); μπιπ (NOTE_G4, 500); μπιπ (NOTE_F4, 500); μπιπ (NOTE_E4, 500); μπιπ (NOTE_C4, 500); μπιπ (NOTE_C4, 500); μπιπ (NOTE_G4, 500); μπιπ (NOTE_C4, 500); μπιπ (NOTE_C4, 500); μπιπ (NOTE_G4, 500); μπιπ (NOTE_C4, 500); }

Βήμα 3: Ibm Cloud

Ibm Cloud
Ibm Cloud

Πρέπει να ρυθμίσετε μια παρουσία IBM-cloud. Μπορείτε να βρείτε πληροφορίες σχετικά με αυτό μέσω αυτού του συνδέσμου: github.

Βήμα 4: Κόμβος-ΚΟΚΚΙΝΟ

Χρησιμοποιούμε τον κόμβο-κόκκινο για τον χειρισμό της γενικής επιχειρησιακής λογικής και την απεικόνιση αυτών των δεδομένων σε ένα διαισθητικό περιβάλλον χρήστη.

Βήμα 5: Node-RED Setup: Light

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

Εισαγάγετε τον ακόλουθο κώδικα στο έργο σας.

[{"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": "Λήψη δεδομένων από ESP", "service": "registered", "allDevices": false, "allApplications": "", "allDeviceTypes": false, "allLogicalInterfaces": "", "allEvents": true, "allCommands": "", "allFormats": "", "qos": 0, "x": 120, "y": 62, "wires":

Βήμα 6: Ρύθμιση Node-RED: Θερμοκρασία

Node-RED Setup: Θερμοκρασία
Node-RED Setup: Θερμοκρασία

Εισαγάγετε τον ακόλουθο κώδικα στο έργο σας.

[{"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": "Λήψη δεδομένων από ESP", "service": "registered", "allDevices": false, "allApplications": "", "allDeviceTypes": false, "allLogicalInterfaces": "", "allEvents": true, "allCommands": "", "allFormats": "", "qos": 0, "x": 145.5, "y": 49, "wires":

Βήμα 7: Ρύθμιση Node-RED: Υγρασία

Node-RED Setup: Υγρασία
Node-RED Setup: Υγρασία

Εισαγάγετε τον ακόλουθο κώδικα στο έργο σας.

[{"id": "144cd53b.c00473", "type": "tab", "label": "Humidity", "disabled": false, "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": "Λήψη δεδομένων από ESP", "service": "registered", "allDevices": false, "allApplications": "", "allDeviceTypes": false, "allLogicalInterfaces": "", "allEvents": true, "allCommands": "", "allFormats": "", "qos": 0, "x": 142, "y": 87, "wires":

Βήμα 8: Ρύθμιση Node-RED: Υγρασία

Node-RED Setup: Υγρασία
Node-RED Setup: Υγρασία

Εισαγάγετε τον ακόλουθο κώδικα στο έργο σας.

[{"id": "4ee73536.ec6fc4", "type": "tab", "label": "Moisture", "disabled": false, "info": ""}, {"id": "a6daac3e. 2d5268 "," type ":" ibmiot out "," z ":" 4ee73536.ec6fc4 "," authentication ":" boundService "," apiKey ":" "," outputType ":" cmd "," deviceId ":" ESP "," deviceType ":" ESP8266 "," eventCommandType ":" ενημέρωση "," format ":" json "," data ":" msg "," qos ": 0," name ":" Αποστολή εντολής στο ESP "," service ":" registered "," x ": 804.1944580078125," y ": 383.0000305175781," wires ": }, {" id ":" 4134fdb7.18e9b4 "," type ":" ibmiot in ", "z": "4ee73536.ec6fc4", "authentication": "boundService", "apiKey": "", "inputType": "evt", "logicInterface": "" "," ruleId ":" "," deviceId ": "ESP", "applicationId": "", "deviceType": "ESP8266", "eventType": "update", "commandType": "", "format": "json", "name": "Λήψη δεδομένων από ESP "," service ":" registered "," allDevices ": false," allApplications ":" "," allDeviceTypes ": false," allLogicalInterfaces ":" "", "allEvents": true, "allCommands": "", "allFormats": false, "qos": 0, "x": 115, "y": 76, "wires":

Βήμα 9: Τελείωσες

Συγχαρητήρια! έχετε τώρα ένα σύστημα παρατήρησης εργοστασίου.

Εάν έχετε οποιαδήποτε απορία, μη διστάσετε να επικοινωνήσετε μαζί μας!