1technophile / OpenMQTTGateway

MQTT gateway for ESP8266 or ESP32 with bidirectional 433mhz/315mhz/868mhz, Infrared communications, BLE, Bluetooth, beacons detection, mi flora, mi jia, LYWSD02, LYWSD03MMC, Mi Scale, TPMS, BBQ thermometer compatibility & LoRa.
https://docs.openmqttgateway.com
GNU General Public License v3.0
3.59k stars 790 forks source link

Support request for atomax Skale II (bluetooth) #1467

Closed Cadsters closed 1 year ago

Cadsters commented 1 year ago

Is your feature request related to a problem? Please describe. I would like my ble scale (atomax Skale II) to be added to the suported bluetooth devices

Describe the solution you'd like Read the weight and battery level, detect button press, and be able to send commands to set the device.

Additional context The scale https://skale.cc/en/

Skale 2 manual https://skale.gitbooks.io/skale-ii-user-manual/content/

Ble API Specification for Skale I and I https://de.decentespresso.com/scale_api

DigiH commented 1 year ago

With the currently include READ and WRITE commands in OpenMQTTGateway you can already read any data as specified in your link, as long as it doesn't require a Notify, and write any setting as specified in the documentation.

If you would also like the scale to be included in Theengs Decoder so that the properties are automatically decoded, we would need to see if and how the scale might also have this information in its advertising data - which is not mentioned in the documentation.

You can help by providing some sample message output from your scale, as seen in MQTT Explorer, and with publishing advertisement and advanced data set to true.

Cadsters commented 1 year ago

Yes i would like to have the scale included in Theengs Decoder please. I have flashed the latest omgw (esp32dev-ble-datatest) This is the data i can retreive from mqtt explorer: {"id":"DB:C5:13:ED:92:8E","mac_type":1,"adv_type":0,"name":"Skale","manufacturerdata":"ef81000000ff","rssi":-77} If i can do more please let me know.

DigiH commented 1 year ago

{"id":"DB:C5:13:ED:92:8E","mac_type":1,"adv_type":0,"name":"Skale","manufacturerdata":"ef81000000ff","rssi":-77}

Thanks, this is the kind of information needed, but we'd also need some additional data as to what the scale was set to and displayed - what weight, in g, kg or oz, lb - to be able to see if and what information might be included in the manufacturerdata.

Cadsters commented 1 year ago

Oké here some new data: {"id":"DB:C5:13:ED:92:8E","mac_type":1,"adv_type":0,"name":"Skale","manufacturerdata":"ef81280100ff","rssi":-79} The scale is set to g (grams) and the number displaying 29.6

DigiH commented 1 year ago

Great, the weight is already decoded now :)

2801 - little endian - 0128 = 296 / 10 = 29.6 g

If you change the scale to different weight settings, oz, so that we can see how the different unit might be registered.

Cadsters commented 1 year ago

may sound stupid but right now i am unable to change from g to oz.... will search the internet for a howto.

DigiH commented 1 year ago

may sound stupid but right now i am unable to change from g to oz.... will search the internet for a howto.

From your above linked online manual

https://skale.gitbooks.io/skale-ii-user-manual/content/operation.html

Touch and hold and button to power on and to switch measurement units between gram and oz. (Part of the model)

or through the app I suppose.

Cadsters commented 1 year ago

I've tried that the past 10 minutes but nothings happening.

DigiH commented 1 year ago

I've tried that the past 10 minutes but nothings happening.

I know, the manual description is also a bit unclear ;) any chance with the app maybe?

Also not that much clearer in the FAQ section

https://skale.gitbooks.io/skale-ii-user-manual/content/common-problems.html

but some additional information about successful unit switching there

To switch to oz, Skale shows '02' and to gram, Skale shows '9'。

One additional question though with the already recorded manufacturerdata above. Was the scale connected to the USB power adapter in both cases?

If so, could you also do some reading with only 4 AAA batteries in the scale?

Also some different reading with the LED display light being ON and OFF. But this again would need the to be able to set it in the app I suppose.

Cadsters commented 1 year ago

tried other batteries, usb-powersuply nothing. In the app i can switch to oz but the display on the scal still shows grams. So the app calculates to oz but nothing changes in the scale..... i'll get back to this.

