I am having a seemingly simple issue with writing a json object over LoRA from one Boron to another. Currently I am able to send sensor data from various sensors in an object over to another boron, and periodically, I want to send in GPS data as well. Whenever it attempts to add the GPS field to the json object to send over to the other boron, the message fails to send.
Here is the code I am using:
Writing GPS Data to json object periodically
// lorawrite of size 1023, data is somewhere around 300-400 bytes
JSONBufferWriter writer(lorawrite, sizeof(lorawrite));
writer.beginObject();
writer.name("id").value(System.deviceID());
writer.name("Pitch").value(String(pitch));
writer.name("Temperature").value(String(temp));
writer.name("Pressure").value(String(pressure));
writer.name("Roll").value(String(roll));
if (millis() - gps_write_timer > 30000)
{
Serial.println(gps_data);
writer.name("GPS").value(String(gps_data));
gps_write_timer = millis();
}
//writer.name("GPS").value(String(gps_data));
writer.endObject();
if (lora_connected && !is_super_node && !cloud_connected)
{
if (LoRA::instance().sendMessage((uint8_t*)lorawrite, strlen(lorawrite)) == RH_ROUTER_ERROR_NONE)
{
Serial.println("sent message to server");
}
else
{
Serial.println("sendtoWait failed. Are the intermediate mesh servers running?");
}
}
getting GPS data
char gps_data[512] = ""; //global
// inside loop
if (millis() - gps_read_timer > 1000)
{
if (GPS_Read(gps_data))
{
if (cloud_connected)
{
Particle.publish(gps_data);
}
Serial.print("GPS Data:");
Serial.println(gps_data);
}
gps_read_timer = millis();
}
bool GPS_Read(char* gps_data)
{
if (GPSSerial.available())
{
String s = GPSSerial.readStringUntil('\n');
snprintf(gps_data, strlen(s), s);
return true;
}
return false;
}
Anything obvious I am doing wrong? sometimes the GPS data does come back as a lot of strange characters but most of the time the data is sound, I am printing it and able to get a correct location.