mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-30 03:49:13 +03:00
changes
This commit is contained in:
52
lib/WifiLocation/examples/googleLocation/googleLocation.ino
Normal file
52
lib/WifiLocation/examples/googleLocation/googleLocation.ino
Normal file
@@ -0,0 +1,52 @@
|
||||
|
||||
#include <Arduino.h>
|
||||
#ifdef ARDUINO_ARCH_SAMD
|
||||
#include <WiFi101.h>
|
||||
#elif defined ARDUINO_ARCH_ESP8266
|
||||
#include <ESP8266WiFi.h>
|
||||
#elif defined ARDUINO_ARCH_ESP32
|
||||
#include <WiFi.h>
|
||||
#else
|
||||
#error Wrong platform
|
||||
#endif
|
||||
|
||||
#include <WifiLocation.h>
|
||||
|
||||
const char* googleApiKey = "YOUR_GOOGLE_API_KEY";
|
||||
const char* ssid = "SSID";
|
||||
const char* passwd = "PASSWD";
|
||||
|
||||
WifiLocation location(googleApiKey);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
// Connect to WPA/WPA2 network
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
WiFi.mode(WIFI_MODE_STA);
|
||||
#endif
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
WiFi.mode(WIFI_STA);
|
||||
#endif
|
||||
WiFi.begin(ssid, passwd);
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
Serial.print("Attempting to connect to WPA SSID: ");
|
||||
Serial.println(ssid);
|
||||
// wait 5 seconds for connection:
|
||||
Serial.print("Status = ");
|
||||
Serial.println(WiFi.status());
|
||||
delay(500);
|
||||
}
|
||||
location_t loc = location.getGeoFromWiFi();
|
||||
|
||||
Serial.println("Location request data");
|
||||
Serial.println(location.getSurroundingWiFiJson());
|
||||
Serial.println("Latitude: " + String(loc.lat, 7));
|
||||
Serial.println("Longitude: " + String(loc.lon, 7));
|
||||
Serial.println("Accuracy: " + String(loc.accuracy));
|
||||
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user