Wireless Serial Port

This application uses two ZentriOS devices each running ZentriOS to demonstrate how to create a wireless serial port. A character typed into the serial port of Module 1 appears instantly at the output of the Module 2 serial port (and vice versa).

Features demonstrated

Module 1 is configured to start the softap interface and a server on bootup.

Module 2 is configured to use the wlan interface and connect a client to the Module 1 softap server.

The final configuration step places both modules into serial interface stream Mode.

The client/server configuration can use either TCP or UDP protocols.

Wireless Serial Port using TCP

We start by configuring each of the modules, one as a TCP server and one as a TCP client.

Copy and paste the commands in the left hand column of the following table into a ZentriOS terminal connected to Module 1.

Module 1 TCP Server Configuration Settings

ZentriOS Commands (Module 1) Description

set softap.auto_start               true
set softap.dhcp_server.enabled      on
set softap.ssid                     server_ap
set softap.dns_server.url           ZentriOS.com

set tcp.server.auto_interface       softap
set tcp.server.auto_start           true
set tcp.server.port                 3000
set tcp.server.idle_timeout         300
set tcp.server.connected_gpio       22

set tcp.keepalive.enabled           1
set tcp.keepalive.initial_timeout  10

set bus.mode stream            stream

save
reboot

<- softap auto starts on reboot
<- DHCP server is enabled
<- Set server softap name
<- Set server DNS name

<- TCP server uses softAP interface
<- TCP server auto starts on reboot
<- TCP server port
<- Don't disconnect clients too quickly
<- GPIO indicates client connection

<- Check the TCP connection is still alive
<- Initial TCP check timeout is 10s

<- Use serial bus stream mode

<- Save settings to flash
<- Reboot the module

On rebooting, Module 1 automatically starts the softap, starts the TCP server, waits for a connection on port 3000 and enters stream mode. Data sent to the Module 1 UART is transmitted over the softap interface.

Now, copy and paste the commands in the left hand column of the following table into a ZentriOS terminal connected to Module 2.

Module 2 TCP Client Configuration Settings

ZentriOS Commands (Module 2) Description

set wlan.ssid                   server_ap
set wlan.auto_join.enabled           true

set tcp.client.remote_host  ZentriOS.com
set tcp.client.remote_port           3000
set tcp.client.auto_interface        wlan
set tcp.client.auto_retries             0
set tcp.client.auto_start               1

set tcp.keepalive.enabled               1
set tcp.keepalive.initial_timeout      10

set bus.mode                       stream

save
reboot

<- Set name of Wi-Fi AP to join
<- Turn on wlan auto-join

<- Set host for tcp client auto-connect
<- Set port for tcp client auto-connect
<- Set interface for tcp client auto-connect
<- No auto retries, TCP keepalive checks the connection
<- Enable tcp client auto-connect

<- Check the TCP connection is still alive
<- Initial TCP check timeout is 10s

<- Use serial bus stream mode

<- Save settings to flash
<- Reboot the module

On rebooting, Module 2 automatically connects to the wlan, connects as a client to the TCP server running on Module 1 and enters stream mode. Data sent to the Module 2 UART is transmitted over the wlan interface.

TCP Wireless Magic!

At this point, all characters typed into the Module 1 serial port appear immediately on the Module 2 serial port output (and vice versa). Give it a go, it's like a little piece of wireless magic!


Wireless Serial Port using UDP Client/Server Configuration

The UDP client/server configuration is similar to the TCP configuration, with changes due to the different options available for UDP. We start by configuring each of the modules, one as a UDP server and one as a UDP client.

Copy and paste the commands in the left hand column of the following table into a ZentriOS terminal connected to Module 1.

Module 1 UDP Server Configuration Settings

ZentriOS Commands (Module 1) Description

set softap.auto_start           1
set softap.dhcp_server.enabled  1
set softap.ssid                 test1ssid
set softap.passkey              test1secretkey

set udp.server.auto_interface   softap
set udp.server.auto_start       1
set udp.server.port             8000
set udp.server.lock_client      1

set bus.mode                    stream

save
reboot


<- softap auto starts on reboot
<- DHCP server is enabled
<- Set server softap name
<- Set server softap passkey

<- UDP server uses softAP interface
<- UDP server auto starts on reboot
<- UDP server port
<- No client after the first is allowed

<- Use serial bus stream mode

<- Save settings to flash
<- Reboot the module

On rebooting, Module 1 automatically starts the softap, waits for a message on port 8000 and enters stream mode. Data sent to the Module 1 UART is transmitted over the softap interface. However a message from Module 2 is required before Module 1 knows the client address and port.

Now, copy and paste the commands in the left hand column of the following table into a ZentriOS terminal connected to Module 2.

Module 2 UDP Client Configuration Settings

ZentriOS Commands (Module 2) Description

set wlan.ssid                   test1ssid
set wlan.passkey                test1secretkey
set wlan.auto_join.enabled      1

