char myssid[] = "dlink"; // your network SSID (name)
char mypass[] = "9819183720"; // your network password
//Credentials for Google GeoLocation API...
const char* Host = "www.googleapis.com";
String thisPage = "/geolocation/v1/geolocate?key=";
String key = "AIzaSyA_hLx4d8ia9wRyit4a4zIBP-DKRpAmDkg";
int status = WL_IDLE_STATUS;
String jsonString = "{\n";
double latitude = 0.0;
double longitude = 0.0;
double accuracy = 0.0;
int more_text = 1; // set to 1 for more debug output
void setup() {
Serial.begin(9600);
Serial.println("Start");
// Set WiFi to station mode and disconnect from an AP if it was previously connected
WiFi.mode(WIFI_STA);
WiFi.disconnect();
delay(100);
Serial.println("Setup done");
// We start by connecting to a WiFi network
Serial.print("Connecting to ");
Serial.println(myssid);
WiFi.begin(myssid, mypass);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println(".");
Firebase.begin( FIREBASE_HOST, FIREBASE_AUTH);
}
void loop() {
char bssid[6];
DynamicJsonBuffer jsonBuffer;
Serial.println("scan start");
// WiFi.scanNetworks will return the number of networks found
int n = WiFi.scanNetworks();
Serial.println("scan done");
if (n == 0)
Serial.println("no networks found");
else
{
Serial.print(n);
Serial.println(" networks found...");
if (more_text) {
// Print out the formatted json...
Serial.println("{");
Serial.println("\"homeMobileCountryCode\": 404,"); // this is a real UK MCC
Serial.println("\"homeMobileNetworkCode\": 20,"); // and a real UK MNC
Serial.println("\"radioType\": \"gsm\","); // for gsm
Serial.println("\"carrier\": \"Vodafone\","); // associated with Vodafone
//Serial.println("\"cellTowers\": ["); // I'm not reporting any cell towers
//Serial.println("],");
Serial.println("\"wifiAccessPoints\": [");
for (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));
if (i < n - 1)
{
Serial.println("},");
}
else
{
Serial.println("}");
}
}
Serial.println("]");
Serial.println("}");
}
Serial.println(" ");
}
// now build the jsonString...
jsonString = "{\n";
jsonString += "\"homeMobileCountryCode\": 234,\n"; // this is a real UK MCC
jsonString += "\"homeMobileNetworkCode\": 27,\n"; // and a real UK MNC
jsonString += "\"radioType\": \"gsm\",\n"; // for gsm
jsonString += "\"carrier\": \"Vodafone\",\n"; // associated with Vodafone
jsonString += "\"wifiAccessPoints\": [\n";
for (int j = 0; j < n; ++j)
{
jsonString += "{\n";
jsonString += "\"macAddress\" : \"";
jsonString += (WiFi.BSSIDstr(j));
jsonString += "\",\n";
jsonString += "\"signalStrength\": ";
jsonString += WiFi.RSSI(j);
jsonString += "\n";
if (j < n - 1)
{
jsonString += "},\n";
}
else
{
jsonString += "}\n";
}
}
jsonString += ("]\n");
jsonString += ("}\n");
//--------------------------------------------------------------------
Serial.println("");
WiFiClientSecure client;
client.setInsecure();
//Connect to the client and make the api call
Serial.print("Requesting URL: ");
Serial.println("https://" + (String)Host + thisPage + "AIzaSyCYNXIYINPmTNIdusMjJloS4_BXSOff1_g");
Serial.println(" ");
//Read and parse all the lines of the reply from server
while (client.available()) {
String line = client.readStringUntil('\r');
if (more_text) {
Serial.print(line);
}
JsonObject& root = jsonBuffer.parseObject(line);
if (root.success()) {
latitude = root["location"]["lat"];
longitude = root["location"]["lng"];
accuracy = root["accuracy"];
}
}
//#include
//#include
//#include
//#include
//#include
//#include
//#include
//#include
//#include
include
include
include "time.h"
define FIREBASE_HOST "bin-latest.firebaseio.com"
define FIREBASE_AUTH "UxBJgEfPoitAhBJqrhP7gIDmY6snCFwsUiylPyFI"
define ARDUINO_ARCH_ESP8266
if defined ARDUINO_ARCH_ESP32 || defined ARDUINO_ARCH_ESP8266
static const char GlobalSignCA[] PROGMEM = R"EOF( -----BEGIN CERTIFICATE----- MIIDgTCCAmkCFHMX5hJGMf6pCAQ7siKXq3qpylYQMA0GCSqGSIb3DQEBCwUAMH0x CzAJBgNVBAYTAklOMRQwEgYDVQQIDAtNYWhhcmFzaHRyYTEPMA0GA1UEBwwGTXVt YmFpMS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KismSxmVjBrFw== -----END CERTIFICATE----- )EOF";
endif
char myssid[] = "dlink"; // your network SSID (name) char mypass[] = "9819183720"; // your network password
//Credentials for Google GeoLocation API... const char* Host = "www.googleapis.com"; String thisPage = "/geolocation/v1/geolocate?key="; String key = "AIzaSyA_hLx4d8ia9wRyit4a4zIBP-DKRpAmDkg";
int status = WL_IDLE_STATUS; String jsonString = "{\n";
double latitude = 0.0; double longitude = 0.0; double accuracy = 0.0; int more_text = 1; // set to 1 for more debug output
void setup() { Serial.begin(9600);
Serial.println("Start"); // Set WiFi to station mode and disconnect from an AP if it was previously connected WiFi.mode(WIFI_STA); WiFi.disconnect(); delay(100); Serial.println("Setup done"); // We start by connecting to a WiFi network Serial.print("Connecting to "); Serial.println(myssid); WiFi.begin(myssid, mypass);
while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(".");
Firebase.begin( FIREBASE_HOST, FIREBASE_AUTH); }
void loop() {
char bssid[6]; DynamicJsonBuffer jsonBuffer; Serial.println("scan start"); // WiFi.scanNetworks will return the number of networks found int n = WiFi.scanNetworks(); Serial.println("scan done"); if (n == 0) Serial.println("no networks found"); else { Serial.print(n); Serial.println(" networks found...");
} // now build the jsonString... jsonString = "{\n"; jsonString += "\"homeMobileCountryCode\": 234,\n"; // this is a real UK MCC jsonString += "\"homeMobileNetworkCode\": 27,\n"; // and a real UK MNC jsonString += "\"radioType\": \"gsm\",\n"; // for gsm jsonString += "\"carrier\": \"Vodafone\",\n"; // associated with Vodafone jsonString += "\"wifiAccessPoints\": [\n"; for (int j = 0; j < n; ++j) { jsonString += "{\n"; jsonString += "\"macAddress\" : \""; jsonString += (WiFi.BSSIDstr(j)); jsonString += "\",\n"; jsonString += "\"signalStrength\": "; jsonString += WiFi.RSSI(j); jsonString += "\n"; if (j < n - 1) { jsonString += "},\n"; } else { jsonString += "}\n"; } } jsonString += ("]\n"); jsonString += ("}\n"); //--------------------------------------------------------------------
Serial.println("");
WiFiClientSecure client; client.setInsecure(); //Connect to the client and make the api call Serial.print("Requesting URL: "); Serial.println("https://" + (String)Host + thisPage + "AIzaSyCYNXIYINPmTNIdusMjJloS4_BXSOff1_g"); Serial.println(" ");
if (client.connect(Host, 443)) { Serial.println("Connected"); client.println("POST " + thisPage + key + " HTTP/1.1"); client.println("Host: " + (String)Host); client.println("Connection: close"); client.println("Content-Type: application/json"); client.println("User-Agent: Arduino/1.0"); client.print("Content-Length: "); client.println(jsonString.length()); client.println(); client.print(jsonString); delay(500); }
//Read and parse all the lines of the reply from server while (client.available()) { String line = client.readStringUntil('\r'); if (more_text) { Serial.print(line); } JsonObject& root = jsonBuffer.parseObject(line); if (root.success()) { latitude = root["location"]["lat"]; longitude = root["location"]["lng"]; accuracy = root["accuracy"]; } }
Serial.println("closing connection"); Serial.println(); client.stop();
Serial.print("Latitude = "); double latt = (latitude); Serial.println(latt); Serial.print("Longitude = "); double longg = (longitude); Serial.println(longg); Serial.print("Accuracy = "); double accuu = (accuracy); Serial.println(accuu);
String latt_to_string=String(latt); String longg_to_string=String(longg); String accuu_to_string=String(accuu); Firebase.pushString("Lamp1/Bin1/Accuracy",accuu_to_string); Firebase.pushString("Lamp1/Bin1/Latitude",latt_to_string); Firebase.pushString("Lamp1/Bin1/Longitude",longg_to_string);
}