User avatar
marciokoko
Posts: 257
Joined: Sat Aug 27, 2016 4:33 pm

Re: Reading response from BLE device on rpi3

Mon Jul 30, 2018 5:01 pm

ok so i backed up from scripting the commands to using bluetoothctl to make sure they work again.

I tried notifications in this way but i still get 00.

Is there a special way to read notifications with bluetoothctl?

Code: Select all

[BT Bee-BLE:/service0010/char0011]# notify on
[CHG] Attribute /org/bluez/hci0/dev_00_0E_0B_00_75_12/service0010/char0011 Notifying: yes
Notify started
[CHG] Device 5D:45:13:FC:7C:59 RSSI: -82
[CHG] Device 00:0E:0E:00:75:12 RSSI: -71
[BT Bee-BLE:/service0010/char0011]# write 0x5B
Attempting to write /org/bluez/hci0/dev_00_0E_0B_00_75_12/service0010/char0011
[CHG] Attribute /org/bluez/hci0/dev_00_0E_0B_00_75_12/service0010/char0011 Value:
  00                                               .               
[CHG] Device C1:7F:AA:E8:DA:5C RSSI: -78
[CHG] Device C1:7F:AA:E8:DA:5C ManufacturerData Key: 0x0157
[CHG] Device C1:7F:AA:E8:DA:5C ManufacturerData Value:
  00 d8 f7 ed 39 ad 97 4e 8a 35 ef 0b f3 5e fd ea  .???9?.N.5?.?^??
  0d 02 c1 7f aa e8 da 5c                          ..?.???\        
[CHG] Device 00:0E:0E:00:75:12 RSSI: -58
[BT Bee-BLE:/service0010/char0011]# write 0x5B
Attempting to write /org/bluez/hci0/dev_00_0E_0B_00_75_12/service0010/char0011
[CHG] Attribute /org/bluez/hci0/dev_00_0E_0B_00_75_12/service0010/char0011 Value:
  00                                               .               
[BT Bee-BLE:/service0010/char0011]# write 0x5B 0x00 0x00 0x00
Attempting to write /org/bluez/hci0/dev_00_0E_0B_00_75_12/service0010/char0011
[CHG] Attribute /org/bluez/hci0/dev_00_0E_0B_00_75_12/service0010/char0011 Value:
  00                                               .   
============

