Hello everyone,
I hope this message finds you well.
I've been working on integrating GPS data from a BK-357 Beitian GPS module into Ubidots using a Particle Photon 2. Despite my efforts, I haven't been able to send the GPS data to Ubidots successfully. The GPS module works perfectly with u-center 2
software and on an Arduino using SoftwareSerial
, but the data isn't being received by Ubidots when using the Particle Photon 2.
Here are the details of my troubleshooting process:
-
GPS Module with
u-center 2
:- Connected the GPS module to
u-center 2
on my computer. - Verified that the GPS module outputs accurate GPS coordinates.
- Connected the GPS module to
-
GPS Module with Arduino:
- Connected the GPS module to an Arduino and utilized
SoftwareSerial
to read the GPS data. - The Arduino read and printed the GPS coordinates correctly, confirming the module's functionality.
- Connected the GPS module to an Arduino and utilized
-
Ubidots Example Code:
- Used the example code provided by Ubidots to send data.
- The example successfully sent data to Ubidots, but the GPS coordinates were hardcoded and not obtained from the GPS module.
-
Particle Photon 2 Integration:
- Attempted to integrate the GPS reading code with Ubidots on the Particle Photon 2, using
Serial1
for communication with the GPS module. but nothing.
- Attempted to integrate the GPS reading code with Ubidots on the Particle Photon 2, using
Here is the code I have been working with:
#include <TinyGPS++.h>
#include "Ubidots.h"
const char *WEBHOOK_NAME = "Ubidots";
Ubidots ubidots("webhook", UBI_PARTICLE);
TinyGPSPlus gps;
const uint32_t GPSBaud = 38400; // Adjust to your GPS module's baud rate
void setup()
{
Serial.begin(9600);
Serial1.begin(GPSBaud); // Use Serial1 for GPS module communication
ubidots.setDebug(true); // Uncomment this line for printing debug messages
}
void loop()
{
while (Serial1.available() > 0) {
gps.encode(Serial1.read());
if (gps.location.isUpdated()) {
float latitude = gps.location.lat();
float longitude = gps.location.lng();
Serial.print("Latitude= ");
Serial.print(latitude, 6);
Serial.print(" Longitude= ");
Serial.println(longitude, 6);
// Read a value from an analog pin (simulating a sensor reading)
float value = analogRead(A0);
// Allocate memory to store context keys values
char *str_lat = (char *)malloc(sizeof(char) * 10);
char *str_lng = (char *)malloc(sizeof(char) * 10);
// Save the coordinates as char
sprintf(str_lat, "%f", latitude);
sprintf(str_lng, "%f", longitude);
// Reserve memory to store context array
char *context = (char *)malloc(sizeof(char) * 50);
// Add context key-value pairs
ubidots.addContext("lat", str_lat);
ubidots.addContext("lng", str_lng);
// Build the context with the coordinates to send to Ubidots
ubidots.getContext(context);
// Send the position
ubidots.add("position", value, context); // Change for your variable name
bool bufferSent = false;
bufferSent = ubidots.send(WEBHOOK_NAME, PUBLIC); // Will use particle webhooks to send data
if (bufferSent)
{
// Do something if values were sent properly
Serial.println("Values sent by the device");
}
// Free memory
free(str_lat);
free(str_lng);
free(context);
}
}
delay(5000); // Adjust delay as needed
}
Here is the example code coming from ubidots :
// This example sends data to a variable along with hardcoded
// GPS coordinates to Ubidots using Particle Webhooks.
/****************************************
Include Libraries
***************************************/
#include "Ubidots.h"
/****************************************
Define Instances and Constants
***************************************/
const char *WEBHOOK_NAME = "Ubidots";
Ubidots ubidots("webhook", UBI_PARTICLE);
/****************************************
Auxiliar Functions
***************************************/
//Put here your auxiliar functions
/****************************************
Main Functions
***************************************/
void setup()
{
Serial.begin(115200);
ubidots.setDebug(true); // Uncomment this line for printing debug messages
}
void loop()
{
float value = analogRead(A0);
/* Harcoded Coordinates */
float latitude = 37.773;
float longitude = -6.2345;
/* Reserves 10 bytes of memory to store context keys values, add as much as needed */
char *str_lat = (char *)malloc(sizeof(char) * 10);
char *str_lng = (char *)malloc(sizeof(char) * 10);
/* Saves the coordinates as char*/
sprintf(str_lat, "%f", latitude);
sprintf(str_lng, "%f", longitude);
/* Reserves memory to store context array */
char *context = (char *)malloc(sizeof(char) * 50);
/* Adds context key-value pairs */
ubidots.addContext("lat", str_lat);
ubidots.addContext("lng", str_lng);
/* Builds the context with the coordinates to send to Ubidots */
ubidots.getContext(context);
/* Sends the position */
ubidots.add("position", value, context); // Change for your variable name
bool bufferSent = false;
bufferSent = ubidots.send(WEBHOOK_NAME, PUBLIC); // Will use particle webhooks to send data
if (bufferSent)
{
// Do something if values were sent properly
Serial.println("Values sent by the device");
}
/* frees memory */
free(str_lat);
free(str_lng);
free(context);
delay(5000);
}
I would greatly appreciate any guidance or suggestions on how to effectively send the GPS data to Ubidots using the Particle Photon 2. If anyone has experience with similar projects or has insights into alternative approaches, your input would be invaluable.
Thank you in advance for your assistance.
Best regards,
Nayel KHOUATRA