Real-time API
using websockets
Lefteris Chatzipetrou
Last Update 5 maanden geleden
In order to achieve more efficient and fast communication, the websocket service of HAM Systems cloud can be used. With the websocket API, you can subscribe to specific devices and every time new data is sent from end-devices you will get updated immediately. You can also issue commands directly from the same connection that can also improve latency.
How does it work
- Open a websocket connection to device node server (usually wss://node0.hamsystems.eu, can be found from the get_user_devices.php endpoint)
- Send api_key or access_token to authenticate.
- You are now connected to the websocket server and can issue commands. e.g. SUBSCRIBE
NodeJS client code
A sample implementation of the websocket API for NodeJS can be found here.
- Extract the archive
- Change the 'API_KEY' to your api key you can get from your user settings page
- Run:
example.js
In case you want to use a different programming language or environment you can check the code in hamapi.js and port it. It is straightforward.
What data do you get from the API?
The API will return all state changes including readings, outputs and settings. Information on device state and commands can be found here