This Typescript package implements the message validation for the EN50491-12-2 "S2" standard for home and building energy management. This implementation is based on the description of the protocol provided in the s2-ws-json repository.
S2-typescript is the library implemented from s2 standard.
npm install s2-typescript
Import the classes needed.
import {
FrbcStorageDescription,
NumberRange,
parseMessage
} from 's2-typescript';
Create instances of classes passing the parameters in an object.
const storageDescription = new FrbcStorageDescription({
diagnostic_label: 'Electric car battery',
fill_level_label: 'mAh',
provides_leakage_behaviour: true,
provides_fill_level_target_profile: true,
provides_usage_forecast: false,
fill_level_range: {start_of_range: 15000, end_of_range: 20000}
});
Open websocket conections using the class.
import { WebSocketServerController } from 's2-typescript';
//Indicate the port or url conection.
const ws = new WebSocketServerController(8000);
Serialize message objects using the JSON library and send through the websocket connection.
const status = new FrbcStorageStatus({
present_fill_level: 18000
});
const serializedStatus = JSON.stringify(status);
ws.BroadcastMessage(serializedStatus);
Deserialized json objects received throught the websocket using the parseMessage function. An instance of the corresponding class of the message will be created.
import { parseMessage } from 's2-typescript';
const deserializeStatus = parseMessage(serializedStatus);
const currentFillLevel = deserializeStatus.present_fill_level;