-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
In the thermostat example, we can use the BLE Xiaomi thermometer as a temperature sensor instead of the local temperature sensor. #1
Comments
I've not used bluetooth on the ESP32 so unfortunately can't advise on that portion of the project. Are you able to read the thermometer properly using bluetooth but without HomeSpan? In other words, is the issue related to incorporating readings you have successfully taken into HomeSpan, or is it with reading the thermometer via bluetooth? Note, for greater visibility you may wish to post questions on the main HomeSpan issues and discussions pages instead (this repository is simply a subset of the main HomeSpan docs/examples). |
Thanks for your interest. I establish a homkit connection via Homspan, and a card with a Wemoos ESP32 Oled Bluetooth and battery is provided. See the information of the Xiaomi Ble thermometer with your card. So far everything is normal. Homspan sends temperature information to Homekit as Duumy Tem Sensor, 22 degrees C. Instead of installing the Dummy Temp Sensor, which I could not do, he explained the temperature information of the xiaomi Atc Thermometer, which is already running on the same card. However, I still couldn't. I keep making mistakes. I would like to ask you, how can I use the temperature sensor of the xiaomi thermometer instead of the Dummy Temp Sensor in the easiest way. We don't have a problem on the Bluetooth side because I'm already reading on the screen and serial output. For example: I will be grateful if you could help me. It should be simple actually, but for some reason I couldn't make it. |
Also, if you have an example of a Homespan Thermostat that works with a real temperature sensor (DHT , DHT22...), we would appreciate it if you could send it to me. Maybe we can work it that way. |
I have an example of a real temperature sensor that uses the I2C bus: https://github.com/HomeSpan/TempSensorI2C. DHT22 and similar sensors require special timing protocols and can be quite unreliable in certain instances. I generally use I2C components whenever available since they all use a standard bus and the ESP32 has a robust library (called |
Hello again, Serial Out : @c 25.50 Sensor 0: a4:c1:38:b2:c7:32 @c 25.50 |
I'm not sure I fully understand what's working and what's not working. From above, it seems that you are able to read the thermometer on the ESP32. Is that correct? If so, what code are you running to produce the "Serial Out" information above? Did you add that code to the example TempSensorI2C sketch, replacing the code that reads from the I2C sensor? If you are able to run a HomeSpan sketch at the same time you can read your sensor via BLE, what exactly is not working? Also, can you confirm that you can run any of the HomeSpan sketches, such as Example 1, without any modification, and the it pairs to HomeKit and operates as expected. Making sure you can do this is a first step to then adding in your BLE sensor. |
Hello again, ` #include <NimBLEDevice.h> #include <U8g2lib.h> #ifdef U8X8_HAVE_HW_I2C #include "ATC_MiThermometer.h" #define HEATING_RELAY 2 const int scanTime = 5; // BLE scan time in seconds // List of known sensors' BLE addresses ATC_MiThermometer miThermometer(knownBLEAddresses); U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /SCL/ 4, /SDA/ 5, /RESET/ -1); #define WIFI_SSID "iphone" struct DummyTempSensor { DummyTempSensor(float t) { float read() { float DummyTempSensor::temp; struct Reference_Thermostat : Service::Thermostat { // Create characteristics, set initial values, and set storage in NVS to true Characteristic::CurrentHeatingCoolingState currentState{ 0, true }; DummyTempSensor tempSensor{ 22 }; // instantiate a dummy temperature sensor with initial temp=22 degrees C Reference_Thermostat()
} boolean update() override {
} // Here's where all the main logic exists to turn on/off heating/cooling by comparing the current temperature to the Thermostat's settings void loop() override {
} // This "helper" function makes it easy to display temperatures on the serial monitor in either F or C depending on TemperatureDisplayUnits String temp2String(float temp) { void drawOLED() { unsigned found = miThermometer.getData(scanTime); for (int i = 0; i < miThermometer.data.size(); i++) { void scanBLE() { // miThermometer.begin(); unsigned found = miThermometer.getData(scanTime); for (int i = 0; i < miThermometer.data.size(); i++) { while (Serial2.available()) { void setup() { Serial.begin(115200); Serial2.begin(115200, SERIAL_8N1, RXD2, TXD2); u8g2.begin(); pinMode(HEATING_RELAY, OUTPUT); #if defined(WIFI_SSID) && defined(WIFI_PASSWORD) homeSpan.begin(Category::Thermostats, "HomeSpan Thermostat"); new SpanAccessory(); new Reference_Thermostat(); miThermometer.begin(); drawOLED(); void loop() { homeSpan.poll(); |
Thanks for the update and good news. Really glad that you got it all working. |
Hello again guys. BLE execution protection was limited to WiFi. There have been escapes. I accept the code. I am sharing the latest version. Good luck. ` #include <NimBLEDevice.h> //////////////////////////////////////////////////////////////////////// #ifdef U8X8_HAVE_HW_I2C #include "ATC_MiThermometer.h" #define HEATING_RELAY 16 #define RXD2 15 const int HOMESPAN_STATUS_PIN = 2; const int scanTime = 5; // BLE scan time in seconds // List of known sensors' BLE addresses ATC_MiThermometer miThermometer(knownBLEAddresses); U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /SCL/ 4, /SDA/ 5, /RESET/ -1); #define WIFI_SSID "iphone" struct DummyTempSensor { DummyTempSensor(float t) { float read() { float DummyTempSensor::temp; struct Reference_Thermostat : Service::Thermostat { // Create characteristics, set initial values, and set storage in NVS to true Characteristic::CurrentHeatingCoolingState currentState{ 0, true }; DummyTempSensor tempSensor{ 22 }; // instantiate a dummy temperature sensor with initial temp=22 degrees C Reference_Thermostat()
} boolean update() override {
} // Here's where all the main logic exists to turn on/off heating/cooling by comparing the current temperature to the Thermostat's settings void loop() override {
} // This "helper" function makes it easy to display temperatures on the serial monitor in either F or C depending on TemperatureDisplayUnits String temp2String(float temp) { void scanBLE() { unsigned found = miThermometer.getData(scanTime); for (int i = 0; i < miThermometer.data.size(); i++) { while (Serial2.available()) { void setup() { Serial.begin(115200); Serial2.begin(115200, SERIAL_8N1, RXD2, TXD2); homeSpan.setStatusPin(HOMESPAN_STATUS_PIN); u8g2.begin(); pinMode(HEATING_RELAY, OUTPUT); #if defined(WIFI_SSID) && defined(WIFI_PASSWORD) homeSpan.begin(Category::Thermostats, "HomeSpan Thermostat"); new SpanAccessory(); new Reference_Thermostat(); miThermometer.begin(); void loop() { |
Hello everyone.
I've been trying to get the Homespan thermostat example to work with the xiaomi thermometer, but I haven't been able to. I want to use bluetooth temperature sensor instead of local temperature sensor. I'm running the thermostat example I bought the screen shot of the Xiaomi mi thermometer, but I couldn't use the values of the Atc thermometer instead of a kind of DummyTempSensor. Homekit values 22 C. I am very glad for your help. I've been trying for 24 hours and I couldn't succeed.
The text was updated successfully, but these errors were encountered: