I'm using ESP8266 and Neo-6M , the coordinate variable is sychronizing but the lati and longi variable are not synchronizing.
#include "thingProperties.h"
#include <TinyGPSPlus.h>
#include <SoftwareSerial.h>
// Define the software serial connection to the GPS module
SoftwareSerial ss(D2, D1);
TinyGPSPlus gps;
void setup() {
// Start the hardware serial for debugging
Serial.begin(9600);
// Start the software serial connection to the GPS module
ss.begin(9600);
// Wait for the serial connection to be ready
delay(1500);
Serial.println("GPS Start");
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
// Set the debug message level and print debug info
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
}
void loop() {
while (ss.available() > 0)
if (gps.encode(ss.read()))
displayInfo();
if (millis() > 5000 && gps.charsProcessed() < 10)
{
Serial.println(F("No GPS detected: check wiring."));
while(true);
}
float Lat = gps.location.lat() ;
float Long = gps.location.lng() ;
float lati = gps.location.lat() ;
float longi = gps.location.lng() ;
coordinate = {Lat, Long};
ArduinoCloud.update();
}
void displayInfo(){
//GPS
Serial.print(F("Location: "));
if (gps.location.isValid())
{
Serial.print(gps.location.lat(), 6);
Serial.print(F(","));
Serial.println(gps.location.lng(), 6);
}
else
{
Serial.print(F("INVALID"));
}
}
void onCoordinateChange() {
Location coordinates = coordinate.getValue();
float target_lat = coordinates.lat ;
float target_lon = coordinates.lon ;
Serial.println(coordinates.lat, 6);
Serial.println(coordinates.lon, 6);
Serial.println("Location updated from the cloud.");
}
/*
Since Lati is READ_WRITE variable, onLatiChange() is
executed every time a new value is received from IoT Cloud.
*/
void onLatiChange() {
// Add your code here to act upon Lati change
Location coordinates = coordinate.getValue();
float Lat = coordinates.lat;
Serial.println(coordinates.lat, 6);
}
/*
Since Longi is READ_WRITE variable, onLongiChange() is
executed every time a new value is received from IoT Cloud.
*/
void onLongiChange() {
Location coordinates = coordinate.getValue();
float Long = coordinates.lon ;
Serial.println(coordinates.lon, 6);
}
// Code generated by Arduino IoT Cloud, DO NOT EDIT.
#include <ArduinoIoTCloud.h>
#include <Arduino_ConnectionHandler.h>
const char DEVICE_LOGIN_NAME[] = "463e41fb-43fa-44c2-a000-38c88a588fa0";
const char SSID[] = SECRET_SSID; // Network SSID (name)
const char PASS[] = SECRET_OPTIONAL_PASS; // Network password (use for WPA, or use as key for WEP)
const char DEVICE_KEY[] = SECRET_DEVICE_KEY; // Secret device password
void onLatiChange();
void onLongiChange();
void onCoordinateChange();
float lati;
float longi;
CloudLocation coordinate;
void initProperties(){
ArduinoCloud.setBoardId(DEVICE_LOGIN_NAME);
ArduinoCloud.setSecretDeviceKey(DEVICE_KEY);
ArduinoCloud.addProperty(lati, READWRITE, ON_CHANGE, onLatiChange);
ArduinoCloud.addProperty(longi, READWRITE, ON_CHANGE, onLongiChange);
ArduinoCloud.addProperty(coordinate, READWRITE, ON_CHANGE, onCoordinateChange);
}
WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PASS);