William Beale
William Beale

Reputation: 1

Creating a python Flask server over Bluetooth tethering on Raspberry Pi Zero W

I am trying to use my Raspberry Pi Zero W as a Bluetooth tethering device to be able to connect my phone (or any other device) over Bluetooth to create a "WiFi Connection" on which I will be able to serve my own python Flask server on a page (such as 192.168.0.1 or my.app / similar), it appears to me that the Pi-Tail achieves this though I am unsure as to how, I have tried AI however I have issues with getting the Pi to connect to my phone, I have had a look at many projects, however these all appear to be using odd Android apps or just be completely un-related whereas I was hoping that this would just be possible to do on a regular web browser.

TLDR: Is it possible to use a RPI 0W as a bluetooth tethering hotspot for my phone to serve a python Flask server, if so how?

Many thanks in advance for any suggestions you may have.

Following these steps:


a. Install the required packages:

sudo apt update
sudo apt install bluez python3-dbus
b. Enable the Bluetooth service:

sudo systemctl enable bluetooth
sudo systemctl start bluetooth
c. Create a new file /etc/systemd/system/bt-agent.service to automatically pair with devices:

sudo nano /etc/systemd/system/bt-agent.service
Add the following content to the file:

\[Unit\]
Description=Bluetooth Agent

\[Service\]
ExecStart=/usr/bin/bt-agent -c NoInputNoOutput

\[Install\]
WantedBy=multi-user.target
d. Enable and start the new service:

sudo systemctl enable bt-agent
sudo systemctl start bt-agent
e. Create a new file /etc/systemd/system/bt-network.service to set up the Bluetooth network:

sudo nano /etc/systemd/system/bt-network.service
Add the following content to the file:

\[Unit\]
Description=Bluetooth Network
After=network.target bluetooth.service

\[Service\]
ExecStart=/usr/bin/bt-network -s nap -a 0000

\[Install\]
WantedBy=multi-user.target
f. Enable and start the new service:

sudo systemctl enable bt-network
sudo systemctl start bt-network
Configure the network interface:

a. Create a new file /etc/network/interfaces.d/bt-netdev to configure the Bluetooth network interface:

sudo nano /etc/network/interfaces.d/bt-netdev
Add the following content to the file:

iface bnep0 inet dhcp
pre-up /usr/sbin/brcm_patchram_plus --enable_hciattrib --enable_btsnoop --patchram /lib/firmware/brcm/BCM43430A1.hcd --baudrate 3000000 --no2bytes --enable_lpm --enable_hciattrib
b. Restart the networking service:

sudo systemctl restart networking
Create a simple web server using Python:

a. Install Flask, a lightweight web framework for Python:

sudo apt install python3-flask
b. Create a new Python script (e.g., app.py) with the following content:

from flask import Flask
app = Flask(__name__)

@app.route('/')
def home():
return "Hello, World!"

if __name__ == '__main__':
app.run(host='0.0.0.0', port=80)
c. Run the script:

sudo python3 app.py
Now, other devices should be able to connect to the Raspberry Pi Zero W via Bluetooth tethering and access the website hosted on it by visiting the Pi's IP address in a web browser. The wlan0 interface will still be available for other purposes.

To find the IP address of the Bluetooth network interface (bnep0), you can use the following command:

ip addr show bnep0
Look for the inet address in the output.

However, there are errors within the bluetooth service with the SAP plugin and now aslso with the vcp, mcp and bap plugin, though these appear to be simply due to the lack of experimental mode being enabled which I can fix though the AI generated code calls for a file at /usr/bin/bt-network which does not exist and so I presume it best to disregard this code and start fresh

I have found this similar post about creating a tethering hotspot but they do not appear to be creating a flask server from what I can find?

Upvotes: 0

Views: 79

Answers (0)

Related Questions