Cov txheej txheem:

LDR Siv Thingsai Cloud: 13 Kauj Ruam
LDR Siv Thingsai Cloud: 13 Kauj Ruam

Video: LDR Siv Thingsai Cloud: 13 Kauj Ruam

Video: LDR Siv Thingsai Cloud: 13 Kauj Ruam
Video: eCME on Management of Anal Cancer 2024, Hlis ntuj nqeg
Anonim
LDR Siv Thingsai Cloud
LDR Siv Thingsai Cloud

HNUB….. hnub no peb yuav kawm txog kev ntsuas qhov hnyav ntawm lub teeb thiab tshaj tawm qhov txiaj ntsig rau hauv THINGSAI IOT huab platform los ntawm kev siv ESP32.

Cov tseev kom ua qhov haujlwm no yog

1. ESP32 Development Board (Kuv tau siv ESP32 DEVKIT V1)

2. LDR sensor

3. Jumper Wires

4. Account hauv THINGSAI IOT PLATFORM

Kauj Ruam 1: Tsim thiab nkag mus rau THINGSIO Platform

Tsim thiab nkag mus rau THINGSIO Platform
Tsim thiab nkag mus rau THINGSIO Platform

Nkag mus rau THINGS AI tus account. Yog tias koj yog tus tshiab ces sau npe rau tus as khauj los ntawm nias lub pob sau npe thiab sau tag nrho cov ntawv pov thawj. Koj tus lej nyiaj yuav raug tsim thiab txij thaum ntawd los koj yuav tuaj yeem ua haujlwm ntawm huab platform thiab tsim koj txoj haujlwm tshwj xeeb

Kauj Ruam 2: Tsim Txoj Haujlwm Tshiab

Tsim Txoj Haujlwm Tshiab
Tsim Txoj Haujlwm Tshiab

Tom qab nkag mus rau hauv tus as khauj, los tsim qhov project tsuas yog nyem rau ntawm qhov haujlwm tshiab thiab tom qab ntawd muab lub npe project.

Kauj Ruam 3: Tsim Tus Ntaus Tshiab

Tsim Tus Ntaus Tshiab
Tsim Tus Ntaus Tshiab

tom qab tsim qhov project yam tom ntej uas koj yuav tsum tau ua yog tsim lub cuab yeej tshiab. Qhia lub npe ntaus ntawv thiab nkag mus rau tus lej ntaus ntawv txawm yog tus kheej lossis lub tshuab tsim.

Kauj Ruam 4: Txheeb Cov Khoom Parameter

Txheeb Cov Khoom Parameter
Txheeb Cov Khoom Parameter

Muab cov cuab yeej ntsuas thiab tom qab ntawd xaiv hom kev ntsuas

Kauj Ruam 5: Hloov Kho Tus Ntaus

Hloov Kho Tus Ntaus
Hloov Kho Tus Ntaus

Xaiv qhov ntsuas thiab tom qab hloov kho lub cuab yeej

Kauj ruam 6: Coding

Coding
Coding

Los ntawm cov qauv piv txwv xaiv cov cai ntawm esp32 luam nws thiab tom qab ntawd muab lo rau hauv arduino IDE thiab hloov qhov tsim nyog raws li qhov xav tau. Kuv tau muab cov cai hauv qab no

#ncig #ncig

#suav nrog

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

tus t; int outputpin = A0; // ds18b20

tus nqi sensor;

//////////////////////////////////////// Txhua qhov kev txiav txim rau CLOUD ////// //////////////////////////

const char* tus tswv = "api.thingsai.io"; // LUB

host = devapi2.thethingscloud.com

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

const char* time_server = "baas.thethingscloud.com"; // qhov no yog los hloov lub sijhawm

const int httpPort = 80;

ua int httpsPort = 443;

const char* neeg rau zaub mov = "api.thingsai.io"; // Neeg rau zaub mov URL

timestamp char [10];

WiFiMulti WiFiMulti;

// Siv chav kawm WiFiClient los tsim kev sib txuas TCP

WiFiClient tus thov kev pab;

/////////////////////////////////////// TIMESTAMP CALCULATION muaj nuj nqi //////// ///////////////////////////////// int GiveMeTimestamp () {unsigned ntev timeout = millis (); // WiFiClient tus thov kev pab;

thaum (client.available () == 0)

{

yog tias (millis () - sijhawm>> 50000)

{

client.stop (); cov. rov 0;

}

}

thaum (client.available ())

{

Txoj hlua kab = client.readStringUntil ('\ r'); // indexOf () yog qhov ua haujlwm los tshawb rau smthng, nws rov qab -1 yog tias tsis pom

int pos = line.indexOf ("\" timestamp / ""); // tshawb rau "\" timestamp / "" txij thaum pib teb tau txais thiab theej tag nrho cov ntaub ntawv tom qab ntawd, nws yuav yog koj lub sijhawm

yog (pos> = 0)

{

int j = 0;

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

{

timestamp [j] = kab [pos + 12 + j];

}

}

}

} ////////////////////////////////////////////////////////////////////////////////////////////////////////

void teeb tsa ()

{

Serial.begin (115200);

ncua (10);

// Peb pib los ntawm kev txuas mus rau WiFi network

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

Serial.println ();

Serial.println ();

Serial.print ("Tos WiFi …");

thaum (WiFiMulti.run ()! = WL_CONNECTED)

{

Serial.print (".");

ncua (500);

}

Serial.println ("");

Serial.println ("Txuas nrog WiFi");

Serial.println ("IP chaw nyob:"); Serial.println (WiFi.localIP ());

ncua (500);

}

