Compare commits
3 Commits
ed1c5c4337
...
e93dc481e0
| Author | SHA1 | Date | |
|---|---|---|---|
| e93dc481e0 | |||
| 35a9f287ef | |||
| b5f75f9f18 |
@@ -17,12 +17,6 @@ using namespace events;
|
||||
|
||||
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.
|
||||
* 16 is the safe number for the stack events, however, if application
|
||||
@@ -60,37 +54,37 @@ int main(void) {
|
||||
lorawan_status_t retcode;
|
||||
|
||||
#if MBED_CONF_APP_HX711_ENABLED
|
||||
loadcell.powerDown();
|
||||
loadcell.setScale(MBED_CONF_APP_HX711_SCALE);
|
||||
loadcell.setOffset(MBED_CONF_APP_HX711_OFFSET);
|
||||
loadcell.powerDown();
|
||||
#endif
|
||||
|
||||
// Initialize LoRaWAN stack
|
||||
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;
|
||||
}
|
||||
|
||||
printf("\r\n Mbed LoRaWANStack initialized \r\n");
|
||||
debug("\r\n Mbed LoRaWANStack initialized \r\n");
|
||||
|
||||
callbacks.events = mbed::callback(lora_event_handler);
|
||||
lorawan.add_app_callbacks(&callbacks);
|
||||
|
||||
// Set number of retries in case of CONFIRMED messages
|
||||
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;
|
||||
}
|
||||
|
||||
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
|
||||
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;
|
||||
}
|
||||
|
||||
printf("\r\n Adaptive data rate (ADR) - Enabled \r\n");
|
||||
debug("\r\n Adaptive data rate (ADR) - Enabled \r\n");
|
||||
|
||||
//led = 0;
|
||||
|
||||
@@ -98,11 +92,11 @@ int main(void) {
|
||||
|
||||
if(retcode == LORAWAN_STATUS_OK || retcode == LORAWAN_STATUS_CONNECT_IN_PROGRESS) {
|
||||
} else {
|
||||
printf("\r\n Connection error, code = %d \r\n", retcode);
|
||||
debug("\r\n Connection error, code = %d \r\n", retcode);
|
||||
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
|
||||
ev_queue.dispatch_forever();
|
||||
@@ -118,7 +112,7 @@ static void send_message() {
|
||||
|
||||
#if MBED_CONF_APP_BATTERY_ENABLED
|
||||
float vbat = bat.read();
|
||||
vbat = vbat * 5 / 3 * 3.3f;
|
||||
vbat = vbat * MBED_CONF_APP_BATTERY_RATIO * 3.3f;
|
||||
cayenne.addAnalogInput(1, vbat);
|
||||
#endif
|
||||
|
||||
@@ -126,15 +120,17 @@ static void send_message() {
|
||||
int err = dht.read();
|
||||
if(err == DHT::SUCCESS) {
|
||||
cayenne.addTemperature(1, dht.getTemperature());
|
||||
cayenne.addRelativeHumidity(2, dht.getHumidity());
|
||||
cayenne.addRelativeHumidity(1, dht.getHumidity());
|
||||
} else {
|
||||
printf("Error code : %d\r\n", err);
|
||||
debug("Error code : %d\r\n", err);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if MBED_CONF_APP_HX711_ENABLED
|
||||
loadcell.powerUp();
|
||||
cayenne.addAnalogInput(2, loadcell.getUnits(5));
|
||||
if (loadcell.waitReadyRetry(20, 100)) {
|
||||
cayenne.addAnalogInput(2, loadcell.getUnits(5));
|
||||
}
|
||||
loadcell.powerDown();
|
||||
#endif
|
||||
|
||||
@@ -147,12 +143,12 @@ static void send_message() {
|
||||
MSG_UNCONFIRMED_FLAG);
|
||||
|
||||
if(retcode < 0) {
|
||||
retcode == LORAWAN_STATUS_WOULD_BLOCK ? printf("send - WOULD BLOCK\r\n")
|
||||
: printf("\r\n send() - Error code %d \r\n", retcode);
|
||||
retcode == LORAWAN_STATUS_WOULD_BLOCK ? debug("send - WOULD BLOCK\r\n")
|
||||
: debug("\r\n send() - Error code %d \r\n", retcode);
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -165,17 +161,17 @@ static void receive_message() {
|
||||
MSG_CONFIRMED_FLAG | MSG_UNCONFIRMED_FLAG);
|
||||
|
||||
if(retcode < 0) {
|
||||
printf("\r\n receive() - Error code %d \r\n", retcode);
|
||||
debug("\r\n receive() - Error code %d \r\n", retcode);
|
||||
return;
|
||||
}
|
||||
|
||||
printf(" Data:");
|
||||
debug(" Data:");
|
||||
|
||||
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);
|
||||
}
|
||||
@@ -184,20 +180,21 @@ static void lora_event_handler(lorawan_event_t event) {
|
||||
switch(event) {
|
||||
case CONNECTED:
|
||||
//led = 1;
|
||||
printf("\r\n Connection - Successful \r\n");
|
||||
debug("\r\n Connection - Successful \r\n");
|
||||
if(MBED_CONF_LORA_DUTY_CYCLE_ON) {
|
||||
send_message();
|
||||
} else {
|
||||
ev_queue.call_every(TX_TIMER, send_message);
|
||||
send_message();
|
||||
ev_queue.call_every(MBED_CONF_APP_TX_TIMER, send_message);
|
||||
}
|
||||
|
||||
break;
|
||||
case DISCONNECTED:
|
||||
ev_queue.break_dispatch();
|
||||
printf("\r\n Disconnected Successfully \r\n");
|
||||
debug("\r\n Disconnected Successfully \r\n");
|
||||
break;
|
||||
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) {
|
||||
send_message();
|
||||
}
|
||||
@@ -206,22 +203,22 @@ static void lora_event_handler(lorawan_event_t event) {
|
||||
case TX_ERROR:
|
||||
case TX_CRYPTO_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
|
||||
if(MBED_CONF_LORA_DUTY_CYCLE_ON) {
|
||||
send_message();
|
||||
}
|
||||
break;
|
||||
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();
|
||||
break;
|
||||
case RX_TIMEOUT:
|
||||
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;
|
||||
case JOIN_FAILURE:
|
||||
printf("\r\n OTAA Failed - Check Keys \r\n");
|
||||
debug("\r\n OTAA Failed - Check Keys \r\n");
|
||||
break;
|
||||
default:
|
||||
MBED_ASSERT("Unknown Event");
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
{
|
||||
"config": {
|
||||
"tx-timer": { "value": 30000 },
|
||||
"lora-radio": {
|
||||
"help": "Which radio to use (options: SX1272,SX1276)",
|
||||
"value": "SX1276"
|
||||
@@ -25,6 +26,7 @@
|
||||
"lora-tcxo": { "value": "NC" },
|
||||
"battery-enabled": { "value": "false" },
|
||||
"battery-adc": { "value": "NC" },
|
||||
"battery-ratio": { "value": "2.0f" },
|
||||
"dht-enabled": { "value": "false" },
|
||||
"dht-type": { "value": "DHT::DHT22" },
|
||||
"dht-data": { "value": "NC" },
|
||||
@@ -256,8 +258,8 @@
|
||||
"main_stack_size": 1024,
|
||||
"target.lpticker_lptim": 0,
|
||||
"target.clock_source": "USE_PLL_HSI",
|
||||
"target.stdio_uart_tx": "PC_10",
|
||||
"target.stdio_uart_rx": "PC_11",
|
||||
"lora.duty-cycle-on": false,
|
||||
"tx-timer": 600000,
|
||||
"lora-radio": "SX1272",
|
||||
"lora-spi-mosi": "D11",
|
||||
"lora-spi-miso": "D12",
|
||||
@@ -277,8 +279,9 @@
|
||||
"lora-ant-switch": "A4",
|
||||
"lora-pwr-amp-ctl": "NC",
|
||||
"lora-tcxo": "NC",
|
||||
"battery-enabled": false,
|
||||
"battery-adc": "PA_2",
|
||||
"battery-enabled": true,
|
||||
"battery-adc": "A1",
|
||||
"battery-ratio": "2.0f",
|
||||
"dht-enabled": true,
|
||||
"dht-data": "D8",
|
||||
"dht-type": "DHT::DHT22",
|
||||
@@ -286,7 +289,7 @@
|
||||
"hx711-clk": "D7",
|
||||
"hx711-data": "D6",
|
||||
"hx711-scale": "21000.0f",
|
||||
"hx711-offset": -2000
|
||||
"hx711-offset": 59600
|
||||
}
|
||||
},
|
||||
"macros": ["MBEDTLS_USER_CONFIG_FILE=\"mbedtls_lora_config.h\""]
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
https://github.com/ARMmbed/minimal-printf/#7a57a3e36a227a3e412cec55b0eeaf649b9fa7c9
|
||||
@@ -0,0 +1,56 @@
|
||||
{
|
||||
"GCC_ARM": {
|
||||
"common": ["-c", "-Wall", "-Wextra",
|
||||
"-Wno-unused-parameter", "-Wno-missing-field-initializers",
|
||||
"-fmessage-length=0", "-fno-exceptions", "-fno-builtin",
|
||||
"-ffunction-sections", "-fdata-sections", "-funsigned-char",
|
||||
"-MMD", "-fno-delete-null-pointer-checks",
|
||||
"-fomit-frame-pointer", "-Os", "-DNDEBUG", "-g1"],
|
||||
"asm": ["-x", "assembler-with-cpp"],
|
||||
"c": ["-std=gnu99"],
|
||||
"cxx": ["-std=gnu++98", "-fno-rtti", "-Wvla"],
|
||||
"ld": ["-Wl,--gc-sections", "-Wl,--wrap,main", "-Wl,--wrap,_malloc_r",
|
||||
"-Wl,--wrap,_free_r", "-Wl,--wrap,_realloc_r", "-Wl,--wrap,_memalign_r",
|
||||
"-Wl,--wrap,_calloc_r", "-Wl,--wrap,exit", "-Wl,--wrap,atexit",
|
||||
"-Wl,-n", "--specs=nano.specs"]
|
||||
},
|
||||
"ARMC6": {
|
||||
"common": ["-c", "--target=arm-arm-none-eabi", "-mthumb", "-Oz",
|
||||
"-Wno-armcc-pragma-push-pop", "-Wno-armcc-pragma-anon-unions",
|
||||
"-DMULADDC_CANNOT_USE_R7", "-fdata-sections",
|
||||
"-fno-exceptions", "-MMD", "-D_LIBCPP_EXTERN_TEMPLATE(...)=",
|
||||
"-fshort-enums", "-fshort-wchar"],
|
||||
"asm": [],
|
||||
"c": ["-D__ASSERT_MSG", "-std=gnu99"],
|
||||
"cxx": ["-fno-rtti", "-std=gnu++98"],
|
||||
"ld": ["--show_full_path", "--legacyalign"]
|
||||
},
|
||||
"ARM": {
|
||||
"common": ["-c", "--gnu", "-Ospace", "--split_sections",
|
||||
"--apcs=interwork", "--brief_diagnostics", "--restrict",
|
||||
"--multibyte_chars", "-O3", "-DNDEBUG"],
|
||||
"asm": [],
|
||||
"c": ["--md", "--no_depend_system_headers", "--c99", "-D__ASSERT_MSG"],
|
||||
"cxx": ["--cpp", "--no_rtti", "--no_vla"],
|
||||
"ld": ["--show_full_path"]
|
||||
},
|
||||
"uARM": {
|
||||
"common": ["-c", "--gnu", "-Ospace", "--split_sections",
|
||||
"--apcs=interwork", "--brief_diagnostics", "--restrict",
|
||||
"--multibyte_chars", "-O3", "-D__MICROLIB",
|
||||
"--library_type=microlib", "-DMBED_RTOS_SINGLE_THREAD", "-DNDEBUG"],
|
||||
"asm": [],
|
||||
"c": ["--md", "--no_depend_system_headers", "--c99", "-D__ASSERT_MSG"],
|
||||
"cxx": ["--cpp", "--no_rtti", "--no_vla"],
|
||||
"ld": ["--library_type=microlib"]
|
||||
},
|
||||
"IAR": {
|
||||
"common": [
|
||||
"--no_wrap_diagnostics", "-e",
|
||||
"--diag_suppress=Pa050,Pa084,Pa093,Pa082", "-Ohz", "-DNDEBUG", "--enable_restrict"],
|
||||
"asm": [],
|
||||
"c": ["--vla", "--diag_suppress=Pe546"],
|
||||
"cxx": ["--guard_calls", "--no_static_destruction"],
|
||||
"ld": ["--skip_dynamic_initialization", "--threaded_lib"]
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1 +1 @@
|
||||
https://github.com/atoy40/mbed-dht/#0aa899f3a68e02eec69e74a6f68c35249530d89d
|
||||
https://github.com/atoy40/mbed-dht/#5e378f5eaf8d3ba88af711e035652d6277124a06
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
https://github.com/atoy40/mbed-hx711/#92640d4fcfc8f2128c3f3f54031cfafed5733bc8
|
||||
https://github.com/atoy40/mbed-hx711/#30e787849a54a53c0e055e21ad45d0f7b2c982b6
|
||||
|
||||
Reference in New Issue
Block a user