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

The websocket API process is as follows:
  1. Open a websocket connection to device node server (usually wss://node0.hamsystems.eu, can be found from the get_user_devices.php endpoint)
  2. Send api_key or access_token to authenticate.
  3. 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

  1. Extract the archive
  2. Change the 'API_KEY' to your api key you can get from your user settings page
  3. 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

Was this article helpful?

0 out of 0 liked this article

Still need help? Message Us