Quick Start Guide
Quick Start Guide
Section titled “Quick Start Guide”Get your ESP32C6 + BCGMCU device connected and streaming data in minutes.
Prerequisites
Section titled “Prerequisites”- ESP32C6 device with BCGMCU module
- Network connectivity (WiFi)
- Provisioning token from cloud service
- HTTPS client library
Step 1: Device Registration
Section titled “Step 1: Device Registration”Register your device to obtain authentication credentials:
// ESP32 Arduino exampleHTTPClient https;https.begin("https://api.endpoint.com/api/v1/device/register");https.addHeader("Content-Type", "application/json");https.addHeader("Authorization", "Bearer " + provisioning_token);
String payload = "{\"device_info\":{" "\"device_id\":\"BCGMCU_001\"," "\"mac_address\":\"" + WiFi.macAddress() + "\"," "\"firmware_version\":\"1.0.0\"," "\"bcgmcu_serial\":\"BCG123456789\"" "}}";
int httpCode = https.POST(payload);Step 2: Store Device Token
Section titled “Step 2: Store Device Token”Extract and store the device token from registration response:
if (httpCode == 200) { String response = https.getString(); // Parse JSON and extract device_token // Store in secure storage (NVS/SPIFFS)}Step 3: Start Streaming Data
Section titled “Step 3: Start Streaming Data”Begin sending real-time biomonitoring data:
void streamBCGData() { HTTPClient https; https.begin("https://api.endpoint.com/api/v1/data/stream"); https.addHeader("Content-Type", "application/json"); https.addHeader("Authorization", "Bearer " + device_token);
// Read BCGMCU data int pulse = bcgmcu.getPulseRate(); int breathing = bcgmcu.getBreathingRate();
String payload = "{\"device_id\":\"BCGMCU_001\"," "\"timestamp\":\"" + getCurrentTimestamp() + "\"," "\"sequence_number\":" + seq_num++ + "," "\"bcg_data\":{" "\"pulse_rate\":" + pulse + "," "\"respiratory_rate\":" + breathing + "}}";
int httpCode = https.POST(payload);}
// Call every second (1Hz)void loop() { streamBCGData(); delay(1000);}Step 4: Handle Status Updates
Section titled “Step 4: Handle Status Updates”Send periodic health checks:
void sendStatusUpdate() { String payload = "{\"device_id\":\"BCGMCU_001\"," "\"status\":{" "\"bcgmcu_online\":" + bcgmcu.isOnline() + "," "\"wifi_signal\":" + WiFi.RSSI() + "," "\"free_memory\":" + ESP.getFreeHeap() + "," "\"uptime\":" + millis()/1000 + "}}";
// Send every 5 minutes (300 seconds) https.POST(payload);}Step 5: Implement Error Handling
Section titled “Step 5: Implement Error Handling”Add retry logic with exponential backoff:
bool sendWithRetry(String endpoint, String payload) { int retries = 0; int delay_ms = 1000;
while (retries < 3) { int httpCode = https.POST(payload);
if (httpCode == 200) { return true; }
if (httpCode == 429 || httpCode >= 500) { delay(delay_ms); delay_ms *= 2; // Exponential backoff retries++; } else { return false; // Don't retry on client errors } } return false;}Complete Example Flow
Section titled “Complete Example Flow”sequenceDiagram participant D as Device participant C as Cloud API
D->>C: Register Device C-->>D: Device Token
loop Every 1 second D->>C: Stream Data C-->>D: Acknowledgment end
loop Every 5 minutes D->>C: Status Update C-->>D: Configuration Check endNext Steps
Section titled “Next Steps”- Review API Overview for complete endpoint list
- Implement Batch Upload for offline data
- Configure Error Handling for production
- Set up Security best practices