Advent 2023 banner

Configure Network and Wi-Fi for AI-Powered Christmas Tree

Photo of Raul Muñoz

Posted on Dec 2, 2023 by Raul Muñoz

11 min read

Welcome to part two of our AI Powered Christmas Tree Series! The goal of this series is to serve as a guide for you to build your own AI powered Machine Learning Christmas Tree, thanks to the Arduino Portenta X8 SoM and Edge Impulse AI Platform.

In this tutorial, we will be discussing how to configure the network for your embedded device. But before jumping into this entry, if you haven’t already, be sure to check out part one: Your First FoundriesFactory AI-Powered Christmas Tree.

Reasons to be Concerned About How Our Network is Configured

Throughout the development process, network configuration is but one of the many variables you may wish to exercise more exact control over, in order to better understand your evaluation board capabilities. By default, the Linux microPlatform™ (LmP) is configured to get an IP from the DHCP server automatically, but there are many reasons you may wish to customize this behavior:

  • Communication with External Devices:
    Many embedded systems interact with external devices or systems over a network. Proper network configuration ensures seamless communication between the embedded system and these external components.
  • Data Transfer and Protocol Handling:
    Embedded systems often need to transfer data over a network. Configuring the network settings allows you to optimize data transfer rates, choose appropriate communication protocols, and handle data in a way that suits the requirements of your application.
  • Security:
    Network security is a critical aspect of embedded systems development. Configuring the network allows you to implement security measures such as encryption, authentication, and access control to protect your embedded system from unauthorized access or data breaches.

The network configurations we will be detailing in this tutorial are relatively simple, but understanding these principles will allow you to make more robust configurations in your future projects.

Prerequisites for Machine Learning Christmas Tree

This is the second entry in our AI Powered Christmas Tree Series. You should follow along with Your First FoundriesFactory AI-Powered Christmas Tree before continuing, as Part 1 covers:

  • Signing Up to create your Factory
  • Flashing Your Device
  • Registering Your Device
  • Installing Fioctl™
  • Deploying Container Application

NetworkManager Command Line Interface (nmcli)

The LmP uses the nmcli (NetworkManager Command Line Interface) utility to configure its network. NetworkManager is a widely used network management service on Linux systems that simplifies the management of network connections, including wired, wireless, mobile broadband, and VPN connections.

Connect to the Board

If you are following along in the series, your device should already be flashed with an LmP Target, and ready for you to login. With the Arduino Portenta X8, it is easiest to connect to the board via SSH. If you are using any of our other supported boards, there are instructions available in our docs to help you with connecting to a board.

Checking status

After successfully logging in, run the following command to get information about the interfaces recognized by NetworkManager:

device:~$ nmcli device status

eth0     ethernet  disconnected  --
wlan0    wifi      disconnected  --
docker0  bridge    unmanaged     --
sit0     iptunnel  unmanaged     --
lo       loopback  unmanaged     --

This command provides a summary of available network interfaces, their states, and associated connections. A device can have multiple connections, but only one connection can be attached to each interface.

To see all connections created, run the command:

device:~$ nmcli connection show

NAME                UUID                                  TYPE      DEVICE
Wired connection 1  ea98ae92-f210-3011-9f00-ff357473fd6f  ethernet  --

This will display information about each configured network connection, including its name and type, e.g. Ethernet in the above example.

nmcli has numerous commands, parameters, and options which you can explore. The nmcli man page can give you more details about its capabilities and the various ways you can manage your network.

Changing Network Configuration

Let’s see some practical examples of how to create a new connection and change it to a fixed IP.

If you are connected over SSH the following commands might affect your connection.

First, create a new Ethernet connection:

device:~$ nmcli con add type ethernet con-name my-connection

If we list our connections again, you should see the new connection in the list:

device:~$ nmcli connection show

NAME                UUID                                  TYPE      DEVICE
Wired connection 1  40643d8d-18ac-387d-9c27-cbd4f15dd8da  ethernet  eth0
my-connection       a2e187ce-8c6e-4b4e-a9fe-622b071757bf  ethernet  --

Start your connection with the command:

device:~$ nmcli con up my-connection

Note that now your connection is now active on eth0, while the previous connection is no longer active and does not have an associated device:

device:~$ nmcli connection show

NAME                UUID                                  TYPE      DEVICE
my-connection       a2e187ce-8c6e-4b4e-a9fe-622b071757bf  ethernet  eth0
Wired connection 1  40643d8d-18ac-387d-9c27-cbd4f15dd8da  ethernet  --

Configuring for Static Connection

