intial test version
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
[env]
|
||||
lib_extra_dirs = ../..
|
||||
|
||||
[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
|
||||
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* BluettiBLE Control Example
|
||||
*
|
||||
* Reads the device and toggles the AC output on/off every 30 seconds to show how
|
||||
* to send control commands. DC output toggling works the same way via
|
||||
* setDCOutput().
|
||||
*
|
||||
* WARNING: this actively switches your inverter output. Only run it when it is
|
||||
* safe to power-cycle whatever is plugged in.
|
||||
*/
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "BluettiBLE.h"
|
||||
|
||||
BluettiBLE bluetti;
|
||||
|
||||
static uint32_t lastToggle = 0;
|
||||
static bool desiredAC = true;
|
||||
|
||||
void onBluettiData(const BluettiDevice* dev) {
|
||||
const BluettiData& d = dev->data;
|
||||
Serial.printf("[%s] SoC %u%% AC out %u W (%s) DC out %u W (%s)\n",
|
||||
d.model, d.totalBatteryPercent,
|
||||
d.acOutputPower, d.acOutputOn ? "ON" : "off",
|
||||
d.dcOutputPower, d.dcOutputOn ? "ON" : "off");
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
delay(1000);
|
||||
|
||||
Serial.println("\nBluettiBLE Control Example\n");
|
||||
|
||||
bluetti.begin();
|
||||
bluetti.setDebug(true);
|
||||
bluetti.setCallback(onBluettiData);
|
||||
|
||||
// CHANGE THESE: your device's advertised BLE name and model.
|
||||
bluetti.addDevice("My Bluetti", "AC3001234567890", BLUETTI_AC300);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
bluetti.loop();
|
||||
|
||||
if (bluetti.isConnected() && millis() - lastToggle > 30000) {
|
||||
Serial.printf(">> setting AC output %s\n", desiredAC ? "ON" : "OFF");
|
||||
if (bluetti.setACOutput(desiredAC))
|
||||
Serial.println(" command sent");
|
||||
else
|
||||
Serial.println(" command not supported / not connected");
|
||||
desiredAC = !desiredAC;
|
||||
lastToggle = millis();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user