mg360
Posts: 2
Joined: Tue Nov 01, 2016 11:11 pm

Setup WiFi access via Bluetooth

Tue Nov 01, 2016 11:50 pm

Hi All,
I want to be able to establish a Bluetooth connection to a headless Raspberry Pi via an app on an iOS or Android device. The scenario is an RPi deployed into the field where it will do a job but it requires internet, and the person deploying it needs a bullet proof super simple way to get the credentials in.

Hence idea is an app the access point name and password is entered. With this the app constructs the wifi configuration files and then transfers them via Bluetooth to the RPi.

My skill with RPi are only moderate and this seem fairly hard so I would like some advice on feasibility.

My questions are:
1. Would it be possible to set the RPi up to look for and accept any Bluetooth connection without confirmation. Ie having to say yes or any other confirmation on the PI would not work.
2. Once a bluetooth connection was made would it be possible transfer a file to the correct location to support wifi access.

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

Re: Setup WiFi access via Bluetooth

Wed Nov 02, 2016 12:44 am

For any Bluetooth connection, you need to first be paired. You can set up a pairing agent on the Pi in 'just works' mode that will accept any pairing request. Then you can set up a terminal over Bluetooth and do what you need via ssh.

mg360
Posts: 2
Joined: Tue Nov 01, 2016 11:11 pm

Re: Setup WiFi access via Bluetooth

Wed Nov 02, 2016 4:34 am

Thanks for the hint on the "Just Works" mode. I will google that and figure out how it works.

Can you think of any reason, like permissions for example, that would prevent the overwriting /etc/wpa_supplicant/wpa_supplicant.conf file with a version that an app generates.

To clarify the change to the file would be:
network={
ssid="From user input in the app"
psk="From user input in the app"
}

Hence the process is:
1. Raspberry pi powers on and goes into "search or connect mode - forgive me on not knowing the correct name for this mode"
2. Bluetooth enabled iOS/Android device comes along and connects to RPi
3. An app on the device asks user for WiFi name and WiFi password
4. The app then generates the wpa_supplicant.conf
5. App writes the new wpa_supplicant.conf to the /etc/wpa_supplicant/ via Bluetooth

Pi - reboot and viola on the internet!!

Can you see any reason why this would not work?

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

Re: Setup WiFi access via Bluetooth

Wed Nov 02, 2016 4:22 pm

For the pairing agent, you can use the BlueZ test-agent code (get it on Github or 'sudo apt-get install bluez-test-scripts').
For the Bluetooth terminal, see this post: viewtopic.php?p=955425#p955425

hans23
Posts: 2
Joined: Fri Nov 18, 2016 10:55 am

Re: Setup WiFi access via Bluetooth

Fri Nov 18, 2016 11:02 am

Did you make any progress regarding this? It seems to be a useful thing to have a generic Bluetooth based WiFi setup app for the Pi, and I imagine that collaborating on the app end in particular would be advantageous.

I am currently thinking about a similar project with a headless Pi that needs internet connectivity and that should be easy to set up. Fiddling with the SD card is an option, but a purely software based solution would be much better.

Thanks,
-Hans

Stan92
Posts: 8
Joined: Wed Nov 02, 2016 8:45 am

Re: Setup WiFi access via Bluetooth

Sun Dec 25, 2016 12:44 am

Hi
I would be also intested
Currently I use an access point via an additional wifi dongle but this has an extra cost

nemiah
Posts: 1
Joined: Mon Feb 20, 2017 3:35 pm

Re: Setup WiFi access via Bluetooth

Mon Feb 20, 2017 3:44 pm

This also seems like a generic feature that would benefit a lot of people (and myself!). I thought there would have already been a solution out there. I'm also working on a headless "box" that needs to be deployed by end users on their own wifi.

I'd be happy to give this ago, I'm more software/firmware orientated and not an expert on the Pi or Linux but it seems achievable.

Who would like to collaborate?

wga22
Posts: 8
Joined: Tue Mar 07, 2017 2:33 am

Re: Setup WiFi access via Bluetooth

Wed Mar 15, 2017 2:29 am

nemiah wrote:This also seems like a generic feature that would benefit a lot of people (and myself!). I thought there would have already been a solution out there. I'm also working on a headless "box" that needs to be deployed by end users on their own wifi.

I'd be happy to give this ago, I'm more software/firmware orientated and not an expert on the Pi or Linux but it seems achievable.

Who would like to collaborate?
I would

Stan92
Posts: 8
Joined: Wed Nov 02, 2016 8:45 am

Re: Setup WiFi access via Bluetooth

