I GOT IT AHAHALKHA
I made a char array containing the data that i needed. I’ll send the code. It’s really messy and inefficient in how it works and can easily be made better, but it works!
Sender code:
//transfer comm and gps code here, send and make reciever of the same type as being sent.
#include “Arduino.h”
#include “GPS_Air530.h”
#include “LoRaWan_APP.h”
//is it 530Z or 530?
Air530Class Gps;
struct TransData
{
double latitude;
double longitude;
double altitudeM;
double signalQuality;
int locationAge;
double speedKmph;
double courseDeg;
int satellitesConnected;;
int gps_year;
int gps_day;
int gps_month;
int gps_hour;
int gps_minute;
int gps_second;
int gps_centisecond;
//year, day, month, hour, minute, second, centisecond, lat, lng, alt.meters, sats, hdop (quality), age, coursedeg, speedkmph
};
TransData data;
#ifndef LoraWan_RGB
#define LoraWan_RGB 0
#endif
#define RF_FREQUENCY 915000000 // Hz
#define TX_OUTPUT_POWER 14 // dBm
#define LORA_BANDWIDTH 0 // [0: 125 kHz,
// 1: 250 kHz,
// 2: 500 kHz,
// 3: Reserved]
#define LORA_SPREADING_FACTOR 7 // [SF7…SF12]
#define LORA_CODINGRATE 1 // [1: 4/5,
// 2: 4/6,
// 3: 4/7,
// 4: 4/8]
#define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx
#define LORA_SYMBOL_TIMEOUT 0 // Symbols
#define LORA_FIX_LENGTH_PAYLOAD_ON false
#define LORA_IQ_INVERSION_ON false
#define RX_TIMEOUT_VALUE 1000
#define BUFFER_SIZE 32 // Define the payload size here
char finalMessage[BUFFER_SIZE];
char rxpacket[BUFFER_SIZE];
static RadioEvents_t RadioEvents;
int sentNumber;//the number of communication is being sent to make sure in sync
int16_t rssi,rxSize; // rssi is recieve strength. Why is it on the sender?
void DoubleToString( char *str, double double_num,unsigned int len);
uint32_t gpsTimer = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Gps.begin(9600);
Gps.setmode(MODE_GPS);
rssi=0;
Radio.Init( &RadioEvents );
Radio.SetChannel( RF_FREQUENCY );
Radio.SetTxConfig( MODEM_LORA, TX_OUTPUT_POWER, 0, LORA_BANDWIDTH,
LORA_SPREADING_FACTOR, LORA_CODINGRATE,
LORA_PREAMBLE_LENGTH, LORA_FIX_LENGTH_PAYLOAD_ON,
true, 0, 0, LORA_IQ_INVERSION_ON, 3000 );
}
void loop() {
// put your main code here, to run repeatedly:
String message = encodeMessage();
message.toCharArray(finalMessage, BUFFER_SIZE);
Radio.Send((uint8_t *)finalMessage, strlen(finalMessage));
Serial.println(“SENT!----------------------------------------------”);
delay(1000);
}
String encodeMessage(){
readGps();//read raw data
updateInfo();//update all variables and data from raw
String message = “”;
char buff[12];
message += data.gps_hour;
message += “:”;
message += data.gps_minute;
message += “:”;
message += data.gps_second;
message += “,”;
message += data.satellitesConnected;
message += “,”;
dtostrf(data.latitude, 5, 6, buff);
message += buff;
message += “,”;
dtostrf(data.longitude, 5, 6, buff);
message += buff;
message += “,”;
message += data.altitudeM;
/*
Serial.println("*********************************");
Serial.println(message);
Serial.println("*********************************");
*/
return message;
}
void readGps(){
if(millis() - gpsTimer > 1000){
while(Gps.available() > 0){
Gps.encode(Gps.read());
}
gpsTimer = millis();
}
if (millis() > 5000 && Gps.charsProcessed() < 10)
{
Serial.println(“No GPS detected: check wiring.”);
while(true);
}
}
void updateInfo()
{
/*//DEBUG PRINTS FOR LOOP
Serial.print("day: "); Serial.println(data.gps_day);
Serial.print("month: ");Serial.println(data.gps_month);
Serial.print("gps_year: "); Serial.println(data.gps_year);
Serial.print("hour: "); Serial.println(data.gps_hour);
Serial.print("gps_minute: "); Serial.println(data.gps_minute);
Serial.print("gps_second: "); Serial.println(data.gps_second);
Serial.print("gps_centisecond: "); Serial.println(data.gps_centisecond);
Serial.print("latitude: "); Serial.println(data.latitude);
Serial.print("longitude: "); Serial.println(data.longitude);
Serial.print("altitudeM: "); Serial.println(data.altitudeM);
Serial.print("satellites: "); Serial.println(data.satellitesConnected;);
Serial.print("signalQuality: "); Serial.println(data.signalQuality);
Serial.print("locationAge: "); Serial.println(data.locationAge);
Serial.print("courseDeg: "); Serial.println(data.courseDeg);
Serial.print(“speedKmph: “); Serial.println(data.speedKmph);
Serial.println(”>>>>>>>>>>>>>>>>>>…”);
delay(1000);
*/
Serial.print(“Date/Time: “);
if (Gps.date.isValid())
{
data.gps_day = Gps.date.day();
data.gps_month = Gps.date.month();
data.gps_year = Gps.date.year();
Serial.printf(”%d/%02d/%02d”,Gps.date.year(),Gps.date.day(),Gps.date.month());
}
else
{
Serial.print(“INVALID”);
}
if (Gps.time.isValid())
{
data.gps_hour = Gps.time.hour();
data.gps_minute = Gps.time.minute();
data.gps_second = Gps.time.second();
data.gps_centisecond = Gps.time.centisecond();
Serial.printf(" %02d:%02d:%02d.%02d",Gps.time.hour(),Gps.time.minute(),Gps.time.second(),Gps.time.centisecond());
}
else
{
Serial.print(" INVALID");
}
Serial.println();
data.latitude = Gps.location.lat();
data.longitude = Gps.location.lng();
data.altitudeM = Gps.altitude.meters();
Serial.print("LAT: “);
Serial.print(Gps.location.lat(),6);
Serial.print(”, LON: “);
Serial.print(Gps.location.lng(),6);
Serial.print(”, ALT: ");
Serial.print(Gps.altitude.meters());
data.satellitesConnected = Gps.satellites.value();
data.signalQuality = Gps.hdop.hdop();
data.locationAge = Gps.location.age();
data.courseDeg = Gps.course.deg();
data.speedKmph = Gps.speed.kmph();
Serial.println();
Serial.print("SATS: “);
Serial.print(Gps.satellites.value());
Serial.print(”, HDOP: “);
Serial.print(Gps.hdop.hdop());
Serial.print(”, AGE: “);
Serial.print(Gps.location.age());
Serial.print(”, COURSE: “);
Serial.print(Gps.course.deg());
Serial.print(”, SPEED: ");
Serial.println(Gps.speed.kmph());
Serial.println();
}
Reciever code:
//use gpsdata structure to store recieved data to do something with, constantly updating.
#include “LoRaWan_APP.h”
#include “Arduino.h”
#ifndef LoraWan_RGB
#define LoraWan_RGB 0
#endif
#define RF_FREQUENCY 915000000 // Hz
#define TX_OUTPUT_POWER 14 // dBm
#define LORA_BANDWIDTH 0 // [0: 125 kHz,
// 1: 250 kHz,
// 2: 500 kHz,
// 3: Reserved]
#define LORA_SPREADING_FACTOR 7 // [SF7…SF12]
#define LORA_CODINGRATE 1 // [1: 4/5,
// 2: 4/6,
// 3: 4/7,
// 4: 4/8]
#define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx
#define LORA_SYMBOL_TIMEOUT 0 // Symbols
#define LORA_FIX_LENGTH_PAYLOAD_ON false
#define LORA_IQ_INVERSION_ON false
#define RX_TIMEOUT_VALUE 1000
#define BUFFER_SIZE 30 // Define the payload size here
char txpacket[BUFFER_SIZE];
char rxpacket[BUFFER_SIZE];
static RadioEvents_t RadioEvents;
int16_t txNumber;
int16_t rssi,rxSize;
struct recieveData
{
double latitude;
double longitude;
double altitudeM;
double signalQuality;
int locationAge;
double speedKmph;
double courseDeg;
int sats;
int gps_year;
int gps_day;
int gps_month;
int gps_hour;
int gps_minute;
int gps_second;
int gps_centisecond;
//year, day, month, hour, minute, second, centisecond, lat, lng, alt.meters, sats, hdop (quality), age, coursedeg, speedkmph
};
recieveData gpsData;
void setup() {
Serial.begin(115200);
txNumber=0;
rssi=0;
RadioEvents.RxDone = OnRxDone;
Radio.Init( &RadioEvents );
Radio.SetChannel( RF_FREQUENCY );
Radio.SetRxConfig( MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR,
LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH,
LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON,
0, true, 0, 0, LORA_IQ_INVERSION_ON, true );
turnOnRGB(COLOR_SEND,0); //change rgb color
Serial.println(“into RX mode”);
}
void loop()
{
Radio.Rx( 0 );
delay(500);
Radio.IrqProcess( );
}
void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr )
{
rssi=rssi;
rxSize=size;
memcpy(rxpacket, payload, size );
rxpacket[size]=’\0’;
turnOnRGB(COLOR_RECEIVED,0);
Radio.Sleep( );
Serial.printf("\r\nreceived packet “%s” with rssi %d , length %d\r\n",rxpacket,rssi,rxSize);
}