Automated Install of Bluetooth Code on RPi

March 21, 2025

Current Version: 2.0 - March 10, 2025

I continue to make changes often based on early adopters comments and experiences. Check here often to see if I have posted a new version.

To check installed current version date on your Raspberry Pi, check the log file in terminal:

journalctl --unit=btwifiset.service -n 100 --no-pager

And look for the line that starts with: ******* Starting BTwifiSet - version date.

About

Bash Script to automatically install a Bluetooth Low Energy (BLE) Server written in Python your Raspberry Pi . BLE advertises a custom service that communicates with the BTBErryWifi app on your iOS/Android device to remotely set the wifi on a headless raspberry pi.

Requirements

Python3: version 3.7 or later must be installed on the Raspberry Pi or the install script will exit.

Automated Install - How To:

Notes

The bash script, which you download below, installs all the necessary dependencies for the bluetooth BLE Python code.

  • The python file (btwifiset.py) is installed in the sub-directory created at: /usr/local/btwifiset.
  • Log entries are written to syslog.
  • Creates a SystemD service file, to trigger automatic start of the python bluetooth server when the Raspberry Pi boots up.
  • The Python code is set to run for 15 minutes (timeout) after the Raspberry Pi. This 15 minutes resets every time you send a command to the RAspberry pI with the app.

It is possible to write log entries to a file that you choose instead. To do so, see the manual install instructions. You can run the automatic install first and then you can edit the service file that is created, which is located at: /etc/systemd/system/btwifiset.service. The manual instructions explain the various options switches to add to the command line.

In a similar way you can change the duration of the timeout described above.

Steps

On your Raspberry Pi: Open a terminal window (or ssh into a headless RPi) and run the following commands at the prompt:

  1. Make sure your Raspberry Pi is up to date:
sudo apt-get update
sudo apt-get full-upgrade
sudo reboot
  1. Navigate to your home directory - type:
cd ~
  1. Download and run the script - type:
curl  https://raw.githubusercontent.com/nksan/Rpi-SetWiFi-viaBluetooth/main/btwifisetInstall.sh | bash

That's it.

The code is open source under the standard MIT license.

What the Install script does:

  • Checks the python version and allows for selection if more than one Python3 interpreter is installed .
  • Creates the directory: btwifiset under /usr/local, and downloads the python file btwifiset.py there.
  • Install dbus and GLib (pyCairo) python modules only if they are not already installed.
  • selects your Country Zone required for Bluetooth Transmission (defaults to US).
  • allows you to create a password for bluetooth encryption - defaults to the RAspberry host name (you should change this).
  • Modifies the existing bluetoothd.service system file to run the bluetooth BLE service created Python.
  • Creates a new systemd service file: btwifiset.service and starts it (+ auto-start on boot).
  • Sets ReverseServiceDiscovery to false in the bluetooth configuration file at /etc/bluetooth/main.conf. This prevents some android phones from forcing pairing which is not required nor desired with BLE.

The script provides written feedback on install progress in the terminal. Upon completion, you are ready to use the BTBerryWifi app on iOS/Android devices with the Raspberry Pi. Enjoy!

The BTBerryWifi App for iOS is on the (Apple App Store), and for Android is on the Google Play Store.
You can also find it by typing: BtBerryWifi , in your store search bar.