1.0.2 • Published 3 years ago

lx-gwbuilder v1.0.2

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

GW Builder - Weather Data Submission Tool

This package is purposed to submit weather data to a weather server using the gWeather protocol. It supports data sorting on a minutely basis and a few basic field types the weather data can stored into.

Usage

Installation

You can install the package in the usual way by running

> yarn add lx-gwbuilder

or

> npm i lx-gwbuilder

Make sure that needle is installed as project dependency.

Integration

First, create a builder instance:

const GwBuilder = require('lx-gwbuilder');

const builder = new GwBuilder(
	"<client-id>",
	"<client-secret>",
	"<host>", // Optional, defaults to "localhost"
	"<path>"  // Optional, defaults to "/gweather"
);

The builder now can be filled with sensor data and measurements. The following describes a general workflow:

builder.CreateSensor(builder.SensorType.Out, "My Outdoor Sensor")
	.AddMeasurement(builder.FieldType.Temperature,		12.0)	// 12.0°C
	.AddMeasurement(builder.FieldType.Humidity,			22  )	// 22%
	.AddMeasurement(builder.FieldType.WindSpeed,		 6.3)	// 6.3 km/h
	// Above defaults to sensor creation minute. 
	// Other identical fields will overwrite the value

	// Below inserts into the full minute at a given UNIX timestamp.
	// Different minute signatures will NOT overwrite each other.
	.AddMeasurement(builder.FieldType.Temperature,		-2.5, 1641819658)

Notice: Values should be unit normalized with the gWeather Protocol. See field reference for unit details

If the data injection is complete, the results can be submitted to the server by simply calling

builder.Submit()

Alternatively, you can submit or work with the data yourself by getting the serialized struct with builder.Serialize()

Class Reference

GwBuilder

Constructor

const builder = new GwBuilder(client_id, client_secret, host, path)
ParameterDescription
client_id: stringThe assigned client ID on the wather server
client_secret: stringThe assigned client secret on the weather server
host: stringHTTPS weather server host name.*Defaults to localhost*
path: stringHTTPS weather server path on given host*Defaults to /gweather*

Methods

builder.ParamsDescription
CreateSensor(...)type: SensorTypename: stringreturns :GwSensorCreates a new sensor The sensor variant typeDisplay Name of the sensorThe newly created sensor
Serialize()returns :objectSerializes the structure to regular JS object Serialized object
Submit()returns :PromiseSubmits the struct to the provided serverResolves with the submission result

Fields

builder.Description
SensorType.InIndoor Sensor
.OutOutdoor Sensor
.WaterWater Sensor
FieldType.TemperatureUnit: °C
.LightUnit: LUX
.HumidityUnit: %
.BarometerAbsoluteUnit: mb/hPa
.BarometerRelativeUnit: mb/hPa
.WindDirectionUnit: °
.WindSpeedUnit: km/h
.WindGustUnit: km/h
.UVUnit: UVi
.RainRateUnit: mm
.RainRateDailyUnit: mm
.SolarRadiationUnit: W/m²
.SoilMoistureUnit: %

GwSensor

Methods

sensor.ParamsDescription
AddMeasurement(...)field: FieldTypevalue: number time: numberreturns* :GwSensorInserts or updates new sensor information The field information typeNumeric value matching the field unit(Optional) Timestamp of the data set.The newly created sensor
Serialize()returns :objectSerializes the sensor to regular JS object Serialized object

Dependencies