oktober 02, 2015

Reconfigure your Wifi

If you want to change the Wifi or network settings of your rabbit (after you have installed Open Karotz), here is what to do:

  • Download the Karotz Wifi Configurator (as ZIP file)
  • Unzip to the root of a FAT32 formatted USB key
  • Run "KarotzWifiConfigurator.exe" from the USB key (run it on a Windows machine).
  • Answer the questions. At the end, a network.conf file is written to the USB key.
  • Use the USB key to boot your rabbit, and listen what to do.
  • Finally, remove the USB key from the rabbit, and reboot your rabbit.

This is how it works.

Yesterday and today I spent some time figuring out how Python and the autorun of my rabbit works.

It seems that the rabbit will boot from a bash script called "autorun" in the root of the USB key, when this file is signed with "autorun.sig" (also in the root of the USB key). More information about this is described here.

I wanted to create a USB key for the re-configuration of Wifi. I discovered how to use the Python file called "config.py", which is on the filesystem of the rabbit, and contains a lot of configuration options. It think that this file was used in the past, in combination with the USB cable and stand alone setup software, to do the initial setup.

It is however also possible to use config.py from a Python script and call the functions. This makes it possible to configure the rabbit with scripts.

This is how I did it. I created a plain autorun file with the following content:

This will just call autorunwifi, which is a Python script file, also on the root of the USB key.

Autorunwifi looks like this:

I commented the sections in the script, and think it is more or less self explaining:

  • Import some basic library stuff so we can use system commands in Python.
  • Define three functions to play a sound and turn on the led (static or pulsing).
  • Expand the path so we can use script files of the Karotz (like config.py).
  • Untar the tools file. This is where the audio player is.
  • Start logging to the USB key (log.txt). 
  • Import the config library.
  • Give config a filehandler for logging.
  • Read the network.conf file as separate lines.
  • Feed the lines to config.py, and config does the rest (i.e. executes the commands).
  • Close logging.
  • In the exception catch block some logging and sound playing is done.

I did several tests, and it worked great. 

Create a file with settings (network.conf)

After finding out what config.py does with it, it was easy to write a C# command-line tool to create a network.conf file. When you download my ZIP, you'll find the command-line tool in the root of the files for the USB key. Just run it, it will ask you some questions and generate a network.conf file.

Have fun!

(The files are also on Github)

Images

wificonfig.png

Wifi Configurator will let you create a network.conf file.

Leave a message