Homemade Environment Sensor + Bluetooth little brother. Here are new possibilities

@Chen555. If you decided to update your LYWSD03MMC and need help for the DTH, let me know. I would love to have DTH for it.

Mine is just ordered from China. I am not sure when it will be here.

Anyone know if this the same thermometer?
The only model number they mention is PAS0402W-3.

https://www.aliexpress.com/item/1005001495537428.html
I've had good luck buying from this store, very fast shipping.

By the look of it, it is the same. But, it is hard to tell. I just ordered mine today.

1 Like

My LYWSD03MMC has arrived. I updated the firmware with the custom firmware. It run overnight just fine. The custom firmware send update approximately once a second.

If anyone happen to need the DTH here it is.

Please also update the buetooth.groovy.

The LYWSD03MMC is a very well made sensor. For $4 to $5 per sensor, it is probably the best value Temperature and Humidity sensor. It also come with a small display.

As you notice, this one run on custom firmware which support Fahrenheit temperature display.

Here comparison to the bigger Xiaomi LYWSD02 (e-ink display).

Here is how it looks in the Hubitat.

Here is the link to the custom firmware GitHub - atc1441/ATC_MiThermometer: Custom firmware for the Xiaomi Thermometer LYWSD03MMC and Telink Flasher via USB to Serial converter

2 Likes

Hi, Iman. I've been trying out the ESP32 I got last week and just now fired up the BLE example code. Here is what the phone app shows:


The Bluetooth Manager doesn't find it when I click on the Find New BTDevice tile.

Let me know if there's anything else I can provide.

I'd like to set this up so I can read data from the ESP32 into node-red for processing.

@LosinIt,

You need a DTH for the ESP. As is the bluetooth manager does not recognize your ESP32 .

There are a couple things that are needed.

  1. in Bluetooth.groovy, you should modify the code in method handleAdvertismentData. Currently, the code is just crude. It looked at some common advertising type that can uniquely identify a device and map it a DTH name. Once it got a DTH name, it will create a child device. Ideally, I like to do it like a Zigbee finger print. But, I do not know how to iterate DTH and match a finger print. From your image, type 0x09 is a name of device. Those ASCII numbers will translate to a name. In some of my device, I use it as DTH name and create an instance of it during discover. Watch out for devices that name themselves as NAME_XXXXXX, where XXXXXX is the last N digits of its mac address. There are a few devices like that. There are other type like 0x16 service GUID, this can be a good signature since the GUID should be unique. This can identify a unique device.

  2. Once you have the DTH name, you can create a DTH for it. you can take one of my DTH as example. Beacon.groovy is probably the simples one. Essentially, you want to listen to one type of advertisement. Common type for this ix 0xFF. It is a manufacture specific advertisement data. Many beacon use this type. Xiaomi devices use different types to encapsulate its data. Basically, what I did was to parse these data and convert them to attributes that our hub understand.

Since you have control on the ESP32, I think you should modify the ESP32 example. A beacon, typically send just 0xFF type. Take a look below link for beacon. iBeacon is very simple packets. It contain GUID that you can use to uniquely identify your device. You can use it to match to a DTH. The draw back is that there is not much more data can be sent. Some devices send data in the Major, Minor fields. These typically enough for Hygrometer type of devices. This is the simplest type of advertisement. Other vendor will use service data.

The BLE gateway support read, write and subscription to GATT attributes. This is a different game. GATT is closer to Zigbee where you start to read, write and listen to attributes changes. I did this for the iBBQ probe. In your ESP32 device, you have to implement the GATT services.

Thanks
Iman

1 Like

Thanks! Will do later today.

I'm running the example code as-is to start with. Here is what the phone app shows:

And here is what is sent to the serial monitor, over and over:

rst:0x5 (DEEPSLEEP_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1044
load:0x40078000,len:8896
load:0x40080400,len:5816
entry 0x400806ac
start ESP32 1
deep sleep (11s since last reset, 11s since last boot)
Advertizing started...
enter deep sleep
ets Jun 8 2016 00:22:57

Being very new to this I'm not quite sure what's next but I'll read the article you linked and get back to you if I need help understand how to make this send my data (3 floating point numbers) so node-red can use it.

Again, thanks SO much!

I just got a few ESP32 myself for my holiday project. I have looked a bit about the DEEPSLEEP. I would not need it. But, from what I learn ESP32 deepsleep is just like shutting down the ESP32. When it wake up, it started just like it start from fresh. Except, It has a way to tell a code that it just wake up from deepsleep rather than a cold boot.

I think the example ESp32 that you are using is doing that.

It seems the advertising packet 0xFF is a beacon. Do you have more info on this? Is this a standard Ibeacon? If yes, you should be able to use the ibeacon DTH just to test. The only adjustment that you need is the GUID in the Bluetooth manager to map the GUID to the DTH.

:+1:

That is my understanding as well and I think I'll want to use the lighter sleep (forgot what it's called at the moment).

