Strictly necessary cookies are on by default and cannot be turned off. Functional, Performance and Tracking/targeting/sharing cookies can be turned on below based on your preferences (this banner will remain available for you to accept cookies). You may change your cookie settings by deleting cookies from your browser. Then this banner will appear again. You can learn more details about cookies HERE.
Strictly necessary (always on)
Functional, Performance and Tracking/targeting/sharing (default off)
This example demonstrates how to connect multiple ACKme modules running WiConnect, an easy to use front end to WICED, 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.
Each module has a pre-assigned static IP address. This makes it easy for a module to send a message to another specific module on the network since all modules have pre-assigned addresses
A message may be sent from one module to one or more modules
There is no security encryption at the network layer, all modules can read messages from other modules if they choose to do so
Message delivery is NOT guaranteed. If a message is sent from one module to one or more modules, and the message fails to be received, there are no retries at the network layer (retries at the Wi-Fi layer still work though).
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.
Each message must have a sender (the source of the message)
Each message must have one or more recipients (the destination of the message)
Each message must have a payload
The message packet structure shown in the following diagram provides everything needed.
Source Address : Source address of the device sending a message. A 1 byte address provides up to 128 unique addresses, and 128 multicast addresses as explained below.
Destination Address : Destination address of the recipient of the message. If individual destination addresses are limited to 0 through 127, then addresses 128 through 255 can be used as multicast addresses. If the sender wants to send particular types of messages to a group of clients, the sender uses a multicast address. Devices interested in those types of messages can listen on the particular multicast address of interest, in addition to their own address
Payload : The message payload
This example assumes each Wi-Fi device has a pre-allocated (or static) IP address. There are several ways to achieve this.
Ensure that each device that joins the Wi-Fi AP uses a static IP address, and that no two clients use the same IP address. You can set a static IP address for your device using the static.ip variable. Note that you will also need to set the static.netmask and static.gateway variables.
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.
WiConnect Commands for Module M0
set wlan.ssid YOUR_NETWORK_NAME
set wlan.passkey YOUR_NETWORK_PASSWORD
set ip.address 192.168.1.100
set ip.gateway 192.168.1.1
set ip.netmask 255.255.255.0
set network.dhcp 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
Verify it works
> 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
TCP client/server. Another option is to run a TCP server and TCP client on each module. Each time a module wants to send a message to another module, it must open a TCP client connection to the module it wishes to message. Each module must also run a separate TCP server to receive messages from other modules. This method provides guaranteed delivery, overcoming the potential for lost messages. Note that each module must solve the address problem described for UDP also.