Skip to content

Commit

Permalink
User serial number for DevEUI
Browse files Browse the repository at this point in the history
  • Loading branch information
janjongboom committed Jan 30, 2019
1 parent e0e3551 commit 0914e22
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
6 changes: 2 additions & 4 deletions README.md
Expand Up @@ -20,7 +20,7 @@ Connect the CryptoAuthentication UDFN Socket Kit to the `I2C_SDA` and `I2C_SCL`

On the SAML21 Xplained Pro development board, connect the LoRa radio to `EXT1`, and the CryptoAuthentication UDFN Socket Kit to `EXT3`.

![SAML21 Xplained Pro with LoRa radio and secure element](media/secure01.png)
![SAML21 Xplained Pro with LoRa radio and secure element](media/secure01.jpg)

## Getting started

Expand All @@ -46,9 +46,7 @@ This application can be built using [Mbed CLI](https://os.mbed.com/docs/mbed-os/

### Setting credentials

You need to set your application EUI if you're using LoRaWAN 1.0.x. In addition, you might need to set your device EUI, if your ATECC608A-MAHTN-T does not have it's Device EUI present in Slot 10. If this is the case, the message `Cannot read device EUI in slot 10` will pop up.

To set these EUIs, open `main.cpp`, and look for `LORAWAN_DEV_EUI` and `LORAWAN_APP_EUI`.
You need to set your application EUI if you're using LoRaWAN 1.0.x. To set this EUIs, open `main.cpp`, and look for `APP_EUI`.

### Setting the channel plan

Expand Down
34 changes: 27 additions & 7 deletions main.cpp
Expand Up @@ -29,8 +29,7 @@

static ATCAIfaceCfg atecc608_i2c_config;

// Keys, if DevEUI is written in a slot on the ATECC608A then that is used
static uint8_t DEV_EUI[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
// Application EUI (only used in LoRaWAN 1.0.x)
static uint8_t APP_EUI[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };

// Max payload size can be LORAMAC_PHY_MAXPAYLOAD.
Expand Down Expand Up @@ -83,15 +82,19 @@ static LoRaWANInterface lorawan(radio);
*/
static lorawan_app_callbacks_t callbacks;

static void print_buffer(const char *message, uint8_t *buffer, size_t buffer_size) {
printf(message);
for (size_t ix = 0; ix < buffer_size; ix++) {
printf("%02x ", buffer[ix]);
}
printf("\r\n");
}

/**
* Entry point for application
*/
int main(void)
{
if (APP_EUI[0] == 0x0 && APP_EUI[1] == 0x0 && APP_EUI[2] == 0x0 && APP_EUI[3] == 0x0 && APP_EUI[4] == 0x0 && APP_EUI[5] == 0x0 && APP_EUI[6] == 0x0 && APP_EUI[7] == 0x0) {
printf("Set your LoRaWAN application EUI first!\n");
return -1;
}

// Setup secure element
atecc608_i2c_config.iface_type = ATCA_I2C_IFACE;
Expand All @@ -104,6 +107,23 @@ int main(void)
//select_device(ATECC608A);
atcab_init(&atecc608_i2c_config);

uint8_t serialnum[ATCA_SERIAL_NUM_SIZE];
ATCA_STATUS serialnum_status = atcab_read_serial_number(serialnum);
if (serialnum_status != ATCA_SUCCESS) {
printf(" Failed to read ATECC608A serial number (%d) \r\n", serialnum_status);
return 1;
}

printf("\r\n Mbed OS LoRaWAN example for ATECC608A-MAHTN-T \r\n");

print_buffer("\tDevice EUI: ", serialnum, 8);
print_buffer("\tApplication EUI: ", APP_EUI, 8);

if (APP_EUI[0] == 0x0 && APP_EUI[1] == 0x0 && APP_EUI[2] == 0x0 && APP_EUI[3] == 0x0 && APP_EUI[4] == 0x0 && APP_EUI[5] == 0x0 && APP_EUI[6] == 0x0 && APP_EUI[7] == 0x0) {
printf(" Set your LoRaWAN application EUI first in main.cpp! \r\n");
return -1;
}

// setup tracing
setup_trace();

Expand Down Expand Up @@ -145,7 +165,7 @@ int main(void)
lorawan_connect_t connect_params;
connect_params.connect_type = LORAWAN_CONNECTION_OTAA;

connect_params.connection_u.otaa.dev_eui = DEV_EUI;
connect_params.connection_u.otaa.dev_eui = serialnum;
connect_params.connection_u.otaa.app_eui = APP_EUI;
connect_params.connection_u.otaa.app_key = (uint8_t*)MBED_CONF_LORA_APPLICATION_KEY; // Will read from ATECC608 instead
connect_params.connection_u.otaa.nb_trials = 10;
Expand Down

0 comments on commit 0914e22

Please sign in to comment.