DigiH commented 1 year ago

tried other batteries, usb-powersuply nothing. In the app i can switch to oz but the display on the scal still shows grams. So the app calculates to oz but nothing changes in the scale..... i'll get back to this.

Sorry if I wasn't clear enough above. I meant could you do and post a reading with the message data when the scale is only powered by the 4 AAA batteries and no USB is connected, totally separate from the g/oz issue?

Cadsters commented 1 year ago

The manufacturerdata only changes when i weigh somthing. If i hold the button to switch it off it displays SLEEP but this does not change the manufacturerdata.

DigiH commented 1 year ago

The manufacturerdata only changes when i weigh somthing. If i hold the button to switch it off it displays SLEEP but this does not change the manufacturerdata.

Yes, could you post something when you weigh an item, but only with batteries in the Skale and not connected to the USB, which I assume that was the case with your two readings above.

Cadsters commented 1 year ago

oké, display shows 93.1 {"id":"DB:C5:13:ED:92:8E","mac_type":1,"adv_type":0,"name":"Skale","manufacturerdata":"ef81a30300ff","rssi":-64}

Cadsters commented 1 year ago

and a other object weighs 123.9 (all on batteries btw) {"id":"DB:C5:13:ED:92:8E","mac_type":1,"adv_type":0,"name":"Skale","manufacturerdata":"ef81d70400ff","rssi":-69}

DigiH commented 1 year ago

93.1 {"id":"DB:C5:13:ED:92:8E","mac_type":1,"adv_type":0,"name":"Skale","manufacturerdata":"ef81a30300ff","rssi":-64}

Thanks a lot, and this was with batteries inside, but no USB conencted, correct?

How were the previous messages done above, also the same as now, only with batteries, but no USB?

Cadsters commented 1 year ago

all on batteries.

Cadsters commented 1 year ago

i will try the 123.9 object without batteries on usb.

Cadsters commented 1 year ago

123.9 object on usb without batteries: {"id":"DB:C5:13:ED:92:8E","mac_type":1,"adv_type":0,"name":"Skale","manufacturerdata":"ef81d70400ff","rssi":-56}

DigiH commented 1 year ago

Thanks, so there doesn't seem to be any battery/USB infromation in the manufacturerdata.

I'll create a test decoder for you to try out with your g setting, but for a final merge into Decoder at some stage we should find out the oz changed setting and message information, hopefully being included in the manufacturerdata then, so that the decoder will be useful for all users.

The test build takes about an hour …

Cadsters commented 1 year ago

oke, i'v asked on discourd howto set to oz, hopefully someone knows. Thanks for your time!!!

Cadsters commented 1 year ago

found this regarding usb or batteries

DigiH commented 1 year ago

found this regarding usb or batteries

Thanks, I think that was only related to the Skale I bug, as also mentioned in the API information about battery level https://de.decentespresso.com/scale_api

P.S.: Which makes me wonder, you have Skale model II as in the heading here, right? Not the previous Skale I by any chance?

Cadsters commented 1 year ago

right i have got a Skale 2

DigiH commented 1 year ago

Hi @Cadsters

the test build has finished. Please install esp32dev-ble-datatest again and post some messages, with confirmation of the correct weight.

The web install is available at

https://docs.openmqttgateway.com/dev/upload/web-install.html

or you can download the firmware directly from

https://github.com/1technophile/OpenMQTTGateway/raw/gh-pages/dev/firmware_build/esp32dev-ble-datatest-firmware.bin

Cadsters commented 1 year ago

Great! {"id":"DB:C5:13:ED:92:8E","mac_type":1,"adv_type":0,"name":"Skale","manufacturerdata":"ef81d60400ff","rssi":-44,"brand":"Atomax","model":"Skale I/II","model_id":"SKALE","type":"SCALE","cidc":false,"weight":123.8}

DigiH commented 1 year ago

Thanks for the confirmation!

Hopefully there will be some feedback about the setting to oz from Discord in the next few days

Also, when you get the chance, can you see if setting intervalacts to very high, with {"intervalacts":600000} (10 minutes)

https://docs.openmqttgateway.com/use/ble.html#setting-the-time-between-active-scanning

