0

I'm using a bluetooth adapter with a scale, in a webapp using the bluetooth web API.

I can grab a service and its characteristic, then call enableNotifications(), and set a callback for the 'characteristicvaluechanged' event. When I press "Print" on the scale the event fires and I can set the value in my app. However, when I try to use readValue(), it's an empty DataView, with a byte length of 20 all zeroes.

Anyone know how to get the value from the scale without pressing the button on the scale to fire the event?

EDIT: I'm using this bluetooth adapter from serial.io: BlueSnap Smart Bluetooth 4.0 (BLE) Adapter iOS https://buy.serialio.com/collections/adapters/products/bluesnap-smart-bluetooth-4-0-ble-to-rs232-adapter

horatio13
  • 11
  • 2
  • I can imagine that you have to send a command to the scale before you can read, or have the data in a notification. Some scales use a very simple protocol, just sending a "P", for printing or "PS" for a stable reading or "PI" for an instable reading is all. Without any information about make an model of the scale or the characteristics used, there is not much more help to expect. – GrooverFromHolland Apr 02 '19 at 19:16

1 Answers1

0

Now there is some more information from you, I can try to answer.
In the comment I gave I assumed it was a BLE-scale, but its not. It is a scale using a serial port connection with a BLE-adapter.
A lot of weighing scales use the DB-II Serial Communication Protocol.
To send a Key-command you have to send a byte array containing 7 bytes:
A prefix of 2 bytes [SOH] (01h) [STX] (02h),
the scale ID 1 byte(default = 01h), the Key-command 1 byte
and a suffix of 3 bytes[ETX] (03h) [EOT] (04h) [LEN] (Total length minus 1).
Some scales use HEX-notation, others just plain bytes. You have to try it out.
To send a Key-command like Activate PRINT Key, in Hex send: 01 02 01 01 03 04 06.
In plain bytes 1211346.

Key Commands:

ZERO: 40h
TARE: 20h
MODE: 10h
SET : 08h
SAMPLE: 04h
HOLD: 02h
PRINT: 01h

More information can be found in this pdf: https://wagicas.pl/download/software/Protocols/DB-II_Serial_Communication_Protocol.pdf

GrooverFromHolland
  • 971
  • 1
  • 11
  • 18