Added tx-timer and battery-ratio config items
This commit is contained in:
@@ -17,12 +17,6 @@ using namespace events;
|
|||||||
|
|
||||||
uint8_t rx_buffer[LORAMAC_PHY_MAXPAYLOAD];
|
uint8_t rx_buffer[LORAMAC_PHY_MAXPAYLOAD];
|
||||||
|
|
||||||
/*
|
|
||||||
* Sets up an application dependent transmission timer in ms. Used only when Duty Cycling is off for
|
|
||||||
* testing
|
|
||||||
*/
|
|
||||||
#define TX_TIMER 30000 //600000
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maximum number of events for the event queue.
|
* Maximum number of events for the event queue.
|
||||||
* 16 is the safe number for the stack events, however, if application
|
* 16 is the safe number for the stack events, however, if application
|
||||||
@@ -60,37 +54,37 @@ int main(void) {
|
|||||||
lorawan_status_t retcode;
|
lorawan_status_t retcode;
|
||||||
|
|
||||||
#if MBED_CONF_APP_HX711_ENABLED
|
#if MBED_CONF_APP_HX711_ENABLED
|
||||||
|
loadcell.powerDown();
|
||||||
loadcell.setScale(MBED_CONF_APP_HX711_SCALE);
|
loadcell.setScale(MBED_CONF_APP_HX711_SCALE);
|
||||||
loadcell.setOffset(MBED_CONF_APP_HX711_OFFSET);
|
loadcell.setOffset(MBED_CONF_APP_HX711_OFFSET);
|
||||||
loadcell.powerDown();
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Initialize LoRaWAN stack
|
// Initialize LoRaWAN stack
|
||||||
if(lorawan.initialize(&ev_queue) != LORAWAN_STATUS_OK) {
|
if(lorawan.initialize(&ev_queue) != LORAWAN_STATUS_OK) {
|
||||||
printf("\r\n LoRa initialization failed! \r\n");
|
debug("\r\n LoRa initialization failed! \r\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("\r\n Mbed LoRaWANStack initialized \r\n");
|
debug("\r\n Mbed LoRaWANStack initialized \r\n");
|
||||||
|
|
||||||
callbacks.events = mbed::callback(lora_event_handler);
|
callbacks.events = mbed::callback(lora_event_handler);
|
||||||
lorawan.add_app_callbacks(&callbacks);
|
lorawan.add_app_callbacks(&callbacks);
|
||||||
|
|
||||||
// Set number of retries in case of CONFIRMED messages
|
// Set number of retries in case of CONFIRMED messages
|
||||||
if(lorawan.set_confirmed_msg_retries(CONFIRMED_MSG_RETRY_COUNTER) != LORAWAN_STATUS_OK) {
|
if(lorawan.set_confirmed_msg_retries(CONFIRMED_MSG_RETRY_COUNTER) != LORAWAN_STATUS_OK) {
|
||||||
printf("\r\n set_confirmed_msg_retries failed! \r\n\r\n");
|
debug("\r\n set_confirmed_msg_retries failed! \r\n\r\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("\r\n CONFIRMED message retries : %d \r\n", CONFIRMED_MSG_RETRY_COUNTER);
|
debug("\r\n CONFIRMED message retries : %d \r\n", CONFIRMED_MSG_RETRY_COUNTER);
|
||||||
|
|
||||||
// Enable adaptive data rate
|
// Enable adaptive data rate
|
||||||
if(lorawan.enable_adaptive_datarate() != LORAWAN_STATUS_OK) {
|
if(lorawan.enable_adaptive_datarate() != LORAWAN_STATUS_OK) {
|
||||||
printf("\r\n enable_adaptive_datarate failed! \r\n");
|
debug("\r\n enable_adaptive_datarate failed! \r\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("\r\n Adaptive data rate (ADR) - Enabled \r\n");
|
debug("\r\n Adaptive data rate (ADR) - Enabled \r\n");
|
||||||
|
|
||||||
//led = 0;
|
//led = 0;
|
||||||
|
|
||||||
@@ -98,11 +92,11 @@ int main(void) {
|
|||||||
|
|
||||||
if(retcode == LORAWAN_STATUS_OK || retcode == LORAWAN_STATUS_CONNECT_IN_PROGRESS) {
|
if(retcode == LORAWAN_STATUS_OK || retcode == LORAWAN_STATUS_CONNECT_IN_PROGRESS) {
|
||||||
} else {
|
} else {
|
||||||
printf("\r\n Connection error, code = %d \r\n", retcode);
|
debug("\r\n Connection error, code = %d \r\n", retcode);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("\r\n Connection - In Progress ...\r\n");
|
debug("\r\n Connection - In Progress ...\r\n");
|
||||||
|
|
||||||
// make your event queue dispatching events forever
|
// make your event queue dispatching events forever
|
||||||
ev_queue.dispatch_forever();
|
ev_queue.dispatch_forever();
|
||||||
@@ -118,7 +112,7 @@ static void send_message() {
|
|||||||
|
|
||||||
#if MBED_CONF_APP_BATTERY_ENABLED
|
#if MBED_CONF_APP_BATTERY_ENABLED
|
||||||
float vbat = bat.read();
|
float vbat = bat.read();
|
||||||
vbat = vbat * 5 / 3 * 3.3f;
|
vbat = vbat * MBED_CONF_APP_BATTERY_RATIO * 3.3f;
|
||||||
cayenne.addAnalogInput(1, vbat);
|
cayenne.addAnalogInput(1, vbat);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -126,15 +120,17 @@ static void send_message() {
|
|||||||
int err = dht.read();
|
int err = dht.read();
|
||||||
if(err == DHT::SUCCESS) {
|
if(err == DHT::SUCCESS) {
|
||||||
cayenne.addTemperature(1, dht.getTemperature());
|
cayenne.addTemperature(1, dht.getTemperature());
|
||||||
cayenne.addRelativeHumidity(2, dht.getHumidity());
|
cayenne.addRelativeHumidity(1, dht.getHumidity());
|
||||||
} else {
|
} else {
|
||||||
printf("Error code : %d\r\n", err);
|
debug("Error code : %d\r\n", err);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if MBED_CONF_APP_HX711_ENABLED
|
#if MBED_CONF_APP_HX711_ENABLED
|
||||||
loadcell.powerUp();
|
loadcell.powerUp();
|
||||||
|
if (loadcell.waitReadyRetry(20, 100)) {
|
||||||
cayenne.addAnalogInput(2, loadcell.getUnits(5));
|
cayenne.addAnalogInput(2, loadcell.getUnits(5));
|
||||||
|
}
|
||||||
loadcell.powerDown();
|
loadcell.powerDown();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -147,12 +143,12 @@ static void send_message() {
|
|||||||
MSG_UNCONFIRMED_FLAG);
|
MSG_UNCONFIRMED_FLAG);
|
||||||
|
|
||||||
if(retcode < 0) {
|
if(retcode < 0) {
|
||||||
retcode == LORAWAN_STATUS_WOULD_BLOCK ? printf("send - WOULD BLOCK\r\n")
|
retcode == LORAWAN_STATUS_WOULD_BLOCK ? debug("send - WOULD BLOCK\r\n")
|
||||||
: printf("\r\n send() - Error code %d \r\n", retcode);
|
: debug("\r\n send() - Error code %d \r\n", retcode);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("\r\n %d bytes scheduled for transmission \r\n", retcode);
|
debug("\r\n %d bytes scheduled for transmission \r\n", retcode);
|
||||||
cayenne.reset();
|
cayenne.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,17 +161,17 @@ static void receive_message() {
|
|||||||
MSG_CONFIRMED_FLAG | MSG_UNCONFIRMED_FLAG);
|
MSG_CONFIRMED_FLAG | MSG_UNCONFIRMED_FLAG);
|
||||||
|
|
||||||
if(retcode < 0) {
|
if(retcode < 0) {
|
||||||
printf("\r\n receive() - Error code %d \r\n", retcode);
|
debug("\r\n receive() - Error code %d \r\n", retcode);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf(" Data:");
|
debug(" Data:");
|
||||||
|
|
||||||
for(uint8_t i = 0; i < retcode; i++) {
|
for(uint8_t i = 0; i < retcode; i++) {
|
||||||
printf("%x", rx_buffer[i]);
|
debug("%x", rx_buffer[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("\r\n Data Length: %d\r\n", retcode);
|
debug("\r\n Data Length: %d\r\n", retcode);
|
||||||
|
|
||||||
memset(rx_buffer, 0, LORAMAC_PHY_MAXPAYLOAD);
|
memset(rx_buffer, 0, LORAMAC_PHY_MAXPAYLOAD);
|
||||||
}
|
}
|
||||||
@@ -184,20 +180,21 @@ static void lora_event_handler(lorawan_event_t event) {
|
|||||||
switch(event) {
|
switch(event) {
|
||||||
case CONNECTED:
|
case CONNECTED:
|
||||||
//led = 1;
|
//led = 1;
|
||||||
printf("\r\n Connection - Successful \r\n");
|
debug("\r\n Connection - Successful \r\n");
|
||||||
if(MBED_CONF_LORA_DUTY_CYCLE_ON) {
|
if(MBED_CONF_LORA_DUTY_CYCLE_ON) {
|
||||||
send_message();
|
send_message();
|
||||||
} else {
|
} else {
|
||||||
ev_queue.call_every(TX_TIMER, send_message);
|
send_message();
|
||||||
|
ev_queue.call_every(MBED_CONF_APP_TX_TIMER, send_message);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case DISCONNECTED:
|
case DISCONNECTED:
|
||||||
ev_queue.break_dispatch();
|
ev_queue.break_dispatch();
|
||||||
printf("\r\n Disconnected Successfully \r\n");
|
debug("\r\n Disconnected Successfully \r\n");
|
||||||
break;
|
break;
|
||||||
case TX_DONE:
|
case TX_DONE:
|
||||||
printf("\r\n Message Sent to Network Server \r\n");
|
debug("\r\n Message Sent to Network Server \r\n");
|
||||||
if(MBED_CONF_LORA_DUTY_CYCLE_ON) {
|
if(MBED_CONF_LORA_DUTY_CYCLE_ON) {
|
||||||
send_message();
|
send_message();
|
||||||
}
|
}
|
||||||
@@ -206,22 +203,22 @@ static void lora_event_handler(lorawan_event_t event) {
|
|||||||
case TX_ERROR:
|
case TX_ERROR:
|
||||||
case TX_CRYPTO_ERROR:
|
case TX_CRYPTO_ERROR:
|
||||||
case TX_SCHEDULING_ERROR:
|
case TX_SCHEDULING_ERROR:
|
||||||
printf("\r\n Transmission Error - EventCode = %d \r\n", event);
|
debug("\r\n Transmission Error - EventCode = %d \r\n", event);
|
||||||
// try again
|
// try again
|
||||||
if(MBED_CONF_LORA_DUTY_CYCLE_ON) {
|
if(MBED_CONF_LORA_DUTY_CYCLE_ON) {
|
||||||
send_message();
|
send_message();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case RX_DONE:
|
case RX_DONE:
|
||||||
printf("\r\n Received message from Network Server \r\n");
|
debug("\r\n Received message from Network Server \r\n");
|
||||||
receive_message();
|
receive_message();
|
||||||
break;
|
break;
|
||||||
case RX_TIMEOUT:
|
case RX_TIMEOUT:
|
||||||
case RX_ERROR:
|
case RX_ERROR:
|
||||||
printf("\r\n Error in reception - Code = %d \r\n", event);
|
debug("\r\n Error in reception - Code = %d \r\n", event);
|
||||||
break;
|
break;
|
||||||
case JOIN_FAILURE:
|
case JOIN_FAILURE:
|
||||||
printf("\r\n OTAA Failed - Check Keys \r\n");
|
debug("\r\n OTAA Failed - Check Keys \r\n");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
MBED_ASSERT("Unknown Event");
|
MBED_ASSERT("Unknown Event");
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"config": {
|
"config": {
|
||||||
|
"tx-timer": { "value": 30000 },
|
||||||
"lora-radio": {
|
"lora-radio": {
|
||||||
"help": "Which radio to use (options: SX1272,SX1276)",
|
"help": "Which radio to use (options: SX1272,SX1276)",
|
||||||
"value": "SX1276"
|
"value": "SX1276"
|
||||||
@@ -25,6 +26,7 @@
|
|||||||
"lora-tcxo": { "value": "NC" },
|
"lora-tcxo": { "value": "NC" },
|
||||||
"battery-enabled": { "value": "false" },
|
"battery-enabled": { "value": "false" },
|
||||||
"battery-adc": { "value": "NC" },
|
"battery-adc": { "value": "NC" },
|
||||||
|
"battery-ratio": { "value": "2.0f" },
|
||||||
"dht-enabled": { "value": "false" },
|
"dht-enabled": { "value": "false" },
|
||||||
"dht-type": { "value": "DHT::DHT22" },
|
"dht-type": { "value": "DHT::DHT22" },
|
||||||
"dht-data": { "value": "NC" },
|
"dht-data": { "value": "NC" },
|
||||||
@@ -256,8 +258,8 @@
|
|||||||
"main_stack_size": 1024,
|
"main_stack_size": 1024,
|
||||||
"target.lpticker_lptim": 0,
|
"target.lpticker_lptim": 0,
|
||||||
"target.clock_source": "USE_PLL_HSI",
|
"target.clock_source": "USE_PLL_HSI",
|
||||||
"target.stdio_uart_tx": "PC_10",
|
"lora.duty-cycle-on": false,
|
||||||
"target.stdio_uart_rx": "PC_11",
|
"tx-timer": 600000,
|
||||||
"lora-radio": "SX1272",
|
"lora-radio": "SX1272",
|
||||||
"lora-spi-mosi": "D11",
|
"lora-spi-mosi": "D11",
|
||||||
"lora-spi-miso": "D12",
|
"lora-spi-miso": "D12",
|
||||||
@@ -277,8 +279,9 @@
|
|||||||
"lora-ant-switch": "A4",
|
"lora-ant-switch": "A4",
|
||||||
"lora-pwr-amp-ctl": "NC",
|
"lora-pwr-amp-ctl": "NC",
|
||||||
"lora-tcxo": "NC",
|
"lora-tcxo": "NC",
|
||||||
"battery-enabled": false,
|
"battery-enabled": true,
|
||||||
"battery-adc": "PA_2",
|
"battery-adc": "A1",
|
||||||
|
"battery-ratio": "2.0f",
|
||||||
"dht-enabled": true,
|
"dht-enabled": true,
|
||||||
"dht-data": "D8",
|
"dht-data": "D8",
|
||||||
"dht-type": "DHT::DHT22",
|
"dht-type": "DHT::DHT22",
|
||||||
@@ -286,7 +289,7 @@
|
|||||||
"hx711-clk": "D7",
|
"hx711-clk": "D7",
|
||||||
"hx711-data": "D6",
|
"hx711-data": "D6",
|
||||||
"hx711-scale": "21000.0f",
|
"hx711-scale": "21000.0f",
|
||||||
"hx711-offset": -2000
|
"hx711-offset": 59600
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"macros": ["MBEDTLS_USER_CONFIG_FILE=\"mbedtls_lora_config.h\""]
|
"macros": ["MBEDTLS_USER_CONFIG_FILE=\"mbedtls_lora_config.h\""]
|
||||||
|
|||||||
Reference in New Issue
Block a user