IoT Websocket Server
This component is used to support actuations over websocket protocol. It is an alternative for mqtt protocol.
Server listens on determined port. It uses 'echo-protocol' for receiving and sending requests.
Websocket client also has to use 'echo-protocol'. After the establishment of connection client has to send initial json object message:
Key | Description |
type | type of message, always "device" for clients |
deviceId | identifier of your device in iotkit database |
deviceToken | token of device which is received after activation |
Example json message:
{
"type": "device",
"deviceId": <deviceId>,
"deviceToken": "eyJ0eXA....asdfwefadA"
}
Basic response codes:
Code | Description |
401 | "Invalid device token" or "Wrong message format" |
500 | Internal server error |
200 | Subscribed to ws server |
1024 | Received actuation message |
Example of actuations message:
{
"code":1024,
"content": {
"type":"command",
"transport":"ws",
"content": {
"accountId":"c4715841-bb1e-4c87-ad78-2376fe596a11",
"deviceId":"example001",
"gatewayId":"example001",
"componentId":"1e447b10-9afd-4221-b4d8-7bc5c5bb6c3f",
"command":"LED.v1.0","params":[{"name":"LED","value":"1"}]
}
}
}
More informations about websockets on website https://github.com/theturtle32/WebSocket-Node/blob/master/docs/index.md
Pre-requirements
-
Node.js v0.10.x
-
grunt-cli
- npm install grunt-cli
-
Git
-
Cloud Foundry CLI and Trusted Analytics Platform account (https://github.com/trustedanalytics)
Requirements to run
- Generate a pair RSA keys and put your public keys in ./keys/ directory as public.pem
https://github.com/trustedanalytics)
On Trusted Analytics Platform (Before installation, make sure that you are logged into Trusted Analytics Platform with command:
cf login
-
Create instances with specified name for each of required services from marketplace:
- PostgreSQL 9.3 or newer with name mypostgres
-
Create following user-provided services with properties filled with real values:
cf cups websocket-ups -p "{\"username\":\"${USER}\",\"password\":\"${PASSWORD}\"}"
-
Executing ./cf-deploy.sh in main repository catalog builds package and pushes it to CF as an app with name {SPACE}-dashboard where space is currently selected space by cf t -s "SPACE"
-
Check logs and wait for application start.