Mundarija:

Thingsai.io Iot bulutli platformasi yordamida harakat detektori: 6 qadam
Thingsai.io Iot bulutli platformasi yordamida harakat detektori: 6 qadam

Video: Thingsai.io Iot bulutli platformasi yordamida harakat detektori: 6 qadam

Video: Thingsai.io Iot bulutli platformasi yordamida harakat detektori: 6 qadam
Video: Mavzu: Buyumlar interneti(Internet of Things) texnologiyalari 2024, Noyabr
Anonim
Thingsai.io Iot bulutli platformasi yordamida harakat detektori
Thingsai.io Iot bulutli platformasi yordamida harakat detektori

Ushbu qo'llanmada men PIR sensori va Esp32 yordamida Thingai.io IOT bulutli platformasi yordamida harakatni aniqlash haqida tushuntiraman.

1 -qadam: komponentlar

Komponentlar
Komponentlar
Komponentlar
Komponentlar

QO'ShIMChA KOMPONENTLARI;

1.esp32 Rivojlanish kengashi

2. PIR sensori

3. Jumper simlari

Dasturiy ta'minot:

1. Arduino IDE

2. Thingsai.io hisobi

2 -qadam: Ulanishlar

Ulanishlar
Ulanishlar

Ulanishlar oddiy.

PIR PIN-kodlari ------------ ESP32 PIN-kodlari

Esp32 da VCC ------------------- 3V3

Gp3 ------------------ GND esp32 da

OUT ------------------- D22 esp32 da

3 -qadam: KODLASH

Ushbu kodni Arduino IDE -ga bir oz yangilang va joylashtiring, shunda Motion sensori chiqishni muammosiz beradi.

#qo'shing

#qo'shing

#qo'shing

int soni = 0, i, m, j, k;

int t, t1, t2, t3;

int pin = 22;

//////////////////////////////////////// CLOUD uchun barcha deklaratsiyalar /////// //////////////////////////

const char* host = "api.thingsai.io"; // YOKI host = devapi2.thethingscloud.com

const char* post_url = "/devices/deviceData"; // OR/api/v2/thingscloud2/_table/data_ac

const char* time_server = "baas.thethingscloud.com"; // bu vaqt tamg'asini aylantirish uchun

const int httpPort = 80;

const int httpsPort = 443;

const char* server = "api.thingsai.io"; // Server manzili

char vaqt belgisi [10];

Wi -Fi ko'p tarmoqli WiFi;

// TCP ulanishlarini yaratish uchun WiFiClient sinfidan foydalaning

WiFiClient mijozi;

//////////////////////////////////////////////////////TIMESTAMP HISOBIY HISOBI ///////// ////////////////////////////////

int GiveMeTimestamp ()

