hola, estoy haciendo un proyecto con un modulo A9G, lo tengo enviando las ubicaciones a google maps, ahora lo quiero vincular a ubidots para que me envie los posiciones en tiempo real , ya cree el mapa en ubidots pero no se como cambiar mi codigo para que este envie los datos, este es mi codigo original:
#include <TinyGPSPlus.h>
#include <SoftwareSerial.h>
static const int RXPin = 16, TXPin = 17;
String s = “www.google.com/maps/dir/”;
unsigned long interval = 10000;
static const uint32_t GPSBaud = 9600;
unsigned long previousMillis = 0;
int data_counter;
const size_t BUFSIZE = 300;
char f_buffer[BUFSIZE];
float f_buf = (float)f_buffer;
TinyGPSPlus gps;// The TinyGPSPlus object
SoftwareSerial ss(RXPin, TXPin);// The serial connection to the GPS device
void setup()
{
Serial.begin(9600);
ss.begin(GPSBaud);
Serial.println(“Starting…”);
ss.println("\r");
ss.println(“AT\r”);
delay(10);
ss.println("\r");
ss.println(“AT+GPS=1\r”);
delay(100);
ss.println(“AT+CREG=2\r”);
delay(6000);
//ss.print(“AT+CREG?\r”);
ss.println(“AT+CGATT=1\r”);
delay(6000);
ss.println(“AT+CGDCONT=1,“IP”,“WWW”\r”);
delay(6000);
// ss.println(“AT+LOCATION=1\r”);
ss.println(“AT+CGACT=1,1\r”);
delay(6000);
//Initialize ends
//Initialize GPS
ss.println("\r");
ss.println(“AT+GPS=1\r”);
delay(1000);
//ss.println(“AT+GPSMD=1\r”); // Change to only GPS mode from GPS+BDS, set to 2 to revert to default.
ss.println(“AT+GPSRD=10\r”);
delay(100);
// set SMS mode to text mode
ss.println(“AT+CMGF=1\r”);
delay(1000);
//ss.println(“AT+LOCATION=2\r”);
Serial.println(“Setup Executed”);
}
void loop() {
smartDelay(2000);
if (millis() > 5000 && gps.charsProcessed() < 10)
Serial.println(F(“No GPS data received: check wiring”));
unsigned long currentMillis = millis();
if ((unsigned long)(currentMillis - previousMillis) >= interval) {
send_gps_data();
previousMillis = currentMillis;
}
}
static void smartDelay(unsigned long ms)
{
unsigned long start = millis();
do
{
while (ss.available())
gps.encode(ss.read());
} while (millis() - start < ms);
}
void send_gps_data()
{
if (gps.location.lat() == 0 || gps.location.lng() == 0)
{
Serial.println(“Return Executed”);
return;
}
data_counter++;
Serial.print("Latitude (deg): ");
f_buf[data_counter] = gps.location.lat();
Serial.println(f_buf[data_counter]);
Serial.print("Longitude (deg): ");
f_buf[data_counter + 1] = gps.location.lng();
Serial.println(f_buf[data_counter + 1]);
Serial.println(data_counter);
Serial.println();
s += String(gps.location.lat(), 6);
s += “,”;
s += String(gps.location.lng(), 6);
s += “/”;
Serial.println(s);
if (data_counter >= 10)
{
data_counter = 0;
Serial.println("Sending Message");
ss.println("AT+CMGF=1\r");
delay(1000);
ss.println("AT+CNMI=2,2,0,0,0\r");
delay(1000);
ss.print("AT+CMGS=\"+573170336838\"\r");
delay(1000);
ss.print(s);
ss.write(0x1A);
delay(1000);
s = "www.google.com/maps/dir/";
}
}
y este es el nuevo codigo que tengo para la conexion a ubidots:
#include <TinyGPSPlus.h>
#include <SoftwareSerial.h>
#include <HttpClient.h>
static const int RXPin = 16, TXPin = 17;
unsigned long interval = 10000;
static const uint32_t GPSBaud = 9600;
unsigned long previousMillis = 0;
int data_counter;
const size_t BUFSIZE = 300;
char f_buffer[BUFSIZE];
float f_buf = (float)f_buffer;
TinyGPSPlus gps; // The TinyGPSPlus object
SoftwareSerial ss(RXPin, TXPin); // The serial connection to the GPS device
// Configuración de la conexión HTTP a Ubidots
const char *ubidotsToken = “tu-token-de-api”;
const char *ubidotsDeviceId = “id-de-tu-dispositivo”;
void setup() {
Serial.begin(9600);
ss.begin(GPSBaud);
Serial.println(“Starting…”);
// Configuración del módulo A9G…
Serial.println(“Setup Executed”);
}
void loop() {
smartDelay(2000);
if (millis() > 5000 && gps.charsProcessed() < 10)
Serial.println(F(“No GPS data received: check wiring”));
unsigned long currentMillis = millis();
if ((unsigned long)(currentMillis - previousMillis) >= interval) {
send_gps_data();
previousMillis = currentMillis;
}
}
static void smartDelay(unsigned long ms) {
unsigned long start = millis();
do {
while (ss.available())
gps.encode(ss.read());
} while (millis() - start < ms);
}
void send_gps_data() {
if (gps.location.lat() == 0 || gps.location.lng() == 0) {
Serial.println(“Return Executed”);
return;
}
data_counter++;
Serial.print("Latitude (deg): ");
f_buf[data_counter] = gps.location.lat();
Serial.println(f_buf[data_counter]);
Serial.print("Longitude (deg): ");
f_buf[data_counter + 1] = gps.location.lng();
Serial.println(f_buf[data_counter + 1]);
Serial.println(data_counter);
Serial.println();
// Construir la URL de Ubidots
String ubidotsURL = “http://things.ubidots.com/api/v1.6/devices/”;
ubidotsURL += ubidotsDeviceId;
ubidotsURL += “?token=”;
ubidotsURL += ubidotsToken;
// Construir el cuerpo del mensaje JSON
String jsonBody = String("{“lat”:") + String(gps.location.lat(), 6) + “,“lng”:” + String(gps.location.lng(), 6) + “}”;
// Inicializar la conexión HTTP
HttpClient client;
client.begin(ubidotsURL);
client.addHeader(“Content-Type”, “application/json”);
// Enviar la solicitud HTTP POST
int httpResponseCode = client.post(jsonBody);
if (httpResponseCode > 0) {
Serial.print("HTTP Response code: ");
Serial.println(httpResponseCode);
} else {
Serial.println(“Error en la solicitud HTTP”);
}
// Cerrar la conexión
client.end();
if (data_counter >= 10) {
data_counter = 0;
}
}
pero no me envia nada a el mapa