Wed Mar 15, 2017 5:55 am

Hi
I suggest you to have a look at bleno.js if you use nodejs on the PI.
I started investigating with a Swift 3.0 app and it seems it could work
I also used network manager for getting the wifi list and managing the connection

Stan

ajdjd
Posts: 3
Joined: Wed Mar 15, 2017 3:44 pm

Re: Setup WiFi access via Bluetooth

Wed Mar 15, 2017 4:01 pm

Yes, I am looking for exactly this. Right now I have wpa_supplicant set up in roaming mode, and one of the networks I set up establishes a connection through my phone's password-protected hotspot. Then I can ssh in and edit /etc/wpa_supplicant/wpa_supplicant.conf. But I'd rather use bluetooth so that I don't have to switch into hotspot mode. In what seems like order of increasing difficulty I'd like to:

1) establish a bluetooth network connection with the pi; ssh in and edit the config files
2) use an app to just send a message over bluetooth with the SSID and PSK, a script will run on the pi to edit the config
3) same as 2 but use a cryptographically signed message
4) same as 2 or 3 but automatically get the SSID and PSK from the android configuration

(I'm not sure if 4 is possible without a rooted phone. All except 1 might be beyond what I'm willing to do as I've only played around a little bit with writing android apps.)

Stan92
Posts: 8
Joined: Wed Nov 02, 2016 8:45 am

Re: Setup WiFi access via Bluetooth

Wed Mar 15, 2017 7:47 pm

In fact, you can do whatever you want for my understandings.
Once your PI is connected to your mobile, you can "invoke" characteristics.
You don't need any ssh connection.

Your PI becomes a Peripheral and advertises Services.
Each service has characteristics and for each characteristic you can read, write values, subscribe, etc...
For a characteristic that has a "read" function, you can return data to your mobile (like a list of SSID, current connected SSID, etc...)
For a characteristic that has a "write" function, you can update your wpa_supplicant.conf file, reboot, shutdown your PI, etc....

Frankly, I suggest you to have a look at this node.js library
https://github.com/sandeepmistry/bleno
It gave me an very good overview about Bluetooth management

ajdjd
Posts: 3
Joined: Wed Mar 15, 2017 3:44 pm

Re: Setup WiFi access via Bluetooth

Thu Mar 16, 2017 12:41 am

Thanks Stan. I wish I had read that reply before I went down the path I did. I did manage to get something adequate working, but I probably wasted some time.

First, I followed the instructions at viewtopic.php?p=955425#p955425 . This involved editing /etc/systemd/system/dbus-org.bluez.service and setting up rfcomm.service to add ExecStart=/usr/bin/rfcomm watch hci0 1 getty rfcomm0 115200 vt100 -a phone

To pair the phone to the pi, I ran bluetoothctl and the command "discoverable on" within bluetoothctl (also in the same instructions).

I added a user named phone, put that user in the group netdev, and set the shell to /home/phone/phone.sh which looks like this:

Code: Select all

#!/bin/bash

echo "SSID:"
read ssid
echo "PSK:"
read psk
NUM=`wpa_cli add_network | tail -n 1`
echo $NUM
wpa_cli set_network $NUM ssid '"'$ssid'"'
echo $ssid
wpa_cli set_network $NUM psk '"'$psk'"'
echo $psk
wpa_cli set_network $NUM priority 5
wpa_cli enable_network $NUM
wpa_cli save_config
Currently I'm running the android app "Bluetooth Terminal" to enter the SSID and PSK. Next on the todo list is to make a simple android app of my own instead of using Bluetooth Terminal. Then I can look at moving to using proper bluetooth services, I guess. Also at some point I guess I'll have to implement editing the PSK. I'll try to keep the bluetooth stuff as simple as possible, though. Just whatever I need to connect the pi to the Internet through the wifi network. Once I've got Internet I can do management through more normal means over the Internet.

Is all of this sent unencrypted through the air, or does bluetooth have some sort of encryption built into the pairing mechanism?

Edit: Oh yeah, I should probably also remove the security problems with not parsing the user input.

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

Re: Setup WiFi access via Bluetooth

Thu Mar 16, 2017 1:01 am

I'm interested in knowing why you think you 'went down the wrong path'? Either you want a Bluetooth getty connection, or you don't. It's up to you. A simple Bluetooth serial connection is a different use case.

Encrypted or not is determined by the one making the connection. The Pi is capable of both.

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

Re: Setup WiFi access via Bluetooth

Thu Mar 16, 2017 1:33 am

Douglas6 wrote:I'm interested in knowing why you think you 'went down the wrong path'? Either you want a Bluetooth getty connection, or you don't. It's up to you. A simple Bluetooth serial connection is a different use case.

Encrypted or not is determined by the one making the connection. The Pi is capable of both.
Using BLE is another option. It does not address security or ease of use, necessarily.

ajdjd
Posts: 3
Joined: Wed Mar 15, 2017 3:44 pm

Re: Setup WiFi access via Bluetooth

Thu Mar 16, 2017 3:22 am

I didn't realize that bleno uses a different technology (BLE vs. bluetooth). I've now got both working using generic android apps (tested with Bluetooth Terminal for bluetooth and nRF Connect for BLE, but there are lots of options). I still haven't tried going through a custom android app.

johnboiles
Posts: 6
Joined: Mon Oct 20, 2014 3:20 am

Re: Setup WiFi access via Bluetooth

Sat Jun 17, 2017 5:07 pm

Since the Pi3 (and I assume also the ZeroW) can use its single wifi adapter to both create an AP and connect to a network. I wonder if the better route would be to build a generic web-based interface for controlling the client wifi on the Pi. Then any device could configure the wifi from a browser without needing a native app that has access to the Bluetooth hardware.


brendanmyers
Posts: 6
Joined: Thu Jul 07, 2016 1:10 am
Location: Sydney, Australia

Re: Setup WiFi access via Bluetooth

Mon Jun 26, 2017 6:35 am

Shameless plug for a tool I wrote a while ago for configuring a Pi's wifi details via bluetooth.

The script to run on the pi
https://github.com/brendan-myers/rpi3-wifi-conf

Android app for sending details to the pi
https://github.com/brendan-myers/rpi3-wifi-conf-android

Original thread on the forum
viewtopic.php?t=153685

bhrigs
Posts: 1
Joined: Tue Jun 12, 2018 10:47 am

Re: Setup WiFi access via Bluetooth

Tue Jun 12, 2018 10:58 am

Hi,

Brendan - thanks for this solution.

I am able to now send the the credentials to the pi, however, the wifi does not get connected. I do receive a success message on both the pi terminal and the android app. Below is the pi log. I can see that the ip address is not set. And then it runs into asking for config values again. Other than that I am unable to figure out what I could have missed. Can someone please guide me with what I might have done wrong. Thanks!

Code: Select all

Waiting for connection on RFCOMM channel 1
('Accepted connection from ', ('AC:C3:3A:78:14:D9', 1))
Found ssid : 
Sbose_2.4GHz
Bhrigs
RTAC58U_2.4G
!
Waiting for SSID...
ssid received
Bhrigs
Waiting for PSK...
psk received
rekha123
mv wifi.conf /etc/wpa_supplicant/wpa_supplicant.conf - 0
ifdown: unknown interface wlan0
sudo ifdown wlan0 - 256
ifup: unknown interface wlan0
sudo ifup wlan0 - 256
wlan0     IEEE 802.11  ESSID:off/any  
          Mode:Managed  Access Point: Not-Associated   Tx-Power=31 dBm   
          Retry short limit:7   RTS thr:off   Fragment thr:off
          Encryption key:off
          Power Management:on
          
iwconfig wlan0 - 0
wlan0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether b8:27:eb:13:75:0d  txqueuelen 1000  (Ethernet)
        RX packets 90  bytes 19197 (18.7 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 67  bytes 12293 (12.0 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ifconfig wlan0 - 0
ip address: <Not Set>
Finished configuration

Waiting for connection on RFCOMM channel 1

I found a solution here: viewtopic.php?t=191061#p1199674

mzanetti
Posts: 4
Joined: Tue Sep 25, 2018 1:25 pm

Re: Setup WiFi access via Bluetooth

Mon Oct 15, 2018 3:26 pm

Hey, there's now also BerryLan to do exactly this. Comes with an app for Android and iOS :)

It uses BLE to provision the wireless credentials.

It's also open source with code available on github.

The website is at http://berrylan.org

wpballa1
Posts: 70
Joined: Sat Jun 27, 2015 12:49 am

Re: Setup WiFi access via Bluetooth

Tue Oct 16, 2018 9:35 pm

BerryLan works fine on a Raspberry Pi 3 but sadly does now work on the ZeroW version. So close...

gnv
Posts: 1
Joined: Fri Oct 11, 2019 8:48 am

Re: Setup WiFi access via Bluetooth

Fri Oct 11, 2019 8:54 am

Just now I have tried BarryLan solution on the Raspberry Pi Zero W. It works fine in my case.

Return to “Advanced users”