|
|
|
|
@ -6,9 +6,11 @@
@@ -6,9 +6,11 @@
|
|
|
|
|
#include "mbed.h" |
|
|
|
|
#include "nvstore.h" |
|
|
|
|
|
|
|
|
|
#define NVKEY_DEVICE_EUI 1 |
|
|
|
|
#define NVKEY_APP_EUI 2 |
|
|
|
|
#define NVKEY_APP_KEY 3 |
|
|
|
|
#define NVKEY_LORA_DEVICE_EUI 0x01 |
|
|
|
|
#define NVKEY_LORA_APP_EUI 0x02 |
|
|
|
|
#define NVKEY_LORA_APP_KEY 0x03 |
|
|
|
|
#define NVKEY_HX711_OFFSET 0x04 |
|
|
|
|
#define NVKEY_HX711_SCALE 0x05 |
|
|
|
|
|
|
|
|
|
#if MBED_CONF_APP_MODE_BOOTSTRAP |
|
|
|
|
|
|
|
|
|
@ -19,23 +21,33 @@ const static uint8_t app_key[] = MBED_CONF_LORA_APPLICATION_KEY;
@@ -19,23 +21,33 @@ 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); |
|
|
|
|
if (rc != NVSTORE_SUCCESS) { |
|
|
|
|
printf("Unable to init NVStore : %d\n", rc); |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
rc = nvstore.reset(); |
|
|
|
|
printf("Reset NVStore : %d\n", rc); |
|
|
|
|
if (rc != NVSTORE_SUCCESS) { |
|
|
|
|
printf("Unable to reset NVStore : %d\n", rc); |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
printf("NVStore initiated and reseted\n"); |
|
|
|
|
|
|
|
|
|
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); |
|
|
|
|
key = NVKEY_LORA_DEVICE_EUI; |
|
|
|
|
if (nvstore.set(key, sizeof(dev_eui), dev_eui) != NVSTORE_SUCCESS) { |
|
|
|
|
printf("Unable to write LoRa Device EUI\n"); |
|
|
|
|
} |
|
|
|
|
key = NVKEY_LORA_APP_EUI; |
|
|
|
|
if (nvstore.set(key, sizeof(app_eui), app_eui) != NVSTORE_SUCCESS) { |
|
|
|
|
printf("Unable to write LoRa Application EUI\n"); |
|
|
|
|
} |
|
|
|
|
key = NVKEY_LORA_APP_KEY; |
|
|
|
|
if (nvstore.set(key, sizeof(app_key), app_key) != NVSTORE_SUCCESS) { |
|
|
|
|
printf("Unable to write LoRa Application key\n"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
while(1) { |
|
|
|
|
printf("Bootstrap done\n"); |
|
|
|
|
@ -131,12 +143,26 @@ int main(void) {
@@ -131,12 +143,26 @@ int main(void) {
|
|
|
|
|
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); |
|
|
|
|
key = NVKEY_LORA_DEVICE_EUI; |
|
|
|
|
rc = nvstore.get(key, sizeof(dev_eui), dev_eui, readsize); |
|
|
|
|
if (rc != NVSTORE_SUCCESS || readsize != sizeof(dev_eui)) { |
|
|
|
|
debug("\r\n Failed to read LoRa Device EUI from NVStore! \r\n"); |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
key = NVKEY_LORA_APP_EUI; |
|
|
|
|
rc = nvstore.get(key, sizeof(app_eui), app_eui, readsize); |
|
|
|
|
if (rc != NVSTORE_SUCCESS || readsize != sizeof(app_eui)) { |
|
|
|
|
debug("\r\n Failed to read LoRa Application EUI from NVStore! \r\n"); |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
key = NVKEY_LORA_APP_KEY; |
|
|
|
|
rc =nvstore.get(key, sizeof(app_key), app_key, readsize); |
|
|
|
|
if (rc != NVSTORE_SUCCESS || readsize != sizeof(app_key)) { |
|
|
|
|
debug("\r\n Failed to read LoRa Application Key from NVStore! \r\n"); |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
connect.connection_u.otaa.app_eui = const_cast<uint8_t *>(app_eui); |
|
|
|
|
connect.connection_u.otaa.dev_eui = const_cast<uint8_t *>(dev_eui); |
|
|
|
|
|