How can I integrate blynk map widget in this code and monitor real time location?
#define BLYNK_TEMPLATE_ID ****"
#define BLYNK_TEMPLATE_NAME "***"
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <SoftwareSerial.h>
#include <TinyGPS++.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
// Create an instance of the SSD1306 display
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
// Create a SoftwareSerial port for the GPS module
SoftwareSerial gpsSerial(0, 2); // RX = GPIO0 (D3), TX = GPIO2 (D4)
// Create a TinyGPSPlus object
TinyGPSPlus gps;
// Blynk Auth Token
char auth[] = "";
// WiFi credentials
char ssid[] = "";
char pass[] = "";
void setup() {
// Start the hardware serial for debugging
Serial.begin(9600);
Serial.println("Starting up...");
// Start the software serial for GPS communication
gpsSerial.begin(9600);
Serial.println("GPS Serial started.");
// Initialize the display
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;);
}
display.display();
delay(2000); // Pause for 2 seconds
display.clearDisplay();
// Initialize Blynk
Blynk.begin(auth, ssid, pass);
}
void loop() {
// Read data from the GPS module
while (gpsSerial.available() > 0) {
char c = gpsSerial.read();
Serial.write(c); // Print raw GPS data for debugging
// Encode GPS data
if (gps.encode(c)) {
// Check if the GPS location data is updated
if (gps.location.isUpdated()) {
// Read latitude and longitude
float latitude = gps.location.lat();
float longitude = gps.location.lng();
// Print the coordinates to the serial monitor for verification
Serial.print("Latitude: ");
Serial.print(latitude, 6);
Serial.print(" Longitude: ");
Serial.println(longitude, 6);
// Display the coordinates on the OLED
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 10);
display.print("Latitude: ");
display.println(latitude, 6);
display.setCursor(0, 30);
display.print("Longitude: ");
display.println(longitude, 6);
display.display();
// Send coordinates to Blynk
Blynk.virtualWrite(V1, latitude);
Blynk.virtualWrite(V2, longitude);
// Send coordinates to Blynk Map Widget
String locationData = "1," + String(latitude, 6) + "," + String(longitude, 6);
Serial.print("Sending to Blynk Map Widget: ");
Serial.println(locationData); // Debug line to confirm data being sent
Blynk.virtualWrite(V3, locationData);
}
}
}
// Provide feedback if GPS data is not being updated
if (millis() % 10000 == 0) {
Serial.println("Waiting for GPS fix...");
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 10);
display.println("Waiting for GPS fix...");
display.display();
}
Blynk.run();
}
1. List item