GPIO-Controlled Network Connection
This example demonstrates how to use a GPIO to control a network connection to a remote server. Once the network connection is open, data can be automatically streamed between WiConnect and the remote server.
ioconn feature makes it easy for an MCU, or blackbox electronic system with a serial output, to add network communication with a remote server. A GPIO is assigned as the ioconn.control_gpio. Toggling the ioconn control GPIO makes and breaks the network connection to the remote server.
The remote server used in the demonstration is the ACKme test TCP echo server, located online at
The TCP echo server simply echoes any messages back to the client.
A computer, connected via USB to the evaluation board, takes the part of the MCU host system.
To set the level of the ioconn control GPIO high, various techniques are possible. In this demonstration, a switch is used to connect a logic high (3.3V) to the ioconn control GPIO pin. In an actual implementation, the host system toggles the ioconn control GPIO.
This demonstration uses the user LED GPIOs on the module for the ioconn control and status GPIOs.
The LEDs are configured so that:
- User LED1 turns on when the ioconn control GPIO is asserted
- User LED2 turns on when a connection with the remote server is established
This demonstration works on either a Mackerel or Moray evaluation board.
Connect the switch between the following pins on the module, depending on your evaluation board:
Connect the module via USB to your computer and open a serial terminal console. See Getting Started.
The following assumes that the module is in the default state. To return to the default state, perform a factory reset.
Set up the local Wi-Fi network parameters.
Set up aliases for the ioconn variables.
For the AMW004-E03 Mackeral evaluation board:
For the AMW006-E03 Moray evaluation board:
Configure the ioconn variables.
Performing a GPIO-Controlled Host Connection
Assert the module
IOC_CTRL GPIO by setting the switch to ON.
If all goes well, the module terminal console displays something like the following:
IOC_CTRL GPIO is still asserted, send a message to the server:
Now check if a message has been received in reply:
The server's response echoes the message sent.
De-assert the ioconn control GPIO by setting the switch to OFF.
The WiConnect response is similar to the following:
Using Stream Mode
A typical use of the GPIO Controlled Network Connection feature is to allow a device to stream data to and from a server. To demonstrate this, put the module in stream mode:
The module terminal console can no longer send commands to WiConnect. Try typing at the terminal. There is no response. Characters you type are transparently streamed to the network, which is currently not connected. See Serial Interface, Stream Mode.
Now assert the ioconn control GPIO by setting the switch to on:
All characters received from the remote server appear automatically on the console.
Now type some characters into the module terminal console. Typed characters are echoed (after round-trip network latency) by the ACKme test server.