Mobile app Map Widget problem

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();
}

1 Like

You seem to have deleted some important stuff from the beginning of the Edgent example sketch.

Also, you shouldn’t be reading your GPS in the void loop, you should be using a timer for this.

What data type have you chosen for your V0 datastream?

Pete.

1 Like

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)

SoftwareSerial mygps(RXPin, TXPin);  
double latitude;     
double longitude;    
float velocity;     
float sats;         
String bearing;     
unsigned int move_index = 1;    
BlynkTimer timer;

void setup()
{
  Serial.begin(115200);
  delay(100);
  BlynkEdgent.begin();
  
  mygps.begin(GPSBaud);
  timer.setInterval(1000L, displayInfo());
}

V0 is location type.
Thank you

Thank you

I added

BlynkTimer timer

void setup()
{
  Serial.begin(115200);
  delay(100);
  BlynkEdgent.begin();
  mygps.begin(GPSBaud);
 
 timer.setInterval(1000L, displayInfo);
}

Do I need take of GPS reading from void loop.

As @BlynkAndroidDev said, with this format of command:

it should be a String data type.

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.

Pete.

I rewrite displayinfo() like this.

void displayInfo() {
  while (mygps.available() > 0) {

    if (gps.encode(mygps.read())) {  
      
      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);

        if (startDevice == 1) {
          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, longitude, latitude, "GPS_Location");
          Blynk.virtualWrite(V0, longitude, latitude);
          //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.print("Date: ");
      if (gps.date.isValid()) {
        Serial.print(gps.date.month());
        Serial.print("/");
        Serial.print(gps.date.day());
        Serial.print("/");
        Serial.println(gps.date.year());
        Date = String(gps.date.day()) + "." + gps.date.month() + "." + gps.date.year();
        if (startDevice == 1) {
          Blynk.virtualWrite(V6, Date);
        }
      } else {
        Serial.println("Not Available");
      }

      Serial.print("Time: ");
      if (gps.time.isValid()) {
        // if (gps.time.hour() < 10)
        // Serial.print(F("0"));
        Serial.print(gps.time.hour() + 5);
        Serial.print(":");
        if (gps.time.minute() < 10)
          Serial.print(F("0"));
        Serial.print(gps.time.minute());
        Serial.print(":");
        if (gps.time.second() < 10)
          Serial.print(F("0"));
        Serial.print(gps.time.second());
        Serial.print(".");
        if (gps.time.centisecond() < 10)
          Serial.print(F("0"));
        Serial.println(gps.time.centisecond());
        Time = String((gps.time.hour() + 5)) + "." + gps.time.minute() + "." + gps.time.second();
        if (startDevice == 1) {
          Blynk.virtualWrite(V7, Time);
        }
      } 
      else {
        Serial.println("Not Available");
      }
      }
  }
  
  
}

In Serial monitor only finding time and date
I don’t know why

14:55:44.652 → Location: Not Available

14:55:45.215 → Date: 6/29/2022

14:55:45.231 → Time: 14:55:44.00

Add some serial print commands to see which of your while and if statements are being met.

I’d personally never use a while command with Blynk, it will lead to disconnections.

Pete.

I did that, antenna started working after few minutes, I got latitude and longitude data. But

Map widget not working. I tried to change V0 from location to String type. Still not working

You can’t use Blynk.virtualWrite(V0, longitude, latitude) with a String data type, that format is just for the Location data type.

Pete.

Try reversing the GPS terms. In my app, the mobile Map widget uses (latitude, longitude), not (longitude, latitude) as needed for the Web Map. Try:

Blynk.virtualWrite(V7, index, latitude, longitude);

@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.

I used myMap.location(move_index, latitude, longitude, “GPS_Location”); code.

Thanks you eyes