lx-gwbuilder
v1.0.2
Published
Submission tool for gWeather protocol weather data submission
Downloads
2
Readme
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)
| Parameter | Description |
|--|--|
| client_id
: string | The assigned client ID on the wather server |
| client_secret
: string | The assigned client secret on the weather server |
| host
: string | HTTPS weather server host name.Defaults to localhost |
| path
: string | HTTPS weather server path on given hostDefaults to /gweather |
Methods
| builder.
| Params | Description |
|--|--|--|
| CreateSensor(...)
| type
: SensorTypename
: stringreturns :GwSensor
| Creates a new sensor The sensor variant typeDisplay Name of the sensorThe newly created sensor |
| Serialize()
| returns :object
| Serializes the structure to regular JS object Serialized object |
| Submit()
| returns :Promise
| Submits the struct to the provided serverResolves with the submission result |
Fields
| builder.
| | Description |
|--|--|--|
| SensorType
| .In
| Indoor Sensor |
| | .Out
| Outdoor Sensor |
| | .Water
| Water Sensor |
| FieldType
| .Temperature
| Unit: °C |
| | .Light
| Unit: LUX |
| | .Humidity
| Unit: % |
| | .BarometerAbsolute
| Unit: mb/hPa |
| | .BarometerRelative
| Unit: mb/hPa |
| | .WindDirection
| Unit: ° |
| | .WindSpeed
| Unit: km/h |
| | .WindGust
| Unit: km/h |
| | .UV
| Unit: UVi |
| | .RainRate
| Unit: mm |
| | .RainRateDaily
| Unit: mm |
| | .SolarRadiation
| Unit: W/m² |
| | .SoilMoisture
| Unit: % |
GwSensor
Methods
| sensor.
| Params | Description |
|--|--|--|
| AddMeasurement(...)
| field
: FieldTypevalue
: number* time
: numberreturns :GwSensor
| Inserts 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 :object
| Serializes the sensor to regular JS object Serialized object |
Dependencies
- needle@3.1.0 by tomas