Cov txheej txheem:

Qhov Chaw Taug Qab Nrog NodeMCU ESP8266: 10 Kauj Ruam
Qhov Chaw Taug Qab Nrog NodeMCU ESP8266: 10 Kauj Ruam

Video: Qhov Chaw Taug Qab Nrog NodeMCU ESP8266: 10 Kauj Ruam

Video: Qhov Chaw Taug Qab Nrog NodeMCU ESP8266: 10 Kauj Ruam
Video: Thov Txim Qhov Kuv Txav Deb Ntawm Koj (Official Music Video 2022) N. Vajxob Xyooj & N. Vanxay lauj 2024, Kaum ib hlis
Anonim
Qhov Chaw Taug Qab Nrog NodeMCU ESP8266
Qhov Chaw Taug Qab Nrog NodeMCU ESP8266

Koj puas xav paub yuav ua li cas koj NodeMCU tuaj yeem taug qab koj qhov chaw nyob? Nws ua tau, txawm tias tsis muaj GPS module thiab tsis muaj zaub. Cov txiaj ntsig yuav yog tswj hwm qhov chaw koj nyob thiab koj yuav pom lawv hauv koj li kev saib xyuas.

Cov teeb tsa hauv qab no tau siv rau NodeMCU 1.0 (ESP-12E Module) nrog Arduino IDE.

  • Windows 10
  • Arduino IDE v. 1.8.4

Kauj Ruam 1: Koj Xav Tau Dab Tsi

Yam koj xav tau txhawm rau ua raws qhov kev qhia no yog cov hauv qab no:

  • Micro USB kab
  • NodeMCU ESP8266

Ntxiv mus, koj yuav xav tau:

  • Qhov chaw API (los ntawm Cov Xeem Uas Tsis Xav Tau)
  • Nkag mus rau wifi lossis hotspot

Kauj ruam 2: Mus rau Unwired Labs

Mus rau Unwired Labs
Mus rau Unwired Labs

Geolocation los tau yooj yim heev vim tias thaum koj lub GPS poob, koj tseem tuaj yeem siv Geolocation txhawm rau taug qab koj qhov chaw nyob. Peb tus tswv tsev uas muab geolocation, yuav yog https://www.unwiredlabs.com/. Mus rau lub vev xaib ntawd thiab sau npe (khawm txiv kab ntxwv nyob rau sab xis saum toj).

Kauj Ruam 3: Sau Npe Kom Tau Txais API Token

Sau npe kom tau txais API Token
Sau npe kom tau txais API Token

Ntawm nplooj ntawv sau npe, koj yuav tsum sau koj lub npe, email (koj tus lej API yuav xa rau koj tus email) thiab siv rooj plaub (piv txwv li, siv tus kheej). Xaiv koj tus account hom. Cov dawb version yuav ua tau zoo xwb, tab sis nco ntsoov tias koj txwv thiab tsis tuaj yeem taug qab koj qhov chaw 24/7. Cia peb pib!

Kauj Ruam 4: Txheeb Koj Tus Email

Mus rau koj tus email thiab koj yuav pom koj tus lej API. Luam theej API API, vim tias koj xav tau qhov ntawd rau tus lej peb yuav siv. Nov yog qhov email zoo li cas:

Nyob zoo!

Ua tsaug rau npe nrog Unwired Labs LocationAPI! Koj tus lej API yog 'koj tus lej API nyob ntawm no' (tsis hais nqe lus). Qhov no yuav muab 100 qhov kev thov/ hnub pub dawb - mus ib txhis.

Yog tias koj xav taug qab 5 lub cuab yeej pub dawb, thov teb nrog cov lus qhia hauv qab no thiab peb yuav hloov kho koj li nyiaj hauv 12 teev:

1. Kev xa tawm hom (Kho vajtse/ App/ Lwm yam):

2. Txog koj qhov project:

3. Lub Vev Xaib:

Koj tuaj yeem nkag mus rau koj lub dashboard ntawm no: https://unwiredlabs.com/dashboard. Yog tias koj ntsib teeb meem lossis muaj lus nug, teb rau email no thiab kuv yuav pab koj!

Zoo Siab Nrhiav!

Sagar

Lab tsis siv

Kauj Ruam 5: Cov Tsev Qiv Ntawv Koj Yuav Xav Tau

Cov Tsev Qiv Ntawv Koj Yuav Xav Tau
Cov Tsev Qiv Ntawv Koj Yuav Xav Tau

Cov kauj ruam tom ntej yog qhib Arduino thiab mus tswj cov tsev qiv ntawv. Koj yuav tsum teeb tsa lub tsev qiv ntawv ArduinoJson. Lwm lub tsev qiv ntawv twb tau tsim los lawm. Thaum koj npaj tau lawm, koj tuaj yeem pib sau cov cai.

Kauj Ruam 6: Ntxiv Code hauv Arduino los Txuas Nrog LocationAPI

Ua tus kos duab tshiab thiab ntxiv cov cai hauv qab no hauv Arduino. Sau koj tus kheej lub npe wifi/hotspot thiab koj tus password. Muab tshuaj txhuam API token koj tau txais hauv email. Tshaj tawm koj cov cai rau koj li NodeMCU.

#suav nrog

#suav nrog

#suav nrog "ESP8266WiFi.h"

// koj lub network SSID (npe) & tus password network

char myssid = "Koj lub npe wifi/hotspot"; char mypass = "Koj tus password";

// unwiredlabs Hostname & Geolocation Endpoint url

const char* Tus tswv tsev = "www.unwiredlabs.com"; Txoj hlua kawg = "/v2/process.php";

// UnwiredLabs API_Token. Sau npe ntawm no kom tau txais tus lej pub dawb

Txoj hlua token = "d99cccda52ec0b";

