Thanks for the response,
both lat and lon are floating point
float lat = 0.0, lon = 0.0;
my function to update GPS
void getGPS()
{
Blynk.virtualWrite(V100, "Getting GPS...");
if (modem.getGPS(&lat, &lon))
{
Serial.printf("lat:%f lon:%f\n", lat, lon);
}
if (lat != 0 && lon != 0)
{
Blynk.virtualWrite(V100, "GPS LOCKED");
Blynk.virtualWrite(V10, lon, lat);
}
else
{
Serial.println("GETTING GPS...");
}
Blynk.virtualWrite(V11, lat);
Blynk.virtualWrite(V12, lon);
}
my switch case:
void action()
{
switch (pinVal)
{
case 0:
Serial.println("All Functions Off!");
Blynk.virtualWrite(V100, "ALL FUNCTION OFF");
Serial.printf("lat:%f lon:%f\n", 0.0, 0.0);
Blynk.virtualWrite(V11, 0);
Blynk.virtualWrite(V12, 0);
break;
case 1:
getGPS();
break;
}
}
Here is a screen shot of my web dashboard:
@PeteKnight The data stream is a “GPS location” as that seems to be the only datastream that the map will take. I have the datastream for location as virtual pin V10.
I am writing to V10 with this code snippet:
Blynk.virtualWrite(V10, lon, lat);
There are not may options that I am seeing as far as configuring goes in the settings, am I missing something?
It says that it wants lat and lon in ‘double’ and in the example only shows values out to 4 decimals.
Maybe I need to make them double??
thanks
Here is my code in entirety if that helps. It is not perfect but it is working in every regard except an accurate GPS.
#include <Arduino.h>
/*************************************************************
Download latest Blynk library here:
https://github.com/blynkkk/blynk-library/releases/latest
Blynk is a platform with iOS and Android apps to control
Arduino, Raspberry Pi and the likes over the Internet.
You can easily build graphic interfaces for all your
projects by simply dragging and dropping widgets.
Downloads, docs, tutorials: http://www.blynk.cc
Sketch generator: http://examples.blynk.cc
Blynk community: http://community.blynk.cc
Follow us: http://www.fb.com/blynkapp
http://twitter.com/blynk_app
Blynk library is licensed under MIT license
This example code is in public domain.
*************************************************************
Attention! Please check out TinyGSM guide:
https://tiny.cc/tinygsm-readme
Change GPRS apm, user, pass, and Blynk auth token to run :)
Feel free to apply it to any other example. It's simple!
*************************************************************/
/* Fill-in your Template ID (only if using Blynk.Cloud) */
// #define BLYNK_TEMPLATE_ID ""
// #define BLYNK_DEVICE_NAME ""
// #define BLYNK_AUTH_TOKEN "";
#define BLYNK_TEMPLATE_ID "********"
#define BLYNK_TEMPLATE_NAME "ESP32 SIM7000"
#define BLYNK_AUTH_TOKEN "*********"
// Select your modem:
#define TINY_GSM_MODEM_SIM7000
Default heartbeat interval for GSM is 60
// If you want override this value, uncomment and set this option:
//#define BLYNK_HEARTBEAT 5
#include <TinyGsmClient.h>
#include <BlynkSimpleTinyGSM.h>
#include <Arduino.h>
#include <Wire.h>
BlynkTimer timer;
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = BLYNK_AUTH_TOKEN;
// Your GPRS credentials
// Leave empty, if missing user or pass
char apn[] = "hologram";
char user[] = "";
char pass[] = "";
#define SerialAT Serial1
#define UART_BAUD 115200
#define PIN_DTR 25
#define PIN_TX 27
#define PIN_RX 26
#define PWR_PIN 4
#define LED_PIN 12
#define BAT_ADC 35
bool reply = false;
int pinVal;
float lat = 0.0, lon = 0.0;
TinyGsm modem(SerialAT);
BLYNK_WRITE(V3)
{
int pinVal = param.asInt();
if (pinVal == 1)
{
digitalWrite(LED_PIN, LOW);
}
else
{
digitalWrite(LED_PIN, HIGH);
}
Serial.println(pinVal);
}
// Syncing the output state with the app at startup
BLYNK_CONNECTED()
{
Blynk.syncVirtual(V0);
Blynk.syncVirtual(V2);
Blynk.syncVirtual(V3);
Blynk.syncVirtual(V10);
Blynk.syncVirtual(V11);
Blynk.syncVirtual(V12);
Blynk.syncVirtual(V100);
}
////////////////////////////////////////// FUNCTIONS //////////////////////////////////////////////////////////////////////////
void getGPS()
{
Blynk.virtualWrite(V100, "Getting GPS...");
if (modem.getGPS(&lat, &lon))
{
Serial.printf("lat:%f lon:%f\n", lat, lon);
}
if (lat != 0 && lon != 0)
{
Blynk.virtualWrite(V100, "GPS LOCKED");
Blynk.virtualWrite(V10, lon, lat);
}
else
{
Serial.println("GETTING GPS...");
}
Blynk.virtualWrite(V11, lat);
Blynk.virtualWrite(V12, lon);
}
BLYNK_WRITE(V0)
{
pinVal = param.asInt();
}
void action()
{
switch (pinVal)
{
case 0:
Serial.println("All Functions Off!");
Blynk.virtualWrite(V100, "ALL FUNCTION OFF");
Serial.printf("lat:%f lon:%f\n", 0.0, 0.0);
Blynk.virtualWrite(V11, 0);
Blynk.virtualWrite(V12, 0);
break;
case 1:
getGPS();
pinVal = pinVal;
break;
}
}
float readBattery(uint8_t pin)
{
int vref = 1100;
uint16_t volt = analogRead(pin);
float battery_voltage = ((float)volt / 4095.0) * 2.0 * 3.3 * (vref);
return battery_voltage;
}
void batteryLevel()
{
float mv = readBattery(BAT_ADC);
Serial.print("mv :");
Serial.println(mv);
Blynk.virtualWrite(V2, ((mv / 4200) * 100));
}
//////////////////////////////////////////// SET UP //////////////////////////////////////////////////////////////////////////////
void setup()
{
Serial.begin(115200); // Set console baud rate
delay(100);
// Set LED OFF
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, LOW);
pinMode(PWR_PIN, OUTPUT);
digitalWrite(PWR_PIN, HIGH);
delay(300);
digitalWrite(PWR_PIN, LOW);
Serial.println("\nPlease Wait...");
delay(1000);
SerialAT.begin(UART_BAUD, SERIAL_8N1, PIN_RX, PIN_TX);
// Restart takes quite some time
// To skip it, call init() instead of restart()
Serial.println("Initializing modem...");
if (!modem.init())
{
Serial.println("Failed to initialize modem, attempting to continue with restarting");
modem.restart();
}
String name = modem.getModemName();
delay(500);
Serial.println("Modem Name: " + name);
modem.sendAT("+SGPIO=0,4,1,1"); // Turns on active antenna for GPS
while (modem.waitResponse(10000L) != 1)
{
Serial.println(" GPS NOT Powered ");
delay(50);
modem.sendAT("+SGPIO=0,4,1,1");
}
Serial.println("GPS Antenna Powered!");
while (!modem.enableGPS()) // Turns on GPS
{
Serial.println("GPS not activacted, trying again...");
delay(50);
}
Serial.println("GPS ACTIVATED!");
Blynk.begin(auth, modem, apn, user, pass);
// Setup a functions to be called
timer.setInterval(10000L, batteryLevel);
timer.setInterval(3000L, action);
}
//////////////////////////////////////// MAIN LOOP /////////////////////////////////////////////////////////////////////
void loop()
{
Blynk.run();
timer.run();
}