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 🙏

© 2024 – Pkg Stats / Ryan Hefner

morning-sun

v1.1.1

Published

Real-time tracking for IoT devices.

Downloads

33

Readme

Morning Sun npm version license

Real-time tracking for photovoltaic panels.

Install

npm i --save morning-sun

Usage

const msunIot = require('morning-sun');

const config = {
  apiKey: 'your-api-key',
  deviceId: 'your-device-id'
};

const msun = msunIot(config);

async function run() {
  await msun.init();

  var data = yourFunctionThatReturnsSensorValues();

  msun.publish(data);
}

run();

Table of contents

Config Object

Your config object must contain your account email, Api key, and Device ID

const config = {
  apiKey: 'your-api-key',
  deviceId: 'your-device-id'
};

Options

| Name | Type | Default | Values | | ------------------------ | ------- | -------- | ------------------ | | offLineQueueing | Boolean | true | true, false | | offlineQueueDropBehavior | String | 'oldest' | 'oldest', 'newest' |

offLineQueueing

Queues the data/logs when they fail to be published.

offlineQueueDropBehavior

The drop behavior when the queue is full.

The oldest option will remove values that were first added to the queue, and the newest will remove values that were recently added to the queue.


The default config object would look like this

const config = {
  apiKey: 'your-api-key',
  deviceId: 'your-device-id',
  offLineQueueing: true,
  offlineQueueDropBehavior: 'oldest'
};

back to top

Features

  1. Publish data

You can publish sensor values (voltage, current, power, and charge rate) from your devices.

  1. Logging

You can log events with different levels (critical, error, warning, info)

back to top

API

.init()

Requests a jsonwebtoken to the server and stores it in the config object. You must call this function before publishing any data.

await msun.init();
.publish(data)

Publishes a data object.

The data object must be formatted correctly.

var data = {
  voltage: 9.5,
  current: 0.41,
  power: 3.895,
  chargeRate: 43.8
};

The values will be converted into two digits before decimal point.

.sleep(ms)

The sleep method returns a Promise after ms

await msun.sleep(1000);
.getTime()

Returns an object with two keys.

const { today, now } = msun.getTime();
{
  today: 2019-11-09
  now: 03:52:35
}
.log.critical(message)
.log.error(message)
.log.warning(message)
.log.info(message)

Creates a log with the message provided.

msun.log.critical('Somethings went wrong!');
msun.log.error('Your error message');
msun.log.critical('Your warning message');
msun.log.critical('Normal information');

back to top

Example

const msunIot = require('morning-sun');

const config = {
  apiKey: 'your-api-key',
  deviceId: 'your-device-id'
};

const msun = msunIot(config);

async function run() {
  await msun.init();

  msun.log.info(`Device(${deviceId}) is starting to send values.`);

  while (true) {
    var data = yourFunctionThatReturnsSensorValues();

    msun.publish(data);

    if (data.power > 50) {
      msun.log.warning(`Current: ${data.current}`);
    }

    await msun.sleep(5000);
  }
}

run();

back to top