Hola, tengo una pregunta muy tonta, pero no llego a ver la solución. El tema es que he unido codigo gps a este codigo radio cliente en este código:
#include <RHReliableDatagram.h>
#include <RH_RF95.h>
#include <SPI.h>
#define CLIENT_ADDRESS 1
#define SERVER_ADDRESS 2
RH_RF95 driver;
RHReliableDatagram manager(driver, CLIENT_ADDRESS);
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#define rxGPS 8
#define txGPS 7
long lat,lon;
int counter = 0;
SoftwareSerial gpsSerial(rxGPS,txGPS);
TinyGPSPlus gps;
void setup() {
while (!Serial) ; // Wait for serial port to be available
if (!manager.init())
Serial.println("init failed");
gpsSerial.begin(9600); // connect gps sensor
Serial.begin(9600); // connect serial
}
uint8_t data[] = "Hello World!";
// Dont put this on the stack:
uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
void loop() {
while(gpsSerial.available()){ // check for gps data
if(gps.encode(gpsSerial.read())){ // encode gps data
if(counter > 50) {
Serial.print("LAT: ");
Serial.println(gps.location.lat(), 6);
Serial.print("LONG: ");
Serial.println(gps.location.lng(), 6);
Serial.println("enviando LAT y LONG por radio");
uint8_t data[] = gps.location.lat(), 6","gps.location.lng(), 6
// Send a message to manager_server
if (manager.sendtoWait(data, sizeof(data), SERVER_ADDRESS))
{
// Now wait for a reply from the server
uint8_t len = sizeof(buf);
uint8_t from;
if (manager.recvfromAckTimeout(buf, &len, 2000, &from))
{
Serial.print("got reply from : 0x");
Serial.print(from, HEX);
Serial.print(": ");
Serial.println((char*)buf);
}
else
{
Serial.println("No reply, is rf95_reliable_datagram_server running?");
}
}
else
Serial.println("sendtoWait failed");
delay(500);
counter = 0;
}
}
}
}
y evidentemente me da fallo en la linea:
uint8_t data[] = gps.location.lat(), 6","gps.location.lng(), 6
cliente_total_1:71: error: expected '}' at end of input
¿cómo hago para que uint8_t tenga como valor LAT,LONG?
Saludos.
uint8_t es equivalente a byte un tipo de dato que puede almacenar entre 0 y 255.
Luego la variable data[] es una matriz que para asignar valores estos deben estar entre llaves y cada uno de ellos separados por coma.
byte data[]={1,2,3};
Ahora tu intentas meter alli un numero tipo double (gps.location.lat()) ?
1 Like
¿cómo sería entonces? Necesito que la lat y la long del gps se envíe por radio, orientarme un poco por favor.
Tienes muchos error. Primero dale "Auto Formato" (Ctrl+T), asi te podrás dar cuenta que te faltan llaves.
Así mismo tienes que entender el alcance o ámbito de variables.
La librería TinyGPSplus establece que gps.location.lat() y gps.location.lng() son de tipo double.
Serial.println(gps.location.lat(), 6); //Latitude in degrees (double)
Serial.println(gps.location.lng(), 6); //Longitude in degrees (double)
En Serial.println() el ,6 indica el numero de decimales a representar en consola.
juanmol:
¿cómo sería entonces? Necesito que la lat y la long del gps se envíe por radio, orientarme un poco por favor.
Aun no logro entender que prender hacer con la matriz data[].
Ante todo, muchas gracias por tu tiempo. Prometo estudiarme los tipos de variables, pero necesito esto mediourgente. No se si tengo que usar la matriz data o no, solo se que en el ejemplo de la parte de radio, envía esta cadena:
uint8_t data[] = "Hello World!";
y yo lo que quiero es enviar la latitud y la longitud, separados por una coma. No se si solo admite datos de tipo int8_t o double o ... ni idea la verdad.
Esto no tiene ningún sentido:
uint8_t data[] = gps.location.lat(), 6","gps.location.lng(), 6
He modificado tu código, ojo no he probado que compile, pero estará más cerca de lo que quieres:
#include <RHReliableDatagram.h>
#include <RH_RF95.h>
#include <SPI.h>
#define CLIENT_ADDRESS 1
#define SERVER_ADDRESS 2
RH_RF95 driver;
RHReliableDatagram manager(driver, CLIENT_ADDRESS);
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#define rxGPS 8
#define txGPS 7
double lat, lon;
int counter = 0;
SoftwareSerial gpsSerial(rxGPS, txGPS);
TinyGPSPlus gps;
//Toma dos doubles y los saca a out separador de una coma
char* locToStr(double n1, double n2, char* out) {
char c_n1[11];
char c_n2[11];
*out = 0;
dtostrf(n1, 1, 7, c_n1);
dtostrf(n2, 1, 7, c_n2);
strcat(out, c_n1);
strcat(out, ",");
strcat(out, c_n2);
return out;
}
void setup() {
while (!Serial) ; // Wait for serial port to be available
if (!manager.init())
Serial.println("init failed");
gpsSerial.begin(9600); // connect gps sensor
Serial.begin(9600); // connect serial
}
//uint8_t data[] = "Hello World!";
uint8_t data[30] = "";
// Dont put this on the stack:
uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
void loop() {
while (gpsSerial.available()) { // check for gps data
if (gps.encode(gpsSerial.read())) { // encode gps data
if (counter > 50) {
lat = gps.location.lat();
lon = gps.location.lng();
Serial.print("LAT: ");
Serial.println(lat, 6);
Serial.print("LONG: ");
Serial.println(lon, 6);
Serial.println("enviando LAT y LONG por radio");
locToStr(lat, lon, data);
//uint8_t data[] = gps.location.lat(), 6","gps.location.lng(), 6
// Send a message to manager_server
if (manager.sendtoWait(data, strlen(data), SERVER_ADDRESS))
{
// Now wait for a reply from the server
uint8_t len = sizeof(buf);
uint8_t from;
if (manager.recvfromAckTimeout(buf, &len, 2000, &from))
{
Serial.print("got reply from : 0x");
Serial.print(from, HEX);
Serial.print(": ");
Serial.println((char*)buf);
}
else
{
Serial.println("No reply, is rf95_reliable_datagram_server running?");
}
}
else
Serial.println("sendtoWait failed");
delay(500);
counter = 0;
}
}
}
}
Muchas gracias harkonnen pero no funciona. Compila pero no envía nada 
No tengo ni idea de cómo hacerlo, tengo el código de ejemplo de lectura del gps y los ejemplos de envío y recepción de radio, pero ni idea de como enviar la latitud y la longitud por radio hacia el receptor. Necesito más ayuda por favor.