Device Communication Protocols
We support a few protocols for devices to communicate with Fostrom. The only caveat is that all protocols are only available over TLS (for now). See below for more information.
We support MQTT
, MQTT over WebSockets
, and HTTP
. Along with that, we developed our own protocol (codenamed Moonlight
), which our Device SDKs use.
The API
Fostrom has a simple API for devices to use. Regardless of the protocol you choose, all protocols support the following API:
heartbeat
- Send a heartbeat to Fostromsend_data
- Send data to Fostromsend_msg
- Send a message to Fostromget_mailbox_size
- Get the size of the mailbox for this devicefetch_next_msg
- Fetch the next message in the device's mailboxack_msg
- Acknowledge a message received from Fostrom. Removed from the mailbox.reject_msg
- Reject a message received from Fostrom. Removed from the mailbox.requeue_msg
- Requeue a message received from Fostrom
Additionally, connecting to Fostrom and closing a connection is protocol-specific.
Connecting and Authenticating
For MQTT, the CONNECT
packet is sent with the device credentials along with some options. For HTTP, the device credentials and options are sent in the headers.
Closing the Connection
For MQTT, closing the connection can be done by sending the DISCONNECT
packet, however it is not strictly required. Simply terminating the connection has the same effect. HTTP connections end when the response is sent.
Choosing the right protocol
The choice of picking the protocol can be made based on:
- whether you need a persistent connection from the device to Fostrom
- whether you can open a TCP socket on the device
Many IoT devices run on battery power and it may not be feasible keep them continously connected to Fostrom. In such cases, we recommend using MQTT (over TCP/TLS) with Keep-Alive: 0
. Set the Offline Threshold accordingly in the Device's Settings pane on Fostrom. A longer value will allow a device to connect less frequently, as it will show as active as long as it connected at least once within the threshold.
If an open connection is valuable (such as to receive messages from Fostrom in realtime), then you should ideally use MQTT with a Keep-Alive of 30 seconds. To keep the connection from terminating you would need to send heartbeats (which most MQTT clients will do automatically) or another packet within the time window.
Fostrom also supports MQTT over WebSockets, which can be useful if you can't open a TCP socket on the device or can't connect to port 8883. This could be useful for devices that are behind an HTTP-only firewall. You can also use HTTP instead.
A note on security
Fostrom currently only supports TLS-based security. All device connections to Fostrom must be made over TLS for all protocols. That means MQTTS
, WSS
, and HTTPS
.
We do understand that TCP and TLS prove to be quite heavy for many IoT devices. We're working on something to mitigate this issue. If this is a blocker for you, contact us and let us know your requirements.