diff --git a/vscode/OmobiLEDdisplayBluetooth/include/BluetoothLeUartServer.h b/vscode/OmobiLEDdisplayBluetooth/include/BluetoothLeUartServer.h index 5421e4c..f957974 100644 --- a/vscode/OmobiLEDdisplayBluetooth/include/BluetoothLeUartServer.h +++ b/vscode/OmobiLEDdisplayBluetooth/include/BluetoothLeUartServer.h @@ -62,6 +62,8 @@ public: bool getDeviceConnected(); bool disconnectCurrentDevice(); + String getDeviceAddress(); + protected: // callbacks for BLEServer void onConnect(BLEServer *pServer, esp_ble_gatts_cb_param_t *param) override; diff --git a/vscode/OmobiLEDdisplayBluetooth/include/EepromManager.h b/vscode/OmobiLEDdisplayBluetooth/include/EepromManager.h index e38964e..ce1b5f5 100644 --- a/vscode/OmobiLEDdisplayBluetooth/include/EepromManager.h +++ b/vscode/OmobiLEDdisplayBluetooth/include/EepromManager.h @@ -27,25 +27,22 @@ private: template const T &writeToEeprom(int address, size_t size, const T &t) { - Serial.println("Writing at: " + String(address) + " size: " + String(sizeof(T))); if (sizeof(T) > size) { - Serial.println("Error writing: Size should be: " + String(size)); + Serial.println("[Error][EepromManager] writing: Size should be: " + String(size) + " but was: " + String(sizeof(T))); return t; } const T &res = EEPROM.put(address, t); - Serial.println("Eeprom commit returned: " + String(EEPROM.commit())); + EEPROM.commit(); return res; } template T &readFromEeprom(int address, size_t size, T &t) { - Serial.println("Reading at: " + String(address) + " size: " + String(sizeof(T))); - if (sizeof(T) > size) { - Serial.println("Error reading: Size should be: " + String(size)); + Serial.println("[Error][EepromManager] reading: Size should be: " + String(size) + " but was: " + String(sizeof(T))); return t; } diff --git a/vscode/OmobiLEDdisplayBluetooth/src/BluetoothLeUartServer.cpp b/vscode/OmobiLEDdisplayBluetooth/src/BluetoothLeUartServer.cpp index 6ed7215..f6ec47a 100644 --- a/vscode/OmobiLEDdisplayBluetooth/src/BluetoothLeUartServer.cpp +++ b/vscode/OmobiLEDdisplayBluetooth/src/BluetoothLeUartServer.cpp @@ -56,6 +56,27 @@ void BluetoothLeUartServer::sendData(String data) txCharacteristic->notify(); } +bool BluetoothLeUartServer::getDeviceConnected() +{ + return this->deviceConnected; +} + +bool BluetoothLeUartServer::disconnectCurrentDevice() { + if(!this->getDeviceConnected()) + return false; + + this->bleServer->disconnect(this->deviceConnectionId); + return true; +} + +String BluetoothLeUartServer::getDeviceAddress() { + + String address = BLEDevice::getAddress().toString().c_str(); + address.toUpperCase(); + + return address; +} + void BluetoothLeUartServer::onConnect(BLEServer* pServer, esp_ble_gatts_cb_param_t *param) { // only allow one device @@ -84,17 +105,4 @@ void BluetoothLeUartServer::onWrite(BLECharacteristic *rxCharacteristic) { if (this->callbacks != nullptr) this->callbacks->onDataReceived(rxCharacteristic->getValue().c_str()); -} - -bool BluetoothLeUartServer::getDeviceConnected() -{ - return this->deviceConnected; -} - -bool BluetoothLeUartServer::disconnectCurrentDevice() { - if(!this->getDeviceConnected()) - return false; - - this->bleServer->disconnect(this->deviceConnectionId); - return true; } \ No newline at end of file diff --git a/vscode/OmobiLEDdisplayBluetooth/src/EepromManager.cpp b/vscode/OmobiLEDdisplayBluetooth/src/EepromManager.cpp index 5deb52d..22c7370 100644 --- a/vscode/OmobiLEDdisplayBluetooth/src/EepromManager.cpp +++ b/vscode/OmobiLEDdisplayBluetooth/src/EepromManager.cpp @@ -8,7 +8,6 @@ EepromManager::EepromManager() EepromUnit *EepromManager::registerEempromUnit(size_t size) { - Serial.println("Registering new EepromUnit with size: " + String(size) + " at " + String(this->currentAddressEnding)); // create a new Unit at the current address ending EepromUnit *newUnit = new EepromUnit(this, this->currentAddressEnding, size); // move the new address ending diff --git a/vscode/OmobiLEDdisplayBluetooth/src/OmobiLedDisplay.cpp b/vscode/OmobiLEDdisplayBluetooth/src/OmobiLedDisplay.cpp index 7367518..bc85f0b 100644 --- a/vscode/OmobiLEDdisplayBluetooth/src/OmobiLedDisplay.cpp +++ b/vscode/OmobiLEDdisplayBluetooth/src/OmobiLedDisplay.cpp @@ -65,18 +65,21 @@ void OmobiLedDisplay::onDataReceived(String dataString) OmobiDisplayStatusCode replyStatus = InternalError; JsonObject replyData = replyDoc.createNestedObject("data"); - if (requestHeader != AuthorizeSessionCommand && !this->sessionAuthorized) + if (requestHeader > KeepAliveCommand && !this->sessionAuthorized) replyStatus = Unauthorized; else switch (requestHeader) { case AuthorizeSessionCommand: { + String combinedCode = this->bleServer->getDeviceAddress() + String(this->properties.deviceCode); + String secret = this->sha256(combinedCode); + if (this->sessionAuthorized) { replyStatus = Success; } - else if (requestData["secret"] == this->sha256(this->properties.deviceCode)) + else if (requestData["secret"] == secret) { replyStatus = Success; this->sessionAuthorized = true; diff --git a/vscode/OmobiLEDdisplayBluetooth/src/main.cpp b/vscode/OmobiLEDdisplayBluetooth/src/main.cpp index ba685d7..919e2d6 100644 --- a/vscode/OmobiLEDdisplayBluetooth/src/main.cpp +++ b/vscode/OmobiLEDdisplayBluetooth/src/main.cpp @@ -13,7 +13,7 @@ void setup() Adafruit_NeoMatrix *displayMatrix = new Adafruit_NeoMatrix( 8, 8, - 1, + 2, 1, PIN, NEO_TILE_TOP + NEO_TILE_LEFT + NEO_TILE_ROWS + NEO_TILE_PROGRESSIVE +