7 static const char *
const TAG =
"kuntze";
9 static const uint8_t CMD_READ_REG = 0x03;
10 static const uint16_t REGISTER[] = {4136, 4160, 4680, 6000, 4688, 4728, 5832};
13 auto get_16bit = [&](
int i) -> uint16_t {
return (uint16_t(data[i * 2]) << 8) | uint16_t(data[i * 2 + 1]); };
16 ESP_LOGV(TAG,
"Data: %s", hexencode(data).c_str());
18 float value = (float) get_16bit(0);
19 for (
int i = 0; i < data[3]; i++)
23 ESP_LOGD(TAG,
"pH=%.1f", value);
28 ESP_LOGD(TAG,
"temperature=%.1f", value);
33 ESP_LOGD(TAG,
"DIS1=%.1f", value);
38 ESP_LOGD(TAG,
"DIS2=%.1f", value);
43 ESP_LOGD(TAG,
"REDOX=%.1f", value);
48 ESP_LOGD(TAG,
"EC=%.1f", value);
53 ESP_LOGD(TAG,
"OCI=%.1f", value);
66 ESP_LOGW(TAG,
"timed out waiting for response");
72 send(CMD_READ_REG, REGISTER[this->
state_ - 1], 2);
79 ESP_LOGCONFIG(TAG,
"Kuntze:");
80 ESP_LOGCONFIG(TAG,
" Address: 0x%02X", this->
address_);
sensor::Sensor * ec_sensor_
sensor::Sensor * ph_sensor_
uint32_t IRAM_ATTR HOT millis()
sensor::Sensor * temperature_sensor_
sensor::Sensor * redox_sensor_
void dump_config() override
sensor::Sensor * dis2_sensor_
void publish_state(float state)
Publish a new state to the front-end.
void on_modbus_data(const std::vector< uint8_t > &data) override
sensor::Sensor * dis1_sensor_
sensor::Sensor * oci_sensor_
Implementation of SPI Controller mode.
void send(uint8_t function, uint16_t start_address, uint16_t number_of_entities, uint8_t payload_len=0, const uint8_t *payload=nullptr)