7static const char *
const TAG =
"sun_gtil2";
9static const double NTC_A = 0.0011591051055979914;
10static const double NTC_B = 0.00022878183547845582;
11static const double NTC_C = 1.0396291358342124e-07;
12static const float PULLUP_RESISTANCE = 10000.0f;
13static const uint16_t ADC_MAX = 1023;
15struct SunGTIL2Message {
17 uint8_t ac_waveform[277];
29 uint32_t limiter_power;
31 char serial_number[10];
36static const uint16_t MESSAGE_SIZE =
sizeof(SunGTIL2Message);
38static_assert(MESSAGE_SIZE == 350,
"Expected the message size to be 350 bytes");
53 return "Starting voltage too low";
62 if (adc_value >= ADC_MAX || adc_value == 0) {
66 float ntc_resistance = PULLUP_RESISTANCE / ((
static_cast<float>(ADC_MAX) / adc_value) - 1.0f);
67 double lr = log(
double(ntc_resistance));
68 double v = NTC_A + NTC_B * lr + NTC_C * lr * lr * lr;
69 return float(1.0 / v - 273.15);
83 memcpy(&msg, this->
rx_message_.data(), MESSAGE_SIZE);
86 if ((msg.end[0] != 0) || (msg.end[38] != 0x08))
89 ESP_LOGVV(TAG,
"Frequency raw value: %02x", msg.frequency);
90 ESP_LOGVV(TAG,
"Unknown values: %02x %02x %02x %02x %02x", msg.unknown1, msg.unknown2, msg.unknown3, msg.unknown4,
107#ifdef USE_TEXT_SENSOR
108 if (this->
state_ !=
nullptr) {
123 LOG_SENSOR(
"",
"AC Power", this->
ac_power_);
124 LOG_SENSOR(
"",
"DC Power", this->
dc_power_);
128#ifdef USE_TEXT_SENSOR
129 LOG_TEXT_SENSOR(
"",
"State", this->
state_);
void publish_state(float state)
Publish a new state to the front-end.
float calculate_temperature_(uint16_t adc_value)
void handle_char_(uint8_t c)
text_sensor::TextSensor * state_
void dump_config() override
sensor::Sensor * dc_power_
text_sensor::TextSensor * serial_number_
sensor::Sensor * limiter_power_
std::vector< uint8_t > rx_message_
sensor::Sensor * dc_voltage_
sensor::Sensor * ac_power_
std::string state_to_string_(uint8_t state)
sensor::Sensor * ac_voltage_
sensor::Sensor * temperature_
void publish_state(const std::string &state)
bool read_byte(uint8_t *data)
struct @67::@68 __attribute__
Providing packet encoding functions for exchanging data with a remote host.
std::string str_sprintf(const char *fmt,...)