Correct.

I believe so.

Great! Where is that now?

I found the array you mentioned and replaced the top line with the UID I generated (just to try it out) with the link I found in the example file

I realized that I need a ground-up intro to BLE because the lingo was confusing me. I found this and it looks like it'll get me there but I'm only part way into it

After reading the article you linked I think I want to use AltBeacon just for the independence. Is there a problem with that?

Never mind, I found it. The ibeacon.groovy right?

I made a copy of the Bluetooth driver and changed the first array item to be the UID that I generated. I installed the ibeacon driver and did the same with the array.

When I go into the BT Manager device and click on the Find New BTbeacon tile nothing gets found. I have a feeling I missed a step...or several.

We never check whether the BT module received any data. It is a good idea to step back.

Lets double check that your bluetooth module receive any bluetooth packets. I tested the module a while back before I sent you the module the first time. To do this is to add log message on parse method for bluetooth.groovy. If you are seeing any activity, that meant we have a good physical connection. The next thing is to debug the code. Let me know a fragment of code that you modify.

If you are not getting any packets, there is no need to debug the code. The issue could be wiring. Lets double check the TX and RX connection again. Perhaps, there is an issue with DTH installation. We could try to re-install/pair the device again. It will be hard for me to guess what is going from this end.

Got nothing in the log with this

I have it wired according to this except it's plugged into a USB socket so 5V and GND are not wired. Is that wrong?

I believe I tested your modules at the first time I sent it. It worked.

I am assuming the ground from the same DC power is connected from the DC adapter. Your wiring should work. But, if you want to try connect one of the GND on both board, it is worth to try. Who knows your adapter isolate the ports individually. This can cause issue on the serial communication as they may work on different level.

The 5V is fine detached.

Other than that, I really do not know where to look. Try to re-install the bluetooth child device. That is the only thing I can think of.

1 Like

I went ahead and wired the 5V and GND between the boards and that didn't change anything. THEN I discovered that the closing "]" was missing from the JSON in the Environment Sensor EX preferences. Having fixed that I now get:

image

So, now I can debug because it's still not finding the beacon. I'll see if I can write more identifying info to the log...

1 Like

This doesn't look right to me as it returns NULL in all cases, unless my limited understanding of groovy has me missing something:

Can we use the cheap LYWSD03MMC as iBeacon?

For example, can I leave one in the car and use it as a presence sensor?

It should work as beacon. The advertisement interval is often enough.

your little brother's bluetooth does not seem to have a good range.
many of the ESP32 also have bad BLE range. but I tested RPI zero w. it has really good range. basically covers basement, first and second floor (communicating with various BLE (Tile, Xiaomi).

@iharyadi if you can tweak the tx power or antenna for your device, that would be great. I think your repeater has great range.

Just FYI, BLE does have much lower range compare to Zigbee. I uses the exactly same module and loaded it with Zigbee or BLE. I got at least 2x the range with Zigbee vs BLE. BLE does have a long range protocol. But, it takes both end to utilize the long range BLE. The device that sending the packet will need to use this BLE long range encoding also. I think BLE in term of range is originally designed for low range wireless use. BLE 5.0 start to venture to long range BLE applications.

In addition, the Environment Sensor Zigbee radio contain separate Power amplifier chip. It is not a fair comparison in term of range in this case. Basically, the little brother put about 8db of power. The big brother put up around 20db of power.

Having said that, this particular BLE module may be weaker than those that comes from different vendors. It is a fair point to bring up. With the same nrf52840 MCU from different vendors, the module that I am making may have lower range. However, I cannot conclude that yet. I am in the process of making a new board that will use a different vendors implementation of nrf52840. I will learn more about the power of this modules soon in respect to BLE once I got more modules from different vendors to play with.

I am not worry about the Zigbee range. It is much lower than the Environment Sensor for sure. They are on different class physically. For BLE, yes... I am hoping some vendors does a better job in their implementation.

Thanks for the input in any case. I really appreciate it.