Mundarija:

Thingsai Cloud yordamida LDR: 13 qadam
Thingsai Cloud yordamida LDR: 13 qadam

Video: Thingsai Cloud yordamida LDR: 13 qadam

Video: Thingsai Cloud yordamida LDR: 13 qadam
Video: Shoti - LDR 2024, Noyabr
Anonim
Thingsai Cloud yordamida LDR
Thingsai Cloud yordamida LDR

HEY ….. bugun biz ESP32 yordamida yorug'lik intensivligini o'lchash va qiymatlarni THINGSAI IOT bulutli platformasiga joylashtirish haqida bilib olamiz.

Ushbu loyihani amalga oshirish uchun talablar

1. ESP32 ishlab chiqish kengashi (men ESP32 DEVKIT V1 dan foydalanganman)

2. LDR sensori

3. Jumper simlari

4. THINGSAI IOT PLATFORM -dagi hisob

1 -qadam: THINGSIO platformasini yaratish va unga kirish

THINGSIO platformasini yaratish va unga kirish
THINGSIO platformasini yaratish va unga kirish

THINGS AI hisobiga kiring. Agar siz yangi bo'lsangiz, ro'yxatdan o'tish tugmachasini bosib, ro'yxatdan o'ting va barcha hisob ma'lumotlarini to'ldiring. Hisob qaydnomangiz yaratiladi va shu vaqtdan boshlab siz bulutli platformada ishlashingiz va o'zingizning shaxsiy loyihangizni yaratishingiz mumkin bo'ladi

2 -qadam: Yangi loyiha yaratish

Yangi loyiha yaratish
Yangi loyiha yaratish

Hisobga kirgandan so'ng, loyihani yaratish uchun yangi loyihani bosing va keyin loyiha nomini bering.

3 -qadam: Yangi qurilmani yaratish

Yangi qurilmani yaratish
Yangi qurilmani yaratish

Loyihani yaratgandan so'ng, siz yangi qurilmani yaratishingiz kerak. Qurilmaning nomini bering va qurilma identifikatorini qo'lda yoki tizim orqali kiriting.

4 -qadam: qurilma parametrlarini aniqlash

Qurilma parametrlarini aniqlash
Qurilma parametrlarini aniqlash

Qurilma parametrini bering va keyin parametr turini tanlang

5 -qadam: Qurilmani yangilash

Qurilmani yangilash
Qurilmani yangilash

Parametrni tanlang va keyin qurilmani yangilang

6 -qadam: kodlash

Kodlash
Kodlash

Namunaviy kodlardan esp32 kodini tanlang, uni nusxa ko'chiring va keyin arduino IDE -ga joylashtiring va talabga muvofiq kerakli o'zgartirishlarni kiriting. Men kodni quyida berdim

#qo'shing #qo'shing

#qo'shing

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

int t; int chiqish pin = A0; // ds18b20

int sensorli qiymat;

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

const char* host = "api.thingsai.io"; // YoKI

xost = 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 CALCULATION funktsiyasi //////// ///////////////////////////////////////// int GiveMeTimestamp () {unsigned long timeout = 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);

// Biz Wi -Fi tarmog'iga ulanishdan boshlaymiz

WiFiMulti.addAP ("wifi", "pswrd");

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 yozing /// //////////////////////

sensor qiymati = analogRead (A0); // analog kirish pin 0 ni o'qing

sensor qiymati = sensor qiymati/100;

Serial.print (sensor qiymati, DEC); // o'qilgan qiymatni chop etadi

Serial.print ("\ n"); // raqamlar orasidagi bo'shliqni bosib chiqaradi

kechikish (1000); // keyingi o'qish uchun 100ms kuting

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 client.printlnni olmadim ("Xost: baas.thethingscloud.com");

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

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

mijoz.println ();

GiveMeTimestamp (); // u Serial.println serveridan vaqt tamg'asi javobini oladigan funktsiyani chaqiradi ("vaqt tamg'asi qabul qilingan");

Serial.println (vaqt tamg'asi);

Serial.println ("ThingsCloudPost ichida");

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

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

PostValue = PostValue +", \" data / ": {" INTENSITY / ":" +\ sensorvalue +"}" +"}";

Serial.println (PostValue);

/ * WiFiClientSecure misoli yaratish */ WiFiClientSecure mijozi;

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

agar (! 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 "); cl

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

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

client.println ("Avtorizatsiya: BearereyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9. 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 */

agar (! client.connected ())

{

Serial.println ();

Serial.println ("Server uzilgan");

client.stop ();

}

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

kechikish (3000); }}

7 -qadam: Kengash va portni tanlash

Kengash va kom -portni tanlash
Kengash va kom -portni tanlash

Asboblardan taxtani tanlang, so'ngra com portini tanlang

8 -qadam: O'chirish ulanishlari

O'chirish ulanishlari
O'chirish ulanishlari
O'chirish ulanishlari
O'chirish ulanishlari
O'chirish ulanishlari
O'chirish ulanishlari

Kodlash amalga oshiriladi, keyin quyida aytib o'tilganidek, quyidagi ulanishlarni amalga oshiring

Ulanishlar:

Esp32 GND - LDR sensori GND

LDR VC uchun 3V3 0f esp32

LDR A0 ga esp32 VP

9 -qadam: kompilyatsiya va yuklash

Kompilyatsiya qilish va yuklash
Kompilyatsiya qilish va yuklash

kodni esp32 ga to'plang va yuklang, so'ngra ketma -ket monitordan o'qishni o'qing. Bu shunday natijani ko'rsatadi

10 -qadam: ketma -ket monitor

Seriyali monitor
Seriyali monitor

Qiymatlar ketma -ket monitorda olinadi va keyin THINGSAI IOT Cloud platformasiga yuboriladi.

11 -qadam: o'qishlar

O'qishlar
O'qishlar

Bu esp32 kartasidan olingan qiymatlarni ko'rsatadi.

12 -qadam: Grafik tasvir

Grafik tasvir
Grafik tasvir

Bu olingan qiymatlarning grafik tasviri. Darslik shu bilan tugadi. Tushundingiz deb umid qilaman. Rahmat

Tavsiya: