Seeking Assistance with Integrating BK-357 Beitian GPS Data into Ubidots using Particle Photon 2

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:

  1. 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.
  2. 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.
  3. 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.
  4. 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.

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

Are you getting log messages on USB serial? Those would be helpful.

Definitely remove the delay(5000); from the bottom of the loop(). You're not processing data from serial fast enough with it, and you'll likely overflow the serial buffer causing corrupted GNSS sentences.

1 Like

Hello everyone!

I hope this message finds you well.

I have try the example code from the Tiny++ library the "SatelliTracker", And I have modify the code to fit the hardware of the Photon2 :

 #include <TinyGPS++/TinyGPS++.h>
 
static const uint32_t GPSBaud = 38400;
// The TinyGPS++ object
TinyGPSPlus gps;
static const int MAX_SATELLITES = 40;
TinyGPSCustom totalGPGSVMessages(gps, "GPGSV", 1); // $GPGSV sentence, first element
TinyGPSCustom messageNumber(gps, "GPGSV", 2);      // $GPGSV sentence, second element
TinyGPSCustom satsInView(gps, "GPGSV", 3);         // $GPGSV sentence, third element
TinyGPSCustom satNumber[4]; // to be initialized later
TinyGPSCustom elevation[4];
TinyGPSCustom azimuth[4];
TinyGPSCustom snr[4];
struct
{
  bool active;
  int elevation;
  int azimuth;
  int snr;
} sats[MAX_SATELLITES];
#define ss Serial1
void setup()
{
  Particle.publish("setup", "SatelliteTracker.ino");
  Particle.publish("setup", "Monitoring satellite location and signal strength using TinyGPSCustom");
  Particle.publish("setup", "Testing TinyGPS++ library v. " + String(TinyGPSPlus::libraryVersion()));
  Particle.publish("setup", "by Mikal Hart");
  
  ss.begin(GPSBaud);
  
  // Initialize all the uninitialized TinyGPSCustom objects
  for (int i=0; i<4; ++i)
  {
    satNumber[i].begin(gps, "GPGSV", 4 + 4 * i); // offsets 4, 8, 12, 16
    elevation[i].begin(gps, "GPGSV", 5 + 4 * i); // offsets 5, 9, 13, 17
    azimuth[i].begin(  gps, "GPGSV", 6 + 4 * i); // offsets 6, 10, 14, 18
    snr[i].begin(      gps, "GPGSV", 7 + 4 * i); // offsets 7, 11, 15, 19
  }
}
void loop()
{
  // Dispatch incoming characters
  if (ss.available() > 0)
  {
    gps.encode(ss.read());
    if (totalGPGSVMessages.isUpdated())
    {
      for (int i=0; i<4; ++i)
      {
        int no = atoi(satNumber[i].value());
        // Particle.publish("debug", "SatNumber is " + String(no));
        if (no >= 1 && no <= MAX_SATELLITES)
        {
          sats[no-1].elevation = atoi(elevation[i].value());
          sats[no-1].azimuth = atoi(azimuth[i].value());
          sats[no-1].snr = atoi(snr[i].value());
          sats[no-1].active = true;
        }
      }
      
      int totalMessages = atoi(totalGPGSVMessages.value());
      int currentMessage = atoi(messageNumber.value());
      if (totalMessages == currentMessage)
      {
        String satInfo = "Sats=" + String(gps.satellites.value()) + " Nums=";
        for (int i=0; i<MAX_SATELLITES; ++i)
          if (sats[i].active)
          {
            satInfo += String(i+1) + " ";
          }
        Particle.publish("satInfo", satInfo);

        String elevationInfo = "Elevation=";
        for (int i=0; i<MAX_SATELLITES; ++i)
          if (sats[i].active)
          {
            elevationInfo += String(sats[i].elevation) + " ";
          }
        Particle.publish("elevationInfo", elevationInfo);

        String azimuthInfo = "Azimuth=";
        for (int i=0; i<MAX_SATELLITES; ++i)
          if (sats[i].active)
          {
            azimuthInfo += String(sats[i].azimuth) + " ";
          }
        Particle.publish("azimuthInfo", azimuthInfo);
        
        String snrInfo = "SNR=";
        for (int i=0; i<MAX_SATELLITES; ++i)
          if (sats[i].active)
          {
            snrInfo += String(sats[i].snr) + " ";
          }
        Particle.publish("snrInfo", snrInfo);

        for (int i=0; i<MAX_SATELLITES; ++i)
          sats[i].active = false;
      }
    }
  }
}

And here is the logs :

As you can see I'm getting some values but there are a bit weird, like for the number of sattelite I'm not supposed to get 0 satellite :

image

By any chance do you guys have some thought about it?

Best regards,
Nayel

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