{

imzosiz uzoq vaqt tugashi = millis ();

// WiFiClient mijozi;

while (client.available () == 0)

{

if (millis () - tanaffus> 50000)

{

client.stop ();

qaytarish 0;

}

}

while (client.available ())

{

String qatori = client.readStringUntil ('\ r'); // indexOf () -smthngni qidirish funktsiyasi, topilmasa -1 qaytaradi

int pos = line.indexOf ("\" vaqt tamg'asi / ""); // javob boshidan "\" vaqt tamg'asi / "" ni qidiring va shundan so'ng barcha ma'lumotlarni nusxa ko'chiring, bu sizning vaqt tamg'angiz bo'ladi

agar (pos> = 0)

{

int j = 0;

uchun (j = 0; j <10; j ++)

{

vaqt belgisi [j] = chiziq [pos + 12 + j];

}

}

}

}

////////////////////////////////////////////////////////////////////////////////////////////////////////

bo'sh o'rnatish ()

{

Serial.begin (115200);

kechikish (10);

pinMod (pin, INPUT);

// Biz Wi -Fi tarmog'iga ulanishdan boshlaymiz

WiFiMulti.addAP ("wifi_name", "Wifi_password");

Serial.println ();

Serial.println ();

Serial.print ("WiFi kuting …");

esa (WiFiMulti.run ()! = WL_CONNECTED) {

Serial.print (".");

kechikish (500);

}

Serial.println ("");

Serial.println ("Wi -Fi ulangan");

Serial.println ("IP -manzil:");

Serial.println (WiFi.localIP ());

kechikish (500);

}

bo'sh halqa ()

{

int analogValue = analogRead (chiqish pin);

{

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// qism qismlarga javob bering. /////////////////////

{

bool isDetected = digitalRead (pin);

agar (aniqlansa) {

Serial.println ("Mavjudlik aniqlandi");

}

kechikish (500);

}

Serial.print ("ulanish");

Serial.println (mezbon); // teskari aniqlangan:- host = devapi2.thethingscloud.com yoki 139.59.26.117

//////////////////////////////////////////////////// TIMESTAMP KODI SNIPPET /////////// ////////////////

Serial.println ("ichida vaqt tamg'asini olish / n");

if (! client.connect (time_server, {

qaytish; //*-*-*-*-*-*-*-*-*-*-*

}

client.println ("GET/api/vaqt tamg'asi HTTP/1.1"); // Bu qism nima qilyapti, men tushunmadim

client.println ("Xost: baas.thethingscloud.com");

client.println ("Keshni boshqarish: keshsiz");

client.println ("Postman-Token: ea3c18c6-09ba-d049-ccf3-369a22a284b8");

mijoz.println ();

GiveMeTimestamp (); // u serverdan vaqt tamg'asi javobini oladigan funktsiyani chaqiradi

Serial.println ("vaqt tamg'asi qabul qilindi");

Serial.println (vaqt tamg'asi);

Serial.println ("ThingsCloudPost ichida");

String PostValue = "{" device_id / ": 61121695839, \" slave_id / ": 2";

PostValue = PostValue + ", \" dts / ":" + vaqt tamg'asi;

PostValue = PostValue +", \" ma'lumotlar / ": {" PIR / ":" +pin +"}" +"}";

Serial.println (PostValue);

/ * WiFiClientSecure misolini yaratish */

WiFiClientSecure mijozi;

Serial.println ("443 -port orqali serverga ulanish");

if (! client.connect (server, 443)) {

Serial.println ("Ulanish muvaffaqiyatsiz tugadi!");

} boshqa {

Serial.println ("Serverga ulandi!");

/ * HTTP so'rovini yaratish */

client.println ( POST/devices/deviceData

client.println ("Xost: api.thingsai.io");

//client.println("Ulanish: yopish ");

client.println ("Kontent turi: application/json");

client.println ("keshni boshqarish: keshsiz");

client.println ("Avtorizatsiya: egasi eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9. IjVhMzBkZDFkN2QwYjNhNGQzODkwYzQ4OSI.kaY6OMj5cYlWNqC2PNT")

client.print ("Content-Length:");

mijoz.println (PostValue.length ());

mijoz.println ();

client.println (PostValue);

/////////////////////////////////////////////// Bulutga ma'lumotlarni joylashtirish tugallandi va endi bulutdan javob shaklini oling. server ///////////////////

Serial.print ("Javob kutilmoqda");

while (! client.available ()) {

kechikish (50); //

Serial.print (".");

}

/ * agar ma'lumotlar mavjud bo'lsa, qabul qiling va Terminalda chop eting */

while (client.available ()) {

char c = client.read ();

Serial.write (c);

}

/ * agar server uzilgan bo'lsa, mijozni to'xtating */

if (! client.connected ()) {

Serial.println ();

Serial.println ("Server uzilgan"); javascript:;

client.stop ();

}

}

Serial.println ("/////////////////////// Oxiri //////////////////// ");

kechikish (3000);

}

}

4 -qadam: Chiqish

Chiqish
Chiqish

Bu sensordan o'qilgan qiymatlarning shtrixli grafikasi, bushay platformasida.

5 -qadam: Grafik

Grafika
Grafika

Bu sensordan olingan qiymatlarning grafik tasviri. Yuqoridagi grafikdan biz sensorning qo'llanilishini tahlil qilishimiz mumkin. Rahmat

Tavsiya: