Multi-client WLAN Communications

This example demonstrates how to connect multiple ZentriOS devices running ZentriOS to a network as Wi-Fi clients, and how to configure each module to send messages to one another. The requirements for this kind of application can vary considerably, here's a list of assumptions we made for this particular example.

The simplest way to enable devices to send messages to one another on a local network is to send messages in UDP broadcast packets. To receive messages, each device runs a UDP client and listens for messages sent on the UDP broadcast address. While UDP broadcast provides a way to send messages successfully, it lacks the ability to address messages to individual clients.

A Simple Message Protocol

To address messages, a simple application layer message protocol can be used. The requirements of a simple message protocol are listed below.

The message packet structure shown in the following diagram provides everything needed.

where ...


This example assumes each Wi-Fi device has a pre-allocated (or static) IP address. There are several ways to achieve this.

For this example, we assume that IP addresses assigned to clients are numbered in the range,,, and so on. We also assume the Wi-Fi AP (which is the network gateway) has an IP address of The assumed configuration of the network is shown here.

Before continuing, ensure your Wi-Fi AP is configured as described above. Or alternately, if you have a different configuration, ensure you have the IP addresses and ranges of your AP handy (you will need to substitute them below as required).

Setup Commands

Commands to setup the first device M0 at address 0 ( are shown below. Enter these commands now.

ZentriOS Commands for Module M0 Command Description

set wlan.ssid             YOUR_NETWORK_NAME
set wlan.passkey          YOUR_NETWORK_PASSWORD
set wlan.static.ip
set wlan.static.gateway
set wlan.static.netmask
set wlan.dhcp.enabled  0
udp_client       50000 50000

<- Set the name of your network
<- Set the password for your network
<- Set the static IP address of the module
<- Set the network gateway for the module
<- Set the network netmask for the module
<- Turn off DHCP (we're using statically assigned IP addresses)
<- Start a UDP client connected to remote & local ports 50000

With module M0 setup and ready, grab the next module (M1), plug it in and set it up using the same commands EXCEPT this time, change the wlan.static.ip variable to so module M1 has address 1.

Verify it works

With both modules setup and connected to the Wi-Fi AP and the UDP client started on both modules, let's test that messages sent from one module are received by the other module.

In the following ZentriOS session, the source and destination addresses (separated by commas) have been added to each message according to the simple message protocol described previously. Also, note that any text entered after a stream_write command is not echoed to the terminal.

Example ZentriOS Session

Module 0 Module 1

> stream_write 0 12

> stream_poll 0
> stream_read 0 50

> stream_poll 0
> stream_read 0 50
> stream_write 0 12

The stream_poll command is used here to check whether data has been received. A more convenient notification method is to setup a GPIO interrupt as described in the udp_client command.

Now you have two modules sending messages to each other, go ahead and add other modules to the network, remembering to increment the address for each new module.

Other Options?

This example describes a simple way to send messages between modules. There are other ways to achieve the same result, but the implementation of alternate methods is more complex.

Supporting ZentriOS Editions and Versions

Change Log

2015-02-19Corrections to variable names