diff --git a/platformio.ini b/platformio.ini index cb7f04c9..5404466e 100644 --- a/platformio.ini +++ b/platformio.ini @@ -13,7 +13,7 @@ default_envs = release [esp32doit] lib_ldf_mode = chain lib_compat_mode = strict -platform = espressif32 @ 6.0.1 +platform = espressif32 @ 6.5.0 board = esp32doit-devkit-v1 framework = arduino board_build.partitions = min_spiffs.csv @@ -26,10 +26,10 @@ build_flags = !python build_date_macro.py -D CONFIG_BT_NIMBLE_MAX_CONNECTIONS=6 -D CONFIG_MDNS_STRICT_MODE=1 - -D CORE_DEBUG_LEVEL=1 + -D CORE_DEBUG_LEVEL=3 -D ARDUINO_SERIAL_EVENT_TASK_STACK_SIZE=3500 lib_deps = - https://github.com/h2zero/NimBLE-Arduino/archive/refs/tags/1.4.0.zip + https://github.com/h2zero/NimBLE-Arduino/archive/refs/tags/1.4.1.zip https://github.com/teemuatlut/TMCStepper/archive/refs/tags/v0.7.3.zip https://github.com/bblanchon/ArduinoJson/archive/refs/tags/v6.20.0.zip https://github.com/witnessmenow/Universal-Arduino-Telegram-Bot/archive/refs/tags/V1.3.0.zip diff --git a/src/BLE_Client.cpp b/src/BLE_Client.cpp index aefbbc35..4d9ed5c9 100644 --- a/src/BLE_Client.cpp +++ b/src/BLE_Client.cpp @@ -220,7 +220,7 @@ bool SpinBLEClient::connectToServer() { */ pClient->setConnectionParams(6, 6, 0, 200); /** Set how long we are willing to wait for the connection to complete (seconds), default is 30. */ - pClient->setConnectTimeout(2); // 5 + pClient->setConnectTimeout(5); // 5 if (!pClient->connect(myDevice->getAddress())) { SS2K_LOG(BLE_CLIENT_LOG_TAG, " - Failed to connect client"); @@ -327,7 +327,7 @@ void MyClientCallback::onDisconnect(NimBLEClient *pClient) { if (addr == spinBLEClient.myBLEDevices[i].peerAddress) { // spinBLEClient.myBLEDevices[i].connectedClientID = BLE_HS_CONN_HANDLE_NONE; SS2K_LOG(BLE_CLIENT_LOG_TAG, "Detected %s Disconnect", spinBLEClient.myBLEDevices[i].serviceUUID.toString().c_str()); - //did another task disconnect this device? + // did another task disconnect this device? if (!spinBLEClient.intentionalDisconnect) { spinBLEClient.myBLEDevices[i].doConnect = true; } else { @@ -797,21 +797,25 @@ void SpinBLEAdvertisedDevice::set(BLEAdvertisedDevice *device, int id, BLEUUID i } void SpinBLEAdvertisedDevice::reset() { + if (this->isHRM) spinBLEClient.connectedHRM = false; + if (this->isPM) spinBLEClient.connectedPM = false; + if (this->isCSC) spinBLEClient.connectedCD = false; + advertisedDevice = nullptr; // NimBLEAddress peerAddress; - connectedClientID = BLE_HS_CONN_HANDLE_NONE; - serviceUUID = (uint16_t)0x0000; - charUUID = (uint16_t)0x0000; - isHRM = false; // Heart Rate Monitor - isPM = false; // Power Meter - isCSC = false; // Cycling Speed/Cadence - isCT = false; // Controllable Trainer - isRemote = false; // BLE Remote - doConnect = false; // Initiate connection flag - postConnected = false; // Has Cost Connect Been Run? - if (dataBufferQueue != nullptr) { + this->connectedClientID = BLE_HS_CONN_HANDLE_NONE; + this->serviceUUID = (uint16_t)0x0000; + this->charUUID = (uint16_t)0x0000; + this->isHRM = false; // Heart Rate Monitor + this->isPM = false; // Power Meter + this->isCSC = false; // Cycling Speed/Cadence + this->isCT = false; // Controllable Trainer + this->isRemote = false; // BLE Remote + this->doConnect = false; // Initiate connection flag + this->postConnected = false; // Has Cost Connect Been Run? + if (this->dataBufferQueue != nullptr) { // Serial.println("Resetting queue"); - xQueueReset(dataBufferQueue); + xQueueReset(this->dataBufferQueue); } } // Poll BLE devices for battCharacteristic if available and read value. diff --git a/src/BLE_Firmware_Update.cpp b/src/BLE_Firmware_Update.cpp index 9c7ae80a..2cc0178b 100644 --- a/src/BLE_Firmware_Update.cpp +++ b/src/BLE_Firmware_Update.cpp @@ -74,8 +74,8 @@ class otaCallback : public BLECharacteristicCallbacks { //------------------------------------------------------------------------------------------ esp_task_wdt_init(10, false); - SS2K_LOG(MAIN_LOG_TAG, "Stop BLE Tasks"); if (BLECommunicationTask != NULL) { + SS2K_LOG(MAIN_LOG_TAG, "Stop BLE Tasks"); vTaskDelete(BLECommunicationTask); BLECommunicationTask = NULL; } @@ -84,7 +84,7 @@ class otaCallback : public BLECharacteristicCallbacks { BLEClientTask = NULL; } - vTaskDelay(5); + // vTaskDelay(5); if (esp_ota_begin(update_partition, OTA_SIZE_UNKNOWN, &otaHandler) != ESP_OK) { downloadFlag = false; @@ -102,7 +102,7 @@ class otaCallback : public BLECharacteristicCallbacks { return; } else { bufferCount = 1; - // SS2K_LOG(BLE_SERVER_LOG_TAG, "--Data received---"); + SS2K_LOG(BLE_SERVER_LOG_TAG, "%d bytes", rxData.length()); // Notify the iOS app so next batch can be sent pTxCharacteristic->setValue(&txValue, 2); // pTxCharacteristic->notify(); @@ -113,7 +113,7 @@ class otaCallback : public BLECharacteristicCallbacks { // smaller than the maximum MTU size). For improvement: let iOS app send byte // length instead of hardcoding "510" //------------------------------------------------------------------- - if (rxData.length() < 510) // TODO Asumes at least 511 data bytes (@BLE 4.2). + if (rxData.length() < 500) // TODO Asumes at least 511 data bytes (@BLE 4.2). { SS2K_LOG(BLE_SERVER_LOG_TAG, "4. Final byte arrived"); //----------------------------------------------------------------- diff --git a/src/BLE_Setup.cpp b/src/BLE_Setup.cpp index 39f1af7a..b4609145 100644 --- a/src/BLE_Setup.cpp +++ b/src/BLE_Setup.cpp @@ -14,7 +14,7 @@ void setupBLE() { // Common BLE setup for both client and server SS2K_LOG(BLE_SETUP_LOG_TAG, "Starting Arduino BLE Client application..."); BLEDevice::init(userConfig->getDeviceName()); - BLEDevice::setMTU(BLE_ATT_MTU_MAX); + BLEDevice::setMTU(515); FTMSWrite = ""; spinBLEClient.start(); startBLEServer(); diff --git a/src/HTTP_Server_Basic.cpp b/src/HTTP_Server_Basic.cpp index 822fc521..4cf9c74d 100644 --- a/src/HTTP_Server_Basic.cpp +++ b/src/HTTP_Server_Basic.cpp @@ -21,6 +21,8 @@ #include #include #include +// just so we cen set wifi powersave to never +#include File fsUploadFile; @@ -53,6 +55,7 @@ void startWifi() { WiFi.mode(WIFI_STA); WiFi.begin(userConfig->getSsid(), userConfig->getPassword()); WiFi.setTxPower(WIFI_POWER_19_5dBm); + esp_wifi_set_ps(WIFI_PS_NONE); WiFi.setAutoReconnect(true); }