tftelkamp / single_chan_pkt_fwd

Single Channel LoRaWAN Gateway
Other
235 stars 310 forks source link

Disable "fake gps" when coordinates are 0,0. #17

Open jpmeijers opened 7 years ago

jpmeijers commented 7 years ago

When the coordinates are set to lat=0, lon=0, the status packet that are sent looks like:

{"stat":{"time":"2017-05-15 14:29:06 GMT","lati":0.00000,"long":0.00000,"alti":10,"rxnb":0,"rxok":0,"rxfw":0,"ackr":0.0,"dwnb":0,"txnb":0,"pfrm":"Single Channel Gateway","mail":"foo@bar.com","desc":"My gateway"}}

but on the TTN NOC I see

{"id":"eui-b827ebffff706141","status":{"time":"1494859297251862030","gps":{"latitude":0.0000012673606,"longitude":0.000002682209,"altitude":10}

Which means we get a floating point rounding error.

What we expected was that the coordinates remain 0, and are then replaced by the coordinates from the TTN Console.

Recommendation: If the coordinates are set to 0,0, do not add them to the status message. In other words, replace line 368 of main.cpp with (untested):

int j;

if(lat==0 || lon==0)
{
  j = snprintf((char *)(status_report + stat_index), STATUS_SIZE-stat_index, "{\"stat\":{\"time\":\"%s\",\"rxnb\":%u,\"rxok\":%u,\"rxfw\":%u,\"ackr\":%.1f,\"dwnb\":%u,\"txnb\":%u,\"pfrm\":\"%s\",\"mail\":\"%s\",\"desc\":\"%s\"}}", stat_timestamp, cp_nb_rx_rcv, cp_nb_rx_ok, cp_up_pkt_fwd, (float)0, 0, 0,platform,email,description);
}
else
{
  j = snprintf((char *)(status_report + stat_index), STATUS_SIZE-stat_index, "{\"stat\":{\"time\":\"%s\",\"lati\":%.5f,\"long\":%.5f,\"alti\":%i,\"rxnb\":%u,\"rxok\":%u,\"rxfw\":%u,\"ackr\":%.1f,\"dwnb\":%u,\"txnb\":%u,\"pfrm\":\"%s\",\"mail\":\"%s\",\"desc\":\"%s\"}}", stat_timestamp, lat, lon, (int)alt, cp_nb_rx_rcv, cp_nb_rx_ok, cp_up_pkt_fwd, (float)0, 0, 0,platform,email,description); 
}
Paul-B commented 7 years ago

I have tried this fix on my pi and can confirm that it works.