the manufacturerdata is still reported regularly with then regular passive scanning only.

Once these two issues are addressed we can officially merge the Skale decoder.

Thanks for your collaboration.

Cadsters commented 1 year ago

I will report back when I have the data, for now thank you very much for your help!

DigiH commented 1 year ago

@Cadsters - While the Skale app seems to be in Chinese only, this video shows how to switch between ounce 盎司, which it was set to in the beginning of the video, and gram .

Info button - then the the two segmented buttons.

Might help us finding the oz manufacturerdata :)

https://www.youtube.com/watch?v=X5-fUhk_B9I

Cadsters commented 1 year ago

Sure i can the the same only the app calculates the g to oz, not the scale the numbers on the display stay the same. I've mailed atomax to hear how its do, lets hope the respond.

Cadsters commented 1 year ago

I found some info on the FCC ID Database. The manual there says nothing about changing units from g to oz. So perhaps its only grams....?

DigiH commented 1 year ago

Yes, I had a look at that as well, but I just couldn't imagine that the scale would not allow to display in oz as well, as it would mean people preferring oz could only use the app.

Also with the link you provided above to the API there is a command to send to the scale to set to oz, as well as LED display ON/OFF, so maybe trying to WRITE that command to the scale will do the trick.

You can use the nRFConnect app to send that command (0x02) easily and quickly.

It would also be possible with the OpenMQTTGateway WRITE command, but they are a bit unclear about their service/characteristic combo in the linked documentation ;)

Otherwise the scale really only displaying in gram would be a very bad design from their side.

Cadsters commented 1 year ago

I have the nRFConnect app and can see and connect to the scale but have to study it a bit to figure out how to send the command. Or can you easely explain it to me

DigiH commented 1 year ago

If you could post a screenshot of the scale when you have connected to it in nRFConnect, so that I can see which services are available there and which allow to write, Then I will probably be able to tell you which one to go in to write the (0x)02 command.

Cadsters commented 1 year ago

nrf_connect_skale2-a nrf_connect_skale2-b

Cadsters commented 1 year ago

Found code from someone who made a clone of the Skale II, perhaps some usefull info....

DigiH commented 1 year ago

Yes, if you go into any of the above services - possibly the 180A Device Information, until you see the

0000ef80-0000-1000-8000-00805f9b34fb

this is then were you would be able to enter and WRITE the 0x02 command

P.S. Looks like it's in the FF08 Service

DigiH commented 1 year ago

Or by writing with the OpenMQTTGateway WRITE command


{
  "ble_write_address":"DB:C5:13:ED:92:8E",
  "ble_write_service":"0000ff08-0000-1000-8000-00805f9b34fb",
  "ble_write_char":"0000ef80-0000-1000-8000-00805f9b34fb",
  "ble_write_value":"02",
  "value_type":"HEX",
  "ttl":4,
  "immediate":true }
Cadsters commented 1 year ago

so have switched to oz by nrfconnect displays 3.2 {"id":"DB:C5:13:ED:92:8E","mac_type":1,"adv_type":0,"name":"Skale","manufacturerdata":"ef81a10300ff","rssi":-54,"brand":"Atomax","model":"Skale I/II","model_id":"SKALE","type":"SCALE","cidc":false,"weight":92.9} without object its 0.0 {"id":"DB:C5:13:ED:92:8E","mac_type":1,"adv_type":0,"name":"Skale","manufacturerdata":"ef81000000ff","rssi":-51,"brand":"Atomax","model":"Skale I/II","model_id":"SKALE","type":"SCALE","cidc":false,"weight":0} other object display sees 1.0 {"id":"DB:C5:13:ED:92:8E","mac_type":1,"adv_type":0,"name":"Skale","manufacturerdata":"ef81280100ff","rssi":-51,"brand":"Atomax","model":"Skale I/II","model_id":"SKALE","type":"SCALE","cidc":false,"weight":29.6}

DigiH commented 1 year ago

So the display switches to oz, but the advertisement data always reports the weight in gram.

Thanks for that confirmation! I will merge the decoder like this.

Cadsters commented 1 year ago

