Comments (21)
The issue i discovered is that this sensor transmits encrypted data. Maybe only if you connect to it directly it transmits unencrypted data but still that's annoying and tedious to do. I resolved by flashing the modified firmware from this repo and then installing the ble scanner featured in #12 .
This new firmware transmits all the data without encryption in the ble broadcast message so it doesn't even need to be directly connected via bluetooth to the raspberry. This also allows to read the sensor data from other devices such as esp32's at the same time. The firmware transmits the temperature, humidity, signal and battery percentage and mVolts as well as the mac address. With the tool in the linked repo you can even set custom values for the temperature and humidity offset, you can manually change the face and you can choose to show the battery falue every 5 seconds. A cool feature is also that when you reinsert the battery it shows the last 3 bytes of the MAC address so you can identify the sensor. If anyone needs help i can post my node red function that i use filter the sensor from all other ble boardcast messages and format all the values.
from node-red-contrib-xiaomi-ble.
This is the flow
The first function is only used to parse the JSON string as node-red's JSON convert node gives an error when converting the output of the BLEscanner. Here's the code.
return {"payload":JSON.parse(msg.payload)};
Then there's the switch node used to filter the BLE messages and only pass the ones coming from the sensor. I use the .id value and search for the MAC address.
Then there's the delay node because the sensor sends a message every ~2 seconds, so i pass 1 message every 5 minutes.
And finally the function code:
buf = new Buffer(msg.payload.advertisement.serviceData[0].data);
temp = (buf.readUInt8(6) << 8) | buf.readUInt8(7);
temp /= 10;
humi = buf.readUInt8(8);
batt = buf.readUInt8(9);
vbat = (buf.readUInt8(10) << 8) | buf.readUInt8(11);
rssi = msg.payload.rssi;
sig = 2*(rssi+100);
if (sig > 100) sig = 100;
fill = batt > 15 ? "green" : batt > 5 ? "yellow" : "red";
text = "Temp: " + temp + "°C, Hum: " + humi + "%, Bat: " + batt + "%, mV: " + vbat + ", Sig: " + sig + "%";
node.status({fill:fill,shape:"dot",text:text});
return {"payload":{"temperature":temp, "humidity":humi, "battery": batt, "battery_mv": vbat, "rssi": rssi}};
Hope this helps.
PS: i know i could have used the function to parse a 16 bit integer directly from the buffer, but i'm lazy and prefer to use bit shifting instead ;-)
from node-red-contrib-xiaomi-ble.
Hi Michele, what node and package are you using as BLE Scan?
I'm using node-red-contrib-ble-scan from @sjroe
from node-red-contrib-xiaomi-ble.
For me it's only battery value
from node-red-contrib-xiaomi-ble.
Hi Michele,
if you could post your Node Red function that would be very useful!
from node-red-contrib-xiaomi-ble.
Same problem. I managed to read the data without changing the firmware using the following shell command taken from
http://www.d0wn.com/using-bash-and-gatttool-to-get-readings-from-xiaomi-mijia-lywsd03mmc-temperature-humidity-sensor/
as I'm very new to node-red, any advice on doing this better is much appreciated.
#!/bin/bash
bt=$(timeout 5 gatttool -b XX:XX:XX:XX:XX:XX --char-write-req --handle='0x0038' --value="0100" --listen)
if [ -z "$bt" ]
then
echo "The reading failed"
else
temphexa=$(echo $bt | awk -F ' ' '{print $12$11}'| tr [:lower:] [:upper:] )
humhexa=$(echo $bt | awk -F ' ' '{print $13}'| tr [:lower:] [:upper:])
temperature100=$(echo "ibase=16; $temphexa" | bc)
humidity=$(echo "ibase=16; $humhexa" | bc)
echo "scale=2;$temperature100/100"|bc
echo $humidity
fi
from node-red-contrib-xiaomi-ble.
This is the flow
The first function is only used to parse the JSON string as node-red's JSON convert node gives an error when converting the output of the BLEscanner. Here's the code.
Hi Michele, what node and package are you using as BLE Scan?
from node-red-contrib-xiaomi-ble.
I'm using node-red-contrib-ble-scan from @sjroe
Thanks a lot! Worked for me)
from node-red-contrib-xiaomi-ble.
This is the flow
The first function is only used to parse the JSON string as node-red's JSON convert node gives an error when converting the output of the BLEscanner. Here's the code.
return {"payload":JSON.parse(msg.payload)};
Then there's the switch node used to filter the BLE messages and only pass the ones coming from the sensor. I use the .id value and search for the MAC address.
Then there's the delay node because the sensor sends a message every ~2 seconds, so i pass 1 message every 5 minutes.
And finally the function code:buf = new Buffer(msg.payload.advertisement.serviceData[0].data); temp = buf.readUInt8(6) << 8; temp += buf.readUInt8(7); temp /= 10; humi = buf.readUInt8(8); batt = buf.readUInt8(9); vbat = buf.readUInt8(10) << 8; vbat += buf.readUInt8(11); rssi = msg.payload.rssi; fill = batt > 15 ? "green" : batt > 5 ? "yellow" : "red"; text = "Temp: " + temp + "°C, Hum: " + humi + "%, Bat: " + batt + "%, mV: " + vbat + ", Sig: " + 2*(rssi+100) + "%"; node.status({fill:fill,shape:"dot",text:text}); return {"payload":{"temperature":temp, "humidity":humi, "battery": batt, "battery_mv": vbat, "rssi": rssi}};
Hope this helps.
PS: i know i could have used the function to parse a 16 bit integer directly from the buffer, but i'm lazy and prefer to use bit shifting instead ;-)
Hi Michele,
i managed to flash and read the data from the sensors with ur help. Thanks for that!
I only got the problem that the sensors show wierd data.
Somtimes the right data appears for 1 periode of the timer.
What type of data send method you choose in the mija custom firmware?
from node-red-contrib-xiaomi-ble.
Hi Michele,
i managed to flash and read the data from the sensors with ur help. Thanks for that!
I only got the problem that the sensors show wierd data.
Somtimes the right data appears for 1 periode of the timer.
What type of data send method you choose in the mija custom firmware?
I've chosen the "Custom" type advertisment. Try opening up the payload and see if the service data look something like this:
From what I see int the ATC Thermometer Documentation, The bytes used by temperature and humidity and so on are theese:
My thermometer howevers doesn't send the first few bytes or so and thus in the function node i read the data from byte 6 onwards. Maybe that's the problem you are having. So i suggest to open the payload and see the service data. My code works with:
0-5: MAC Address
6-7: Temperature
8: Humidity
9: Battery percentage
10-11: Battery voltage
So you should see those values in the debug window:
hint: clicking on the HEX value in the debug windows converts it to a decimal number. If the temperature in your room is less than 25.5°C, you should see the full temperature multiplied by 10 directly in byte 7 (here 22.1°C)
If the temperature on the display is less than 25.5°C and you don't see the full number in the 7th byte, there is a problem with the advertisment data. Try putting a picture of the service data
from node-red-contrib-xiaomi-ble.
Here is mine:
I set the method to mii. Ill change it to Custom and see.
from node-red-contrib-xiaomi-ble.
Here is mine:
From what i see, that isn't a ATC Custom broadcast message. You can see it by the MAC address which is sent backwards from byte 5 to byte 10. Are you sure you flashed the firmware correctly and/or enabled Custom type broadcasting? When the battery is re-inserted, the sensor shows "Atc" and flashed the last 3 bytes of the MAC address in the humidity section, so in your case it will show f3, then 7b and then 0a. By default the firmware also flashes the battery percentage every 5 seconds or so.
from node-red-contrib-xiaomi-ble.
Thanks for your help! Ive set the Advertisement now to atc.... Now it works perfekt thank you.
from node-red-contrib-xiaomi-ble.
Nice to hear that!
from node-red-contrib-xiaomi-ble.
Hello, the code don't work if the temperature goes below 0 degree celsius. The temperature then is a strange number (6552)
from node-red-contrib-xiaomi-ble.
Hello, the code don't work if the temperature goes below 0 degree celsius. The temperature then is a strange number (6552)
I've never tried and honestly never thought about that, because in my scenario that never happens. Maybe trying to use a dedicated function to parse a 16 bit integer could help, but i can't test it.
from node-red-contrib-xiaomi-ble.
Thank you. Now it works. With this dedicatet function:
if (msg.payload.temperature > 2000) msg.payload.temperature = msg.payload.temperature-6553.7
return msg;
from node-red-contrib-xiaomi-ble.
Thanks for this, @MicheleSilla810, I've been tearing my hair out trying to get it working...
My sensor too only reported the battery (as 109) and about every second/third attempt reports an error.
I implemented your solution but I am getting a weird temp. value:
temperature: 4520.3
humidity: 56
battery: 193
battery_mv: 42024
rssi: -33
The display itself shows 21.6 C so seems the sensor is working... Any clue?
from node-red-contrib-xiaomi-ble.
Hi,
I have a problem recreating this solution. In the serviceData I have an array, which expands everytime when node red receives new message. When the node red service is restarted, it starts from the beginning.
Any help please?
Thank you.
from node-red-contrib-xiaomi-ble.
Hi,
I have a problem recreating this solution. In the serviceData I have an array, which expands everytime when node red receives new message. When the node red service is restarted, it starts from the beginning.
Any help please?
Thank you.
hi!
i don’t have any clue. i’ve never seen such behavior. maybe it’s the ble node that’s causing some problem?
from node-red-contrib-xiaomi-ble.
Thanks for this, @MicheleSilla810, I've been tearing my hair out trying to get it working...
My sensor too only reported the battery (as 109) and about every second/third attempt reports an error.
I implemented your solution but I am getting a weird temp. value:
temperature: 4520.3 humidity: 56 battery: 193 battery_mv: 42024 rssi: -33
The display itself shows 21.6 C so seems the sensor is working... Any clue?
hi!
i’m super sorry for the late response, i somehow didn’t see the email.
have you got it working?
from node-red-contrib-xiaomi-ble.
Related Issues (20)
- Xiaomi Flower Care - no data HOT 2
- How data is retrieved from the sensors? HOT 8
- Does not work after upgrading Node-Red HOT 2
- Suggestion: Change to maintained fork of Noble library HOT 1
- Support for ClearGrass humidity/temerature sensor HOT 5
- Support for lywsd02 HOT 1
- installation problem on Windows 10 HOT 4
- "noble.stopScanning();" isn't working HOT 1
- Support for noble.address? HOT 4
- Node Not accepting address property Pi3b Raspbian Buster HOT 2
- LYWSD03MMC always shows 109% on Battery value HOT 1
- "Searching" status without any outgoing information HOT 2
- LYWSD03MMC error: Peripheral already connected HOT 6
- Negative temperatures issue? HOT 3
- Original message object should be preserved HOT 1
- Installing pallete to Node Red Failing HOT 2
- Will this run on a RPi 3B+? HOT 1
- usb-v1.6.4-node-v72-linux-arm64.tar.gz cannot found? HOT 1
- LYWSDCGQ/01ZM with 1.3.3 just battery level HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-red-contrib-xiaomi-ble.