Basic WebSocket Client Example

Use a websocket client to send GPIO values to a remote server.

API Features Demonstrated

Platforms

This app works on:

Requirements and Prerequisites

Requires a Gecko OS evaluation board, such as a WGM160P_eval.

Other Gecko OS hardware can also be used by changing the source of the logged data to suit your device.

Resources

The initialization file settings.ini is packaged into the App file downloaded to the device.

Description

This example app implements a websocket client that sends GPIO values to the websocket.org echo server. The echoed text is received and displayed on the Gecko OS terminal.

Instructions for Use

Open a Gecko OS serial terminal to the device. See Getting Started, Opening a Gecko OS Terminal.

This app assumes your Gecko OS device is set up with the credentials to join your local network. If you have not already set up network credentials, on the Gecko OS terminal, run the commands:

network_up -s
save

See the Wi-Fi Command API documentation for network_up and save.

When the app runs, it displays output similar to the following:

> Attempting to connect to ws://echo.websocket.org
[Associating to Zentri_Guest]
> Obtaining IPv4 address via DHCP
IPv4 address: 192.168.6.113
[Associated]
> [Opening: echo.websocket.org:80]
> Resolving host: echo.websocket.org
Connecting (WS): 174.129.224.73:80
[2016-02-24 | 07:02:59: Opened: 0]
> Connected. Socket handle: 0
Network up
Echoed data: 000: gpios:35DA
Echoed data: 001: gpios:F5DE
Echoed data: 002: gpios:35DE
Echoed data: 003: gpios:F5DE
Echoed data: 004: gpios:35DE
Echoed data: 005: gpios:F5DE

Implementation

gos_app_init

gos_app_deinit

websocket_attempt_connect_handler

websocket_disconnect_handler

websocket_receive_handler

websocket_transmit_handler

wlan_network_event_handler

Source

See:

See also: