Fostrom (Fostrom v0.0.6)
Fostrom is an IoT Cloud Platform built for developers. Monitor and control your fleet of devices, from microcontrollers to industrial IoT. Designed to be simple, secure, and fast. Experience first-class tooling with Device SDKs, type-safe schemas, programmable actions, and more.
The Fostrom Device SDK for Elixir works on Linux and macOS, and helps you quickly integrate, start monitoring, and controlling your IoT devices in just a few lines of code.
Installation
The package can be installed by adding fostrom
to your list of dependencies in mix.exs
:
def deps do
[
{:fostrom, "~> 0.0.1"}
]
end
Configuration
# Add in config/config.exs or config/runtime.exs:
config :fostrom, :config,
fleet_id: "<fleet-id>",
device_id: "<device-id>",
device_secret: "<device-secret>",
env: Config.config_env(),
handler: MyApp.FostromHandler
Defining a Handler
defmodule MyApp.FostromHandler do
use Fostrom.Handler
# handle_mail needs to return either :ack, :reject, or :requeue
def handle_mail(%Fostrom.Mail{} = mail) do
# process the mail here
:ack
end
end
Sending Datapoints and Messages
# To send a datapoint:
Fostrom.send_datapoint("<packet-schema-name>", %{ ...payload })
# To send a message:
Fostrom.send_msg("<packet-schema-name>", %{ ...payload })
A Note on the Fostrom Device Agent
The Fostrom Device SDK downloads and runs the Fostrom Device Agent in the background. The Agent is downloaded when the library is first compiled. The Device Agent is started when your Elixir Application starts, and it remains running in the background forever.
We recommend you allow the Device Agent to run continously, even if your program has exited or crashed, so that when your program is automatically restarted by a process manager, the reconnection to Fostrom is nearly instant. However, if you wish to stop the Device Agent manually, you can call Fostrom.DeviceAgent.stop()
in some terminate()
callback in your application.
Summary
Functions
@spec send_datapoint(String.t(), map() | nil) :: :ok | {:error, Fostrom.Exception.t()}
Send a Datapoint to Fostrom
Takes the packet schema name and a payload. Payload must be a map, and is required to send datapoints.
Note
Ensure the packet schema exists and is for a datapoint.
@spec send_msg(String.t(), map() | nil) :: :ok | {:error, Fostrom.Exception.t()}
Send a Message to Fostrom
Takes the packet schema name and a payload. Payload must either be a map or nil.
Note
Ensure the packet schema exists and is for a message.