From this point, we can now easily manipulate this connection. To change your connection to a static address, run the command:

device:~$ nmcli con mod my-connection ipv4.addresses ""

After running this command, the my-connection profile will be updated to include the specified IPv4 address. You can further configure this connection with additional parameters and settings as needed using the nmcli con mod commands. Don't forget to check out the nmcli man page for examples of what settings you can configure.

At this time, the changes are associated to the connection profile; but they are not active on our running connection. To apply your changes, run:

device:~$ nmcli device reapply eth0

If we do not run this command here, our changes won’t take effect until we disconnect and reconnect the device from the network.

Configuring for Connection to Dynamic Host Configuration Protocol (DHCP)

The steps to enable automatic DHCP addressing are very similar to those above for static addressing. We are still using the nmcli con mod command but with the following parameters:

device:~$ nmcli con mod my-connection ipv4.method auto ipv4.addresses ""
  • ipv4.method auto: This part of the command sets the IPv4 addressing method to "auto." In this mode, the network connection will automatically obtain its IPv4 configuration
  • ipv4.addresses "": This clears any previously defined IPv4 addresses for the connection. The double quotes with an empty string effectively remove any statically assigned IPv4 address.

Again, these changes currently are only updates to the connection profile. To apply them to our active connection we need to run:

device:~$ nmcli device reapply eth0

Connection Details

There are many other parameters that can be configured using nmcli. You can view a list of many of these parameters for any connection profile using the below command:

device:~$ nmcli -p con show my-connection
The -p flag is for “pretty” and is only used to display the output in a more human-readable format.

This command is useful for inspecting and verifying the settings and configuration of any connection profile. The output will look like this:

                    Connection profile details (my-configuration)
===============================================================================                          my-configuration
connection.uuid:                        a2e187ce-8c6e-4b4e-a9fe-622b071757bf
connection.stable-id:                   --
connection.type:                        802-3-ethernet
connection.interface-name:              --
connection.autoconnect:                 yes
connection.autoconnect-priority:        0
connection.autoconnect-retries:         -1 (default)
connection.multi-connect:               0 (default)
connection.auth-retries:                -1
connection.timestamp:                   1693951625                   no
connection.permissions:                 --                        --
connection.master:                      --
connection.slave-type:                  --
connection.autoconnect-slaves:          -1 (default)
connection.secondaries:                 --
connection.gateway-ping-timeout:        0
connection.metered:                     unknown
connection.lldp:                        default
connection.mdns:                        -1 (default)
connection.llmnr:                       -1 (default)
connection.dns-over-tls:                -1 (default)
connection.wait-device-timeout:         -1
802-3-ethernet.port:                    --
802-3-ethernet.speed:                   0
802-3-ethernet.duplex:                  --          no
802-3-ethernet.mac-address:             --
802-3-ethernet.cloned-mac-address:      --
802-3-ethernet.mac-address-blacklist:   --
802-3-ethernet.mtu:                     auto
802-3-ethernet.s390-subchannels:        --
802-3-ethernet.s390-nettype:            --
802-3-ethernet.s390-options:            --
802-3-ethernet.wake-on-lan:             default
802-3-ethernet.wake-on-lan-password:    --
802-3-ethernet.accept-all-mac-addresses:-1 (default)
ipv4.method:                            auto
ipv4.dns:                               --
ipv4.dns-search:                        --
ipv4.dns-options:                       --
ipv4.dns-priority:                      0
ipv4.addresses:                         --
ipv4.gateway:                           --
ipv4.routes:                            --
ipv4.route-metric:                      -1
ipv4.route-table:                       0 (unspec)
ipv4.routing-rules:                     --
ipv4.ignore-auto-routes:                no
ipv4.ignore-auto-dns:                   no
ipv4.dhcp-client-id:                    --
ipv4.dhcp-iaid:                         --
ipv4.dhcp-timeout:                      0 (default)
ipv4.dhcp-send-hostname:                yes
ipv4.dhcp-hostname:                     --
ipv4.dhcp-fqdn:                         --
ipv4.dhcp-hostname-flags:               0x0 (none)
ipv4.never-default:                     no
ipv4.may-fail:                          yes
ipv4.required-timeout:                  -1 (default)                       -1 (default)
ipv4.dhcp-vendor-class-identifier:      --
ipv4.dhcp-reject-servers:               --
ipv6.method:                            auto
ipv6.dns:                               --
ipv6.dns-search:                        --
ipv6.dns-options:                       --
ipv6.dns-priority:                      0
ipv6.addresses:                         --
ipv6.gateway:                           --
ipv6.routes:                            --
ipv6.route-metric:                      -1
ipv6.route-table:                       0 (unspec)
ipv6.routing-rules:                     --
ipv6.ignore-auto-routes:                no
ipv6.ignore-auto-dns:                   no
ipv6.never-default:                     no
ipv6.may-fail:                          yes
ipv6.required-timeout:                  -1 (default)
ipv6.ip6-privacy:                       -1 (unknown)
ipv6.addr-gen-mode:                     stable-privacy
ipv6.ra-timeout:                        0 (default)
ipv6.dhcp-duid:                         --
ipv6.dhcp-iaid:                         --
ipv6.dhcp-timeout:                      0 (default)
ipv6.dhcp-send-hostname:                yes
ipv6.dhcp-hostname:                     --
ipv6.dhcp-hostname-flags:               0x0 (none)
ipv6.token:                             --
proxy.method:                           none
proxy.browser-only:                     no
proxy.pac-url:                          --
proxy.pac-script:                       --

With this we can see all pertinent profile details. You can use this to examine other profile setups and ensure parity with them, as well as ensure any new profiles you make are set up correctly to your specification.

Connecting via Wi-Fi

Certainly, the easiest way to get your device online is to just go ahead and plug an Ethernet cable in and from there you will be up and running in seconds. But that is not always the best or most practical solution - maybe your device is going to be stored someplace it is not easy to run a physical wire to, or maybe the Ethernet cable you have on hand is too short. If you are using an Arduino Portenta X8, you may have of course noticed by now that it does not have a traditional rj45 Ethernet port and needs a USB-C adapter: yet another reason to consider Wi-Fi.

For hobbyists and production devices live out in the field alike, it is not always practical to rely on a wired connection. For this reason, we are going to discuss configuring your device via Wi-Fi. This is a useful option to have available, even if you plan on predominantly using physical cables, purely as a backup option if nothing else.

Once again, connect to the device terminal, and once you are logged in, follow the commands below to configure Wi-Fi.

Checking Status

The first step is to ensure that the device’s Wi-Fi radio is actually turned on:

device:~$ nmcli radio wifi on

If it is not, this command will do just that! From here, we want to update our available network list:

device:~$ nmcli device wifi rescan

This command instructs NetworkManager to re-scan for nearby Wi-Fi networks. It will output a list of available networks and their signal strengths. You should see output similar to the below:

device:~$ nmcli dev wifi list

IN-USE  BSSID              SSID                   MODE   CHAN  RATE        SIGNAL  BARS  SECURITY
        34:0A:33:1E:41:05  HOMEOFFICE_2           Infra  1     270 Mbit/s  100     ****  WPA2
        10:72:23:B5:51:67  HOMEOFFICE_1           Infra  6     130 Mbit/s  100     ****  WPA2
        34:0A:33:1E:41:03  HOMEOFFICE_2_5G        Infra  161   270 Mbit/s  94      ****  WPA2

Connecting to a Wi-Fi Network

Since we have now established that (a) the device’s Wi-Fi is on and (b) there is at least one network available to join, we are free to go ahead and connect to our desired network using the SSID and password:

device:~$ nmcli dev wifi connect <SSID> password <PASSWORLD>

Replace SSID with the name of the Wi-Fi network you want to connect to, and PASSWORD with the actual password or passphrase for that network. After running this command, NetworkManager will attempt to connect to the specified Wi-Fi network using the provided credentials.

We already checked that it’s in range, so assuming we have the correct PASSWORD, it should connect with no issues.

And it’s as simple as that! Our device is now connected to the Wi-Fi network and ready to go online.

Turning Wi-Fi Off

If for any reason you want to disable Wi-Fi on your device, the command to do so is:

device:~$ nmcli radio wifi off

When you run this command, it will disable the Wi-Fi radio on your system. In this state, you won’t be able to scan for any available networks or connect to them until you enable it again.

You can do this with the same command from earlier:

device:~$ nmcli radio wifi on

Turning off Wi-Fi can be useful when you want to conserve battery power or need to switch to a wired network connection.

Recap and Conclusion

In this tutorial, we covered how to:

  • Configure your network and switch between static and dynamic IP
  • Enable Wi-Fi and join a network

Join us in the next tutorial as we discuss the basic principles of the Yocto Project and the Linux microPlatform.

Continue Building Ai-Powered Christmas Tree

If you are interested in our entire 14-part series on how to build an AI powdered Christmas tree, browse through each section below. Each part brings you closer to mastering your build:

Related posts

Keep up to date with