Hi all…i am creating project in which i am using blynk Gps stream widget to get my mobile location on Wemos d1 board when i press 1 on serial monitor… but it kinda not work the way i want…my longitude and lattitude variables always stays zero…i have provided the code below(i know my coding style is way bad and i am trying to improve…yes i am student …and newbie here)…and sorry if my english is bad too…
#define BLYNK_PRINT Serial
#define BLYNK_MAX_SENDBYTES 200
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = "put your own";
char userEmail[] = "put your own";
char ssid[] = "put your own";
char pass[] = "put your own";
float latitude = 0.00;
float longitude= 0.00;
double altitude;
double speed;
byte input_char=0;
long user_input=0;
bool proDebug = 1; // TODO - set to 0 if not debugging
int i=0;
int online;
BLYNK_WRITE(V0) // read virtual pin 0 for co-ordinates
{
latitude = param[0].asDouble();
longitude = param[1].asDouble();
altitude = param[2].asDouble();
speed = param[3].asDouble();
}
void getLocation()
{
if(i == 9)
{
Serial.println("Device unreachable");
i=0;
online = 0;
}
if(i == 0)
{
Serial.println();
Serial.println("press 1 to get phone Location:");
Serial.println();
while(Serial.available() == 0) {Blynk.run();}
while(Serial.available())
{
input_char = Serial.read() - 48;
user_input = user_input * 10 + input_char;
Blynk.run();
}
if(user_input == 1)
{
online = 1;
}
else
{
Serial.println("wrong entry.");
Serial.println();
}
}
if(online == 1)
{
if(latitude != 0.00 && longitude != 0.00) // if co-ordinates are valid
{
//String toSend is the string that will be sent as the emails body
String toSend = "Phone Located! \n received co-ordinates \n LAT ";
toSend += String(latitude, 8);
toSend += " LNG ";
toSend += String(longitude, 8);
toSend += ". View location on: ";
toSend += "www.google.com/maps/?q=";
toSend += String(latitude, 8);
toSend += ",";
toSend += String(longitude, 8);
delay(500);
if(proDebug)
{
Serial.println("Phone geolocation found");
Serial.println("Sending Email...");
Serial.println(toSend);
}
Blynk.email(userEmail, "PhoneLocator | Notification", toSend); // send email
if(proDebug)
{
Serial.println("Success");
Serial.println("Email Sent");
Serial.println("Restarting Protocol");
Serial.println("");
}
delay(500);
i=0;
online = 0;
latitude = 0.00;
longitude= 0.00;
}
else
{
if(i==0 || i == 8)
{
Serial.println("Geolocation not Received");
Serial.println("server responded with");
Serial.println(latitude, 8);
Serial.println(longitude, 8);
Serial.println("");
Serial.println("checking again.");
Serial.println("");
}
i++;
}
//while end
}
input_char=0;
user_input=0;
}
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
delay(1000);
if(proDebug)
{
while(!Serial) {};
delay(1000);
Serial.println("Tracker is online");
Serial.println("");
delay(500);
}
}
void loop()
{
Blynk.run();
getLocation();
}