Quick start

Here’s how you set up communication between a group of devices and your business software through flespi gateway.

• See the information below to find the shortest way to start using the platform.
• If you need more detailed description please follow the link and find out flespi show and tell in 10 minutes.
• To get the full overview of API used in these steps take a look at API guidelines.
• If you need connect device to flespi please try our connect device how-to.

1

Create a channel

POST
flespi.io/gw/channels?data=[{“protocol_id”:1,”name”:”test_channel”}]

The entire request using command-line Curl tool:

curl -X POST --header 'Content-Type: application/json' --header 
                                        
'Authorization: FlespiToken XXXXXXXX' -d' [{"name":"test_channel","protocol_id":1}]'
'https://flespi.io/gw/channels'

XXXXXXXX: To get your personal authorization token visit our registration page. After regisration you can create new tokens using TOKENS tab. Find detailed description of token manipulations in platform API documentation.

Protocol ID = 1 corresponds to simple “echo” protocol used for testing purposes. It replies to every incoming message with the data received bypassing parsing operations.

Find more information about the options in REST API docs

Reply:
{
    "result": [
        {
            "enabled": true,
            "id": 1,
            "name": "test_channel",
            "protocol_id": 1,
            "uri": "flespi.io:9876"
        }
    ]
}

Following the request a channel named “test_channel” with an id=1 will be created. The channel starts listening flespi.io:9876 for incoming connections from tracking devices sending data using protocol with id=1. The list of all the integrated protocols and their identifiers is available by:

GET
flespi.io/gw/protocols/all
curl -X GET --header 'Authorization: FlespiToken XXXXXXXX' 
            
'https://flespi.io/gw/protocols'

View request in REST API

If you have special devices that use protocols not yet supported by flespi gateway, please e-mail us at info@flespi.com.

2

Configure tracking devices to send data to

flespi.io:9876

Hint: you can emulate tcp connection to "echo"-protocol channel with telnet: write your message, hit Enter, and the channel will reply with your message.

telnet flespi.io 9876
                                        
                                    
3

Verify that the device is successfully connected to the host:port provided

GET
flespi.io/gw/channels/1/connections/all
curl -X GET --header 'Authorization: FlespiToken XXXXXXXX'
            
'https://flespi.io/gw/channels/1/connections/all'

View request in REST API

Reply:
{
    "result": [
        {
            "channel_id": 1,
            "established": 1487155758,
            "id": 1,
            "ident": "123456789",
            "ip": "1.2.3.4",
            "terminal": false
        }
    ]
}

The reply means that a device with “123456789” identification string (which may be IMEI, phone number, serial number, etc.) established connection with id=1 to channel with id=1 on Friday Dec 23 2016 08:52:43 GMT +0300, from IP address 1.2.3.4.

4

Get unified messages from devices
on channel 1

GET
flespi.io/gw/channels/1/messages?data={"timeout":10}

You can send REST API request in a push-mode: in case if there is no messages in message buffer request hangs for timeout value.

#!/bin/bash
                                        
while [ "true" ]; do
echo "perform the request to flespi.io with 10 seconds timeout"
FLESPI_RESPONSE=$(curl -s -X GET --header 'Authorization: FlespiToken XXXXXXXX' -d '{"timeout":10,"curr_key":'$CURR_KEY'}' 'https://flespi.io/gw/channels/1/messages')
# get timestamp NEXT_KEY from response for the next request
NEXT_KEY=$(echo $FLESPI_RESPONSE | jq -r '.next_key')
if [ "$NEXT_KEY" != "null" ]; then
CURR_KEY=$NEXT_KEY # remember NEXT_KEY # show response result parsed with json tool echo $FLESPI_RESPONSE | jq
fi
done

View request in REST API

Reply:
{
    "result": [
        {
            "ident": "123456789",
            "lat": 40.780911,
            "lon": -73.962084,
            "adc_1": 44,
            "adc_2": 299,
            "io_12": 11764,
            "channel_id": 1,
            "timestamp": 1487159220,
        },
        {
            "ident": "123456789",
            "lat": 40.781788,
            "lon": -73.963694,
            "adc_1": 45,
            "adc_2": 280,
            "io_12": 11964,
            "channel_id": 1,
            "timestamp": 1487159225,
        },
        {
            "ident": "123456789",
            "lat": 40.783649,
            "lon": -73.964810,
            "adc_1": 44,
            "adc_2": 322,
            "io_12": 11794,
            "channel_id": 1,
            "timestamp": 1487159230,
        },
        {
            "ident": "123456789",
            "lat": 40.784112,
            "lon": -73.966344,
            "adc_1": 44,
            "adc_2": 314,
            "io_12": 11947,
            "channel_id": 1,
            "timestamp": 1487159235,
        },
        {
            "ident": "123456789",
            "lat": 40.784599,
            "lon": -73.966108,
            "adc_1": 41,
            "adc_2": 311,
            "io_12": 11941,
            "channel_id": 1,
            "timestamp": 1487159240,
        },
        {
            "ident": "123456789",
            "lat": 40.785046,
            "lon": -73.965529,
            "adc_1": 40,
            "adc_2": 303,
            "io_12": 11934,
            "channel_id": 1,
            "timestamp": 1487159245,
        }
    ],
    "next_key": 1487159220
}
5

Ready to try? Let's go!