sabeechen / AirthingsMQTT

An ESP32 arduino sketch that searches for a compatible Airthings device and publishes the radon level, temperature, and humidity to an MQTT server.
MIT License
21 stars 14 forks source link

get data using esp32 #3

Closed fandySondok closed 3 years ago

fandySondok commented 4 years ago

Hi @sabeechen, i have airthings wave product, i try to get data from it using your code, but actually, i realize airthings wave need to sync their data to the cloud, and i see an example from airthings using raspberry pi, they need to input serial number on it for sync i think. Is your code couldn't get data from airthings wave anymore or there is some setting that i missing in your code?

i try using your code, and esp32 can connect to device but failed to read from the device.

sabeechen commented 3 years ago

Sorry this took me a while to get back to you on. I've been unproductively reticent lately.

This sketch will just connect to the first airthings wave device it can find over bluetooth, which should work for you so long as you only have one device. If you have more, you'd need to modify the script to only look at a particular device somewhere around this line.

As for problems connecting and reading ... thats been my experience too. I'm not sure if the problem is with my code, the ESP32 BLE library (which I've heard bad things about) or something else but its always been flaky.

I actually haven't run this for a while, so I tried flashing it to an ESP32 Devkit I had lying around and I was only able to get it to connect and successfully make a reading maybe 1 out of 10 attempts. It does work for me eventually, but when I wrote this originally I can remember sometimes it would go hours trying without success and then randomly work again. Note that I'm using an Airthings Wave and not a Wave plus. Not sure if it works with the Wave plus.

Does it eventually work if you let it run for a few minutes and keep retrying? It should try to connect every 30 seconds until it succeeds, then wait an hour before trying to take another reading.

fandySondok commented 3 years ago

It's okay, thanks for the reply.

Yeah, i have a bad experience with esp32 BLE from my previous project, i don't know it's from the library or the hardware.

Yeah, i have the same experience as you when i try to run your code to my ESP32 Devkit. Unfortunately, i couldn't successfully get data from my Airthings Wave.

I already keep my esp32 on for a few hours, and the sleep is working every 30 s, and always connect to Airthings Wave, but fail to get the data.

Maybe i will try using raspi, to make sure the data always coming every time i execute the code.

sabeechen commented 3 years ago

I suspect its the library, as I've heard the same from many other sources and I don't hear the same about using BLE in the ESP-IDF. The reason this sketch hard resets after an attempt is because I've found the BLE library sometimes soft-locks the device if I use it enough time. It seems to me like there is some kind of race condition, but I lack the know-how to dive into it. For now, I think this is as good as its going to get.