From 7dae13e986c47acee8a0acb69d841b6f78a07c91 Mon Sep 17 00:00:00 2001 From: Makoto Shimojima Date: Tue, 15 Aug 2023 11:48:57 +0900 Subject: [PATCH 1/3] Fix: write to commandCharacterisic to return the response back to the central. --- iot_train.ino | 1 + 1 file changed, 1 insertion(+) diff --git a/iot_train.ino b/iot_train.ino index af1e668..be7ead6 100644 --- a/iot_train.ino +++ b/iot_train.ino @@ -590,6 +590,7 @@ void onCommandWritten(BLEDevice central, BLECharacteristic characteristic) { Serial.println("Command: error: command dispatcher is busy."); commandResponse.response = CMD_RESP_BUSY; } + commandCharacteristic.writeValue(commandResponse.byteArray, sizeof(commandResponse.byteArray)); } void onLedWritten(BLEDevice central, BLECharacteristic characteristic) { From fcc3bbb0c84fa2997263f89ac8e4920d76ce123d Mon Sep 17 00:00:00 2001 From: Makoto Shimojima Date: Tue, 15 Aug 2023 12:26:49 +0900 Subject: [PATCH 2/3] Feat: return MaBeee version. --- iot_train.ino | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/iot_train.ino b/iot_train.ino index be7ead6..1268397 100644 --- a/iot_train.ino +++ b/iot_train.ino @@ -544,12 +544,22 @@ void onCommandWritten(BLEDevice central, BLECharacteristic characteristic) { case CMD_MABEEE_GET_NAME: case CMD_MABEEE_GET_ID: - case CMD_MABEEE_GET_VER: case CMD_MABEEE_GET_BDADDR: case CMD_MABEEE_GET_RSSI: { commandResponse.response = CMD_RESP_EXECUTING; } break; + case CMD_MABEEE_GET_VER: { + versionPacket ver; + mabeeeVersionCharacteristic.readValue(ver.byteArray, sizeof(ver.byteArray)); + // Serial.print("MaBeee version: firmware "); + // Serial.print(ver.major); + // Serial.print(" hardware "); + // Serial.println(ver.minor); + memcpy(commandResponse.payload, ver.byteArray, sizeof(ver.byteArray)); + commandResponse.response = CMD_RESP_OK; + } break; + case CMD_XIAO_GET_STATE: { commandResponse.payload[0] = (unsigned char)stateCentral; commandResponse.response = CMD_RESP_OK; From ed86190ebd79eb575c073aef11b0a0ad7afed438 Mon Sep 17 00:00:00 2001 From: Makoto Shimojima Date: Tue, 15 Aug 2023 14:44:53 +0900 Subject: [PATCH 3/3] feat: implement CMD_MABEEE_GET_NAME. --- iot_train.ino | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/iot_train.ino b/iot_train.ino index 1268397..34b31af 100644 --- a/iot_train.ino +++ b/iot_train.ino @@ -542,19 +542,27 @@ void onCommandWritten(BLEDevice central, BLECharacteristic characteristic) { commandResponse.response = CMD_RESP_OK; } break; - case CMD_MABEEE_GET_NAME: case CMD_MABEEE_GET_ID: case CMD_MABEEE_GET_BDADDR: case CMD_MABEEE_GET_RSSI: { commandResponse.response = CMD_RESP_EXECUTING; } break; + case CMD_MABEEE_GET_NAME: { + String MaBeee = mabeee.localName(); + // Serial.print("MaBeee name: "); + // Serial.println(MaBeee); + bzero(commandResponse.payload, sizeof(commandResponse.payload)); + memcpy(commandResponse.payload, MaBeee.c_str(), MaBeee.length()); + commandResponse.response = CMD_RESP_OK; + } break; + case CMD_MABEEE_GET_VER: { versionPacket ver; mabeeeVersionCharacteristic.readValue(ver.byteArray, sizeof(ver.byteArray)); // Serial.print("MaBeee version: firmware "); // Serial.print(ver.major); - // Serial.print(" hardware "); + // Serial.print(", hardware "); // Serial.println(ver.minor); memcpy(commandResponse.payload, ver.byteArray, sizeof(ver.byteArray)); commandResponse.response = CMD_RESP_OK;