sandromaio
Posts: 2
Joined: Thu Oct 19, 2017 5:53 pm

Bluetooth unable to write

Thu Oct 19, 2017 6:29 pm

Hi all,

Just bought a raspberry pi3 and after playing with solenoid and lamps decided to start controlling by Bluetooth. The strange is when I scan on a mobile using nativescript I get nothing, although if I connect inserting the BLUETOOTH_ADDR manually it works fine giving me the following JSON as example (bellow).

I have also created a server in python with bluez, although when I try to write it says "Unable to write to the service 1111". I know the write option is false and I have no idea how to set it to true.

I have paired the mobile with the phone, tried the the socket .. no success :(. Any ideias how to I look into this? I see videos on youtube guys doing this straight forward and I can not event send one message.

Thanks

JSON example:
{
"UUID": "MY_RASPBERRY_PI3_BLUE_ADDR",
"name": "raspberrypi",
"state": "connected",
"services": [
{
"UUID": "1111",
"characteristics": [
{
"UUID": "1234",
"name": "1234",
"properties": {
"read": true,
"write": false,
"writeWithoutResponse": false,
"notify": false,
"indicate": false,
"broadcast": false,
"authenticatedSignedWrites": false,
"extendedProperties": false
}

Server sample
from bluetooth import *
server_socket=BluetoothSocket( RFCOMM )
server_socket.bind(("", 3 ))
server_socket.listen(1)
client_socket, address = server_socket.accept()
data = client_socket.recv(1024)
print "received [%s]" % data
client_socket.close()
server_socket.close()

User avatar
LetHopeItsSnowing
Posts: 354
Joined: Sat May 26, 2012 6:40 am
Location: UK
Contact: Website

Re: Bluetooth unable to write

Fri Oct 20, 2017 9:38 am

I recently create a bluetooth remote and in the end I gave up using python-bluetooth, I found it to be unreliable and outdated. In the end I rolled my own bluetooth comm api using sockets and bluez via dbus.

If you want to give it a go, you will find instructions it at:

http://bluedot.readthedocs.io/en/latest/btcommapi.html
"am I getting slower, or is stuff more complicated; either way I now have to write it down - stuffaboutcode.com"

User avatar
Douglas6
Posts: 4090
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Bluetooth unable to write

Fri Oct 20, 2017 7:04 pm

Based on the contents of your JSON, you're trying to do BLE. Rfcomm won't help you there, it's blind to BLE. Looks like you'll need to set up a BLE service on the Pi, maybe, it's hard to tell what you are trying to do.

sandromaio
Posts: 2
Joined: Thu Oct 19, 2017 5:53 pm

Re: Bluetooth unable to write

Sat Oct 21, 2017 11:14 am

I think I am making a major confusion between Bluetooth and Bluetooth LE. The goal is to have my phone sending commands (strings encrypted) to the RPI3 which will then do whatever it needs to do and reply if required. The data going back and forward is not that massive.

Am I taking the wrong approach? I think I might need to get a usb dongle ... all the examples that I see they use the usb dongle.

User avatar
Douglas6
Posts: 4090
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Bluetooth unable to write

Sat Oct 21, 2017 12:44 pm

The easiest way to do that, on an Android phone, is to use classic Bluetooth serial communication. There is some set-up you'll need to do on the Pi, see this post: viewtopic.php?p=947185#p947185.

Initially, on the phone, you can use one of a number of Bluetooth terminal apps.

User avatar
LetHopeItsSnowing
Posts: 354
Joined: Sat May 26, 2012 6:40 am
Location: UK
Contact: Website

Re: Bluetooth unable to write

Mon Oct 23, 2017 8:11 am

I agree with douglas6 - if you want to short cut this process, take a look at the bluedot.btcomm api - its a lot simpler to use than python-bluetooth (IMO).

Then have a look at the BlueTerm app on Android - its really easy to use serial terminal.
"am I getting slower, or is stuff more complicated; either way I now have to write it down - stuffaboutcode.com"

Return to “Beginners”

Who is online

Users browsing this forum: No registered users and 76 guests