Mündəricat:

PInt@t10n: Ağıllı Bitki İzləmə Sistemi: 9 Addım
PInt@t10n: Ağıllı Bitki İzləmə Sistemi: 9 Addım

Video: PInt@t10n: Ağıllı Bitki İzləmə Sistemi: 9 Addım

Video: PInt@t10n: Ağıllı Bitki İzləmə Sistemi: 9 Addım
Video: ЗАПРЕЩЁННЫЕ ТОВАРЫ с ALIEXPRESS 2023 ШТРАФ и ТЮРЬМА ЛЕГКО! 2024, Iyul
Anonim
PInt@t10n: Ağıllı Bitki İzləmə Sistemi
PInt@t10n: Ağıllı Bitki İzləmə Sistemi

Bu layihə ibm iot buludu üçün bir sınaq olaraq yaradıldı. Ibm buluduna məlumat göndərmək və almaq üçün bir esp-8266 istifadə edirik. Esp və ibm buludu arasındakı əlaqə MQTT vasitəsi ilə baş verir.

Bütün məlumatları idarə etmək və istifadəçiyə istifadəçi interfeysi təqdim etmək üçün node-red istifadə edirik. Çox başlanğıc dostudur.

Başlamaq üçün sizə lazımdır:

  • Esp-8266
  • dht 11/22 temperatur/nəmlik sensoru
  • işığa həssas diod (işığın ölçülməsi)
  • səs -küy
  • torpaq nəm sensoru
  • ibm bulud hesabı

Addım 1: Sensorlarınızı qoşun

Sensorlarınızı birləşdirin
Sensorlarınızı birləşdirin
Sensorlarınızı birləşdirin
Sensorlarınızı birləşdirin
Sensorlarınızı birləşdirin
Sensorlarınızı birləşdirin

Daha əvvəl də qeyd etdiyimiz kimi, sensor məlumatlarını oxumaq və göndərmək üçün esp8266 -dan istifadə edəcəyik. Bu dərs üçün, sensorlarınızı mikro nəzarətçinizə necə bağlayacağınızı bildiyinizi güman edəcəyik. Bir kodu esp8266 -ya necə yükləməyi də artıq bilməlisiniz.

Esp modelimizin yalnız bir analoq portu var, buna görə də işıq sensörümüzdən analoq məlumat almağı seçdik, çünki o zaman bitkinin nə qədər işıq aldığını izləyə bilərik.

Bütün digər sensorlar rəqəmsal olaraq bağlanır. DHT11 sensorumuz məlumatları rəqəmsal olaraq göndərir və sensor məlumatlarını şərh etmək üçün dht kitabxanasından istifadə edirik.

Yuxarıda istifadə etdiyimiz sensorlar üçün bir dövrə diaqramı tapa bilərsiniz. Ancaq unutmayın ki, istifadə etdiyimiz sensorlar tez -tez bir modulla gəlir, buna görə diaqramda daxil etdiyimiz bütün əlavə rezistorlar olmadan onu mikro nəzarətçinizə asanlıqla qoşa bilərsiniz.

Addım 2: Kod

İstifadə etdiyimiz arduino eskizidir. Şərhləri oxusanız kodun necə işlədiyini öyrənə bilərsiniz.

#ArduinoJson.h daxil edin #DHT_U.h daxil edin #DHT.h daxil edin #ESP8266WiFi.h daxil edin #ESP8266WiFiMulti.h daxil edin #PubSubClient.h daxil edin