Txoj hlua jsonString = "{ n";

// Variables los khaws cov lus teb uas tsis xav tau

ob latitude = 0.0; ob qhov ntev = 0.0; ob qhov tseeb = 0.0;

void teeb tsa () {

Serial.begin (115200);

// Teeb WiFi rau hom chaw nres tsheb thiab txiav tawm ntawm AP yog tias nws tau txuas yav dhau los

WiFi.mode (WIFI_STA); WiFi.disconnect (); Serial.println ("Teeb tsa ua tiav");

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

Serial.print ("Txuas rau"); Serial.println (myssid); WiFi.begin (myssid, mypass);

thaum (WiFi.status ()! = WL_CONNECTED) {

ncua (500); Serial.print ("."); } Serial.println ("."); }

void voj () {

char bssid [6]; DynamicJsonBuffer jsonBuffer;

// WiFi.scanNetworks yuav rov qab pom cov naj npawb ntawm tes hauj lwm

int n = WiFi.scanNetworks (); Serial.println ("ua tiav scan");

yog tias (n == 0) {

Serial.println ("Tsis muaj tes hauj lwm muaj"); } lwm {Serial.print (n); Serial.println ("pom cov network"); }

// tam sim no tsim jsonString…

jsonString = "{ n"; jsonString += "\" token / ": \" "; jsonString += token; jsonString +=" / ", / n"; jsonString += "\" id / ": \" saikirandevice01 / ", / n"; jsonString += "\" wifi / ": [n"; rau (int j = 0; j <n; ++ j) {jsonString += "{ n"; jsonString += "\" bssid / ": \" "; jsonString += (WiFi. BSSIDstr (j)); jsonString +=" / ", / n"; jsonString += "\" teeb liab / ":"; jsonString += WiFi. RSSI (j); jsonString += "\ n"; yog (j <n - 1) {jsonString += "}, / n"; } lwm {jsonString += "} n"; }} jsonString += ("] n"); jsonString += ("} n"); Serial.println (jsonString);

WiFiClientSecure tus neeg siv khoom;

// Txuas rau tus neeg siv khoom thiab ua tus hu api

Serial.println ("Thov URL: https://" + (String) Host + endpoint); yog (client.connect (Tus tswv, 443)) {Serial.println ("Txuas"); client.println ("POST" + endpoint + "HTTP/1.1"); client.println ("Host:" + (String) Host); client.println ("Kev sib txuas: kaw"); client.println ("Cov ntsiab lus-Hom: thov/json"); client.println ("Tus neeg siv-Tus neeg sawv cev: Arduino/1.0"); client.print ("Cov ntsiab lus-Ntev:"); client.println (jsonString.length ()); client.println (); cov. client.print (jsonString); ncua (500); }

// Nyeem thiab txheeb xyuas txhua kab ntawm cov lus teb los ntawm server

thaum (client.available ()) {Txoj kab = client.readStringUntil ('\ r'); JsonObject & hauv paus = jsonBuffer.parseObject (kab); yog (root.success ()) {latitude = root ["lat"]; longitude = hauv paus ["lon"]; raug = paus ["raug"];

Serial.println ();

Serial.print ("Latitude ="); Serial.println (latitude, 6); Serial.print ("Ntev ="); Serial.println (ntev, 6); Serial.print ("Qhov tseeb ="); Serial.println (qhov tseeb); }}

Serial.println ("kaw qhov txuas");

Serial.println (); client.stop (); cov.

ncua (5000);

}

Kauj Ruam 7: Qhib Serial Monitor kom pom yog tias koj txuas nrog

Mus rau cov cuab yeej hauv Arduino thiab qhib qhov saib ua ntej. Txhawm rau saib yog tias koj tau txuas nrog internet, koj yuav tsum pom cov hauv qab no hauv cov ntawv saib xyuas:

Teeb tsa tiav

Txuas rau (koj lub npe wifi)… luam theej duab

Kauj Ruam 8: Tau txais Kev Sib Koom Tes

Yog tias nws ua haujlwm tau zoo, koj yuav tsum pom hauv qab ua tiav tag nrho cov npe ntawm cov ntaub ntawv. Tsuas yog qhov peb xav tau yog tus lej hauv qab qhov thov URL, yog li peb yuav xav tau qhov latitude thiab longitude. Cov no yog cov tswj.

Thov URL:

Txuas

Latitude = 52.385259 TZS

Ntev = 5.196099

Qhov tseeb = 41.00

kaw kev twb kev txuas

Tom qab 5 vib nas this tus lej yuav hloov pauv tas li thiab koj yuav zaum pom qhov latitude, longitude thiab qhov tseeb hloov pauv. Tias yog vim li cas API tau sim nws yog qhov zoo tshaj plaws los taug qab qhov chaw kom raug raws li qhov ua tau.

Kauj ruam 9: Mus rau Google Maps

Mus rau Google Maps
Mus rau Google Maps

Mus rau https://www.google.com/maps/ thiab ntaus koj qhov chaw nyob hauv kab ntawv tshawb fawb. Kev tswj hwm yuav tsum tau sau ua raws li hauv qab no: 52.385259, 5.196099. Google Maps yuav tsum qhia qhov chaw koj nyob ntawm daim duab qhia chaw.

Kauj Ruam 10: Xa Qhov Chaw Rau Koj Lub Txawb

Xa Qhov Chaw Rau Koj Lub Txawb
Xa Qhov Chaw Rau Koj Lub Txawb

Thiab … Koj ua tiav! Yog li, yog tias koj xav xa qhov chaw rau koj lub xov tooj ntawm tes, nws ua tau. Google Maps yuav xa email nrog koj qhov kev tswj hwm yog tias koj xav tau.

Zoo siab nrhiav!

Pom zoo: