-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patho2test.h
45 lines (40 loc) · 1.22 KB
/
o2test.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "esphome.h"
// #include "Wire.h"
const uint16_t I2C_ADDRESS = 0x74;
const uint16_t POLLING_PERIOD = 5000; //milliseconds
class MyCustomSensor : public PollingComponent, public Sensor {
public:
// constructor
MyCustomSensor() : PollingComponent(POLLING_PERIOD) {}
float get_setup_priority() const override { return esphome::setup_priority::BUS; } //Access I2C bus
void setup() override {
//Add code here as needed
// Wire.begin();
// ESP_LOGD("custom","THIS IS A ESPLOGD PRINT TEST");
// Serial.println("THIS IS A SERIAL PRINT TEST");
}
void update() override {
uint8_t recvbuf[9] = {0};
Wire.beginTransmission(I2C_ADDRESS);
Wire.write(0xFF);
Wire.write(0x01);
Wire.write(0x86);
Wire.write(0x00);
Wire.write(0x00);
Wire.write(0x00);
Wire.write(0x00);
Wire.write(0x79);
Wire.endTransmission();
// publish_state(42.0);
delay(10);
int i=0;
Wire.requestFrom(0x74,9);
while (Wire.available())
{
recvbuf[i++]=Wire.read();
}
// ESP_LOGD(recvbuf);
float con = (((recvbuf[2]*256) + recvbuf[3]) * 0.1);
publish_state(con);
}
};