Close

Tomorrow looks good for initial release

A project log for Easy RasPi configuration

Allow customers to easily configure your RasPi product.

Peter WalshPeter Walsh 11/03/2020 at 19:470 Comments

Most of the functionality is implemented and working, only need to add some things from the todo list and do a little testing. Also, sprucing up the web page a little.

Little things, like doing a syntax check on some of the fields (the static fields in particular), so the user can't typo an invalid entry.

Tomorrow looks good for an initial release.

I still need to implement the FileSharing page, but the underlying code to make actual changes is done, so it should only be a matter of formatting the web page.

I now have a system for easily parsing any of the linux data formats - either from config files (dhcpcd.conf) or commands (iwlist). For example, I have a function "GetDHCPInfo()" that returns the struct listed below.

In addition to being easy to work with this data in perl, the parser system also makes note of where it found each data item, so that updates can happen inline in the config file. Setting "DNS2->{NewValue} = "4.4.4.4" and calling $Parser->Update() will change the corresponding field within the original file. Boo-yah!

'DHCPInfo' => {
       'wlan0' => {
                    'DNS1' => '1.1.1.1',
                    'Enabled' => 1,
                    'IPAddr' => '192.168.1.31/24',
                    'Router' => '192.168.1.1',
                    'DNS2' => '1.0.0.1',
                    'DHCP' => 0
                  },
       'eth0' => {
                   'DHCP' => 1,
                   'Router' => '',
                   'IPAddr' => '',
                   'DNS2' => '',
                   'Enabled' => 1,
                   'DNS1' => ''
                 },
       'wlan1' => {
                    'Enabled' => 0,
                    'DNS1' => '',
                    'Router' => '',
                    'DNS2' => '',
                    'IPAddr' => '',
                    'DHCP' => 1
                  }
     },

There's some devil in the details. For example, if a static block does not already exist in the file then the caller has to add it manually, but there's helper functions to do this. Here's how easy it is to add a new static block to the end of dhcpcd.conf:


my $IFConfig = [
    "",
    "interface $IFName",
    "    static ip_address=$IPAddr",
    "    static routers=$Router",
    "    static domain_name_servers=$DNSS1 $DNS2",
    ""];

    $ConfigFile->AddLines($IFConfig);

If there's any interest I might upload the parser to CPAN. It's pretty useful, and can be used to parse just about any simple data layout.

Discussions