Multi-client WLAN Communications

This example demonstrates how to connect multiple ACKme modules running WiConnect 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 modules to send messages to one another on a local network is to send messages in UDP broadcast packets. To receive messages, each module 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 ...

Implementation

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 192.168.1.100, 192.168.1.101, 192.168.1.102, and so on. We also assume the Wi-Fi AP (which is the network gateway) has an IP address of 192.168.1.1. 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).

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

WiConnect Commands for Module M0 Command Description

set wlan.ssid    YOUR_NETWORK_NAME
set wlan.passkey YOUR_NETWORK_PASSWORD
set static.ip   192.168.1.100
set static.gateway   192.168.1.1
set static.netmask   255.255.255.0
set network.dhcp.enabled 0
udp_client 192.168.1.255 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 static.ip variable to 192.168.1.101 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 WiConnect 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 WiConnect Session

Module 0 Module 1

> stream_write 0 12 
0,1,Hello-M1






> stream_poll 0
1
> stream_read 0 50 1,0,Hello-M0

> stream_poll 0
1
> stream_read 0 50 0,1,Hello-M1
> stream_write 0 12 1,0,Hello-M0

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.

Change Log

ModifiedChangesWiConnect Version
Required
2014-05-08Created1.1+
2015-02-19Corrections to variable names1.1+