Ich bin ein totaler Anfänger was programmieren an geht! Habe mir die script aus diversen Foren zusammen getragen, Nur jetzt weis ich nicht was mir python mit den ausgebe erzählen will!
Ich hoffe ihr könnt mir helfen wäre echt toll!
Ich habe einen Raspi 2 mit einem 4.0 bluetooth Dongel!
Ich will meine eq3 Bluetooth Heizkörper Thermostate mit einem python script auslesen!
Code: Alles auswählen
#!/usr/bin/python
# -*- coding: utf-8 -*-
import pexpect # install with: pip install pexpect
import sys
bluetooth_adr = sys.argv[1]
#bluetooth_adr = '00:1A:22:06:75:27'
gatt_handle = sys.argv[2]
gatt_value = sys.argv[3]
# start and connect gatttool
tool = pexpect.spawn('gatttool -b ' + bluetooth_adr + ' --interactive')
tool.expect('\[LE\]>')
tool.sendline('connect')
tool.expect('Connection successful')
# write to the handle
tool.sendline('char-write-req ' + gatt_handle + ' ' + gatt_value)
# get back notifications
tool.expect('Notification handle = .*')
# make some nicer output
handle = tool.after.split('\n')[0].split(': ')[0].split()[3]
values = tool.after.split('\n')[0].split(': ')[1]
print handle + ': ' + values
print ' dec:',
for value in values.split():
print str(int(value, 16)),
print ''
print '-----------------------'
# play with the values
mode = values.split()[2]
vent = int(values.split()[3], 16)
temp = int(values.split()[5], 16) / 2.0
modestr = 'Unbekannt'
if mode == '08':
modestr = 'Automatik'
if mode == '09':
modestr = 'Manuell'
if mode == '0a':
modestr = 'Urlaub'
if mode == '0c':
modestr = 'Boost'
if mode == '18':
modestr = 'Fenster auf'
if mode == '28':
modestr = 'Locked'
print ' Modus: ' + modestr
if not modestr == 'Unbekannt':
print 'Ventil: ' + str(vent) + '%'
print ' Temp.: ' + str(temp) + '°C'
# disconnect gatttool
tool.sendline('disconnect')
tool.sendline('quit')
Code: Alles auswählen
python eq.py 00:1A:22:06:75:27 0x0411 03
Code: Alles auswählen
[Traceback (most recent call last):
File "eq.py", line 16, in <module>
tool.expect('Connection successful')
File "/usr/local/lib/python2.7/dist-packages/pexpect/spawnbase.py", line 321, in expect
timeout, searchwindowsize, async)
File "/usr/local/lib/python2.7/dist-packages/pexpect/spawnbase.py", line 345, in expect_list
return exp.expect_loop(timeout)
File "/usr/local/lib/python2.7/dist-packages/pexpect/expect.py", line 107, in expect_loop
return self.timeout(e)
File "/usr/local/lib/python2.7/dist-packages/pexpect/expect.py", line 70, in timeout
raise TIMEOUT(msg)
pexpect.exceptions.TIMEOUT: Timeout exceeded.
<pexpect.pty_spawn.spawn object at 0x76a45890>
command: /usr/bin/gatttool
args: ['/usr/bin/gatttool', '-b', '00:1A:22:06:75:27', '--interactive']
buffer (last 100 chars): '0:1A:22:06:75:27\r\n\x1b[0;91mError: \x1b[0mconnect: Device or resource busy (16)\r\n[00:1A:22:06:75:27][LE]> '
before (last 100 chars): '0:1A:22:06:75:27\r\n\x1b[0;91mError: \x1b[0mconnect: Device or resource busy (16)\r\n[00:1A:22:06:75:27][LE]> '
after: <class 'pexpect.exceptions.TIMEOUT'>
match: None
match_index: None
exitstatus: None
flag_eof: False
pid: 6364
child_fd: 5
closed: False
timeout: 30
delimiter: <class 'pexpect.exceptions.EOF'>
logfile: None
logfile_read: None
logfile_send: None
maxread: 2000
ignorecase: False
searchwindowsize: None
delaybeforesend: 0.05
delayafterclose: 0.1
delayafterterminate: 0.1
searcher: searcher_re:
0: re.compile("Connection successful")
Lg Ci