Cov txheej txheem:

Ntsuas Kev Ntsuas: 5 Kauj Ruam
Ntsuas Kev Ntsuas: 5 Kauj Ruam

Video: Ntsuas Kev Ntsuas: 5 Kauj Ruam

Video: Ntsuas Kev Ntsuas: 5 Kauj Ruam
Video: mi noog ntsuag no; nkauj noog hawj 22/5/2023 2024, Kaum ib hlis
Anonim
Ntsuas Kev Ntsuas
Ntsuas Kev Ntsuas

Hauv qhov kev qhia no kuv yuav piav qhia txog kev ntsuas qhov sib thooj ntawm ib lub cuab yeej thiab tshaj tawm qhov muaj txiaj ntsig rau hauv Thingsai, io huab platform los ntawm kev siv lub ntsuas qhov ntsuas thiab esp32 pawg thawj coj loj.

Hall effect sensor yog cov cuab yeej siv los ntsuas qhov loj ntawm qhov chaw sib nqus. Nws qhov hluav taws xob tso tawm ncaj qha ncaj qha rau lub zog sib nqus lub zog los ntawm nws. Hall effect sensors tau siv rau kev hnov qhov sib thooj, qhov chaw nyob, ntsuas kom nrawm, thiab daim ntawv thov tam sim no.

Kauj ruam 1: QHOV TSEEB

QHOV TSEEB
QHOV TSEEB
QHOV TSEEB
QHOV TSEEB
QHOV TSEEB
QHOV TSEEB

Kho vajtse Cheebtsam:

1. Hall Sensor

2. esp32 pawg thawj coj loj

3. Jumper xov hlau

Cheeb Tsam Software:

1. Arduino IDE

2. ThingsIO. AI

Kauj Ruam 2: Kev Sib Txuas:

Kev sib txuas
Kev sib txuas

Hall sensor ---------------------- esp32

Ua tsaug ------------------------------ vp

Gnd ------------------------------- Gn ib

Vcc ------------------------------ 3V3

Kauj ruam 3: CODING:

#suav nrog

#suav nrog

#suav nrog

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

int ntsuas;

int outputpin = A0; // ds18b20

////////////////////////////////////////// Txhua qhov kev ceeb toom

rau CLOUD ////////////////////////////////

const char* tus tswv = "api.thingsai.io"; // LOS YOG host =

devapi2.thethingscloud.com

const char* post_url = "/devices/deviceData"; // LUB

/api/v2/yamcloud2/_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 ///////////////////////////////////////

muab GiveMeTimestamp ()

{

tsis kos npe ntev

timeout = millis ();

// WiFiClient tus thov kev pab;

thaum

(client.available () == 0)

{

yog tias (millis () -

lub sij hawm> 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 = np

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

txuas mus rau WiFi network

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

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 (outputpin);

{

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Xa Xa cov lus nug thiab

YUAV TSUM TSHUAJ RESPONSE /////////////////////////

int ntsuas

= 0;

ntsuas =

hallRead ();Serial.print ("Hall ntsuas ntsuas:");Serial.println (ntsuas);

ncua (1000);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 txaisclient.println ("Tus tswv tsev: 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 ua txoj haujlwm

uas yuav tau txais cov lus teb timestamp los ntawm cov server

Serial.println ("timestamp tau txais");

Serial.println (timestamp);Serial.println ("hauv ThingsCloudPost");

Txoj hlua PostValue =

"{" device_id / ": 61121696007, \" qhev_id / ": 2";

PostValue = Cov

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

PostValue = Cov

PostValue +", \" data / ": {" sib thooj / ":" +ntsuas +"}" +"}";Serial.println (PostValue);

/ * tsim qhov piv txwv ntawm WiFiClientSecure */

WiFiClientSecure tus neeg siv khoom;Serial.println ("Txuas rau server ntawm chaw nres nkoj 443");

yog

(! client.connect (neeg rau zaub mov, 443)) {Serial.println ("Kev sib txuas tsis tau ua tiav!");

lwm yam {Serial.println ("Txuas rau server!");

/* tsim

thov */

client.println ( POST

/khoom siv/ntaus ntawv Cov ntaub ntawv HTTP/1.1 ");client.println ("Tus tswv: api.thingsai.io");//client.println("Connection: kaw ");client.println ("Cov ntsiab lus-Hom: thov/json");client.println ("cache-control: tsis-cache");

client.println ( Tso Cai:

Beear eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9. IjVhMzBkZDFkN2QwYjNhNGQzODkwYzQ4OSI.kaY6OMj5cYlWNqC2PNTkXs9PKy6_m9tdW5client.print ("Cov ntsiab lus-Ntev:");client.println (PostValue.length ());

client.println (); cov.client.println (PostValue);

//////////////////////////////////// POSTING cov ntaub ntawv mus rau

huab tau ua tiav thiab tam sim no tau txais daim ntawv teb huab server //////////////////

Serial.print ( Tos kom teb

);

thaum

(! client.available ()) {

ncua (50);

//Serial.print (".");

}

/* yog cov ntaub ntawv

muaj ces tau txais thiab luam tawm rau Terminal */

thaum

(client.available ()) {

kab 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 ( ////////////////////// Qhov kawg

///////////////////// );

ncua (3000);

}}

Kauj Ruam 4: RESULT:

QHOV TSEEB
QHOV TSEEB

Cov txiaj ntsig uas tau nyeem los ntawm lub ntsuas hluav taws xob tau raug xa mus rau IOT huab tau ua tiav thiab daim duab tau raug tsim los ua qhov sib thooj piv rau lub sijhawm. Nrog rau qhov no ua haujlwm ntawm lub ntsuas cua tau tshuaj xyuas thiab siv raws li thaj chaw xav tau ntawm daim ntawv thov.

Kauj Ruam 5: Ua kom tiav Tutorial:

Qhov no yog qhov haujlwm tiav rau kev ntsuas qhov sib thooj ntawm ib lub cuab yeej los ntawm kev siv cuab yeej sensor esp32 thiab thingsai.io huab platform. Ua tsaug

Pom zoo: