What should I add to the below code to update dashboard with location

#include "thingProperties.h"
#include <TinyGPS++.h>

TinyGPSPlus gps;

void setup() {
// Initialize serial and wait for port to open:
Serial.begin(9600);// Serial monitor
Serial1.begin(9600); // Hardware serial for GPS communication
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
delay(1500);

// Defined in thingProperties.h
initProperties();

// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);

/*
The following function allows you to obtain more information
related to the state of network and IoT Cloud connection and errors
the higher number the more granular information you’ll get.
The default is 0 (only errors).
Maximum is 4
*/
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
}

void loop() {
ArduinoCloud.update();
// Your code here
// Check if data is available from the GPS module
while (Serial1.available() > 0) {
gps.encode(Serial1.read()); // Feed the GPS data to the TinyGPS++ library
// If a valid GPS fix is obtained (location updated), get the coordinates
if (gps.location.isUpdated()) {
// Update latitude and longitude cloud variables
latitude = gps.location.lat();
longitude = gps.location.lng();
Serial.print("Latitude: ");
Serial.println(latitude);
Serial.print("Longitude: ");
Serial.println(longitude);
}
}
}

/*
Since Latitude is READ_WRITE variable, onLatitudeChange() is
executed every time a new value is received from IoT Cloud.
*/
void onLatitudeChange() {
// Add your code here to act upon Latitude change
latitude = gps.location.lat();
}

/*
Since Longitude is READ_WRITE variable, onLongitudeChange() is
executed every time a new value is received from IoT Cloud.
*/
void onLongitudeChange() {
// Add your code here to act upon Longitude change
longitude = gps.location.lng();
}

/*
Since Location is READ_WRITE variable, onLocationChange() is
executed every time a new value is received from IoT Cloud.
*/
void onLocationChange() {
// Add your code here to act upon Location change
location =Location (latitude,longitude);
}

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the < CODE/ > icon above the compose window) to make it easier to read and copy for examination

https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum

Posting your code using code tags prevents parts of it being interpreted as HTML coding and makes it easier to copy for examination

In my experience the easiest way to tidy up the code and add the code tags is as follows
Start by tidying up your code by using Tools/Auto Format in the IDE to make it easier to read. Then use Edit/Copy for Forum and paste what was copied in a new reply. Code tags will have been added to the code to make it easy to read in the forum thus making it easier to provide help.

Hi @apurva_s45. It looks like your sketch code already has everything that is needed to set the latitude and longitude Arduino Cloud IoT Variables to the values provided by the GPS module.

Have you added Widgets to your Arduino Cloud IoT dashboard to display the values of the Variables?

Do you see the expected values if you open the Arduino Cloud Editor Serial Monitor while your board is running the Thing sketch?

Yes I have added the widgets to the dashboard and I hv also linked the necessary variables but I'm not seeing any response in dashboard and no I'm not getting any output on serial monitor of cloud

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.