Problem with connecting the scale to bluetooth

This is what I was afraid of and the only materials I could find was this code:

def on_button_pressed(event):
     # Send a read weight command to the Bluetooth module
     # The read weight command is 0x03
     bluetooth.send(0x03)

     # Wait for a response from the Bluetooth module
     response = bluetooth.receive()

     # Check if the response is valid
     if response[0] != 0x00:
         # The response is not valid
         text.text = "Error"
         return

     # The weight is in the second byte of the response
     weight = response[1]

     text.text = str(weight)

but i have no idea if it is correct and how to use it

Yes, you send a byte with the value 3. Then you expect the first byte, which must be 0. If the first byte is other than 0, then there is an error. Then you redo the reading from the beginning. However, if the first byte is 0, then you wait for the next byte, which is the weight value read.

Does the scale use bluetooth 2.1 or 4.0? I.e. classic or LE?

I managed to get to such data of this weight provided by the manufacturer and here the question is whether it will help us :-)?

REGISTERS
The balance has the following registers programmed in accordance with MODBUS-RTU

Register No.: 1
Contents: Weight status
Register type: Read
Data type: bit
Number of bytes:2

Register No.: 2 and 3
Content: Max. weight load
Register type: Read
Data type: ulong
Number of bytes:4

Register 1
The register shows the status of indicators placed on the balance display and
indicates overloading, underloading, stability of readings. setting
the appropriate bit means that the indicator is on or a given balance condition occurs.
b0 - ZERO b4 - minus sign
b1 – reserved b5 – exceeded max. scale load (on the display
“nnnnnn”)
b2 – NET b6 – underload weight (display “------”)
b3 – B.TARE b7 – stable weight indication
Read-only register.

Registers 2 and 3
The registers show the maximum load on the balance. It is a four-byte type number
ulong.
Read-only registers.

What is a weighing device? Type, symbol, manufacturer?

Patryk widzę że dogadamy się w naszym języku :slight_smile: To jest waga POSNET WS-1 z dodatkowym modułem bluetooth a tu dostałem info o jej para,metrach razem z protokołami
parametry

1 Like

Zobacz ten post. Tam jest link do rozszerzenia na Github, które umożliwia komunikację Modbus przez wifi, bt lub usb. Jest tez tam skompilowana aplikacja. Musisz znać adres urządzenia.

Waga chyba nie ma wbudowanego bluetooth, wiec pewnie dokładasz jakis zewnętrzny moduł?

1 Like

Tak oni dodają moduł oddzielny moduł

1 Like

Spróbuj ten projekt. Wykorzystuje on sposób który pokazałeś w kodzie w trzecim poście. Jeśli to nie zadziała, trzeba użyć rozszerzenie.

waga.aia (4.0 KB)

Po uruchomieniu aplikacji wyświetla mi gdy wciskam READ Error 515: Not connected to a Bluettooth device

Tak, dodaj bloki łączenia się z modułem BT, ponieważ o nich zapomniałem...

waga1.aia (4.2 KB)

Niestety nie pobiera danych :frowning: Połączyło się i am status connected ale danych nie pobiera.
Siedzę nad tym problemem juz 2 godziny i żadnego pomysłu :frowning:

Więc ten kawałek kodu jest bezużyteczny. Użyj aplikacji testowej z github, do ktorej podałem wyżej link. Ona obsługuje protokół modbus poprzez BT. W razie wątpliwości, trzeba będzie poprosić o pomoc autora rozszerzenia i tej aplikacji. Bo ja za dużo na tych protokołach nie znam się.

Let me describe the problem again, because unfortunately I was not able to solve it. Not enough knowledge :frowning:

I need to make an application that will connect to the scale via BT in the simplest way and will read the weight. I received the following information from the manufacturer:
parameters:

  • COM1 transmission parameter: 115200, n81
  • COM1 protocol: MODBUS-RTU
  • COM1 power supply: 1
    The bluetooth module is plugged into COM1

Examples:

  1. Scale status reading (register 1)

Question:

01 03 00 00 00 01 84 0a
Where:
01 – scale number,
03 - function number,
00 00 - number of the first read register reduced by 1,
00 01 - number of read registers,
84 0a – CRC checksum.

Answer:

01 03 02 00 80 b9 e4

Where:
01 – scale number,
03 - function number,
02 – number of received bytes of the Data field,
00 80 – scale condition: stable,
b9 e4 – CRC checksum

Can anyone help :-)?

I suggest that you try to read with the test application Motbus.apk. If possible, first try with a serial connection and the specified communication parameters, Then you can try with BT. Note: the extension only implements BT classic, not BT LE.
When this works, then you can use the app Modbus as a guide to implement your app.
You can find the test app Modbus and the extension with documentation at: GitHub - rkl099/Appinventor-Modbus: Appinventor ModbusRTU and ModbusTCP 1.1. Extension and app to implement single 16b/32b register read and 16b write. Uppdated for Andoid12
Documentation, specification and "howto" can be found on many sites on the net.
The sequence 01 03 00 00 00 01 84 0a is a normal Modbus message that will be handled by the app/extension and the app/extension also takes care of the response and return the requested data.
Good luck
rkl099

1 Like

No one here will give you ready-made blocks, because no one here has such a device. We can point the way, but the rest of the work you have to do yourself. As I mentioned before, and now Rolf, download the test apk by Rolf from github with which you will be able to read the data. Once you manage to read the data from this scale, then we can move on with your app.

You entered 8 bytes that need to be sent. So try sending them and see if you get a reply.

01 03 00 00 00 01 84 0a

waga2.aia (4.2 KB)

Hello - Partey_F you are great!
Thank you very much :wink:
Something is starting to happen because it returns me, for example: [1,3,2,0,128,185,228,1] so it works :slight_smile:

What you receive is a list of bytes. Now it is enough to read this data into a variable, then download the byte with the index you are interested in. Which value from this list is the weight of the item?

Earlier you wrote that the response should be 7 bytes. Now you have shown 8 bytes.

It is suggested by the instruction that there are over 200 registers and how it is in the instructions is not very clearly explained to me.

Now I've found out that register1 is the state of the scale, not the weight data.

Weight data is register 7-8 as described by the manufacturer:

Readout of net weight or number of pieces (registers 7 and 8).

Question:
01 03 00 06 00 02 24 0a

Where:
01 – scale number,
03 - function number,
00 06 - number of the first read register reduced by 1,
00 02 - number of read registers,
24 0a – CRC checksum.
Answer:
01 03 04 00 00 07 d0 f9 9f

Where:
01 – scale number,
03 - function number,
04 – number of received bytes of the Data field,
00 00 07 d0 – 2000,
f9 9f – CRC checksum

In the application, I changed the query to: 01,03,00,06,00,02,36,10
and the number of returned bits is 9 and I think it's ok :slight_smile:

with a weight of 0.435 kg, it gives me 1,3,4,0,0,1,179,186,22 all the time, the value is always the same, if I change the load on the scale, it changes, i.e. the reading is correct :slight_smile: Now the fun with converting it to the correct numbers :- )

This should be enough:

waga.aia (4,8 KB)

Thanks lovely, works perfect you are great :slight_smile: