philipptrenz / bosch-glm-rangefinder Goto Github PK
View Code? Open in Web Editor NEWPython script to remote control a BOSCH GLM 100C rangefinder via its Bluetooth serial interface
License: MIT License
Python script to remote control a BOSCH GLM 100C rangefinder via its Bluetooth serial interface
License: MIT License
Hello all,
I managed to read the distance value with your code.
Thank you very much for that.
The GLM 50 C can also measure angle/inclination.
I found the command to start the measuring of the angle, but
unfortunately I didn't find the correct command to read the value from the device.
Finding the command was a little bit tricky,
but I add a function to your code that automatically tries all possible commands.
(Sorry for the bad code, but these are my first tests with python)
It would be tool, if you could check, if there is a command to read the angle.
Thanks in advance
Some of the commands I found:
#[192, 64, 0, 238], #measure length
#[192, 65, 0, 150], #laser on
#[192, 66, 0, 205], #laser off
#[192, 69, 0, 208], #horn on
#[192, 70, 0, 139], #horn off
#[192, 71, 0, 243], #backlight on
#[192, 72, 0, 177], #backlight off
#[192, 84, 0, 22], #level in mainframe off
#[192, 85, 0, ???],#lock angle on device (first time locked, second call releases the measuring)
#[194, 64, 0, ???],#measure length but with longer received data b'\x00\x044<\x96\x08\x00\x00'
def findCmd2(self):
with open ('cmds' + str(time.time()), 'w') as f:
f.write('start finding command structure\n\n')
#list
addrList = range(192,256) #startbyte: everything greater greater or equal 192 [C0] works
cmdList = range(0,256) #command
cmdData = range(0,1)#range(0,2) #data: found no use so far
#build command
for g in addrList:
for i in cmdList:
for c in cmdData:
checkSumArr = [g, i, 0] #create command used for checksum
checkSumBytes = bytes(checkSumArr) #convert decimal command
k = crc8(checkSumBytes) #calculate checksum
cmdArr = [g,i,c,k] #create full command for device
cmd = bytes(cmdArr) #convert decimal command
#exclude bad commands
#command cause strange beahviour or decive reboot
if ((cmdArr == [192, 53, 0, 166]) or
(cmdArr == [192, 55, 0, 86]) or
(cmdArr == [192, 56, 0, 20]) or
(cmdArr == [192, 54, 0, 46]) or
(cmdArr == [192, 58, 0, 228]) or
(cmdArr == [192, 59, 0, 156]) or
(cmdArr == [192, 60, 0, 82]) or
(cmdArr == [192, 61, 0, 42]) or
(cmdArr == [192, 55, 1, 86]) or
(cmdArr == [192, 55, 1, 240]) or
(cmdArr == [192, 56, 1, 20]) or
(cmdArr == [192, 56, 1, 178]) or
(cmdArr == [192, 53, 1, 0]) or
(cmdArr == [192, 54, 1, 46]) or
(cmdArr == [192, 55, 1, 240]) or
(cmdArr == [192, 54, 1, 136]) or
(cmdArr == [192, 58, 1, 228]) or
(cmdArr == [192, 59, 1, 156]) or
(cmdArr == [192, 60, 1, 82]) or
(cmdArr == [192, 61, 1, 42]) or
(cmdArr == [192, 57, 1, 108]) or
(cmdArr == [192, 57, 1, 202]) or
(cmdArr == [192, 58, 1, 66]) or
(cmdArr == [192, 59, 1, 58]) or
(cmdArr == [192, 60, 1, 244]) or
(cmdArr == [192, 61, 1, 140]) or
(cmdArr == [192, 62, 0, 162]) or
(cmdArr == [192, 62, 1, 4]) or
(cmdArr == [192, 63, 0, 218]) or
(cmdArr == [193, 54, 0, 102]) or
(cmdArr == [192, 57, 0, 108]) or
((i > 50) and (i<60))):
continue
print("cmd:\t ", end='')
print(cmdArr, end='')
f.write("cmd:\t ")
f.write(str(cmdArr))
self.socket.send(cmd)
sleep(0.01) #seems not necessary
data = self.socket.recv(1024)
sleep(0.5) #seems not necessary
if ((self.status[data[0]] is 'ok') or (self.status[data[0]] is 'invalid access level')):
#print('')
print("\tdata:\t", end='')
print(data)
f.write("\tdata:\t")
f.write(str(data))
f.write('\n')
#print(data, end='')
#print("cmd status: ", end='')
#print(self.status[data[0]])
continue
else:
print('')
if (self.status[data[0]] != 'communication timeout'):
print('--> unknown return:\t', end='')
print(data)
f.write('\n')
if self.status[data[0]] is 'unknown command':
print('uC', end='')
if self.status[data[0]] is 'unknown return value2':
print('uC', end='')
if self.status[data[0]] is 'invalid access level':
print('--> invalid access level')
if self.status[data[0]] is 'hardware error':
print('--> hardware error')
if self.status[data[0]] is 'device not ready':
print('--> device not ready')
if self.status[data[0]] is 'communication timeout':
print('--> communication timeout')
def crc8(data, iv=0xaa, poly=0xa6):
value = iv
for b in data:
for i in range(8):
x, value = (value >> 7) ^ (b >> (7-i)) & 1, (value << 1) & 0xff
if x:
value ^= poly
return value
Hi,
I used the glm50c,py for test, just slightly modified the original
changing from GLM100 to GLM50
and using only GLM50 for search string
adding prints to check
the result is:
/usr/bin/python3.5 /home/zoltan/PycharmProjects/MC50Boschlaser/glm50c.py
Searching for BOSCH GLM50C ...
Found BOSCH GLM50C @ 00:13:43:59:FC:1B
address:
00:13:43:59:FC:1B
Connecting to BOSCH GLM50C failed connect(self)
Could not connect to BOSCH GLM50C
Process finished with exit code 0
the address is the same if I connect manually, as can be seen on the picture.
what can be the solution?
best regards
Zoltan
I patched the file that it can also find the GLM50C.
>>> rangefinder = GLM100C()
Searching for BOSCH GLM100C ...
BOSCH GLM50C X9225
Found BOSCH GLM100C @ 00:13:43:71:78:EF
but then a new error appeared on my Raspberry Pi Zero W with raspbian:
>>> rangefinder.measure_from_back()
Traceback (most recent call last):
File "<string>", line 3, in send
_bluetooth.error: (9, 'Bad file descriptor')
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/chg/git/BOSCH-GLM-rangefinder/glm100c.py", line 103, in measure_from_back
m = self.measure()
File "/home/chg/git/BOSCH-GLM-rangefinder/glm100c.py", line 78, in measure
self.socket.send(self.cmds['measure'])
File "<string>", line 5, in send
bluetooth.btcommon.BluetoothError: (9, 'Bad file descriptor')
Running with sudo did not improve the situation so this is not a permission issue ;(
Any Ideas what's wrong?
sudo pip3 install pybluez on Ubuntu 20.04 results in
ERROR: bosch-glm-rangefinder 0.0 has requirement PyBluez==0.22, but you'll have pybluez 0.23 which is incompatible.
Is pybluez 0.23 really incompatible?
good afternoon,
I'm using MAC OS.
I can find the GLM50C but I cannot connect.
I even tried a fork that you had indicated in an issue that is closed and doesn't work.
can you help?
Searching for BOSCH GLM50C
Found BOSCH GLM50C @ b'00:13:43:85:21:53'
Trying to connect with GLM50C
Can't connect with GLM50C
Could not connect to GLM50C
fatal error: bluetooth/bluetooth.h: No such file or directory
solved by
sudo apt-get install libbluetooth-dev
Hi all,
does someone knows how to parse the measure result from hex to decimal:
e.g. I got following data:
1,816 m => 00041386000036
edit: I found a other thread where it is described:
receive frame: [status][length][...][checksum]
00 status
04 length
0x00008613 little endian result => hex to dec => 34323 *0,05 => 1716 + 100mm device length => 1,816m
I too tried with glm50c. Scripts says could not connect to glm50c but the scripts is able to find the device plz find any solution to it
Best Regards
Pratham Bumb
Hi there,
I'm wondering what the listen command is supposed to do as I'm currently getting some strange results..
Also if you have any leads on where to find other commands from the protocol it would be of great help!
Thanks :)
After pressing the Bluetooh key on the Bosch PLR 30 C, the bluetooth item appears in the Bosch PLR 30 C's screen, and Ubuntu does discover the Bosch PLR 30 C. In Ubuntu, when I click on Connect, Ubuntu says:
After Confirming that ... still Disconnected.
Tip how to get the Bluetooth connection working?
Hi,
Thanks for the great code!
It is working with PLR50C with some trivial changes see AlbrechtL@faa9bc7.
BTW: It looks like that Peter Iannucci reversed engineered a lot of more functions https://github.com/piannucci/pymtprotocol. Do you plan to use some of the code?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.