set udp.client.auto_interface   wlan
set udp.client.auto_start       1
set udp.client.remote_host      10.10.10.1
set udp.client.remote_port      8000

set bus.mode                    stream

save
reboot


<- Set name of Wi-Fi AP to join
<- Set passkey to use for Wi-Fi AP
<- Turn on wlan auto-join

<- UDP client uses wlan interface
<- UDP client connects automatically
<- Set server host for UDP client auto-connect
<- Set server port for UDP client auto-connect

<- Use serial bus stream mode

<- Save settings to flash
<- Reboot the module

On rebooting, Module 2 automatically connects to the Module 1 softap and enters stream mode. Data sent to the Module 1 UART is transmitted over the wlan interface. On Module 2 sending the first message, Module 1 stores the IP and port of Module 2 for later responses to Module 1.

UDP Wireless Magic!

Type characters into the client (Module 2) ZentriOS terminal. They appear immediately on the Module 1 ZentriOS terminal.

Now type characters into the server (Module 1) ZentriOS terminal. They appear immediately on the Module 2 ZentriOS terminal.

Note: Because UDP is a connectionless protocol, the client must send the first message. Then the server records the address of the client and can respond. If you type first on the Module 1 ZentriOS terminal, there is no response at the Module 2 ZentriOS terminal because the server has no record of a client.

If this is a problem, you can simply set up both modules with a UDP server configuration. See below.

Wireless Serial Port using UDP Symmetrical Server Configuration

UDP is a connectionless protocol, so the terms server and client are used loosely. With ZentriOS, the difference is that a module configured as a UDP server has more options, such as a configurable UDP server port, and some server behavior based on expecting a communication from a client.

If you want either module to be capable of receiving the first communication, just set up both as servers.

Module 1 still runs the softap, but Module 2 has a static IP address and DHCP is not required.

Instead of using a client lock, Module 1 is hard coded with the known IP address and port of Module 2.

Module 1 UDP Server Configuration Settings

ZentriOS Commands (Module 1) Description

set softap.auto_start           1
set softap.dhcp_server.enabled  0
set softap.ssid                 test1ssid
set softap.passkey              test1secretkey

set udp.server.auto_interface   softap
set udp.server.auto_start       1
set udp.server.port             8000
set udp.server.remote_host      10.10.10.2
set udp.server.remote_port      8008

set bus.mode                    stream

save
reboot


<- softap auto starts on reboot
<- DHCP server is disabled
<- Set server softap name
<- Set server softap passkey

<- UDP server uses softAP interface
<- UDP server auto starts on reboot
<- UDP server port
<- Known IP address for Module 2
<- Known port for Module 2

<- Use serial bus stream mode

<- Save settings to flash
<- Reboot the module

On rebooting, Module 1 automatically starts the softap, waits for a UDP message on port 8000 and enters stream mode. Data sent to the Module 1 UART is transmitted over the softap interface to the configured remote host and remote port.

Module 2 UDP Server Configuration Settings

ZentriOS Commands (Module 2) Description

set wlan.ssid                   test1ssid
set wlan.passkey                test1secretkey
set wlan.auto_join.enabled      1

set wlan.dhcp.enabled        0
set wlan.static.ip              10.10.10.2

set udp.server.auto_interface   wlan
set udp.server.auto_start       1
set udp.server.port             8008
set udp.server.remote_host      10.10.10.1
set udp.server.remote_port      8000

set bus.mode                    stream

save
reboot


<- Set name of Wi-Fi AP to join
<- Set passkey to use for Wi-Fi AP
<- Turn on wlan auto-join

<- Do not use DHCP to obtain IP address
<- Set static IP address, known to Module 1

<- UDP client uses wlan interface
<- UDP client connects automatically
<- Set port, known to Module 1
<- Set Module 1 address for UDP auto-connect
<- Set Module 1 port for UDP auto-connect

<- Use serial bus stream mode

<- Save settings to flash
<- Reboot the module

On rebooting, Module 2 sets its static IP, joins the WLAN, waits for a UDP message on port 8008 and enters stream mode. Data sent to the Module 2 UART is transmitted over the wlan interface to the configured remote host and remote port.

More UDP Wireless Magic!

Type characters into the Module 1 ZentriOS terminal. They appear immediately on the Module 2 ZentriOS terminal.

Alternatively, type characters into the Module 2 ZentriOS terminal. They appear immediately on the Module 1 ZentriOS terminal.

You can send the first message from either module.

High Speed Connections

The above communications take place with the default UART settings of 115200 baud and no flow control. This is appropriate for a demonstration at human typing speeds. It is possible to use a similar system for high speed communications, for example at UART speeds above 1 Megabaud. In this case it is necessary to configure flow control.

See the High Speed UART app note for examples of configuring baud rates and setting flow control.


Supporting ZentriOS Editions and Versions

Change Log

ModifiedChanges
2014-04-03Created
2015-02-03Added tcp.keepalive, additional tcp.client variables
2015-03-24Added UDP alternative
2018-01-23Modified for WL