Mundarija:
2025 Muallif: John Day | [email protected]. Oxirgi o'zgartirilgan: 2025-01-13 06:58
Bu mening yozgi amaliyot loyiham. Faqat NodeMCU yordamida GPS modulisiz har qanday qurilmaning joylashishini kuzatishimiz mumkinligini eshitganimda, men juda hayron qolaman. Bu orqali biz istalgan qurilmani kuzata olamiz. Shuningdek, biz faqat WiFi orqali qurilmani qanday kuzatishimiz mumkin. Buni tushunish uchun saralash tavsifi.
- · Bu deyarli barcha WiFi -ni tekshiradi.
- · Bu qurilma joylashuvini Google -ga Google API yordamida yuboring
- · Bunga ko'ra, u qurilmangiz joylashuvini aniqlaydi
- · Sizda ushbu loyiha uchun kuchli tarmoq aloqasi mavjud.
1 -qadam: ehtiyot qismlar va asboblar
Qismlar
- NodeMCU (ESP8266 1.0 12E)
- USB kabeli
Asboblar
NodeMcu 1.0 12E platasi bilan Arduino IDE
Google API
2 -qadam: Google API -ni toping
- Brauzeringizni oching va yozing: console.developer.google.com
- Yangi loyiha yarating
- Yangi loyihani yaratgandan so'ng, hisob ma'lumotlarini bosing
- API kalitini bosing
-
Sizning API kalitingiz yaratildi
Oson tushunish uchun quyidagi rasmga qarang |>
3 -qadam: Arduino IDE -da NodeMCu -ni o'rnating
- Arduino IDE-ni quyidagi havoladan yuklab oling: https:// www. Asosiy/dasturiy ta'minot arduino.cc/en/
- Arduino IDE -da Node MCu kartasini qo'shing
-
NodeMCU -ga kod yuklash uchun siz ARDUINO IDE -ga NodeMCu taxtasini qo'shishingiz kerak.
- Arduino IDE -da fayl va afzalliklarga o'ting
- Va Qo'shimcha kengash menejerlari bo'limida quyidagi havolani nusxalash
-
arduino.esp8266.com/stable/package_esp8266c…
- va OK ni bosing
- Kengash yuklab olinadi
- Asboblar va taxtaga o'ting va NodeMCU 1.0 12E ni tanlang
- Tushunish uchun avobe rasmiga qarang
4 -qadam: ArduinoJson kutubxonasini yuklab oling
- Ga o'ting
Sketch o'z ichiga kutubxonani boshqarish kutubxonasini boshqaradi
Qidiruv maydoniga Arduino Json kiriting
ArduinoJson kutubxonasining so'nggi versiyasini yuklab oling
kutubxonani yuklab olgandan so'ng, yopish tugmasini bosing
Dan kutubxona qo'shing
SketchincludeLibraryArduinoJson
5 -qadam: Dastur
Quyidagi dasturni NodeMCU kartasiga yuklang. va ketma -ket monitorda qurilmangiz (NodeMCU 1.0 12E platasi) manzilini ko'ring.
#qo'shing
#qo'shing
#qo'shing
char myssid = "Sizning SSID"; // sizning tarmoq SSID (ismingiz)
char mypass = "Sizning parolingiz"; // tarmoq parolingiz
// Google GeoLocation API uchun hisob ma'lumotlari…
const char* Xost = "www.googleapis.com";
String thisPage = "/geolocation/v1/geolocate? Key =";
// --- Google xaritalarining ap kalitini bu erdan oling:
developers.google.com/maps/documentation/geolocation/intro
String key = "Sizning Google API kalitingiz"; // 2 -qadamdan toping
Ko'rsatma
int holati = WL_IDLE_STATUS;
JsonString qatori = "{ n";
er -xotin kenglik = 0,0;
ikki uzunlik = 0,0;
ikki tomonlama aniqlik = 0,0;
int more_text = 1; // ko'proq disk raskadrovka chiqishi uchun 1 ga sozlang
bo'sh o'rnatish () {
Serial.begin (9600);
Serial.println ("Boshlash");
// Wi -Fi -ni stantsiya rejimiga o'rnating va
agar u ilgari ulangan bo'lsa, APdan uzing
WiFi rejimi (WIFI_STA);
WiFi.disconnect ();
kechikish (100);
Serial.println ( O'rnatish
bajarilgan );
// Biz a ga ulanishdan boshlaymiz
Wi -Fi tarmog'i
Serial.print ( ulanmoqda
);
Serial.println (myssid);
WiFi.begin (myssid, mypass);
esa (WiFi.status ()! = WL_CONNECTED) {
kechikish (500);
Serial.print (".");
}
Serial.println (".");
}
void loop () {
char bssid [6];
DynamicJsonBuffer jsonBuffer;
Serial.println ("skanerlashni boshlash");
// WiFi.scanNetworks qaytadi
topilgan tarmoqlar soni
int n = WiFi.scanNetworks ();
Serial.println ("skandon");
agar (n == 0)
Serial.println ("tarmoqlar topilmadi");
boshqa
{
Serial.print (n);
Serial.println ("tarmoqlar topildi …");
agar (more_text) {
// Formatlangan jsonni chop eting …
Serial.println ("{");
Serial.println ("\" homeMobileCountryCode / ": 234,"); // bu Buyuk Britaniyaning haqiqiy MCC
Serial.println ("\" homeMobileNetworkCode / ": 27,"); // va haqiqiy Buyuk Britaniya MNC
Serial.println ("\" radioType / ": \" gsm / ","); // gsm uchun
Serial.println ("\" tashuvchisi / ": \" Vodafone / ","); // Vodafone bilan bog'liq
Serial.println ("\" cellTowers / ": ["); // Men hech qanday uyali minoralar haqida xabar bermayman
Serial.println ("],");
Serial.println ("\" wifiAccessPoints / ": [");
uchun (int i = 0; i <n; ++ i)
{
Serial.println ("{");
Serial.print ("\" macAddress / ": \" ");
Serial.print (WiFi. BSSIDstr (i));
Serial.println ("\", ");
Serial.print ("\" signalStrength / ":");
Serial.println (WiFi. RSSI (i));
agar (i <n - 1)
{
Serial.println ("},");
}
boshqa
{
Serial.println ("}");
}
}
Serial.println ("]");
Serial.println ("}");
}
Serial.println ("");
}
// endi jsonString -ni yarating …
jsonString = "{ n";
jsonString += "\" homeMobileCountryCode / ": 234, / n"; // bu Buyuk Britaniyaning haqiqiy MCC
jsonString += "\" homeMobileNetworkCode / ": 27, / n"; // va haqiqiy Buyuk Britaniya MNC
jsonString += "\" radioType / ": \" gsm / ", / n"; // gsm uchun
jsonString += "\" tashuvchisi / ": \" Vodafone / ", / n"; // Vodafone bilan bog'liq
jsonString += "\" wifiAccessPoints / ": [ n";
uchun (int j = 0; j <n; ++ j)
{
jsonString += "{ n";
jsonString += "\" macAddress / ": \" ";
jsonString += (WiFi. BSSIDstr (j));
jsonString += "\", / n ";
jsonString += "\" signalStrength / ":";
jsonString += WiFi. RSSI (j);
jsonString += "\ n";
agar (j <n - 1)
{
jsonString += "}, / n";
}
boshqa
{
jsonString += "} n";
}
}
jsonString += ("] n");
jsonString += ("} n");
//--------------------------------------------------------------------
Serial.println ("");
WiFiClientSecure mijozi;
// Mijozga ulaning va api -ga qo'ng'iroq qiling
Serial.print ("URL so'ralmoqda:");
// ---- Bu erda Google Xaritalarning Api kalitini oling, havola:
Serial.println ("https://" + (String) Xost + thisPage + "GOOGLE-MAPS-API-API-KEY-BU YERDA");
Serial.println ("");
if (client.connect (Xost, 443)) {
Serial.println ("Ulangan");
client.println ("POST" + thisPage + key + "HTTP/1.1");
client.println ("Xost:" + (String) Xost);
client.println ("Ulanish: yopish");
client.println ("Kontent turi: application/json");
client.println ("Foydalanuvchi-Agent: Arduino/1.0");
client.print ("Content-Length:");
mijoz.println (jsonString.length ());
mijoz.println ();
client.print (jsonString);
kechikish (500);
}
// Barcha satrlarni o'qing va tahlil qiling
serverdan javob
while (client.available ()) {
String qatori = client.readStringUntil ('\ r');
agar (more_text) {
Serial.print (chiziq);
}
JsonObject & root = jsonBuffer.parseObject (chiziq);
agar (root.success ()) {
kenglik = ildiz ["manzil"] ["lat"];
uzunlik = ildiz ["manzil"] ["lng"];
aniqlik = ildiz ["aniqlik"];
}
}
Serial.println ("yopilish aloqasi");
Serial.println ();
client.stop ();
Serial.print ("Kenglik =");
Serial.println (kenglik, 6);
Serial.print ("Uzunlik =");
Serial.println (uzunlik, 6);
Serial.print ("Aniqlik =");
Serial.println (aniqlik);
kechikish (10000);
Serial.println ();
Serial.println ("Qayta ishga tushirilmoqda …");
Serial.println ();
kechikish (2000);
}