I would like to carry out the following project: Using data received by my GPS, I must send it as a message via a transmitter. The coordinates must be received by my radio receiver.
I tried this code implanted in my arduino nano card connected to the gps module and the transmitter:
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include <RH_ASK.h>
#include <SPI.h>
RH_ASK driver;
TinyGPSPlus gps;
#define S_RX 4
#define S_TX 3
SoftwareSerial SoftSerial(S_RX, S_TX);
void setup(void) {
Serial.begin(9600);
SoftSerial.begin(9600);
Serial.begin(9600);
if (!driver.init())
Serial.println(“init failed”);
}
void loop() {
while (SoftSerial.available() > 0) {
if (gps.encode(SoftSerial.read())) {
if (gps.location.isValid()) {
Serial.print("Latitude = ");
Serial.println(gps.location.lat(), 6);
Serial.print("Longitude = ");
Serial.println(gps.location.lng(), 6);
}
else
Serial.println(“Location Invalid”);
}
const char *msg =("Longitude = ", "Latitude = ");
driver.send((uint8_t *)msg, strlen(msg));
driver.waitPacketSent();
delay(1000);
}
}
after I must receive my contact details with this program:
#include <RH_ASK.h>
#include <SPI.h> // Not actualy used but needed to compile
RH_ASK driver;
void setup()
{
Serial.begin(9600); // Debugging only
if (!driver.init())
Serial.println(“init failed”);
}
void loop()
{
uint8_t buf[9]; // a classic latitude coordinate has 9 characters
uint8_t buflen = sizeof(buf);
if (driver.recv(buf, &buflen)) // Non-blocking
{
int i;
Serial.print("Message: ");
Serial.println((char*)buf);
}
}
the problem is that I will not impose a maximum character " uint8_t buf[9]; " but I don’t think we can do it via the RH_ASK.h library.
→https://www.airspayce.com/mikem/arduino/RadioHead/classRH__ASK.html
I would like to know if my code is valid knowing that I need the longitude and the latitude in the reception message. Thanks