Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions iot_train.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
*
Expand Down
24 changes: 23 additions & 1 deletion iot_train.ino
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/

#define VERSION_MAJOR 0
#define VERSION_MINOR 2
#define VERSION_MINOR 3

#include <math.h>
#include "iot_train.h" // IoT Train definitions
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -146,6 +153,7 @@ void setup() {
mabeeeVolt.timestamp = 0;
mabeeeVolt.float1 = 0.0F;
updateVolt();
updateVer();

// device ready
led.resetB();
Expand Down Expand Up @@ -261,6 +269,7 @@ void doCentral() {
Serial.println("Central: Connected.");
stateCentral = C_CONNECTED;
entry = true;
updateMaBeeeName();
} else {
counter--;
if (!counter) {
Expand Down Expand Up @@ -339,6 +348,7 @@ void doCentral() {
Serial.println("Central: Disconnected.");
stateCentral = C_SCANNING;
entry = true;
updateMaBeeeName();
}
} break;
}
Expand Down Expand Up @@ -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;
}
Expand Down