ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
renogy_inverter_ble.h
Go to the documentation of this file.
1#pragma once
2
3#ifdef USE_ESP32
4
5#include <esp_gattc_api.h>
6#include <array>
11
13
15
16// Largest Modbus response: 3 header + 2 * 32 data + 2 CRC bytes
17static constexpr size_t MAX_FRAME = 69;
18
19// Renogy inverter BLE GATT (RIV1230PU). Notify char 0xFFF1 (svc 0xFFF0), write char 0xFFD1
20// (svc 0xFFD0), init char 0xFFD4 (svc 0xFFD0). Modbus device id 0x20, function 0x03.
22 SUB_SENSOR(ac_input_voltage)
23 SUB_SENSOR(ac_output_voltage)
24 SUB_SENSOR(ac_output_current)
25 SUB_SENSOR(ac_output_frequency)
26 SUB_SENSOR(input_frequency)
27 SUB_SENSOR(battery_voltage)
28 SUB_SENSOR(temperature)
29 SUB_SENSOR(load_current)
30 SUB_SENSOR(load_active_power)
31 SUB_SENSOR(load_apparent_power)
32
33 public:
34 void dump_config() override;
35 void update() override;
36 void gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if,
37 esp_ble_gattc_cb_param_t *param) override;
38
39 protected:
40 // Read cycle: IDLE -> (update) INIT read(0xFFD4) -> MAIN read(4000) -> LOAD read(4408) -> IDLE
41 enum class State : uint8_t { IDLE, INIT, MAIN, LOAD };
42
43 void start_cycle_();
44 void read_register_(uint16_t start_register, uint16_t word_count);
45 void on_frame_complete_(uint16_t len);
46 void abort_cycle_();
47
49 uint8_t frame_len_{0};
50 uint16_t notify_handle_{0};
51 uint16_t write_handle_{0};
52 uint16_t init_handle_{0};
53 // Reassembles the Modbus response, which arrives in MTU-sized notification chunks
54 std::array<uint8_t, MAX_FRAME> frame_;
55};
56
57} // namespace esphome::renogy_inverter_ble
58
59#endif // USE_ESP32
virtual void dump_config()
This class simplifies creating components that periodically check a state.
Definition component.h:514
void read_register_(uint16_t start_register, uint16_t word_count)
const void size_t len
Definition hal.h:68
uint16_t temperature
Definition sun_gtil2.cpp:12