diff --git a/apps/wsn-main/Makefile b/apps/wsn-main/Makefile index 048b24d..8d59c4d 100644 --- a/apps/wsn-main/Makefile +++ b/apps/wsn-main/Makefile @@ -12,4 +12,6 @@ USEMODULE += bme280_i2c USEMODULE += wsn EXTERNAL_MODULE_DIRS += $(CURDIR)/../../sys/wsn +CFLAGS += -DNODE_ID=\"$(NODE_ID)\" + include $(RIOTBASE)/Makefile.include diff --git a/apps/wsn-main/main.c b/apps/wsn-main/main.c index 3d3fd55..ff95dae 100644 --- a/apps/wsn-main/main.c +++ b/apps/wsn-main/main.c @@ -24,6 +24,10 @@ #define TICKS_PER_SEC US_PER_SEC #endif +#ifndef NODE_ID + #define NODE_ID "" +#endif + #define SLEEP 5 // seconds @@ -98,6 +102,18 @@ int main(void) nanocbor_fmt_uint(&enc, 0); nanocbor_fmt_uint(&enc, now / TICKS_PER_SEC); + // Serial number + nanocbor_fmt_uint(&enc, 1); + nanocbor_fmt_uint(&enc, cpuid); + + // Name (Node Identifier) + nanocbor_fmt_uint(&enc, 2); + nanocbor_put_tstr(&enc, NODE_ID); + + // Frame sequence number + nanocbor_fmt_uint(&enc, 3); + nanocbor_fmt_uint(&enc, loop); + saul_reg_t *dev = saul_reg; while (dev) { // TODO Support 2 BME280 sensors at addresses 0x76 and 0x77 diff --git a/sys/include/wsn.h b/sys/include/wsn.h index 030cdf1..9f94bb5 100644 --- a/sys/include/wsn.h +++ b/sys/include/wsn.h @@ -13,6 +13,11 @@ #ifndef WSN_H #define WSN_H +/** + * @brief Uniquely identifies the mote + */ +extern uint64_t cpuid; + /** * @brief Code to run at boot * diff --git a/sys/wsn/Makefile.dep b/sys/wsn/Makefile.dep index 0cf4ed5..61a3cbc 100644 --- a/sys/wsn/Makefile.dep +++ b/sys/wsn/Makefile.dep @@ -1,3 +1,5 @@ +FEATURES_REQUIRED = periph_cpuid + # Storage USEMODULE += fatfs_vfs USEMODULE += mtd_sdcard diff --git a/sys/wsn/wsn.c b/sys/wsn/wsn.c index fdd2fe4..039917b 100644 --- a/sys/wsn/wsn.c +++ b/sys/wsn/wsn.c @@ -2,14 +2,39 @@ #include #include #include +#include // Project #include "settings.h" #include "wsn.h" +uint64_t cpuid = 0; + + void wsn_boot(void) { + /* + * ID + * + * XXX In the cc2539 the CPU id is based on the MAC address, which is + * defined by two 32bit little-endian words stored in memory: first the + * most-significat word (IEEE_ADDR_MSWORD), then the less-significat word + * (IEEE_ADDR_MSWORD). But the CPU id is read from memory as-is. + * + * For example if in memory we have 00:4b:12:00 2e:15:40:19 then: + * - MAC address is 00:12:4B:00:19:40:15:2E + * - But CPU id is 00:4b:12:00:2e:15:40:19 + * + */ + uint8_t buffer[CPUID_LEN]; + cpuid_get(buffer); + + for (unsigned int i = 0; i < CPUID_LEN; i++) { + cpuid = cpuid << 8; + cpuid |= buffer[i]; + } + /* * Storage */