Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WiFi OTA #24

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
55 changes: 0 additions & 55 deletions senseBox-bike-atrai-v2/boards/sensebox_mcu_esp32s2.json

This file was deleted.

9 changes: 4 additions & 5 deletions senseBox-bike-atrai-v2/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,8 @@
[env:sensebox_mcu_esp32s2]
platform = espressif32
board = sensebox_mcu_esp32s2
platform_packages =
platformio/framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#2.0.17
platform_packages = platformio/framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#2.0.17
framework = arduino
build =
include_dir = lib/sensors
lib_ldf_mode = deep
lib_deps =
adafruit/Adafruit SSD1306 @ ^2.5.10
adafruit/Adafruit HDC1000 Library@^2.0.2
Expand All @@ -26,3 +22,6 @@ lib_deps =
stm32duino/STM32duino VL53L8CX@^1.0.3
adafruit/Adafruit MPU6050@^2.2.6
sensebox/SenseBoxBLE@^1.1.0
adafruit/Adafruit NeoPixel@^1.12.2
arduino-libraries/Arduino_ESP32_OTA@^0.3.0
arduino-libraries/Arduino_DebugUtils@^1.4.0
37 changes: 24 additions & 13 deletions senseBox-bike-atrai-v2/src/ble/BLEModule.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
#include "BLEModule.h"
#include "Utf16Converter/Utf16Converter.h"

// void (*BLEModule::receiveCallback)(BLEDevice, BLECharacteristic) = nullptr;
void (*BLEModule::receiveCallback)(String) = nullptr;

void BLEModule::receivedData()
{
int size = 32;
uint8_t receivedData[size];
SenseBoxBLE::read(receivedData, size);

String data = utf16leToString(receivedData, size);

BLEModule::receiveCallback(data);
}

BLEModule::BLEModule()
{
// service = nullptr;
bleName = "";
}

Expand All @@ -18,7 +29,12 @@ bool BLEModule::begin()
delay(200);
SenseBoxBLE::addService("CF06A218F68EE0BEAD048EBC1EB0BC84");

xTaskCreate(bleTask, "bleTask", 1024, NULL, 1, NULL);
delay(200);
SenseBoxBLE::configHandler = &receivedData;

int configCharacteristic = SenseBoxBLE::setConfigCharacteristic("29BD0A8551E44D3C914E126541EB2A5E", "60B1D5CE353944D2BB35FF2DAABE17FF");

xTaskCreate(bleTask, "bleTask", 2048, NULL, 1, NULL);

return true;
}
Expand Down Expand Up @@ -71,21 +87,16 @@ bool BLEModule::writeBLE(int characteristicId, float value, float value2, float
return SenseBoxBLE::write(characteristicId, value, value2, value3, value4, value5);
}

// void BLEModule::setReceiveCallback(void (*callback)(BLEDevice, BLECharacteristic)) {
// receiveCallback = callback;
// }

// void BLEModule::onReceive(BLEDevice central, BLECharacteristic characteristic) {
// if (receiveCallback) {
// receiveCallback(central, characteristic);
// }
// }
void BLEModule::setReceiveCallback(void (*callback)(String data))
{
BLEModule::receiveCallback = callback;
}

void BLEModule::bleTask(void *pvParameters)
{
while (true)
{
SenseBoxBLE::poll();
vTaskDelay(pdMS_TO_TICKS(5));
vTaskDelay(pdMS_TO_TICKS(10));
}
}
9 changes: 4 additions & 5 deletions senseBox-bike-atrai-v2/src/ble/BLEModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class BLEModule
// Get the BLE module ID
String getBLEName();

const char** getBLEConnectionString();
const char **getBLEConnectionString();

// Create a BLE characteristic
static int createCharacteristic(const char *uuid);
Expand All @@ -27,17 +27,16 @@ class BLEModule
static bool writeBLE(int characteristicId, float value, float value2, float value3, float value4, float value5);

// Set callback for receiving data
// void setReceiveCallback(void (*callback)(BLEDevice, BLECharacteristic));
void setReceiveCallback(void (*callback)(String data));
static void (*receiveCallback)(String data);

// Task function for polling BLE
static void bleTask(void *pvParameters);

private:
// BLEService* service;
String bleName;

// static void onReceive(BLEDevice central, BLECharacteristic characteristic);
// static void (*receiveCallback)(BLEDevice, BLECharacteristic);
static void receivedData();
};

#endif // BLE_MODULE_H
32 changes: 32 additions & 0 deletions senseBox-bike-atrai-v2/src/ble/Utf16Converter/Utf16Converter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include "Utf16Converter.h"

String utf16leToString(uint8_t *data, size_t length)
{
String result = "";

// Ensure the length is even
if (length % 2 != 0)
{
return result;
}

for (size_t i = 0; i < length; i += 2)
{
// Combine the two bytes to form a UTF-16 character
uint16_t utf16_char = data[i] | (data[i + 1] << 8);

// If the character is null (0x0000), break the loop as it indicates the end of the string
if (utf16_char == 0x0000)
{
break;
}

// Append the character to the result string if it is within the ASCII range
if (utf16_char <= 0x007F)
{
result += (char)utf16_char;
}
}

return result;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef UTF16_CONVERTER_H
#define UTF16_CONVERTER_H

#include <Arduino.h>

String utf16leToString(uint8_t *data, size_t length);

#endif // UTF16_CONVERTER_H
4 changes: 3 additions & 1 deletion senseBox-bike-atrai-v2/src/display/Display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,10 @@ void SBDisplay::showConnectionScreen()
isBicycleAnimationShowing = false;
}

String name = SenseBoxBLE::getMCUId();
String bleId = "[" + SenseBoxBLE::getMCUId() + "]";

String name = "senseBox:bike " + bleId;

String bleIdBegin = bleId.substring(0, bleId.length() / 2);
String bleIdEnd = bleId.substring(bleId.length() / 2);
const char *message[] = {
Expand Down
Loading