goHACK.me Slave Mode

This example demonstrates how to use the WiConnect goHACK.me API in slave mode with a PC terminal acting as the host (instead of a microprocessor).

By the time you have completed this demonstration, you will be able to ...

Factory Reset

To get started, let's factory reset your board to ensure that any existing configuration does not get in the way of the demo. Use the commands shown below as a guide to factory reset the board now.

WiConnect Commands Description

get wlan.mac
factory_reset <MAC address>

<- Get the wlan MAC address for your device
<- Factory reset the device; paste the MAC address returned by 'get wlan.mac'

If your board is already activated with goHACK.me, we need to deactivate in order to setup a new caps file. Sign in to goHACK.me and deactivate it now. If this is your first time connecting a board to goHACK.me, don't worry, we'll soon have you setup and ready to go.

Connect to Wi-Fi

Connect your board to your Wi-Fi network using the network_up command as shown below.

WiConnect Commands Description

network_up -s

<- Scan & select your network, then enter the network password

Create a Caps File

Create a demo caps file by copy and pasting the following text into the terminal. This is a simple caps file that only has 1 stream and 1 control, and sets up message boxes to enable messaging with goHACK.me.

WiConnect Commands Description

file_create slave_caps.json 783
    "model": "Demo 1.0",
    "title": "gHm Slave Demo",
    "streams": [
            "slug": "stream1",
            "title": "My Stream",
            "unit": "",
            "symbol": "",
            "type": "integer"
    "controls": [
            "slug": "control1",
            "title": "My Control",
            "value": 0,
            "type": "select",
            "options": {
                "0": "0-Red",
                "1": "1-Green",
                "2": "2-Blue"
} } ], "messages": [ { "slug": "from-device", "title": "From Device" }, { "slug": "to-device", "title": "To Device" } ] }

<- Create the capabilities file and write it to the file system

<- Streams are listed here

<- This caps file has 1 stream called "streams1"

<- This caps file has 1 control called "control1"

<- This caps file has messages enabled

<- The "from-device" box holds messages from the device to goHACK.me

<- The "to-device" box holds messages for the device from goHACK.me

Set the Caps File

Use the ghm_capabilities command to set the caps file for use with goHACK.me as shown below.

WiConnect Commands Description

ghm_capabilities set slave_caps.json

<- Set the caps file to use with goHACK.me


If you do not already have an account on the goHACK.me website, go to goHACK.me and create a free account. Activate the board with goHACK.me by using the ghm_activate command.

WiConnect Commands Description

ghm_activate <email@address.com> <yourpassword>

<- Requires a gHm account

Open a web browser and connect to goHACK.me, and login. Select the Device tab in the vertical column at the left of the webpage and your device appears.

Write Streams & Read Controls

Now for some fun! Enter the following commands one-by-one, taking note of the instructions in the right-hand column.

WiConnect Commands Instructions

get ghm.status
get ghm.capabilities
ghm_write stream1 239
ghm_read control1

ghm_read control1

1. Verify your device is activated with goHACK.me
2. Verify the name of the capabilities file in use
3. Write the value '239' to stream1
4. Synchronize with goHACK.me; the value of Stream 1 changes on goHACK.me
5. Read the value of control1; it is the same as the value on goHACK.me
6. On the goHACK.me website, change the value of 'My Control'
7. Synchronize with goHACK.me (push stream samples and pull controls)
8. Read the updated value of control1

Send a message to goHACK.me

WiConnect Commands Description

ghm_message post
stream_write 0 5
stream_write 0 7
stream_close 0

<- Get ready to post a message to goHACK.me
<- Send the start of the message "Hello"

<- Send the rest of the message  " there!"

<- Finish & close out the message 

Read a message from goHACK.me

To read messages from goHACK.me, you first have to use goHACK.me to send a message. Setup a message entry board on goHACK.me as follows ...

WiConnect Commands Description

ghm_message list
ghm_message get 0
stream_read 0 100

<- Get a list of any messages waiting to be read
<- Get #0 message; opens with stream handle 0
<- Read up to 100 bytes of stream handle 0

For completeness, the following text provides an example session log of reading a message from goHACK.me.

WiConnect Session Log - Reading a Message

> ghm_message list
Request GET /api/token/messages/to-device/index
Connecting (https): api.gohack.me:443
Starting TLS
HTTP response: 200
! # Message ID                           Timestamp     Length
# 0 0ee16f11-bff0-42b6-b022-9f93a7b4c768 1407160356842 0x0018
> ghm_message get 0
Request GET /api/token/messages/to-device/0ee16f11-bff0-42b6-b022-9f93a7b4c768/body/text
Connecting (https): api.gohack.me:443
Starting TLS
HTTP response: 200
[2014-08-04 | 14:10:41: Opened: 0]
> stream_read 0 100
Hello from goHACK.me!
[2014-08-04 | 14:10:45: Closed: 0]

Change Log

ModifiedChangesWiConnect Version