From 230bf6150d32e709291f894dfa40b7365bba7e1c Mon Sep 17 00:00:00 2001 From: morita Date: Tue, 15 Aug 2023 23:32:43 +0900 Subject: [PATCH 1/3] add firmware version characteristic --- iot_train.h | 10 ++++++++++ iot_train.ino | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/iot_train.h b/iot_train.h index 4c078a4..b1f3a62 100644 --- a/iot_train.h +++ b/iot_train.h @@ -93,6 +93,10 @@ typedef union { #define XIAO_VOLT_CHAR_PROP (BLERead|BLENotify) // property:voltage characteristic, readable/notifiable #define XIAO_VOLT_CHAR_TYPE BLECharacteristic // type:voltage characteristic, byte array #define XIAO_VOLT_CHAR_LEN 8 // length:voltage characteristic, 8 bytes +#define XIAO_VER_CHAR_UUID "AD0C2003-64E9-48B0-9088-6F9E9FE4972E" // UUID:firmware version characteristic +#define XIAO_VER_CHAR_PROP (BLERead|BLENotify) // property:firmware version characteristic, readable/notifiable +#define XIAO_VER_CHAR_TYPE BLECharacteristic // type:firmware version characteristic, byte array +#define XIAO_VER_CHAR_LEN 4 // length:firmware version characteristic, 4 bytes // BLE peripheral GATT profile: MaBeee side #define MABEEE_CTRL_SERV_UUID "B9F5FF00-D813-46C6-8B61-B453EE2C74D9" // UUID:MaBeee control service @@ -244,6 +248,12 @@ void updatePwm(); */ void updateVolt(); +/** + * @brief update firmware version value + */ +void updateVer(); + + /** * @brief Set the Accel Period * diff --git a/iot_train.ino b/iot_train.ino index af1e668..9b85b07 100644 --- a/iot_train.ino +++ b/iot_train.ino @@ -46,6 +46,7 @@ BLECharacteristic tempCharacteristic(XIAO_TEMP_CHAR_UUID, XIAO_TEMP_CHAR_PROP, X BLECharacteristic ledCharacteristic(XIAO_LED_CHAR_UUID, XIAO_LED_CHAR_PROP, XIAO_LED_CHAR_LEN); // GATT: LED characteristic BLECharacteristic pwmCharacteristic(XIAO_PWM_CHAR_UUID, XIAO_PWM_CHAR_PROP, XIAO_PWM_CHAR_LEN); // GATT: PWM characteristic BLECharacteristic voltCharacteristic(XIAO_VOLT_CHAR_UUID, XIAO_VOLT_CHAR_PROP, XIAO_VOLT_CHAR_LEN); // GATT: voltage characteristic +BLECharacteristic verCharacteristic(XIAO_VER_CHAR_UUID, XIAO_VER_CHAR_PROP, XIAO_VER_CHAR_LEN); // GATT: firmware version characteristic // handler for writable characteristics void onCommandWritten(BLEDevice, BLECharacteristic); @@ -135,6 +136,7 @@ void setup() { xiaoService.addCharacteristic(ledCharacteristic); xiaoService.addCharacteristic(pwmCharacteristic); xiaoService.addCharacteristic(voltCharacteristic); + xiaoService.addCharacteristic(verCharacteristic); BLE.addService(xiaoService); // update values @@ -146,6 +148,7 @@ void setup() { mabeeeVolt.timestamp = 0; mabeeeVolt.float1 = 0.0F; updateVolt(); + updateVer(); // device ready led.resetB(); @@ -467,6 +470,13 @@ void updateVolt() { voltCharacteristic.writeValue(mabeeeVolt.byteArray, sizeof(mabeeeVolt.byteArray)); } +void updateVer() { + versionPacket ver; + ver.major = VERSION_MAJOR; + ver.minor = VERSION_MINOR; + verCharacteristic.writeValue(ver.byteArray, sizeof(ver.byteArray)); +} + void setAccelPeriod(uint16_t period) { accelPeriod = period; } From d264feaf5c831b485338d588abfe4445eff0c934 Mon Sep 17 00:00:00 2001 From: morita Date: Tue, 15 Aug 2023 23:33:53 +0900 Subject: [PATCH 2/3] Added characteristic to pass MaBeee name to peripheral --- iot_train.h | 8 ++++++++ iot_train.ino | 12 ++++++++++++ 2 files changed, 20 insertions(+) diff --git a/iot_train.h b/iot_train.h index b1f3a62..b02c288 100644 --- a/iot_train.h +++ b/iot_train.h @@ -97,6 +97,10 @@ typedef union { #define XIAO_VER_CHAR_PROP (BLERead|BLENotify) // property:firmware version characteristic, readable/notifiable #define XIAO_VER_CHAR_TYPE BLECharacteristic // type:firmware version characteristic, byte array #define XIAO_VER_CHAR_LEN 4 // length:firmware version characteristic, 4 bytes +#define XIAO_MABEEENAME_CHAR_UUID "AD0C2004-64E9-48B0-9088-6F9E9FE4972E"// UUID:device name characteristic +#define XIAO_MABEEENAME_CHAR_PROP (BLERead|BLENotify) // property:MaBeee device name characteristic, readable/notifiable +#define XIAO_MABEEENAME_CHAR_TYPE BLECharacteristic // type:MaBeee device name characteristic, byte array +#define XIAO_MABEEENAME_CHAR_LEN 12 // length:MaBeee device name characteristic, 12 bytes // BLE peripheral GATT profile: MaBeee side #define MABEEE_CTRL_SERV_UUID "B9F5FF00-D813-46C6-8B61-B453EE2C74D9" // UUID:MaBeee control service @@ -253,6 +257,10 @@ void updateVolt(); */ void updateVer(); +/** + * @brief update MaBeee device name value + */ +void updateMaBeeeName(); /** * @brief Set the Accel Period diff --git a/iot_train.ino b/iot_train.ino index 9b85b07..d1c6514 100644 --- a/iot_train.ino +++ b/iot_train.ino @@ -47,6 +47,8 @@ BLECharacteristic ledCharacteristic(XIAO_LED_CHAR_UUID, XIAO_LED_CHAR_PROP, XIAO BLECharacteristic pwmCharacteristic(XIAO_PWM_CHAR_UUID, XIAO_PWM_CHAR_PROP, XIAO_PWM_CHAR_LEN); // GATT: PWM characteristic BLECharacteristic voltCharacteristic(XIAO_VOLT_CHAR_UUID, XIAO_VOLT_CHAR_PROP, XIAO_VOLT_CHAR_LEN); // GATT: voltage characteristic BLECharacteristic verCharacteristic(XIAO_VER_CHAR_UUID, XIAO_VER_CHAR_PROP, XIAO_VER_CHAR_LEN); // GATT: firmware version characteristic +BLECharacteristic maNameCharacteristic(XIAO_MABEEENAME_CHAR_UUID, XIAO_MABEEENAME_CHAR_PROP, XIAO_MABEEENAME_CHAR_LEN); // GATT: device name characteristic + // handler for writable characteristics void onCommandWritten(BLEDevice, BLECharacteristic); @@ -58,6 +60,8 @@ void updateAccel(); void updateGyro(); void updateTemp(); void updateVolt(); +void updateVer(); +void updateMaBeeeName(); // MaBeee BLE device properties and GATT profile: BLEDevice mabeee; // MaBeee BLE device @@ -137,6 +141,7 @@ void setup() { xiaoService.addCharacteristic(pwmCharacteristic); xiaoService.addCharacteristic(voltCharacteristic); xiaoService.addCharacteristic(verCharacteristic); + xiaoService.addCharacteristic(maNameCharacteristic); BLE.addService(xiaoService); // update values @@ -264,6 +269,7 @@ void doCentral() { Serial.println("Central: Connected."); stateCentral = C_CONNECTED; entry = true; + updateMaBeeeName(); } else { counter--; if (!counter) { @@ -342,6 +348,7 @@ void doCentral() { Serial.println("Central: Disconnected."); stateCentral = C_SCANNING; entry = true; + updateMaBeeeName(); } } break; } @@ -477,6 +484,11 @@ void updateVer() { verCharacteristic.writeValue(ver.byteArray, sizeof(ver.byteArray)); } +void updateMaBeeeName() { + String MaBeee = mabeee.localName(); + maNameCharacteristic.writeValue(MaBeee.c_str(), MaBeee.length()); +} + void setAccelPeriod(uint16_t period) { accelPeriod = period; } From 21f11273cc06cbe8c7613315709489ad1ff4e848 Mon Sep 17 00:00:00 2001 From: morita Date: Thu, 17 Aug 2023 12:40:36 +0900 Subject: [PATCH 3/3] change minor version to 3 --- iot_train.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iot_train.ino b/iot_train.ino index d1c6514..4933990 100644 --- a/iot_train.ino +++ b/iot_train.ino @@ -11,7 +11,7 @@ */ #define VERSION_MAJOR 0 -#define VERSION_MINOR 2 +#define VERSION_MINOR 3 #include #include "iot_train.h" // IoT Train definitions