Thread Tools
This thread is privately moderated by Jack Crossfire, who may elect to delete unwanted replies.
May 13, 2017, 05:41 PM
Registered User
Jack Crossfire's Avatar
Thread OP
Discussion

BLE peripheral on a raspberry pi zero w


It would be worth releasing the lion kingdom's fully functional BLE stack for the RPZW as open source, but it would make rent go up again when a CEO sold a startup based on it. The mane idea is it starts a shell using Popen, then feeds the input characteristic to stdin while feeding stdout to the notification handle. Stderr is dumped to the console. This restricts the python to just a bluetooth layer. The shell must be started as 'bash' not 'bash -i' or it'll generate SIGINT.

The system is based on modifying bluez/test/example-advertisement & bluez/test/example-gatt-server
1st, you have to run example-advertisement once. This runs continuously as connections come & go. Then, you have to run example-gatt-server to wait for a connection. After the connection ends, it has to be restarted.

There is no callback in the bluez dbus interfact to detect when it's connected or disconnected. Instead, 99% of the time, you get a StartNotify when it's connected. StopNotify callback when it's disconnected. When that doesn't happen, you always get a StartNotify callback when it's reconnected.

When StartNotify is called twice in a row, issue os.system('killall -9 python3') to cause the python script & Popen subprocess to die. This won't kill a subprocess started by the Popen subprocess. That requires giving another process name to killall. An outer loop can restart it, where StartNotify then calls Popen. Besides this method, your BLE client can always send codes to the characteristic when it connects. There are many tricks to redirecting I/O from the subprocess.

There are still problems when starting it from /etc/rc.local instead of ssh. Having more than 1 characteristic also doesn't work.
Sign up now
to remove ads between posts


Quick Reply
Message:
Thread Tools

Similar Threads
Category Thread Thread Starter Forum Replies Last Post
Discussion Raspberry Pi Zero driving APA102 leds mtgtopdeck Night Flying 16 Jun 16, 2017 04:54 PM
Discussion Raspberry Pi robot building kit: Raspberry Pi 3B + AlphaBot + Camera GeekBuying Geekbuying.com 0 Feb 05, 2017 04:53 AM
Question Bare Raspberry pi zero as Fc? Maxzor Multirotor Drone Electronics 20 Apr 20, 2016 06:54 AM
Help! Raspberry Pi Zero RVaitor DIY Electronics 1 Apr 07, 2016 09:30 PM