Cron task to connect to specific wireless network

  • Hi folks,

    I have a WiFi hotspot on my phone that I want my RPi3 running Kodi on Libreelec to connect to. Unfortunately the 'automatically connect' setting doesn't do what its name suggests, so I'm trying to set a Cron job that tries to connect to the WiFi network every few seconds. To no avail, I've tried

    Nmcli (I don't think Libreelec supports Nmcli)

    Iwconfig wlan0 essid Argentum

    A couple of points - the phones hotspot is rarely on, only when I want to download subtitles basically. There is another WiFi network from my router, which my RPi3 is connected to via ethernet, but that shouldn't affect it.

    The Cron script file I am putting in /storage/cronjobs/wificon.sh since i dont have permissions to /use/bin/.

    NB: the wifi's essid is Argentum and it is wpa2 encrypted...

    Thanks in advance

    • Official Post

    The connmanctl app can be used to configure connections. Connecting to a wireless network requires a two-step process so you'll need to write a script that watches for the input prompt and provide the passphrase.

  • Hey Chewitt,

    Yep I actually managed to sort it out yesterday with Cron running a bash script. None the less thanks for the pointer.

    Crontab job entry:-

    * * * * * bash /storage/cronjobs/wificon.sh

    Bash script:-

    connmanctl scan wifi

    connmanctl services

    connmanctl connect wifi_b827eb5c2cda_53696c766572_managed_psk

    Took me a while to find out I needed to include the word 'bash' in the Cron job entry, and also the sequence of commands required in the bash script. Obviously your wifi unique identifier will be different to mine, but you can find that out when you run 'connmanctl services' - HTH anyone else trying to do the same thing. Works like a charm.

  • Hi everyone, I would like to do something similar, I would like to every wifi connection to run the command to change the DNS. For now I tried with the crontab -e and entered: " * / 2 * * * * connmanctl config wifi_************_**************************_managed_psk --nameservers 8.8.8.8 8.8.4.4> cron.log " but nothing happens and in the cron.log file nothing appears! Now I read this post which seems to me much better than a CronJob. I would like to use it too but for example the folders etc or storage I do not see them, I am connected in SSH with root user and default password, how should I do? Thanks