Hi Guys ,
MKR 1500 with GPS shield attached. Sketch Example Arduino_MKRGPS GPSlocation.ino
GPS coordinates ( altitude , longitude ) shows all 0 . any help will be appreciated .
/*
Sketch generated by the Arduino IoT Cloud Thing "Untitled"
https://create.arduino.cc/cloud/things/84b0b52f-20a4-4f0e-bf93-2bb09584fa83
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
CloudLocation coordinates;
Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
which are called when their values are changed from the Dashboard.
These functions are generated with the Thing and added at the end of this sketch.
*/
#include <Arduino_MKRGPS.h>
#include "thingProperties.h"
void setup() {
// initialize serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
// If you are using the MKR GPS as shield, change the next line to pass
// the GPS_MODE_SHIELD parameter to the GPS.begin(...)
if (!GPS.begin()) {
Serial.println("Failed to initialize GPS!");
while (1);
}
else Serial.println("GPS Ready");
// 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
float lat = GPS.latitude();
float lon = GPS.longitude();
//coordinates = Location(GPS.latitude(),GPS.longitude());
coordinates = Location(lat, lon);
// print GPS values
Serial.print("Location: ");
Serial.print(lat, 7);
Serial.print(", ");
Serial.println(lon, 7);
}
For informed help, please read and follow the instructions in the "How to get the best out of this forum" post, linked at the head of every forum category.
Explain your setup, post links to devices, post all the code, using code tags, (for text as well), and avoid posting illegible screenshots.
By the way, you need to be outside, with a clear view of the sky, for a GPS to work.
Thanks for your Replay:
I modified the sketch here is the original code .
/*
GPS Location
This sketch uses the GPS to determine the location of the board
and prints it to the Serial monitor.
Circuit:
- MKR board
- MKR GPS attached via I2C cable
This example code is in the public domain.
*/
#include <Arduino_MKRGPS.h>
void setup() {
// initialize serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
// If you are using the MKR GPS as shield, change the next line to pass
// the GPS_MODE_SHIELD parameter to the GPS.begin(...)
if (!GPS.begin()) {
Serial.println("Failed to initialize GPS!");
while (1);
}
}
void loop() {
// check if there is new GPS data available
if (GPS.available()) {
// read GPS values
float latitude = GPS.latitude();
float longitude = GPS.longitude();
float altitude = GPS.altitude();
float speed = GPS.speed();
int satellites = GPS.satellites();
// print GPS values
Serial.print("Location: ");
Serial.print(latitude, 7);
Serial.print(", ");
Serial.println(longitude, 7);
Serial.print("Altitude: ");
Serial.print(altitude);
Serial.println("m");
Serial.print("Ground speed: ");
Serial.print(speed);
Serial.println(" km/h");
Serial.print("Number of satellites: ");
Serial.println(satellites);
Serial.println();
}
}
this code works fine without uploading it to the cloud. I get error if uploaded to cloud and add Variable . that why I modify it but now getting gps coordinate all 0 .
This is what happen when I added that code inside the loop. if (GPS.available()) {
when I remove this code if (GPS.available()) { ....I get altitude longitude all 0
void loop() {
ArduinoCloud.update();
// Your code here
// Check if there is new GPS data available
if (GPS.available()) {
Connected to GPRS Network
ArduinoIoTCloudTCP::handle_ConnectMqttBroker could not connect to mqtts-sa.iot.arduino.cc:8883
ArduinoIoTCloudTCP::handle_ConnectMqttBroker 1 connection attempt at tick time 20451
ArduinoIoTCloudTCP::handle_ConnectMqttBroker could not connect to mqtts-sa.iot.arduino.cc:8883
ArduinoIoTCloudTCP::handle_ConnectMqttBroker 2 connection attempt at tick time 29252
ArduinoIoTCloudTCP::handle_ConnectMqttBroker could not connect to mqtts-sa.iot.arduino.cc:8883
ArduinoIoTCloudTCP::handle_ConnectMqttBroker 3 connection attempt at tick time 42191
ArduinoIoTCloudTCP::handle_ConnectMqttBroker could not connect to mqtts-sa.iot.arduino.cc:8883
ArduinoIoTCloudTCP::handle_ConnectMqttBroker 4 connection attempt at tick time 63091
ArduinoIoTCloudTCP::handle_ConnectMqttBroker could not connect to mqtts-sa.iot.arduino.cc:8883
ArduinoIoTCloudTCP::handle_ConnectMqttBroker 5 connection attempt at tick time 100258
ArduinoIoTCloudTCP::handle_ConnectMqttBroker could not connect to mqtts-sa.iot.arduino.cc:8883
ArduinoIoTCloudTCP::handle_ConnectMqttBroker 6 connection attempt at tick time 137477
"ArduinoIoTCloudTCP::handle_ConnectMqttBroker could not connect to mqtts-sa.iot.arduino.cc:8883" means something is wrong with the connection. Does a test script connect?
GPS.available() never indicates new data. Maybe move the antenna until 'GPS.available() != false'
I am not getting any error anymore after this :
/ If you are using the MKR GPS as shield, change the next line to pass
//the GPS_MODE_SHIELD parameter to the GPS.begin(...)
But Its seems that I don't have good GPS signal inside . Will try it outside next time .
It doen't look like an error compared to the output in:
The line looks like it might be noting that it is applying a DaylightSavingsTime offset of -18000 seconds until the next time DST changes on 2024 March 10
% date -ur 1710054000
Sun Mar 10 07:00:00 UTC 2024
% date -ur $(( 1710054000 - 18000 ))
Sun Mar 10 02:00:00 UTC 2024
Finally Its working with TinyGPS++ Library instead . I was able to Track my device remotely But
this option consume a lot of Data, GPS constantly keep sending coordinates through sim cart .
I don't have option to add Delay () with arduino iot platform . Delay () will crash the device . My other option is to request coordinates by sending sms text message .