Repeater and Test code for ESP Now

This commit is contained in:
2026-02-15 19:10:19 +11:00
parent a64fef899b
commit 8a2402cb63
8 changed files with 553 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
monitor_speed = 115200
monitor_filters = esp32_exception_decoder
[env:esp32-s3]
platform = espressif32
board = esp32-s3-devkitc-1
framework = arduino
monitor_speed = 115200
monitor_filters = esp32_exception_decoder
build_flags =
-D ARDUINO_USB_MODE=1
-D ARDUINO_USB_CDC_ON_BOOT=1
[env:esp32-c3]
platform = espressif32
framework = arduino
board = esp32-c3-devkitm-1
board_build.mcu = esp32c3
board_build.f_cpu = 160000000L
board_build.flash_mode = dio
board_build.partitions = default.csv
monitor_speed = 115200
monitor_filters = time, default, esp32_exception_decoder
upload_speed = 921600
build_flags =
-Os
-D ARDUINO_ESP32C3_DEV
-D CONFIG_IDF_TARGET_ESP32C3
-D ARDUINO_USB_MODE=1
-D ARDUINO_USB_CDC_ON_BOOT=1
[env:m5stick]
platform = espressif32
board = m5stick-c
framework = arduino
board_build.mcu = esp32
board_build.f_cpu = 240000000L
board_build.partitions = no_ota.csv
monitor_speed = 115200
monitor_filters = esp32_exception_decoder
build_flags =
-Os
lib_deps =
M5StickC

View File

@@ -0,0 +1,102 @@
/**
* VictronBLE FakeRepeater Example
*
* Sends fake Solar Charger data over ESPNow every 10 seconds.
* Use with the Receiver example to test ESPNow without needing
* a real Victron device or the VictronBLE library.
*
* No VictronBLE dependency - just WiFi + ESPNow.
*/
#include <Arduino.h>
#include <WiFi.h>
#include <esp_now.h>
// ESPNow packet structure - must match Receiver
struct __attribute__((packed)) SolarChargerPacket {
uint8_t chargeState;
float batteryVoltage; // V
float batteryCurrent; // A
float panelVoltage; // V
float panelPower; // W
uint16_t yieldToday; // Wh
float loadCurrent; // A
int8_t rssi; // BLE RSSI
char deviceName[16]; // Null-terminated, truncated
};
static const uint8_t BROADCAST_ADDR[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
static uint32_t sendCount = 0;
static unsigned long lastSendTime = 0;
static const unsigned long SEND_INTERVAL_MS = 10000;
void setup() {
Serial.begin(115200);
delay(1000);
Serial.println("\n=== VictronBLE FakeRepeater ===\n");
WiFi.mode(WIFI_STA);
WiFi.disconnect();
Serial.println("MAC: " + WiFi.macAddress());
if (esp_now_init() != ESP_OK) {
Serial.println("ERROR: ESPNow init failed!");
while (1) delay(1000);
}
esp_now_peer_info_t peerInfo = {};
memcpy(peerInfo.peer_addr, BROADCAST_ADDR, 6);
peerInfo.channel = 0;
peerInfo.encrypt = false;
if (esp_now_add_peer(&peerInfo) != ESP_OK) {
Serial.println("ERROR: Failed to add broadcast peer!");
while (1) delay(1000);
}
Serial.println("ESPNow initialized, sending fake data every 10s");
Serial.println("Packet size: " + String(sizeof(SolarChargerPacket)) + " bytes\n");
}
void loop() {
unsigned long now = millis();
if (now - lastSendTime < SEND_INTERVAL_MS) {
delay(100);
return;
}
lastSendTime = now;
sendCount++;
// Generate varying fake data
SolarChargerPacket pkt;
pkt.chargeState = (sendCount % 4) + 3; // Cycle through Bulk(3), Absorption(4), Float(5), Storage(6)
pkt.batteryVoltage = 51.0f + (sendCount % 20) * 0.15f;
pkt.batteryCurrent = 2.0f + (sendCount % 10) * 0.5f;
pkt.panelVoltage = 65.0f + (sendCount % 15) * 0.8f;
pkt.panelPower = pkt.batteryCurrent * pkt.batteryVoltage;
pkt.yieldToday = 100 + sendCount * 10;
pkt.loadCurrent = 0;
pkt.rssi = -60 - (sendCount % 30);
memset(pkt.deviceName, 0, sizeof(pkt.deviceName));
strncpy(pkt.deviceName, "FakeMPPT", sizeof(pkt.deviceName) - 1);
esp_err_t result = esp_now_send(BROADCAST_ADDR,
reinterpret_cast<const uint8_t*>(&pkt),
sizeof(pkt));
if (result != ESP_OK) {
Serial.println("[TX FAIL] " + String(esp_err_to_name(result)));
} else {
Serial.printf("[TX #%lu] %s Batt:%.2fV %.2fA PV:%.0fW Yield:%uWh RSSI:%d\n",
sendCount,
pkt.deviceName,
pkt.batteryVoltage,
pkt.batteryCurrent,
pkt.panelPower,
pkt.yieldToday,
pkt.rssi);
}
}