Skip to content

Websocket Server

Websocket Server

Where can you find it
Websocket Server is placed under the Data Connector menu.

Find

ResIOT has a websocket at your disposal that you can access in order for you to keep track of all your device communications. This is the address of your websocket:

Your Address

You can also find the URL in the "Real Time Monitor" page of your application server. Meanwhile there is a websocket used to keep track of the various action on the platform. This is the address of the websocket:

Your Address

Every device communication is sent via a JSON formatted string.

{
    "Connector": string,        --The Connector ID the communication has been received on
    "MsgType": string,          --The type of communication recognized
    "AppEui": string,           --The Application EUI of the device communicating
    "DevEui": string,           --The Device EUI of the device communicating
    "Port": string,             --The communication port used for the communication
    "GatewayEUIs": []string,    --The gateways EUIs that received the communication
    "Payload": string,          --An hex encoded representation of the payload
    "Extra": []{                --An array containing all the additional "Custom" data configured on the connector
        "fieldname": string,    --The label in your "Custom" field in the connector data pattern
        "fieldvalue": string    --The matched value
    },
    "DT":                       --Time the communication has been sent or received from the network server
}

Of course, depending on the type of the communication received, some of the fields can be empty or nil.

Here's an example of a gateway alive communication.

{
    "CommType": "comm_gwalive",
    "Connector": "69643d3139",
    "AppEui":"",
    "DevEui":"",
    "Port":"",
    "GatewayEUIs":["218000AC0000a05f"],
    "Payload":"",
    "Extra":{},
    "DT":"2017-06-15T09:17:11.2072656+02:00"
}

Here's an example of a join request.

{
    "CommType":"comm_join",
    "Connector":"636f6e313332",
    "AppEui":"006c3b194374ac7f",
    "DevEui":"0732227a557d8679",
    "Port":"",
    "GatewayEUIs":[],
    "Payload":"",
    "Extra":{},
    "DT":"2017-06-15T09:36:20.6935937+02:00"
}

Or a simple Rx communication.

{
    "CommType":"comm_rx",
    "Connector":"636f6e313332",
    "AppEui":"006c3b194374ac7f",
    "DevEui":"0732227a557d8679",
    "Port":"128",
    "GatewayEUIs":["218000AC0000a05f"],
    "Payload":"9b690291010f1b2401ce01c0",
    "Extra":{
        "adr":"true",
        "channel":"4",
        "duplicate":"false",
        "frequency":"867.3",
        "modBW":"125",
        "rssi":"-18",
        "seqno":"1953",
        "sf":"7",
        "snr":"9.5"
    },
    "DT":"2017-06-15T09:36:46.5295312+02:00"
}

And a downlink tx. Also note this is not how to send a tx via the socket, this is how a downlink sent via the platform will appear on your communication log.

{
    "CommType":"comm_tx",
    "Connector":"636f6e313332",
    "AppEui":"006c3b194374ac7f",
    "DevEui":"0732227a557d8679",
    "Port":"1",
    "Payload":"2525",
    "Command":"",
    "Reference":"",
    "Confirmation":false,
    "Extra":{
        "priority":0,
        "window":"BOTH"
    },
    "DT":"2017-06-15T09:41:09.6691796+02:00"
}

Sending a Downlink with the WebSocket

The WebSocket allows you to communicate with your devices using the following JSON command:

{
    "function": string,     --The action you want to perform. So far only 'TX' is allowed. Required
    "Payload": string,      --Your payload. This has to be hex encoded if Raw is false. See below
    "AppEui": string,       --The Application EUI of the device you want to reach. Required
    "DevEUI": string,       --The Device EUI of the device you want to reach. Required
    "Connector": string,    --The connector you want to use to reach your device. If left empty, the most suitable one will be chosen by ResIOT
    "Port": number,         --The communication port you want to use for the communication. Required
    "WSCommand": string,    --The WebSocket command. Used only if you're trying to use a WebSocket connector
    "Reference": string,    --A reference used by the server when confirming(comm_tx) the reception of your communication by the node.
    "Raw": boolean,         --If set to false, the Payload has to be hex encoded. False if omitted
    "Confirm": boolean,     --If set to true, the Network server will send a tx_confirm message when the node has received your communication. False if omitted
}

So, let's say you want to reach a node with the payload "HI!". All you have to do is sending this json to your socket:

{
    "function": "TX",
    "Payload": "HI!",       --or "Raw": false, and "Payload": "484921"
    "AppEui": "ABCDEF1234567890",
    "DevEui": "0987654321ABCDEF",
    "Connector": "",
    "Port": 50,
    "Reference": "abcdefgh",
    "Raw": true,
    "Confirm": true
}

The websocket will finally answers with a JSON if the command has been run correctly

{

    "Result": "Success",        --The result of your request. Can either be 'Fail' or 'Success'
    "Details": "",              --The error description in case Result is 'Fail'
    "Reference": "abcdefgh"     --The reference of your request, if set
}

Please notice a "Success" result does not necessarely mean the communication has been received by the network server. It only means your downlink request was correct and that an attempt to contact the server has been made successfully.

How to connect to a WebSocket (Example):

  1. - Take your WebSocket Address(Top of this page)
  2. - Visit the site www.websocket.org and paste the URL into the Location field then click on Connect.
  3. - You are now connected to the WebSocket! You can send messages or just read what pass through there.

Find Find

Usage
Websocket Server Page contains some examples of JSON files that describes how communication between devices and Websocket works.