Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

badger_temp_sensor_send and badger_temp_sensor_send_status should not send JSON and not use confirmed uplinks #5

Open
avbentem opened this issue Feb 5, 2017 · 2 comments

Comments

@avbentem
Copy link

avbentem commented Feb 5, 2017

Sending JSON is just a waste of bandwidth, and so is using confirmed uplinks for all data.

badgerboard/src/badger.cpp

Lines 533 to 587 in a2b1dfe

bool badger_temp_sensor_send()
{
if(s_fabo_init_successful == false)
return false;
char json_data[60];
float temp = faboHumidity.getTemperature();
float humidity = faboHumidity.getHumidity();
int temp_decimal1 = (int)temp;
temp -= temp_decimal1;
temp *= 100;
int temp_decimal2 = (int)temp;
int hum_decimal1 = (int)humidity;
humidity -= hum_decimal1;
humidity *= 100;
int hum_decimal2 = (int)humidity;
snprintf(json_data, 60, "{\"T\":%d.%d,\"H\":%d.%d}", temp_decimal1, temp_decimal2, hum_decimal1, hum_decimal2);
#ifdef SERIAL_DEBUG
Serial.println(json_data);
#endif
return LoRa_send(19, (uint8_t*) json_data, strlen(json_data));
}
bool badger_temp_sensor_send_status(uint8_t status)
{
char json_data[LORA_TX_BUF_LEN_MAX];
float temp = 0;
float humidity = 0;
if(s_fabo_init_successful == true)
{
temp = faboHumidity.getTemperature();
humidity = faboHumidity.getHumidity();
}
float voltage = badger_read_vcc_mv() / 1000.0;
int temp_decimal1 = (int)temp;
temp -= temp_decimal1;
temp *= 10;
int temp_decimal2 = (int)temp;
int hum_decimal1 = (int)humidity;
humidity -= hum_decimal1;
humidity *= 10;
int hum_decimal2 = (int)humidity;
int volt_decimal1 = (int)voltage;
voltage -= volt_decimal1;
voltage *= 10;
int volt_decimal2 = (int)voltage;
snprintf(json_data, LORA_TX_BUF_LEN_MAX, "{\"S\":%d,\"T\":%d.%d,\"H\":%d.%d,\"V\":%d.%d,\"P\":%d/%d}", status, temp_decimal1, temp_decimal2, hum_decimal1, hum_decimal2, volt_decimal1, volt_decimal2, (uint16_t)s_tx_successful_count + 1, (uint16_t)s_tx_failed_count);
#ifdef SERIAL_DEBUG
Serial.println(json_data);
#endif
return LoRa_send(19, (uint8_t*) json_data, strlen(json_data), NO_ACK);
}

Something like the following will do just fine; the backend application can easily decode it if documented.

// Reserve 6 bytes (3 words) to send temperature, humidity and voltage
byte data[6];

double temp = faboHumidity.getTemperature();
double humi = faboHumidity.getHumidity();

// Encode the 2 doubles into the first 4 bytes
int temp = 100 * hts221.getTemperature();
int humi = 100 * hts221.getHumidity();
data[0] = temp >> 8; // or: highByte(temp)
data[1] = temp; // or: lowByte(temp)
data[2] = humi >> 8;
data[3] = humi;
// For some reason the core library uses port 19; please document!
return LoRa_send(19, (uint8_t*) data, 4, NO_ACK);
...
long voltage = badger_read_vcc_mv();
data[4] = voltage >> 8;
data[5] = voltage;
// One could use a different port here
return LoRa_send(19, (uint8_t*) data, 6, NO_ACK);

(I'd argue that sending the values should be part of the core library at all. For decoding the above see also Getting Badgerboard to work with TTN.)

@KertIlm
Copy link
Collaborator

KertIlm commented Feb 8, 2017

Hi,

Status packet is not meant to be sent very often and is meant rather as keepalive packet, thus its confirmed. Since Badgerboard is meant mostly for making proof-of-concepts, and JSON is simply human readable, we started with it. But we will add similar function You proposed.

@avbentem
Copy link
Author

avbentem commented Feb 8, 2017

As far as I can tell from the code, the status message is sent unconfirmed, but the regular message uses the default, and your default is to send confirmed messages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants