Initial release v1.0.0 - BLE Device Simulator with MCP Integration

Features:
- MCP server with tools for AI-controlled device simulation
- FastAPI backend with REST API and WebSocket support
- Real-time device updates via WebSocket
- Web UI for manual device control
- ESP32 firmware for BLE device simulation
- Docker containerization with MQTT broker

Supported device types:
- Heart Rate Monitor (BLE Heart Rate Service)
- Treadmill (BLE Fitness Machine Service)
- Bike Trainer (BLE Cycling Power Service)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-19 11:50:10 -05:00
commit 1c6b9db903
27 changed files with 3455 additions and 0 deletions

View File

@@ -0,0 +1,59 @@
#ifndef BLE_SERVICES_H
#define BLE_SERVICES_H
#include <Arduino.h>
// ============================================
// BLE Service UUIDs (Bluetooth SIG standard)
// ============================================
// Heart Rate Service
#define HEART_RATE_SERVICE_UUID "180D"
#define HEART_RATE_MEASUREMENT_UUID "2A37"
#define BODY_SENSOR_LOCATION_UUID "2A38"
// Fitness Machine Service
#define FITNESS_MACHINE_SERVICE_UUID "1826"
#define TREADMILL_DATA_UUID "2ACD"
#define FITNESS_MACHINE_FEATURE_UUID "2ACC"
// ============================================
// Function Prototypes
// ============================================
/**
* Initialize NimBLE stack (call once at startup)
*/
void initBLE();
/**
* Stop BLE advertising and deinit
*/
void stopBLE();
/**
* Setup BLE as Heart Rate Monitor
* Creates Heart Rate Service with measurement characteristic
*/
void setupBLE_HeartRate();
/**
* Setup BLE as Treadmill (Fitness Machine)
* Creates Fitness Machine Service with treadmill data
*/
void setupBLE_Treadmill();
/**
* Send heart rate notification
* @param bpm Heart rate in beats per minute
*/
void notifyHeartRate(uint8_t bpm);
/**
* Send treadmill data notification
* @param speed Speed in 0.01 km/h units
* @param incline Incline in 0.1% units
*/
void notifyTreadmill(uint16_t speed, int16_t incline);
#endif // BLE_SERVICES_H

View File

@@ -0,0 +1,37 @@
#ifndef CONFIG_H
#define CONFIG_H
// ============================================
// Firmware Version
// ============================================
#define FIRMWARE_VERSION "1.0.0"
// ============================================
// AP Mode Configuration
// ============================================
#define AP_SSID_PREFIX "BLE-Sim-" // Will append chip ID for uniqueness
#define AP_PASSWORD "" // Open network (or set a password)
#define AP_IP IPAddress(192, 168, 4, 1)
#define AP_GATEWAY IPAddress(192, 168, 4, 1)
#define AP_SUBNET IPAddress(255, 255, 255, 0)
// ============================================
// Default Values (used until configured)
// ============================================
#define DEFAULT_MQTT_PORT 1883
#define DEFAULT_DEVICE_ID_PREFIX "esp32-"
// ============================================
// Timing Configuration
// ============================================
#define BLE_NOTIFY_INTERVAL 1000 // BLE notification interval (ms)
#define MQTT_RECONNECT_INTERVAL 5000 // MQTT reconnect attempt interval (ms)
#define STATUS_REPORT_INTERVAL 10000 // Status report to MQTT (ms)
#define WIFI_CONNECT_TIMEOUT 15000 // WiFi connection timeout (ms)
// ============================================
// NVS Configuration Keys
// ============================================
#define NVS_NAMESPACE "ble-sim"
#endif // CONFIG_H

View File

@@ -0,0 +1,64 @@
#ifndef CONFIG_MANAGER_H
#define CONFIG_MANAGER_H
#include <Arduino.h>
#include <Preferences.h>
// ============================================
// Configuration Structure
// ============================================
struct DeviceConfig {
bool configured = false;
String wifiSsid = "";
String wifiPassword = "";
String mqttHost = "";
uint16_t mqttPort = 1883;
String deviceId = "";
};
// ============================================
// Configuration Manager Class
// ============================================
class ConfigManager {
public:
ConfigManager();
// Load config from NVS
bool load();
// Save config to NVS
void save();
// Clear all config
void clear();
// Check if configured
bool isConfigured() const { return config.configured; }
// Getters
const String& getWifiSsid() const { return config.wifiSsid; }
const String& getWifiPassword() const { return config.wifiPassword; }
const String& getMqttHost() const { return config.mqttHost; }
uint16_t getMqttPort() const { return config.mqttPort; }
const String& getDeviceId() const { return config.deviceId; }
// Setters
void setWifiCredentials(const String& ssid, const String& password);
void setMqttConfig(const String& host, uint16_t port);
void setDeviceId(const String& id);
// Get unique AP name based on chip ID
String getAPName() const;
// Get unique default device ID based on chip ID
String getDefaultDeviceId() const;
private:
DeviceConfig config;
Preferences preferences;
};
// Global instance
extern ConfigManager configManager;
#endif // CONFIG_MANAGER_H

View File

@@ -0,0 +1,30 @@
#ifndef WEB_PORTAL_H
#define WEB_PORTAL_H
#include <Arduino.h>
/**
* Initialize and start the web portal
* Runs on AP interface at 192.168.4.1
*/
void setupWebPortal();
/**
* Handle web portal requests (call in loop)
*/
void handleWebPortal();
/**
* Get status info for web portal display
*/
struct PortalStatus {
bool wifiConnected;
bool mqttConnected;
String ipAddress;
String deviceType;
bool bleStarted;
};
void updatePortalStatus(const PortalStatus& status);
#endif // WEB_PORTAL_H