1.1.1 • Published 4 years ago

morning-sun v1.1.1

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

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

NameTypeDefaultValues
offLineQueueingBooleantruetrue, false
offlineQueueDropBehaviorString'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

1.1.1

4 years ago

1.1.0

4 years ago

1.0.12

4 years ago

1.0.11

4 years ago

1.0.10

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago