Balena wifi-connect

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

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

1 Like

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

Hi,

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

Best Regards
Aivaras Chomskis

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.

Hi,

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

#!/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

import os

os.system('wifi-connect')

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

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):

#!/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.

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

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

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?

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

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?

Yes, something is not working.

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

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

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

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

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

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


#!/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.

#!/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