Used NVStore to keep lora device keys and added a boostrap mode
This commit is contained in:
@@ -4,6 +4,50 @@
|
||||
#include "lorawan/LoRaWANInterface.h"
|
||||
#include "lorawan/system/lorawan_data_structures.h"
|
||||
#include "mbed.h"
|
||||
#include "nvstore.h"
|
||||
|
||||
#define NVKEY_DEVICE_EUI 1
|
||||
#define NVKEY_APP_EUI 2
|
||||
#define NVKEY_APP_KEY 3
|
||||
|
||||
#if MBED_CONF_APP_MODE_BOOTSTRAP
|
||||
|
||||
const static uint8_t dev_eui[] = MBED_CONF_LORA_DEVICE_EUI;
|
||||
const static uint8_t app_eui[] = MBED_CONF_LORA_APPLICATION_EUI;
|
||||
const static uint8_t app_key[] = MBED_CONF_LORA_APPLICATION_KEY;
|
||||
|
||||
int main(void) {
|
||||
int rc;
|
||||
uint16_t key;
|
||||
uint16_t rsize;
|
||||
uint8_t test[8];
|
||||
|
||||
// NVStore is a sigleton, get its instance
|
||||
NVStore &nvstore = NVStore::get_instance();
|
||||
|
||||
rc = nvstore.init();
|
||||
printf("Init NVStore : %d\n", rc);
|
||||
rc = nvstore.reset();
|
||||
printf("Reset NVStore : %d\n", rc);
|
||||
|
||||
key = NVKEY_DEVICE_EUI;
|
||||
nvstore.set(key, sizeof(dev_eui), dev_eui);
|
||||
key = NVKEY_APP_EUI;
|
||||
nvstore.set(key, sizeof(app_eui), app_eui);
|
||||
key = NVKEY_APP_KEY;
|
||||
nvstore.set(key, sizeof(app_key), app_key);
|
||||
|
||||
while(1) {
|
||||
printf("Bootstrap done\n");
|
||||
wait(1);
|
||||
}
|
||||
}
|
||||
|
||||
#else // MBED_CONF_APP_MODE_BOOTSTRAP
|
||||
|
||||
static uint8_t dev_eui[] = MBED_CONF_LORA_DEVICE_EUI;
|
||||
static uint8_t app_eui[] = MBED_CONF_LORA_APPLICATION_EUI;
|
||||
static uint8_t app_key[] = MBED_CONF_LORA_APPLICATION_KEY;
|
||||
|
||||
#if MBED_CONF_APP_DHT_ENABLED
|
||||
#include "DHT.h"
|
||||
@@ -72,6 +116,32 @@ HX711 loadcell(MBED_CONF_APP_HX711_DATA, MBED_CONF_APP_HX711_CLK);
|
||||
|
||||
int main(void) {
|
||||
lorawan_status_t retcode;
|
||||
lorawan_connect_t connect;
|
||||
int rc;
|
||||
uint16_t key;
|
||||
uint16_t readsize;
|
||||
|
||||
connect.connect_type = LORAWAN_CONNECTION_OTAA;
|
||||
|
||||
// NVStore is a sigleton, get its instance
|
||||
NVStore &nvstore = NVStore::get_instance();
|
||||
|
||||
if (nvstore.init() != NVSTORE_SUCCESS) {
|
||||
debug("\r\n NVStore initialization failed! \r\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
key = NVKEY_DEVICE_EUI;
|
||||
nvstore.get(key, sizeof(dev_eui), dev_eui, readsize);
|
||||
key = NVKEY_APP_EUI;
|
||||
nvstore.get(key, sizeof(app_eui), app_eui, readsize);
|
||||
key = NVKEY_APP_KEY;
|
||||
nvstore.get(key, sizeof(app_key), app_key, readsize);
|
||||
|
||||
connect.connection_u.otaa.app_eui = const_cast<uint8_t *>(app_eui);
|
||||
connect.connection_u.otaa.dev_eui = const_cast<uint8_t *>(dev_eui);
|
||||
connect.connection_u.otaa.app_key = const_cast<uint8_t *>(app_key);
|
||||
connect.connection_u.otaa.nb_trials = MBED_CONF_LORA_NB_TRIALS;
|
||||
|
||||
#if MBED_CONF_APP_HX711_ENABLED
|
||||
loadcell.powerDown();
|
||||
@@ -109,7 +179,7 @@ int main(void) {
|
||||
|
||||
debug("\r\n Adaptive data rate (ADR) - Enabled \r\n");
|
||||
|
||||
retcode = lorawan.connect();
|
||||
retcode = lorawan.connect(connect);
|
||||
|
||||
if(retcode == LORAWAN_STATUS_OK || retcode == LORAWAN_STATUS_CONNECT_IN_PROGRESS) {
|
||||
} else {
|
||||
@@ -247,3 +317,5 @@ static void lora_event_handler(lorawan_event_t event) {
|
||||
MBED_ASSERT("Unknown Event");
|
||||
}
|
||||
}
|
||||
|
||||
#endif // MBED_APP_MODE_BOOTSTRAP
|
||||
@@ -1,5 +1,6 @@
|
||||
{
|
||||
"config": {
|
||||
"mode-bootstrap": { "value": "false" },
|
||||
"tx-timer": { "value": 600000 },
|
||||
"lora-radio": {
|
||||
"help": "Which radio to use (options: SX1272,SX1276)",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/bin/sh
|
||||
#!/bin/bash
|
||||
|
||||
# patterns
|
||||
DEVICEEUI=ABBAABBAABBAABBA
|
||||
|
||||
Reference in New Issue
Block a user