npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

sensordata-websocket

v1.2.8

Published

This package allows for easy websocket connection to sensordata.space, where data can be stored for various graphical representations.

Readme

Sensordata-WebSocket

This package allows for easy websocket connection to sensordata.space, where data can be stored for various graphical representations.
The devices can also receive commands and event changes from the server, which can be used to control the devices.

How to use it

Installation

npm install sensordata-websocket

Initialization

import SocketClient from 'sensordata-websocket';

or 

const SocketClient = require('sensordata-websocket');

Create a new instance of the SocketClient class

const sensordataClient = new SocketClient();

Declare communication functions

sendStatus()

This function specifies the status that is to be sent to the server.
The status is a flat json object of numbers | strings | booleans.
It is recommended that the status is a global variable, so that it can be easily modified.
Each property of the status object will represent an entity of the device.

let status = {
    count: 0,
    led: false,
}

function sendStatus() {
    // here you can modify the status object
    // and then return it
    return status;
}

receivedCommand()

This function is called when a command is received from the server.
The command provided is a string value.

function receivedCommand(command) {
    console.log(`Received command: ${command}`);
    if (command === "increment") {
        status.count++;
    } else if (command === "decrement") {
        status.count--;
    }
}

entityChanged()

This function is called when an entity is changed on the server.
The device is informed of the new value of the entity.

function entityChanged(entity, value) {
    console.log(`Entity "${entity}" changed to ${value}`);
    if (entity === "led") {
        status.led = value;
    }
}

Connect to the server

Each instance you are running, represents a device on the server.
Each device has a mac-address that is automatically acquired from the sensordata-websocket library.
That means that you cannot run multiple instances on the same machine, because they will have the same mac-address.

Also, in order to authenticate the device, you need to provide a token that is provided by the server on your user-profile page.

The following code connects the communication functions to the sensordataClient instance, passing the device object, and then it connects to the server.

function main() {
    const device = {
        deviceApp: "Example JS device",
        version: "1.0.0",
        deviceType: "PC",
        token: process.env.DEVICE_TOKEN,
    }

    sensordataClient.setSendStatusFunction(sendStatus);
    sensordataClient.setReceivedCommandFunction(receivedCommand);
    sensordataClient.setEntityChangedFunction(entityChanged);
    sensordataClient.setDevice(device);
    sensordataClient.init("api.sensordata.space", 443, true);
}

main();

Send status to the server

Anytime you want to send the status to the server, you can call the sendStatusWithSocket method like so:

const saveToDB = false;
sensordataClient.sendStatusWithSocket(saveToDB);

This method internnally calls the sendStatus function (created earlier), to get the current status and then it sends the status to the server.

sendNotification(message, data)

This function sends a notification to the server. According to the notification service that you have chosen, the notification will be sent to the user either with expo notifications or pushover.

const message = "This is a notification message";
const options = {
    // ...pushover options (only if you are using pushover)
}
sensordataClient.sendNotification(message, options);

sendLog(message)

This function sends a log message to the server. The log message will be saved in the database and can be viewed in the logs section of the device settings.

const message = "This is a log message";
sensordataClient.sendLog(message);

Examples

Check out the examples folder for detailed usage scenarios: