diff --git a/iot_train.h b/iot_train.h index 4c078a4..b02c288 100644 --- a/iot_train.h +++ b/iot_train.h @@ -93,6 +93,14 @@ 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 +#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 @@ -244,6 +252,16 @@ void updatePwm(); */ void updateVolt(); +/** + * @brief update firmware version value + */ +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 af1e668..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 @@ -46,6 +46,9 @@ 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 +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); @@ -57,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 @@ -135,6 +140,8 @@ void setup() { xiaoService.addCharacteristic(ledCharacteristic); xiaoService.addCharacteristic(pwmCharacteristic); xiaoService.addCharacteristic(voltCharacteristic); + xiaoService.addCharacteristic(verCharacteristic); + xiaoService.addCharacteristic(maNameCharacteristic); BLE.addService(xiaoService); // update values @@ -146,6 +153,7 @@ void setup() { mabeeeVolt.timestamp = 0; mabeeeVolt.float1 = 0.0F; updateVolt(); + updateVer(); // device ready led.resetB(); @@ -261,6 +269,7 @@ void doCentral() { Serial.println("Central: Connected."); stateCentral = C_CONNECTED; entry = true; + updateMaBeeeName(); } else { counter--; if (!counter) { @@ -339,6 +348,7 @@ void doCentral() { Serial.println("Central: Disconnected."); stateCentral = C_SCANNING; entry = true; + updateMaBeeeName(); } } break; } @@ -467,6 +477,18 @@ 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 updateMaBeeeName() { + String MaBeee = mabeee.localName(); + maNameCharacteristic.writeValue(MaBeee.c_str(), MaBeee.length()); +} + void setAccelPeriod(uint16_t period) { accelPeriod = period; }