found something strange after a tare with object then removed object (92.9 g) the display shows -92.8 {"id":"DB:C5:13:ED:92:8E","mac_type":1,"adv_type":0,"name":"Skale","manufacturerdata":"ef8160fcffff","rssi":-56,"brand":"Atomax","model":"Skale I/II","model_id":"SKALE","type":"SCALE","cidc":false,"weight":6460.8} the weight shows 6460.8

DigiH commented 1 year ago

Good find, let me quickly fix that.

Fixed with https://github.com/theengs/decoder/pull/291

DigiH commented 1 year ago

If you go to the above mentioned development test build page tomorrow you can install any build with the nightly Decoder including the new Skale decoder.

Cadsters commented 1 year ago

I tried the dev build of esp32dev-ble-datatest (7ffdb5), webflashed It looks like the commit didn't make it. {"id":"DB:C5:13:ED:92:8E","mac_type":1,"adv_type":0,"name":"Skale","manufacturerdata":"ef81000000ff","rssi":-54} I will try again tomorrow.

DigiH commented 1 year ago

@Cadsters

Correct, sorry, I hadn't realised that the nightly OpenMQTTGateway dev builds don't currently link to the Decoder dev branch.

I created a new manual run and the builds can now be accessed on the dev page … and included in future nightly dev builds.

Cadsters commented 1 year ago

Got reaction from atomax the say: "Please use the iOS Skale app to change the oz/g unit. " so i gues it's not working throug the button on the scale. While playing a bit with nRFConnect i found a way to detect on wich unit it is set. When it is set to gram: Unknown Service 0000ef83-0000-1000-8000-00805f9b34fb Properties: READ Parsed value: (0x) 00-29-00-02-37-51-A6-10-00-01-FF-FF-FF-00-00 Raw value: (0x) 00-29-00-02-37-51-A6-10-00-01-FF-FF-FF-00-00 and when set to oz: Unknown Service 0000ef83-0000-1000-8000-00805f9b34fb Properties: READ Parsed value: (0x) 00-29-00-02-34-51-A6-10-00-00-FF-FF-FF-00-00 Raw value: (0x) 00-29-00-02-34-51-A6-10-00-00-FF-FF-FF-00-00 Using this you could calculate the value in oz and still display it. Finaly a question, does omgw connect to the device? or if not, could this be done? Because when not connected the scale auto-switches off even when it's powerd via usb. Also it would decrease the lag a bit.

DigiH commented 1 year ago

Thanks for finding this out @Cadsters.

OMG with Theengs Decoder only currently interprets and decodes the freely broadcast advertising data sent out by devices, without any connection to get any property values. If and how this might be implemented in the future is open, but your finding about the auto switch off is valuable input in this regard.

One thing you could do is use the OMG READ command through your controller to regularly read your above finding, which should then prevent the Skale from switching off whenever it is in use.

I take it the two identical lines for gram an oz above are just a copy and paste issue!?! ;)

Also you not mentioning the previously mis-decoded negative weight I assume it is verified as fixed with your latest test install?

Cadsters commented 1 year ago

I have corrected the reading of the setting of g/ozin the previous msg, and yes the negative value works now. I will try you suggestion to do a regularly read command and see if the scale stays powered. Wil report back later this week.

Cadsters commented 1 year ago

I have tried to read the weight values in a fixed interval but he scale switches of after 60 seconds after the latest weight event dispite this. However, it stays on when there is an active connection (app-mode). I also noticed that there is a delay (2-4 seconds) between the moment of weighing and the indication of the value in mqtt. This behaviour and the fact that omgw does not make an active connection makes it less usable for me but is perhaps usefull for someone else. The issue can be closed as far as I'm concerned unless you need more data or think there is room for improvement.

DigiH commented 1 year ago

Just to clarify, or maybe I wasn't clear enough above. You used the OMG READ command to read a value from the scale, possibly the battery level or weight, although that would be in the broadcast, not just making sure the broadcasts are 'read' at a fixed interval, correct?

As the OMG READ commands actually make a connection to the scale, read the value, and then disconnect again I assumed that this would prevent the scale from switching off after 60 second, if the READ would happen every 30 seconds or so. Implementing as a switch in your controller, this could then be a 'keep scale on' switch - at least that was my idea.