void lub voj ()

{

int analogValue = analogRead (tus pin);

{/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Xa tsuas yog lus nug thiab tau txais cov lus teb /// //////////////////////

sensorvalue = analogRead (A0); // nyeem analog input tus pin 0

sensorvalue = tus nqi sensor/100;

Serial.print (sensorvalue, DEC); // luam tawm tus nqi nyeem

Serial.print ("\ n"); // luam qhov chaw nruab nrab ntawm cov lej

ncua (1000); // tos 100ms rau kev nyeem ntawv tom ntej

Serial.print ("txuas rau"); Serial.println (tus tswv tsev); // txhais tau ib sab:- host = devapi2.thethingscloud.com lossis 139.59.26.117

///////////////////////////////////// TIMESTAMP CODE SNIPPET ////////// /////////////////

Serial.println ("sab hauv tau txais timestamp / n");

yog (! client.connect (time_server, {rov qab; //*-*-*-*-*-*-*-*-**

client.println ("Tau txais/api/timestamp HTTP/1.1"); // Qhov haujlwm no ua dab tsi, kuv tsis tau txais client.println ("Host: baas.thethingscloud.com");

client.println ("Cache-Control: tsis-cache");

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

client.println (); cov.

GiveMeTimestamp (); // nws yuav hu lub luag haujlwm uas yuav tau txais lub sijhawm timestamp teb los ntawm server Serial.println ("timestamp tau txais");

Serial.println (timestamp);

Serial.println ("hauv ThingsCloudPost");

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

PostValue = PostValue + ", \" dts / ":" + timestamp;

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

Serial.println (PostValue);

/ * tsim qhov piv txwv ntawm WiFiClientSecure */ WiFiClientSecure tus thov kev pab;

Serial.println ("Txuas rau server ntawm chaw nres nkoj 443");

yog (! client.connect (server, 443))

{

Serial.println ("Kev sib txuas tsis tau ua tiav!");

}

lwm tus

{Serial.println ("Txuas rau server!"); / * tsim kev thov HTTP */

client.println ( POST/pab kiag li lawm/deviceData

client.println ("Tus tswv: api.thingsai.io"); //client.println("Connection: kaw "); cl

ient.println ("Cov ntsiab lus-Hom: thov/json");

client.println ("cache-control: tsis-cache");

client.println ("Kev Tso Cai: BearereyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9. IjVhMzBkZDFkN2QwYjNhNGQzODkwYzQ4OSI.kaY6OMj5cYlWNqC2PNTkXs9Jy9j9" client.print ("Cov ntsiab lus-Ntev:");

client.println (PostValue.length ());

client.println (); cov.

client.println (PostValue); ////////////////////////////////// POSTING cov ntaub ntawv rau ntawm huab tau ua tiav thiab tam sim no tau txais daim ntawv teb huab neeg rau zaub mov ////////////////////

Serial.print ("Tos kom teb");

thaum (! client.available ()) {

ncua (50); //

Serial.print (".");

} / * yog tias muaj cov ntaub ntawv ces txais thiab luam tawm rau Terminal * /

thaum (client.available ())

{

char c = client.read (); cov.

Serial.write (c);

}

/ * yog tias tus neeg rau zaub mov raug txuas, nres tus neeg siv khoom */

yog (! client.connected ())

{

Serial.println ();

Serial.println ("Cov neeg rau zaub mov raug txuas");

client.stop (); cov.

}

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

ncua (3000); }}

Kauj Ruam 7: Xaiv Pawg Thawj Coj thiab Com Port

Xaiv Board thiab Com Port
Xaiv Board thiab Com Port

Los ntawm cov cuab yeej xaiv lub rooj tsavxwm thiab tom qab ntawd xaiv lub com chaw nres nkoj

Kauj Ruam 8: Kev Sib Txuas Circuit

Kev Sib Txuas Circuit
Kev Sib Txuas Circuit
Kev Sib Txuas Circuit
Kev Sib Txuas Circuit
Kev Sib Txuas Circuit
Kev Sib Txuas Circuit

Coding yog ua tiav ces ua cov kev sib txuas hauv qab no raws li tau hais hauv qab no

Kev sib txuas:

GND ntawm esp32 rau GND ntawm LDR sensor

3V3 0f esp32 rau Vcc ntawm LDR

VP ntawm esp32 rau A0 ntawm LDR

Kauj ruam 9: Sau thiab xa tawm

Compile thiab Upload
Compile thiab Upload

suav sau thiab xa cov cai rau hauv esp32 thiab tom qab ntawd nyeem cov ntawv nyeem los ntawm tus saib xyuas. Qhov ntawd yuav qhia qhov tshwm sim zoo li no

Kauj ruam 10: Serial Monitor

Saib Xyuas
Saib Xyuas

Qhov muaj txiaj ntsig tau txais ntawm cov ntawv saib xyuas tom qab ntawd lawv raug xa mus rau THINGSAI IOT Cloud platform.

Kauj ruam 11: Nyeem ntawv

Nyeem
Nyeem

Qhov no qhia pom qhov txiaj ntsig tau los ntawm pawg thawj coj esp32.

Kauj Ruam 12: Cov Duab Sawv Cev

Cov duab sawv cev
Cov duab sawv cev

Nov yog cov duab sawv cev ntawm cov txiaj ntsig tau txais. Ntawd yog qhov kawg ntawm kev qhia. Vam tias koj nkag siab. Ua Tsaug

Pom zoo: