How to start a pbap session with CreateSession - python

I'm developping a smartphone bluetooth simulator for my company, in python 2.7 with bluez 5.48 on Ubuntu 18.04, and 5.37 on Ubuntu 16.04. Everything is up-to-date, and I already corvered all the adapter/device/agent-api from the bluez doc, through dbus. It works well without any problem (settings, pairing, connection...).
Now I'm trying to add a PBAP service (PBAP PSE) to share the phonebook, that sync with a car system (PBAP PCE), with the obex-api.
As far as I understand, I first call:
CreateSession()
with Target = pbap, but it returns:
"Unable to find service record"
And that's the blocking point, I have no idea why, nor what a service record means.
I tried to start profile with sdptool, but it doesn't seem to change anything.
The tests in bluez repo give me the same error.
I tried a lot of different config, profile, bluetooth adapters etc... no success.
Thanks for your help!
bluez doc : https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc

Related

Python as Windows Service Using speedtest-cli returns Error 1053

I have successfully created a py script that monitors network bandwidth and records it in a database. When I run it in debug everything works perfectly. However, when I start the service it errors with a 1053. If I comment out the import speedtest the windows service starts just fine. I know the issue is directly related to the module.
I searched the web to it's furthest reaches trying to figure this one out. I have increased my windows service timeout and made sure that my cx_freeze includes the speedtest module, among other small adjustments for testing purposes. All of which still result in the same error on windows service start.
Any help is much appreciated.

Remote bluetooth camera trigger for phone

I would like to build a camera trigger for my phone by simulating a BLE keyboard that sends the Volume Up key to the phone connected by Bluetooth. I want this because I want to trigger the native Camera app, and not an embedded camera view.
I'm agnostic about technology used but ideally for simplicity I'd like it to be a command line utility in my Macbook, with something like Go or Node.js.
I've looked into Noble for Node.js, which doesn't seem to be oriented at emitting, and found projects for arduino, and found a couple of StackOverflow questions asking the same, but nothing definitive yet.
Apparently the Bleno project for Node.js could be better suited, but apparently it's very outdated.
Would someone please point me in the right direction?
Thank you
Edit
I was able to use Bleno to emit 0xEA and 0xE9 (Volume Up and Volume Down apparently), and using the LightBlue app I'm able to inspect that receive those messages, however, connecting to the MacBook through the phone's bluetooth does not increase/decrease volume.
Edit
Found this outdated project written in Swift 3 for reference
Edit Apparently the pybluez project looks like it could be a good option
You should be able to use the terminal for that. Eg. in Windows, you can start the camera app using start microsoft.windows:camera
Something similar should be available even in Mac. Try that out. Otherwise, go to the root directory where the camera app is stored. And then trigger that from code.
You need to create a Bluetooth HID (or HID over GATT) peripheral that your phone can connect to and will receive the key commands from.
There is a project here that did it with a Raspberry Pi:
https://gist.github.com/ukBaz/a47e71e7b87fbc851b27cde7d1c0fcf0#gistcomment-2997623
Unfornately the underlaying Bluetooth library will not move across to your Mac Book.
The HID protocol is documented here: https://github.com/jpbrucker/BLE_HID/blob/master/doc/HID.md
In summary, I think what your saying is that you want to make an cli application which is on your laptop/desktop connect to your phone via Bluetooth and simulate a volume key from your laptop/desktop keyboard.
Android:
To do this you will need:
Python 3.5 or above
PyBluez
Keyboard(Python module/API)
Android Studio
Java Development Kit 8 (preferably 11 or 14)
Android BLE
So in order to do this I would create a cli application with python3 and I would record the key presses on the laptop/desktop machine by using the keyboard module this then gets transmitted(bluetooth) via the PyBluez module to your phone. Your phone then accepts the bluetooth data via Android BLE and then simulates the volume button press.
DISCLAIMER:
This only works when the phone is already paired to your pc and only work on android phones 4.4.4 and above.
Some Links That Could Help You:
Bluetooth lib for python 3 ,
detect key press in python? ,
Create a socket for 4.0 bluetooth transmission
IOS:
To do this you will need:
Python 3.5 or above
PyBluez
Keyboard(Python module/API)
XCode
Swift
Core Bluetooth Module
So in order to do this I would create a cli application with python3 and I would record the key presses on the laptop/desktop machine by using the keyboard module this then gets transmitted(bluetooth) via the PyBluez module to your phone. Your phone then accepts the bluetooth data via Core Blutooth Module in swift and then simulates the volume button press.
DISCLAIMER:
The phone and laptop/desktop must be paired before it runs this might sound obvious but some people might ignore this.
Some Links That Could Help You:
iOS use the volume buttons as input ,
https://developer.apple.com/documentation/corebluetooth/transferring_data_between_bluetooth_low_energy_devices

Django: ERR_CONNECTION_REFUSED

I'm actually learning to use the Django framework with PostgreSQL with Docker and docker-compose.
Regularly, when I make a mistake (for example a syntax error in the views.py file), I cannot reach my Django app anymore trough my web browser.
Firefox tells me:
Unable to connect
Firefox can't establish a connection to the server at localhost:8000
Chrome tells me:
This site can’t be reached
localhost refused to connect.
ERR_CONNECTION_REFUSED
I had this several times and I always managed to find the error in my code, to correct it and then everything went well again.
Currently, my code is working fine. But if I encounter this again (and this happens very often), I would like to be able to find the error quickly by myself.
So here is my question:
How can I see which file at which line contains the error ?
I would like to have a correct error message telling me what went wrong instead of that annoying ERR_CONNECTION_REFUSED browser page over and over.
I hope I explained my issue well because I struggled to describe it to Google.
Thanks a lot in advance. :)
FYI:
Ubuntu 18.04.3 LTS Bionic (window manager i3wm)
Docker 19.03.4
docker-compose 1.17.1
python 3.7 (docker image)
Django 2.2.6 (inside the python 3.7 image)
PostgreSQL 12.0 (docker image)
Visual Studio Code 1.39.2
I finally found a solution.
I had the bad habit to run my docker-compose in detached mode.
When attached, the syntax errors are shown directly from the terminal when de container is stopped.
I also added a script where I run my server in a loop. This way, the server will relaunch automatically over and over until I correct the error. I don't have to restart my Django server manually.
Thank you for helping me anyway.

BlueZ-4.101 on embedded ARM device

I'm implementing Bluetooth on an embedded device and have a few questions about the BlueZ protocol stack. I'm using BlueZ-4.101 (do not have the option to upgrade to BlueZ-5), and do not have Python available.
Here are my questions after spending some time looking into BlueZ:
Is bluetoothd needed in my situation? As in, is it just a daemon that handles Python dbus messages between user-space and the kernel, or is it more? I've looked through the source and can only find mostly dbus related calls
How does one determine the value of DeviceID in /etc/bluetooth/main.conf? I found these instructions (section 3.4), but they are for a different platform using BlueZ 5
Will sdptool work without setting the DeviceID value? I've tried the following command and receive timeouts every time (only for my local device):
# sdptool browse local
Browsing FF:FF:FF:00:00:00 ...
Service Search failed: Connection timed out
Is it viable to replace all of the python simple-agent scripts with libbluetooth instead, or do I need to try and port them over to a supported scripting language?
Any help would be greatly appreciated!!!
If more logs are needed I can try and get them.

Macbook Pro 2015 connecting to a TI Sensortag cc2541

Background - What I would like to do is to be able to push buttons on a BT sensor and trigger some actions like tweet or play a particular sound etc. I have a TI CC2541 Sensortag that I would like to control with a python program.
Issue - I am unable to get Mac OS X bluetooth to recognize the BLE on TI Sensortag.
Attempts - I installed lightblue which recognizes the sensor. But I am not sure how that can help control the sensor programmatically.
I heard about Bluez in my research, but I guess it is related to linux only systems. I have used Evothings and that can connect to the sensortag through my phone on the same network. I can make small changes to the javascript on evothings studio to capture events from the Sensortag and affect changes on the evothings app.
I am trying to get my Mac to recognize the BLE Sensortag after which I can control the device programmatically. Do I need to buy one of these pluggable BLE dongles to get this to work? OR am I attempting something wrong.
Please advise.
Oh I see now, I can help you with that.
Here's your recipe to success:
Make sure that your hardware supports BLE 4.x (yours does)
Link your tag through the preferences/Bluetooth widget
Check with lightblue app that you can connect or read some values
If all the above checks out, and it should given the information you provided, then at hardware level you're golden.
At software level, there are many ways to connect and retrieve data. You can use XCODE and build a native OSX app or you can build a NodeJS app to retrieve data from the tag.
On this blog post you find all you need for the Node scenario. It is documented for the Raspberry Pi however, the code for running this elsewhere, including OSX, is exactly the same
The code is hosted here and I keep it up to date as I make more advancements.
https://github.com/kywix/iamsblog/tree/master/SensorTag
Shortly:
Open terminal and git clone that repo
cd into the folder SensorTag
type npm install (to install all the libraries necessary)
node logger.js to run the basic example
turn on your device
btw on the same repo you will find python code as well. I blog regularly about the Sensor Tag.
I will make note of creating a post just for folks like you that seek this type of info, I have been there..

Categories

Resources