Hello I need your help guys,
In my project I added GPS antenna for finding my device on map.
GPS working well, it showing Latitude and Longitude, direction very well, but I map widget cannot find my device’s location.
I added map widget and linked to this Virtual pin 0;
here is my code.
#define BLYNK_PRINT Serial
//#define BLYNK_DEBUG
#define APP_DEBUG
// Uncomment your board, or configure a custom board in Settings.h
//#define USE_WROVER_BOARD
//#define USE_TTGO_T7
#include "BlynkEdgent.h"
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
static const int RXPin = 16, TXPin = 17;
static const uint32_t GPSBaud = 9600;
TinyGPSPlus gps; // The TinyGPS++ object
WidgetMap myMap(V0);
SoftwareSerial mygps(RXPin, TXPin);
float latitude;
float longitude;
float velocity;
float sats;
String bearing;
unsigned int move_index = 1;
void setup()
{
Serial.begin(115200);
delay(100);
BlynkEdgent.begin();
mygps.begin(GPSBaud);
}
void loop() {
while (mygps.available() > 0)
{
// sketch displays information every time a new sentence is correctly encoded.
if (gps.encode(mygps.read()))
displayInfo();
}
timer.run();
BlynkEdgent.run();
}
void displayInfo()
{
if (gps.location.isValid() )
{
sats = gps.satellites.value(); //get number of satellites
latitude = (gps.location.lat()); //Storing the Lat. and Lon.
longitude = (gps.location.lng());
velocity = gps.speed.kmph(); //get velocity
bearing = TinyGPSPlus::cardinal(gps.course.value()); // get the direction
Serial.print("SATS: ");
Serial.println(sats); // float to x decimal places
Serial.print("LATITUDE: ");
Serial.println(latitude, 6); // float to x decimal places
Serial.print("LONGITUDE: ");
Serial.println(longitude, 6);
Serial.print("SPEED: ");
Serial.print(velocity);
Serial.println("kmph");
Serial.print("DIRECTION: ");
Serial.println(bearing);
Blynk.virtualWrite(V1, String(latitude, 6));
Blynk.virtualWrite(V2, String(longitude, 6));
Blynk.virtualWrite(V3, sats);
Blynk.virtualWrite(V4, velocity);
Blynk.virtualWrite(V5, bearing);
myMap.location(move_index, latitude, longitude, "GPS_Location");
//Blynk.virtualWrite(V0, move_index, latitude, longitude, "GPS_Location");
}
else
{
Serial.println("Location: Not Available");
Blynk.virtualWrite(V1, 0.0000);
Blynk.virtualWrite(V2, 0.0000);
}
Serial.println();
}
Is V0 data stream of String type? It should be either Location or String type for WidgetMap.location to work. If it is of Location type you should use virtualWrite(mPin, lon, lat)
If you want to use a Location data type then you need to switch to using Blynk.virtualWrite(V0, longitude, latitude)
You need to remove the code that takes the GPS reading from your void loop and incorporate it into your displayInfo function, which is now called with a timer.
@drewc228 the command you use should work only via String Data Stream (we support it since legacy blynk for map widget to add several markers), while for Data Stream of Location type it would not work (wont be saved). Location Data Stream requires only lon,lat pair to be sent.