Ok I just tried other commands found here, (https://www.tinyosshop.com/datasheet/TS ... manual.pdf) and I think they work.

0x5A should return module id and software version, I get 0f and 01. Not sure if thats right, but at least it returns 2 bytes as expected.
0x5D should return the operating voltage of the relay board which is 12, well it returns 32, but again, at least its 1 byte.

I also tried 0x65 and it activated the 1st relay, but by terminal window got stuck. It might be an issue of my ssh connection to the rpi...yeah it was a Lan issue. It doesn't get stuck anymore.

So it seems to be just that particular one:

Code: Select all

[BT Bee-BLE:/service0010/char0011]# write 0x5A
Attempting to write /org/bluez/hci0/dev_00_0E_0B_00_75_12/service0010/char0011
[CHG] Attribute /org/bluez/hci0/dev_00_0E_0B_00_75_12/service0010/char0011 Value:
  0f 01                                            ..              
[BT Bee-BLE:/service0010/char0011]# write 0x5D
Attempting to write /org/bluez/hci0/dev_00_0E_0B_00_75_12/service0010/char0011
[CHG] Attribute /org/bluez/hci0/dev_00_0E_0B_00_75_12/service0010/char0011 Value:
  32                            
Ok Im getting the notification I think as seen here, but it still contains 00. It might be my interpretation of it then because if I get attribute-info the value for it is 00 as well:

Code: Select all

[BT Bee-BLE]# select-attribute /org/bluez/hci0/dev_00_0E_0B_00_75_12/service0010
[BT Bee-BLE:/service0010]# select-attribute /org/bluez/hci0/dev_00_0E_0B_00_75_12/service0010/char0011
[BT Bee-BLE:/service0010/char0011]# write 0x6F
Attempting to write /org/bluez/hci0/dev_00_0E_0B_00_75_12/service0010/char0011
[BT Bee-BLE:/service0010/char0011]# write 0x5B
Attempting to write /org/bluez/hci0/dev_00_0E_0B_00_75_12/service0010/char0011
[BT Bee-BLE:/service0010/char0011]# write 0x5B
Attempting to write /org/bluez/hci0/dev_00_0E_0B_00_75_12/service0010/char0011
[BT Bee-BLE:/service0010/char0011]# acquire-notify
[CHG] Attribute /org/bluez/hci0/dev_00_0E_0B_00_75_12/service0010/char0011 NotifyAcquired: yes
AcquireNotify success: fd 7 MTU 23
[BT Bee-BLE:/service0010/char0011]# write 0x5B
Attempting to write /org/bluez/hci0/dev_00_0E_0B_00_75_12/service0010/char0011
[CHG] /org/bluez/hci0/dev_00_0E_0B_00_75_12/service0010/char0011 Notification:
  00                                               .               
[BT Bee-BLE:/service0010/char0011]# attribute-info /org/bluez/hci0/dev_00_0E_0B_00_75_12/service0010/char0011
Characteristic - Unknown
	UUID: 0000ffe1-0000-1000-8000-00805f9b34fb
	Service: /org/bluez/hci0/dev_00_0E_0B_00_75_12/service0010
	Value:
  00                                               .               
	Notifying: no
	Flags: read
	Flags: write-without-response
	Flags: notify
[BT Bee-BLE:/service0010/char0011]# 
So where did I get that idea that I should get a list or array as a response? Well:

1. Because it seems logical to have a 4 channel relay bt device to respond with such data in order to know the state of the relays.

2. Because when I used to have an rpi2 with an hm10 module hardwired to gpio pins for tx and rx and connected to the tsrb board using this code I would get this as a result:
{1: 0, 2: 0, 3: 0, 4: 0}
Using this code :

Code: Select all

#!/usr/bin/env python

import serial

def convert_hex_to_int(hexChars):
    #convert string of hex chars to a list of ints
    try:
        ints = [ord(char) for char in hexChars]
        return ints
    except TypeError:
        pass
    return []
def convert_hex_to_bin_str(hexChars):
    #convert hex char into byte string
    response = convert_hex_to_int(hexChars)[0]
    # convert int to binary string
    responseBinary = bin(response)
    # first 2 chars of binary string are '0b' so ignore these
    return responseBinary[2:]

ser = serial.Serial(
	port='/dev/serial0',
	baudrate=9600,
	parity=serial.PARITY_NONE,
	stopbits=serial.STOPBITS_ONE,
	bytesize=serial.EIGHTBITS,
	timeout=1
)

print "Serial is open: " + str(ser.isOpen())

print "Now Writing"
ser.write("[")
#ser.write("AT+CONNL")
print "Did write, now read"
x = ser.readline()
print "got '" + x + "'"

responseBits = convert_hex_to_bin_str (x)
# binary conversion drops values until a 1 is encountered
# assume missing values are 0 and pad to give a value for all relays
responseBits = responseBits.zfill(4)
# reverse chars so that relay 1 is first
responseBits = list(responseBits)
responseBits.reverse()
# create dictionary of relay states
relayStates = {}
relay = 1
for bit in responseBits:
    relayStates[relay] = int(bit)
    relay += 1
print relayStates

ser.close()

User avatar
marciokoko
Posts: 257
Joined: Sat Aug 27, 2016 4:33 pm

Re: Reading response from BLE device on rpi3

Mon Aug 13, 2018 2:21 am

Hello? Help please

Return to “Beginners”

Who is online

Users browsing this forum: HawaiianPi, jackandjill, jim_mcnally and 30 guests