#define STASSID "ucll-projectweek-IoT" #define STAPSK "Foo4aiHa" #define DHTPin 5 #define moistPin 4 #define DHTType DHT11 DHT dht (DHTPin, DHTType); ESP8266WiFiMulti WiFiMulti; float temp = 0; üzən rütubət = 0; boolean nəm = yalan; int işığı = 0; const char* ssid = STASSID; const char* parol = STAPSK; const char* mqtt_server = "cmfwqk.messaging.internetofthings.ibmcloud.com"; WiFiClient espClient; PubSubClient müştəri (espClient); uzun müddətMsg = 0; char msg [50]; int dəyəri = 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-aQTT_EtTineThenTT_ThenThen #" iot-2/evt/status/fmt/json "#define MQTT_TOPIC_DISPLAY" iot-2/cmd/update/fmt/json "#include" pitches.h "// melodiyada qeydlər: // qeyd müddəti: 4 = dörddəbir qeyd, 8 = səkkizinci qeyd və s.: int shortTone = 80; int longTone = 200; int standardDelay = 50; int delayBetweenBars = 50; void setup_wifi () {gecikmə (10); // WiFi şəbəkəsinə qoşulmaqla başlayırıq Serial.println (); Serial.print ("Bağlanır"); Serial.println (ssid); WiFi.begin (ssid, parol); while (WiFi.status ()! = WL_CONNECTED) {gecikmə (500); Serial.print ("."); } Serial.println (""); Serial.println ("WiFi bağlıdır"); Serial.println ("IP ünvanı:"); Serial.println (WiFi.localIP ()); } boş zəng (char* mövzu, bayt* yük, imzasız int uzunluğu) {Serial.print ("Mesaj gəldi ["); Serial. çap (mövzu); Serial.print ("]"); for (int i = 0; i <uzunluq; i ++) {Serial.print ((char) faydalı yük ); } Serial.println (); StaticJsonDocument jsonBuffer; deserializeJson (jsonBuffer, faydalı yük); JsonObject kökü = jsonBuffer.as (); if (kök ["mahnı"] == "darude") {darude (); } if (kök ["mahnı"] == "ulduz müharibələri") {ulduz müharibələri (); } if (kök ["mahnı"] == "jacques") {Serial.println ("jakakakakakkakaka"); jacques (); }} void reconnect () {// (! client.connected ()) {Serial.print ("MQTT bağlantısı cəhd edilir …"); // Bağlanmağa cəhd edin (client.connect (MQTT_DEVICEID, MQTT_USER, MQTT_TOKEN)) {Serial.println ("bağlı"); client.subscribe (MQTT_TOPIC_DISPLAY); } başqa {Serial.print ("uğursuz oldu, rc ="); Serial.print (client.state ()); Serial.println ("5 saniyə ərzində yenidən cəhd edin"); // Yenidən sınamaq üçün 5 saniyə gözləyin (5000); }}} void setup () {Serial.begin (9600); pinMode (moistPin, INPUT); dht.begin (); pinMode (0, Çıxış); setup_wifi (); client.setServer (mqtt_server, MQTT_PORT); client.setCallback (geri zəng); gecikmə (20); } void loop () {if (! client.connected ()) {reconnect (); } client.loop (); nəm = digitalRead (moistPin); işıq = analogOxu (A0); temp = dht.readTemperature (); rütubət = dht.readHumidity (); Serial.println ("Temperatur =" + String (temp, 1) + "\ nNəm =" + String (rütubət, 1) + "\ nNəm:" + String (nəm) + "\ nİşıq:" + String (işıq)); String yükü = "{" ts / ": {" t / ":"+String (temp, 1)+", \" h / ":"+String (rütubət, 1)+"}, \" ms / ": {" m / ":"+String (nəm)+"}, \" ls / ": {" l / ":"+String (işıq)+"}}"; Serial.println (faydalı yük); if (client.publish (MQTT_TOPIC, (char*) payload.c_str ())) {Serial.println ("tamam dərc et"); } başqa {Serial.println ("yayımlanmadı"); } gecikmə (2000); } void darude () {ton (0, NOTE_B3, qısa ton); gecikmə (qısa ton); noTone (0); gecikmə (standart gecikmə); ton (0, NOTE_B3, qısa ton); gecikmə (qısa ton); noTone (0); gecikmə (standart gecikmə); ton (0, NOTE_B3, qısa ton); gecikmə (qısa ton); noTone (0); gecikmə (standart gecikmə); ton (0, NOTE_B3, qısa ton); gecikmə (qısa ton); noTone (0); gecikmə (standart gecikmə); ton (0, NOTE_B3, uzun ton); gecikmə (uzun ton); noTone (0); gecikmə (delayBetweenBars); ton (0, NOTE_B3, qısa ton); gecikmə (qısa ton); noTone (0); gecikmə (standart gecikmə); ton (0, NOTE_B3, qısa ton); gecikmə (qısa ton); noTone (0); gecikmə (standart gecikmə); ton (0, NOTE_B3, qısa ton); gecikmə (qısa ton); noTone (0); gecikmə (standart gecikmə); ton (0, NOTE_B3, qısa ton); gecikmə (qısa ton); noTone (0); gecikmə (standart gecikmə); ton (0, NOTE_B3, qısa ton); gecikmə (qısa ton); noTone (0); gecikmə (standart gecikmə); ton (0, NOTE_B3, qısa ton); gecikmə (qısa ton); noTone (0); gecikmə (standart gecikmə); ton (0, NOTE_B3, uzun ton); gecikmə (uzun ton); noTone (0); gecikmə (standart gecikmə); ton (0, NOTE_E4, qısa ton); gecikmə (qısa ton); noTone (0); gecikmə (standart gecikmə); ton (0, NOTE_E4, qısa ton); gecikmə (qısa ton); noTone (0); gecikmə (standart gecikmə); ton (0, NOTE_E4, qısa ton); gecikmə (qısa ton); noTone (0); gecikmə (standart gecikmə); ton (0, NOTE_E4, qısa ton); gecikmə (qısa ton); noTone (0); gecikmə (standart gecikmə); ton (0, NOTE_E4, qısa ton); gecikmə (qısa ton); noTone (0); gecikmə (standart gecikmə); ton (0, NOTE_E4, qısa ton); gecikmə (qısa ton); noTone (0); gecikmə (standart gecikmə); ton (0, NOTE_E4, uzun ton); gecikmə (uzun ton); noTone (0); gecikmə (standart gecikmə); ton (0, NOTE_D4, qısa ton); gecikmə (qısa ton); noTone (0); gecikmə (standart gecikmə); ton (0, NOTE_D4, qısa ton); gecikmə (qısa ton); noTone (0); gecikmə (standart gecikmə); ton (0, NOTE_D4, qısa ton); gecikmə (qısa ton); noTone (0); gecikmə (standart gecikmə); ton (0, NOTE_D4, qısa ton); gecikmə (qısa ton); noTone (0); gecikmə (standart gecikmə); ton (0, NOTE_D4, qısa ton); gecikmə (qısa ton); noTone (0); gecikmə (standart gecikmə); ton (0, NOTE_D4, qısa ton); gecikmə (qısa ton); noTone (0); gecikmə (standart gecikmə); ton (0, NOTE_D4, uzun ton); gecikmə (uzun ton); noTone (0); gecikmə (standart gecikmə); ton (0, NOTE_A3, uzun ton); gecikmə (uzun ton); noTone (0); gecikmə (standart gecikmə); ton (0, NOTE_B3, qısa ton); gecikmə (qısa ton); noTone (0); gecikmə (standart gecikmə); ton (0, NOTE_B3, qısa ton); gecikmə (qısa ton); noTone (0); gecikmə (standart gecikmə); ton (0, NOTE_B3, qısa ton); gecikmə (qısa ton); noTone (0); gecikmə (standart gecikmə); ton (0, NOTE_B3, qısa ton); gecikmə (qısa ton); noTone (0); gecikmə (standart gecikmə); ton (0, NOTE_B3, uzun ton); gecikmə (uzun ton); noTone (0); gecikmə (delayBetweenBars); ton (0, NOTE_B3, qısa ton); gecikmə (qısa ton); noTone (0); gecikmə (standart gecikmə); ton (0, NOTE_B3, qısa ton); gecikmə (qısa ton); noTone (0); gecikmə (standart gecikmə); ton (0, NOTE_B3, qısa ton); gecikmə (qısa ton); noTone (0); gecikmə (standart gecikmə); ton (0, NOTE_B3, qısa ton); gecikmə (qısa ton); noTone (0); gecikmə (standart gecikmə); ton (0, NOTE_B3, qısa ton); gecikmə (qısa ton); noTone (0); gecikmə (standart gecikmə); ton (0, NOTE_B3, qısa ton); gecikmə (qısa ton); noTone (0); gecikmə (standart gecikmə); ton (0, NOTE_B3, uzun ton); gecikmə (uzun ton); noTone (0); gecikmə (standart gecikmə); ton (0, NOTE_E4, uzun ton); gecikmə (uzun ton); noTone (0); gecikmə (standart gecikmə); ton (0, NOTE_B3, qısa ton); gecikmə (qısa ton); noTone (0); gecikmə (standart gecikmə); ton (0, NOTE_B3, qısa ton); gecikmə (qısa ton); noTone (0); gecikmə (standart gecikmə); ton (0, NOTE_B3, qısa ton); gecikmə (qısa ton); noTone (0); gecikmə (standart gecikmə); ton (0, NOTE_B3, qısa ton); gecikmə (qısa ton); noTone (0); gecikmə (standart gecikmə); ton (0, NOTE_B3, uzun ton); gecikmə (uzun ton); noTone (0); gecikmə (delayBetweenBars); ton (0, NOTE_B3, qısa ton); gecikmə (qısa ton); noTone (0); gecikmə (standart gecikmə); ton (0, NOTE_B3, qısa ton); gecikmə (qısa ton); noTone (0); gecikmə (standart gecikmə); ton (0, NOTE_B3, qısa ton); gecikmə (qısa ton); noTone (0); gecikmə (standart gecikmə); ton (0, NOTE_B3, qısa ton); gecikmə (qısa ton); noTone (0); gecikmə (standart gecikmə); ton (0, NOTE_B3, qısa ton); gecikmə (qısa ton); noTone (0); gecikmə (standart gecikmə); ton (0, NOTE_B3, qısa ton); gecikmə (qısa ton); noTone (0); gecikmə (standart gecikmə); ton (0, NOTE_B3, uzun ton); gecikmə (uzun ton); noTone (0); gecikmə (standart gecikmə); ton (0, NOTE_E4, uzun ton); gecikmə (uzun ton); noTone (0); gecikmə (standart gecikmə); } boş döyüş ulduzları () {bip (NOTE_A4, 500); səs siqnalı (NOTE_A4, 500); bip (NOTE_A4, 500); səs siqnalı (NOTE_F4, 350); səs siqnalı (NOTE_C5, 150); səs siqnalı (NOTE_A4, 500); səs siqnalı (NOTE_F4, 350); səs siqnalı (NOTE_C5, 150); bip (NOTE_A4, 650); gecikmə (500); bip (NOTE_E5, 500); bip (NOTE_E5, 500); bip (NOTE_E5, 500); səs siqnalı (NOTE_F5, 350); səs siqnalı (NOTE_C5, 150); səs siqnalı (NOTE_GS4, 500); səs siqnalı (NOTE_F4, 350); səs siqnalı (NOTE_C5, 150); bip (NOTE_A4, 650); } boş səs siqnalı (int note, int müddəti) {// BuzzerPin tonunda səs tonu (0, qeyd, müddət); gecikmə (müddəti); noTone (0); gecikmə (standart gecikmə); } void heartOfCourage () {} void jacques () {bip (NOTE_C4, 500); bip (NOTE_D4, 500); bip (NOTE_E4, 500); səs siqnalı (NOTE_C4, 500); səs siqnalı (NOTE_C4, 500); bip (NOTE_D4, 500); bip (NOTE_E4, 500); səs siqnalı (NOTE_C4, 500); bip (NOTE_E4, 500); bip (NOTE_F4, 500); səs siqnalı (NOTE_G4, 500); bip (NOTE_E4, 500); bip (NOTE_F4, 500); səs siqnalı (NOTE_G4, 500); səs siqnalı (NOTE_G4, 500); səs siqnalı (NOTE_A4, 500); səs siqnalı (NOTE_G4, 500); bip (NOTE_F4, 500); bip (NOTE_E4, 500); səs siqnalı (NOTE_C4, 500); səs siqnalı (NOTE_G4, 500); səs siqnalı (NOTE_A4, 500); səs siqnalı (NOTE_G4, 500); bip (NOTE_F4, 500); bip (NOTE_E4, 500); səs siqnalı (NOTE_C4, 500); səs siqnalı (NOTE_C4, 500); səs siqnalı (NOTE_G4, 500); səs siqnalı (NOTE_C4, 500); səs siqnalı (NOTE_C4, 500); səs siqnalı (NOTE_G4, 500); səs siqnalı (NOTE_C4, 500); }

