fostrom

0.0.9 • Public • Published

Fostrom Device SDK

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.

Example

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.

A Note on the Device Agent

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.

Package Sidebar

Install

npm i fostrom

Weekly Downloads

6

Version

0.0.9

License

MIT

Unpacked Size

14.6 kB

Total Files

4

Last publish

Collaborators

  • arjunbajaj
  • siddhantdhaware