Skip to content

Commit

Permalink
BLE MacAddress and display
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulaScharf committed Nov 11, 2024
1 parent 06ce8be commit ad389e3
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 27 deletions.
6 changes: 6 additions & 0 deletions sensebox-bike-atrai-v2-esp32s3/partition.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Name, Type, SubType, Offset, Size, Flags
nvs, data, nvs, 0x9000, 0x5000,
otadata, data, ota, 0xe000, 0x2000,
app0, app, ota_0, 0x10000, 0x300000,
spiffs, data, spiffs, 0x310000,0xE0000,
coredump, data, coredump,0x3F0000,0x10000,
1 change: 1 addition & 0 deletions sensebox-bike-atrai-v2-esp32s3/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
[env:adafruit_feather_esp32s3]
platform = espressif32
board = adafruit_feather_esp32s3
board_build.partitions = partition.csv
platform_packages = platformio/framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#2.0.17
framework = arduino
lib_deps =
Expand Down
23 changes: 19 additions & 4 deletions sensebox-bike-atrai-v2-esp32s3/src/ble/BLEModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ bool isConnectedVar = false;
BLEServer *pServer;
BLEService *pService;

char macString[32]; // Enough space for the MAC string

BLEModule::BLEModule()
{
Expand All @@ -12,7 +13,14 @@ BLEModule::BLEModule()

bool BLEModule::begin()
{
BLEDevice::init("senseBox-BLE[xxxyyy]"); // not sure how to adjust the id
uint8_t baseMac[6];
esp_read_mac(baseMac, ESP_MAC_BT);
snprintf(macString, sizeof(macString), "%02X:%02X:%02X:%02X:%02X:%02X",
baseMac[0], baseMac[1], baseMac[2], baseMac[3], baseMac[4], baseMac[5]);
char bleName[64];
snprintf(bleName, sizeof(bleName), "senseBox-BLE[%s]", macString);

BLEDevice::init(bleName);
pServer = BLEDevice::createServer();

return true;
Expand All @@ -30,9 +38,11 @@ bool BLEModule::isConnected()

const char **BLEModule::getBLEConnectionString()
{
String bleId = "[xxxyyy]";
String bleIdBegin = bleId.substring(0, bleId.length() / 2);
String bleIdEnd = bleId.substring(bleId.length() / 2);
char bleId[34];
snprintf(bleId, sizeof(bleId), "[%s]", macString);
std::string bleIdStr = bleId;
std::string bleIdBegin = bleIdStr.substr(0, bleIdStr.length() / 2);
std::string bleIdEnd = bleIdStr.substr(bleIdStr.length() / 2);
const char *MESSAGE_CONFIGURE_WIFI[] = {
"senseBox",
"bike",
Expand Down Expand Up @@ -113,3 +123,8 @@ void BLEModule::bleStartPoll(const char *uuid)
pAdvertising->setMinPreferred(0x12);
BLEDevice::startAdvertising();
}

const char *BLEModule::getMacAddress()
{
return macString; // Enough space for the MAC string;
}
2 changes: 2 additions & 0 deletions sensebox-bike-atrai-v2-esp32s3/src/ble/BLEModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class BLEModule

static bool isConnected();

const char *getMacAddress();

private:
// BLEService* service;
String bleName;
Expand Down
18 changes: 4 additions & 14 deletions sensebox-bike-atrai-v2-esp32s3/src/display/Display.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#include "Display.h"
#include <SPI.h>
// #include <Wire.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <QRCodeGenerator.h>
#include <Adafruit_MAX1704X.h>
#include "bicycle_loading_bitmap.h"

// Adafruit_SSD1306 SBDisplay::display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
Adafruit_SSD1306 SBDisplay::display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
QRCode SBDisplay::qrcode;

float batteryCharge = 0;
Expand Down Expand Up @@ -117,24 +117,14 @@ void SBDisplay::showSystemStatus()
display.display();
}

void SBDisplay::showConnectionScreen()
void SBDisplay::showConnectionScreen(String name, const char *message[])
{
if (isBicycleAnimationShowing)
{
isBicycleAnimationShowing = false;
}

// String bleIdBrackets = "[" + bleId + "]";
// String name = "senseBox:bike " + bleIdBrackets;
// String bleIdBegin = bleIdBrackets.substring(0, bleIdBrackets.length() / 2);
// String bleIdEnd = bleIdBrackets.substring(bleIdBrackets.length() / 2);
// const char *message[] = {
// "senseBox",
// "bike",
// bleIdBegin.c_str(),
// bleIdEnd.c_str()};

// drawQrCode(name.c_str(), message);
drawQrCode(name.c_str(), message);

drawBattery(0, 0, 16, 4);
display.display();
Expand Down
2 changes: 1 addition & 1 deletion sensebox-bike-atrai-v2-esp32s3/src/display/Display.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class SBDisplay
public:
static void begin();
static void showSystemStatus();
static void showConnectionScreen();
static void showConnectionScreen(String name, const char *message[]);
static void drawQrCode(const char *qrStr, const char *lines[]);
static void showLoading(String msg, float val);
static void drawProgressbar(int x, int y, int width, int height, int progress);
Expand Down
27 changes: 19 additions & 8 deletions sensebox-bike-atrai-v2-esp32s3/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "sensors/DistanceSensor/DistanceSensor.h"
#include "sensors/AccelerationSensor/AccelerationSensor.h"
#include "sensors/BatterySensor/BatterySensor.h"
// #include "display/Display.h"
#include "display/Display.h"
#include "ble/BLEModule.h"
// #include "led/LED.h"

Expand All @@ -22,7 +22,7 @@ BaseSensor *sensors[] = {
// &batterySensor
};

// SBDisplay display;
SBDisplay display;

BLEModule bleModule;
// LED led(1, 1);
Expand All @@ -39,19 +39,19 @@ void setup()

// led.startRainbow();

// SBDisplay::begin();
SBDisplay::begin();

// pinMode(IO_ENABLE, OUTPUT);
// digitalWrite(IO_ENABLE, LOW);

// SBDisplay::showLoading("Setup BLE...", 0.2);
SBDisplay::showLoading("Setup BLE...", 0.2);
bleModule.begin();

// batterySensor.begin();

bleModule.createService("4fafc201-1fb5-459e-8fcc-c5c9c331914b");

// SBDisplay::showLoading("Setup Sensors...", 0.4);
SBDisplay::showLoading("Setup Sensors...", 0.4);
for (BaseSensor *sensor : sensors)
{
sensor->begin();
Expand All @@ -62,14 +62,14 @@ void setup()
// delay(100);
// digitalWrite(3, HIGH);

// SBDisplay::showLoading("Start measurements...", 0.8);
SBDisplay::showLoading("Start measurements...", 0.8);
// Start sensor measurements
for (BaseSensor *sensor : sensors)
{
sensor->startSubscription();
}

// SBDisplay::showLoading("Enable BLE...", 1);
SBDisplay::showLoading("Enable BLE...", 1);

// Start BLE advertising
for (BaseSensor *sensor : sensors)
Expand All @@ -81,7 +81,18 @@ void setup()

// led.stopRainbow();

// display.showConnectionScreen();
const char* macString = bleModule.getMacAddress();
String bleId = "[" + String(macString) + "]";
String bleIdBegin = bleId.substring(0, bleId.length() / 2);
String bleIdEnd = bleId.substring(bleId.length() / 2);
String name = "senseBox:bike " + bleId;
const char *message[] = {
"senseBox",
"bike",
bleIdBegin.c_str(),
bleIdEnd.c_str()};

display.showConnectionScreen(name, message);
bleModule.bleStartPoll("4fafc201-1fb5-459e-8fcc-c5c9c331914b");
}

Expand Down

0 comments on commit ad389e3

Please sign in to comment.