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 JavaScript works in Node.js and Bun, on Linux and macOS, and helps you quickly integrate, start monitoring, and controlling your IoT devices in just a few lines of code.
import Fostrom from 'fostrom';
const fostrom = new Fostrom({
fleet_id: "<fleet-id>",
device_id: "<device-id>",
device_secret: "<device-secret>",
})
// Setup the on_mail handler, to process incoming mail.
fostrom.onMail = async (mail) => {
const {id, name, payload, mailbox_size} = mail
console.debug(`Received Mail (${mailbox_size}): ${name} ${id}`)
await mail.ack()
}
async function main() {
await fostrom.connect()
// To send a message to Fostrom
await fostrom.sendMsg("<packet-schema-name>", { ...payload })
// To send a datapoint to Fostrom
await fostrom.sendDatapoint("<packet-schema-name>", { ...payload })
}
main()
Please note, to use import Fostrom from 'fostrom';
you'll need to set "type": "module"
in package.json
.
The Fostrom Device SDK downloads and runs the Fostrom Device Agent in the background. The Agent is downloaded when the package is installed through npm
. The Device Agent is started when fostrom.connect()
is called, 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, you can call Fostrom.stopAgent()
in your code before terminating your program.