# Balena wifi-connect

**URL:** <https://forums.balena.io/t/balena-wifi-connect/326926>\
**Category:** Project help\
**Created:** [June 11, 2021, 7:41am UTC](https://forums.balena.io/t/balena-wifi-connect/326926 "2021-06-11T07:41:04Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aivaras](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@Aivaras](https://forums.balena.io/u/Aivaras)\
**Post date:** [June 11, 2021, 7:41am UTC](https://forums.balena.io/t/balena-wifi-connect/326926/1 "2021-06-11T07:41:04Z")

</div>

Hi,

I have a question about Balena wifi-connect. What changes need to be made to wifi-connect to make an access point when where is no familiar wifi network around ?  
 ![wifi](https://global.discourse-cdn.com/balena/original/2X/6/62dc881f83eca7d4485921547ef6df406f944fd9.png)

also there is a code that start wifi-connect at every orange pi zero start-up.

I am using Orange-pi zero with armbian OS

---

<div class="post-metadata">

**Author:** ![rmorillo24](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/rmorillo24/32/10359_2.png) [@rmorillo24](https://forums.balena.io/u/rmorillo24)\
**Post date:** [June 11, 2021, 8:51am UTC](https://forums.balena.io/t/balena-wifi-connect/326926/3 "2021-06-11T08:51:56Z")

</div>

Hi Aivaras

To your first question, balena WiFi Connect is designed to do exactly what you are asking for. Upon startup it will try to connect to one of the known networks. If it can’t, it will create the AP to allow you connect and access the captive portal to configure a new access to the visible networks. This way, if no known network is visible, you should be able to see in your phone (or any other device nearby) a WiFi SSID with the WiFI Connect AP.

For making it start after boot, you will have to configure it as a linux service, and linux will take care of it. Try using this instructions and see if you can get it to work: [https://linuxconfig.org/how-to-automatically-execute-shell-script-at-startup-boot-on-systemd-linux](https://linuxconfig.org/how-to-automatically-execute-shell-script-at-startup-boot-on-systemd-linux)

---

<div class="post-metadata">

**Author:** ![Aivaras](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@Aivaras](https://forums.balena.io/u/Aivaras)\
**Post date:** [June 14, 2021, 7:58am UTC](https://forums.balena.io/t/balena-wifi-connect/326926/6 "2021-06-14T07:58:54Z")

</div>

Hi,

Maybe you have a script to start wifi-connect on boot ?

Best Regards  
Aivaras Chomskis

---

<div class="post-metadata">

**Author:** ![nitish](https://avatars.discourse-cdn.com/v4/letter/n/34f0e0/32.png) [@nitish](https://forums.balena.io/u/nitish)\
**Post date:** [June 15, 2021, 2:39pm UTC](https://forums.balena.io/t/balena-wifi-connect/326926/7 "2021-06-15T14:39:46Z")

</div>

Hi Aivaras,

As my colleague highlighted, it would be best to try one of the ways highlighted with the link for creating a startup boot script. The reason there are a couple of methods is all distros have slightly diff services bundled; so you might want to confirm what is armbian OS coming with.

Let us know how it goes or if you run into any errors while running this.

---

<div class="post-metadata">

**Author:** ![Aivaras](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@Aivaras](https://forums.balena.io/u/Aivaras)\
**Post date:** [July 14, 2021, 12:34pm UTC](https://forums.balena.io/t/balena-wifi-connect/326926/10 "2021-07-14T12:34:46Z")

</div>

Hi,

So I made some a script that starts wifi-connect on boot.

```auto
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

(sleep 10;python /root/.local/New directory/wifi.py)

exit 0

```

But script starts every time orange pi zero starts. So I want it to start if there is no active connection. Maybe do someone has a suggestion how to do it ?

Also Wifi.py script

```auto
import os

os.system('wifi-connect')

```

---

<div class="post-metadata">

**Author:** ![mehalter](https://avatars.discourse-cdn.com/v4/letter/m/b5a626/32.png) [@mehalter](https://forums.balena.io/u/mehalter)\
**Post date:** [July 14, 2021, 5:00pm UTC](https://forums.balena.io/t/balena-wifi-connect/326926/11 "2021-07-14T17:00:55Z")

</div>

Hi Aivaras,

It looks like `wifi-connect` does not support checking the wifi connection before running out of the box, but there is a balena block project that has a script that achieves this sort of behavior. The code for this logic can be found in the `start.sh` script here: [GitHub - balenablocks/wifi-connect: Easy WiFi setup for Linux devices from your mobile phone or laptop](https://github.com/balenablocks/wifi-connect)

It looks like you should be able to use `wget` to check the current internet connectivity and run `wifi-connect` accordingly. Here is an example script that you can try pulling from what is in the repo linked above (replace `freq=120` with whatever check frequency you want in seconds):

```auto
#!/bin/sh -e

freq=120

sleep 10

while [[true]]; do

    echo "Checking internet connectivity ..."
    wget --spider --no-check-certificate 1.1.1.1 > /dev/null 2>&1

    if [$? -eq 0]; then
        echo "Your device is already connected to the internet."
        echo "Skipping setting up Wifi-Connect Access Point. Will check again in $freq seconds"
    else
        echo "Your device is not connected to the internet."
        echo "Starting up Wifi-Connect.\n Connect to the Access Point and configure the SSID and Passphrase for the network to connect to."
        python /root/.local/New directory/wifi.py # this could also probably be just `wifi-connect` instead of calling the python wrapper
    fi

    sleep $freq

done

```

Let us know how this goes.

---

<div class="post-metadata">

**Author:** ![Aivaras](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@Aivaras](https://forums.balena.io/u/Aivaras)\
**Post date:** [July 14, 2021, 5:10pm UTC](https://forums.balena.io/t/balena-wifi-connect/326926/13 "2021-07-14T17:10:27Z")

</div>

Thank you for a code, I will try it and tell how it goes 😊

---

<div class="post-metadata">

**Author:** ![Aivaras](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@Aivaras](https://forums.balena.io/u/Aivaras)\
**Post date:** [July 14, 2021, 8:53pm UTC](https://forums.balena.io/t/balena-wifi-connect/326926/14 "2021-07-14T20:53:01Z")

</div>

I think it is not working 😃 because hotspot doesn’t show up

---

<div class="post-metadata">

**Author:** ![rcooke-warwick](https://avatars.discourse-cdn.com/v4/letter/r/ba9def/32.png) [@rcooke-warwick](https://forums.balena.io/u/rcooke-warwick)\
**Post date:** [July 16, 2021, 11:00am UTC](https://forums.balena.io/t/balena-wifi-connect/326926/16 "2021-07-16T11:00:25Z")

</div>

I saw that you are using armbian, and I wonder if it has all of the dependancies required to run wifi connect? Does it have NetworkManager do you know?

---

<div class="post-metadata">

**Author:** ![Aivaras](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@Aivaras](https://forums.balena.io/u/Aivaras)\
**Post date:** [July 16, 2021, 11:05am UTC](https://forums.balena.io/t/balena-wifi-connect/326926/17 "2021-07-16T11:05:52Z")

</div>

I tried manually to start a wifi-connect service and it works, so I think it has all dependencies and a NetworkManager.

---

<div class="post-metadata">

**Author:** ![rcooke-warwick](https://avatars.discourse-cdn.com/v4/letter/r/ba9def/32.png) [@rcooke-warwick](https://forums.balena.io/u/rcooke-warwick)\
**Post date:** [July 16, 2021, 11:08am UTC](https://forums.balena.io/t/balena-wifi-connect/326926/18 "2021-07-16T11:08:17Z")

</div>

Ok thats a good sign. So you are saying now that you use a script based on the one my colleague recently posted, no access point is generated?

---

<div class="post-metadata">

**Author:** ![Aivaras](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@Aivaras](https://forums.balena.io/u/Aivaras)\
**Post date:** [July 16, 2021, 11:11am UTC](https://forums.balena.io/t/balena-wifi-connect/326926/19 "2021-07-16T11:11:22Z")

</div>

Yes, something is not working.

I am using your colleagues script in /etc/rc.local.

---

<div class="post-metadata">

**Author:** ![rcooke-warwick](https://avatars.discourse-cdn.com/v4/letter/r/ba9def/32.png) [@rcooke-warwick](https://forums.balena.io/u/rcooke-warwick)\
**Post date:** [July 16, 2021, 12:23pm UTC](https://forums.balena.io/t/balena-wifi-connect/326926/21 "2021-07-16T12:23:12Z")

</div>

Do you get the logging messages? Does it get as far as `Starting up Wifi-connect.....`

---

<div class="post-metadata">

**Author:** ![Aivaras](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@Aivaras](https://forums.balena.io/u/Aivaras)\
**Post date:** [July 16, 2021, 12:57pm UTC](https://forums.balena.io/t/balena-wifi-connect/326926/22 "2021-07-16T12:57:08Z")

</div>

Okay, I will try to find a console log because it doesn’t show nothing then I am using Putty.

---

<div class="post-metadata">

**Author:** ![Aivaras](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@Aivaras](https://forums.balena.io/u/Aivaras)\
**Post date:** [July 19, 2021, 11:39am UTC](https://forums.balena.io/t/balena-wifi-connect/326926/24 "2021-07-19T11:39:20Z")

</div>

Maybe someone can test a code on armbian ? because I can’t find that log file.

---

<div class="post-metadata">

**Author:** ![Aivaras](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@Aivaras](https://forums.balena.io/u/Aivaras)\
**Post date:** [July 20, 2021, 6:00am UTC](https://forums.balena.io/t/balena-wifi-connect/326926/26 "2021-07-20T06:00:46Z")

</div>

So I have run that code manually.  
root@orangepizero:/etc# sudo ./rc.local  
./rc.local: 7: [[: not found  
root@orangepizero:/etc#

---

<div class="post-metadata">

**Author:** ![Aivaras](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@Aivaras](https://forums.balena.io/u/Aivaras)\
**Post date:** [July 20, 2021, 10:55am UTC](https://forums.balena.io/t/balena-wifi-connect/326926/27 "2021-07-20T10:55:11Z")

</div>

So this code works, but something is not right. It can’t create a wifi-hotspot.

```auto

#!/bin/sh -e

freq=120

sleep 10

while true; do

    echo "Checking internet connectivity ..."
    wget --spider --no-check-certificate 1.1.1.1 > /dev/null 2>&1

    if [$? -eq 0]; then
        echo "Your device is already connected to the internet."
        echo "Skipping setting up Wifi-Connect Access Point. Will check again i>
    else
        echo "Your device is not connected to the internet."
        echo "Starting up Wifi-Connect.\n Connect to the Access Point and confi>
        python3 /home/wifi.py # this could also probably be just `wifi-connect`>
    fi

    sleep $freq

done

```

But If code is written like this hotspot works.

```auto
#!/bin/sh -e

freq=120

sleep 10

while true; do

    echo "Checking internet connectivity ..."
    wget --spider --no-check-certificate 1.1.1.1 > /dev/null 2>&1

    if [$? -eq 0]; then
        echo "Your device is already connected to the internet."
        echo "Skipping setting up Wifi-Connect Access Point. Will check again i>
        python3 /home/wifi.py
    else
        echo "Your device is not connected to the internet."
        echo "Starting up Wifi-Connect.\n Connect to the Access Point and confi>
    fi

    sleep $freq

done

```

log:  
Checking internet connectivity …  
Your device is already connected to the internet.  
Skipping setting up Wifi-Connect Access Point. Will check again in 120 seconds
