Skip to content

Commit ec9b391

Browse files
committed
Transmit device type in device ID
1 parent 2867f95 commit ec9b391

File tree

5 files changed

+16
-2
lines changed

5 files changed

+16
-2
lines changed

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
// Arm System View Description, downloaded from https://www.st.com/en/microcontrollers-microprocessors/stm32l476rc.html#
1818
"svdFile": "scripts/STM32L4x6.svd",
1919
"configFiles": [
20-
// Tell OpenOCD to open the ST Link connection to STM32F1 MCU.
20+
// Tell OpenOCD to open the ST Link connection to STM32 MCU.
2121
"interface/stlink-v2.cfg",
2222
// Previously: "target/stm32f1x.cfg",
2323
"target/stm32l4x.cfg",

libs/sensor_network/src/sensor_network.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,9 @@ const uint8_t *get_hardware_id(void) {
371371
return hw_id;
372372
}
373373

374+
// Device Type e.g. l476
375+
static const char *DEVICE_TYPE = MYNEWT_VAL(DEVICE_TYPE);
376+
374377
const char *get_device_id(void) {
375378
// Get the randomly-generated Device ID that will be sent in every CoAP Server message. Changes upon restart.
376379
if (device_id_text[0]) { return device_id_text; }
@@ -385,6 +388,12 @@ const char *get_device_id(void) {
385388
s += 2;
386389
}
387390
device_id_text[DEVICE_ID_TEXT_LENGTH - 1] = 0;
391+
// Overwrite the start of the device ID by the device type followed by ",", e.g. "l476,010203".
392+
if (strlen(DEVICE_TYPE) > 0) {
393+
assert(strlen(DEVICE_TYPE) < DEVICE_ID_TEXT_LENGTH - 1); // DEVICE_TYPE too long
394+
strcpy(device_id_text, DEVICE_TYPE);
395+
device_id_text[strlen(DEVICE_TYPE)] = ',';
396+
}
388397
console_printf("%srandom device id %s\n", _net, device_id_text);
389398
return device_id_text;
390399
}

libs/sensor_network/syscfg.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
# Strings must be enclosed by '"..."'
55

66
syscfg.defs:
7+
DEVICE_TYPE:
8+
description: 'Device type that will be prepended to the Device ID'
9+
value: '""'
10+
711
# CoAP Server Connection Settings: Collector Node and Standalone Node will send sensor data to this server
812
COAP_HOST:
913
description: 'CoAP host e.g. 104.199.85.211 (for coap.thethings.io)'

logs/libapp.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

targets/stm32l4_my_sensor/syscfg.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ syscfg.vals:
3737
###########################################################################
3838
# Network Settings
3939

40+
DEVICE_TYPE: '"l476"' # Device type that will be prepended to the Device ID. thethings.io converts the raw temperature depending on the device type.
4041
NBIOT_BAND: 8 # Connect to this NB-IoT band
4142
SENSOR_NETWORK: 1 # Enable Sensor Network library
4243
SENSOR_COAP: 1 # Send sensor data to CoAP server

0 commit comments

Comments
 (0)