Skip to content

Commit

Permalink
library updates
Browse files Browse the repository at this point in the history
  • Loading branch information
doudar committed Mar 5, 2024
1 parent da4bd4c commit 8317e8e
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 22 deletions.
6 changes: 3 additions & 3 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
32 changes: 18 additions & 14 deletions src/BLE_Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions src/BLE_Firmware_Update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
Expand All @@ -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();
Expand All @@ -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");
//-----------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/BLE_Setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions src/HTTP_Server_Basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include <Update.h>
#include <DNSServer.h>
#include <ArduinoJson.h>
// just so we cen set wifi powersave to never
#include <esp_wifi.h>

File fsUploadFile;

Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit 8317e8e

Please sign in to comment.