[SOLVED] Unable to post GPS data to Ubidots using Arduino Yun

Hi,

I am using an Arduino Yun with a DF robot sim808 shield. I am using the shield to post GPS data to track a vehicle. The only part of the code that is not working is the context part to post GPS data.

Here is my full code.

#include <UbidotsYUN.h>
#define TOKEN "my token"
#include <Console.h>
#include <DFRobot_sim808.h>
#include <SoftwareSerial.h>

Ubidots client(TOKEN);

#define PIN_TX    10
#define PIN_RX    11
SoftwareSerial mySerial(PIN_TX, PIN_RX);
DFRobot_SIM808 sim808(&mySerial);

float  Longitude = 0;
float Latitude = 0;
float Speedperkm = 0;

unsigned long previousMillis = 0;
const long interval = 4000;

void setup() {
  Bridge.begin();
  mySerial.begin(9600);
  Console.begin();
  client.init();

  while (!sim808.init()) {
    delay(1000);
    Console.print("Sim808 init error\r\n");
   }

  if ( sim808.attachGPS())
      Console.println("Open the GPS power success");
  else
     Console.println("Open the GPS power failure");

}

void loop() {
  unsigned long currentMillis = millis();

  if (sim808.getGPS()) {
    Longitude = sim808.GPSdata.lon;
    Latitude = sim808.GPSdata.lat;
    Speedperkm = sim808.GPSdata.speed_kph;

   Console.print("Longitude : ");
   Console.println(Longitude, 6);
   Console.print("Latitude : ");
   Console.println(Latitude, 6);
   Console.print("Speed per Km : ");
   Console.println(Speedperkm);
   Console.println();
   }

  if (currentMillis - previousMillis >= interval) {
    previousMillis = currentMillis;

    char context[50];

    sprintf(context, "lat=%.6f$lng=%.6f", Latitude, Longitude);

    client.add("Longitude", Longitude);
    client.add("Latitude", Latitude);
    client.add("Speed per Km", Speedperkm, context);
   client.sendAll();
  }
}

If context work, then 1 can visualize the data real time on a map instead of just GPS numbers.

Please help me solve this problem.
Regards.

Hello,

You should send your latitude and longitude coordinates as a context of your value (more information here), in your code you are creating two variables without context called ‘Latitude’ and ‘Longitude’.

Ubidots’ Yun library actually doesn’t support to send values with context, I’ll ask to the technical team to schedule this feature in order to add it, meanwhile you can wrap our actual library for sending the context or take a look to this video and to build your script based on that video, the video shows how to create an http request with context.

Regards