Addım 3: Ibm Cloud

Ibm Bulud
Ibm Bulud

Bir IBM-bulud nümunəsi qurmalısınız. Bu barədə məlumatı bu linkdən əldə edə bilərsiniz: github.

Addım 4: Node-QIRMIZI

Ümumi iş məntiqimizi idarə etmək və bu məlumatları intuitiv bir istifadəçi interfeysində görmək üçün node-red istifadə edirik.

Addım 5: Node-QIRMIZI Quraşdırma: İşıq

Node-QIRMIZI Quraşdırma: İşıq
Node-QIRMIZI Quraşdırma: İşıq

Aşağıdakı kodu layihənizə daxil edin.

[{"id": "deb0d57.1c46528", "type": "tab", "label": "Light", "disabled": false, "info": ""}, {"id": "8a0fcaac. 4e54 "," type ":" ibmiot in "," z ":" deb0d57.1c46528 "," authentication ":" boundService "," apiKey ":" "," inputType ":" evt "," logicalInterface ":" "," ruleId ":" "," deviceId ":" ESP "," applicationId ":" "," deviceType ":" ESP8266 "," eventType ":"+"," commandType ":" "," format ": "json", "name": "ESP -dən məlumat alın", "service": "qeydiyyatdan keçdi", "allDevices": false, "allApplications": "", "allDeviceTypes": false, "allLogicalInterfaces": "", "allEvents": doğru, "allCommands": "", "allFormats": "", "qos": 0, "x": 120, "y": 62, "teller":

Addım 6: Node-QIRMIZI Quraşdırma: Temperatur

Node-QIRMIZI Quraşdırma: Temperatur
Node-QIRMIZI Quraşdırma: Temperatur

Aşağıdakı kodu layihənizə daxil edin.

[{"id": "fbad3799.f0e0e", "type": "tab", "label": "Temperature", "disabled": false, "info": ""}, "" id ":" b8618eb9. 1c9288 "," type ":" ibmiot in "," z ":" fbad3799.f0e0e "," authentication ":" boundService "," apiKey ":" "," inputType ":" evt "," logicalInterface ":" "," ruleId ":" "," deviceId ":" ESP "," applicationId ":" "," deviceType ":" ESP8266 "," eventType ":"+"," commandType ":" "," format ": "json", "name": "ESP -dən məlumat alın", "service": "qeydiyyatdan keçdi", "allDevices": false, "allApplications": "", "allDeviceTypes": false, "allLogicalInterfaces": "", "allEvents": doğru, "allCommands": "", "allFormats": "", "qos": 0, "x": 145.5, "y": 49, "teller":

Addım 7: Node-QIRMIZI Quraşdırma: Rütubət

Node-QIRMIZI Quraşdırma: Rütubət
Node-QIRMIZI Quraşdırma: Rütubət

Aşağıdakı kodu layihənizə daxil edin.

[{"id": "144cd53b.c00473", "type": "tab", "label": "Rütubət", "əlil": yalan, "məlumat": ""}, {"id": "d958f58b. 2678e "," type ":" ibmiot in "," z ":" 144cd53b.c00473 "," authentication ":" boundService "," apiKey ":" "," inputType ":" evt "," logicalInterface ":" "," ruleId ":" "," deviceId ":" ESP "," applicationId ":" "," deviceType ":" ESP8266 "," eventType ":"+"," commandType ":" "," format ": "json", "name": "ESP -dən məlumat alın", "service": "qeydiyyatdan keçdi", "allDevices": false, "allApplications": "", "allDeviceTypes": false, "allLogicalInterfaces": "", "allEvents": doğru, "allCommands": "", "allFormats": "", "qos": 0, "x": 142, "y": 87, "teller":

Addım 8: Node-QIRMIZI Quraşdırma: Nəm

Node-QIRMIZI Quraşdırma: Nəm
Node-QIRMIZI Quraşdırma: Nəm

Aşağıdakı kodu layihənizə daxil edin.

[{"id": "4ee73536.ec6fc4", "type": "tab", "label": "Nəm", "əlil": yalan, "məlumat": ""}, {"id": "a6daac3e. 2d5268 "," type ":" ibmiot out "," z ":" 4ee73536.ec6fc4 "," authentication ":" boundService "," apiKey ":" "," outputType ":" cmd "," deviceId ":" ESP "," deviceType ":" ESP8266 "," eventCommandType ":" yeniləmə "," format ":" json "," data ":" msg "," qos ": 0," name ":" ESP -ə əmr göndər "," xidmət ":" qeydiyyatdan keçdi "," x ": 804.1944580078125," y ": 383.0000305175781," teller ": }, {" id ":" 4134fdb7.18e9b4 "," type ":" ibmiot in ", "z": "4ee73536.ec6fc4", "identifikasiya": "boundService", "apiKey": "", "inputType": "evt", "logicalInterface": "", "ruleId": "", "deviceId": "ESP", "applicationId": "", "deviceType": "ESP8266", "eventType": "update", "commandType": "", "format": "json", "name": "Məlumat əldə edin ESP -dən "," xidmət ":" qeydiyyatdan keçmiş "," allDevices ": yalan," allApplications ":" "," allDeviceTypes ": yalan," allLogicalInterfaces ":" "," allEvents ": doğru," allCommands ":" ", "allFormats": yalan, "qos": 0, "x": 115, "y": 76, "teller":

Addım 9: Hazırsınız

Təbrik edirik! indi işləyən bir bitki müşahidə sisteminiz var.

Hər hansı bir sualınız varsa, bizimlə əlaqə saxlamaqdan çəkinməyin!