@1st-setup/openthermgateway 中文文档教程

发布于 4年前 浏览 23 项目主页 更新于 3年前

这是一个 NodeJS 模块,能够连接到 Opentherm 网关 (OTGW)

使用方法:见openthermgw_example.js

Install

npm install @1st-setup/openthermgateway

Usage:

Listening to traffic coming from OTGW:

const openthermGatway = require('@1st-setup/openthermgateway');

var myOTGW = new openthermGatway("/dev/ttyUSB0",null, {debug:true});
myOTGW.on("error", (err) => {
    console.error(err.toString());
});

myOTGW.on("exception", (err) => {
    console.error(err.toString());
});

myOTGW.on("inError", (err) => {
    console.error(err.toString());
});

myOTGW.on("otgwError", (err) => {
    console.error(JSON.stringify(err,null,"\t"));
});

myOTGW.on("initialized",() => {
    console.log("Initialized");
    myOTGW.sendCommand("PS=0",(err, response) => {

    });
})

myOTGW.on("connected",() => {
    console.log("Connected");
})

myOTGW.on("otgwData",(data) => {
    console.log("otgw >> "+JSON.stringify(data,null,"\t"));
    console.log("otgw.data >> "+JSON.stringify(myOTGW.data,null,"\t"));
})

myOTGW.on("printSummary",(data) => {
    console.log("printSummary >> "+JSON.stringify(data,null,"\t"));
})

Sending commands to OTGW (see: OTGW Serial commands):

const openthermGatway = require('@1st-setup/openthermgateway');

var myOTGW = new openthermGatway("/dev/ttyUSB0",null, {debug:true});

// To get About opentherm gateway (prints the welcome message) 
myOTGW.sendCommand("PR=A", (err, response) => {
    if (err) {
        console.error(`Error sending command: Error:${err}`);
    }
    else {
        console.log(`Response to command PR=A: ${response}`);
    }
})

Class openthermGatway

Methods:

Constructor(serialDevice, serialOptions, otgwOptions)

当你使用new创建一个新的openthermGateway对象时调用

输入:

  • serialDevice:包含串行设备完整路径的字符串。 例如:“/dev/ttyUSB0”

  • serialOptions:对象包含'serialport'模块的openOptions

  • otgwOptions:具有以下属性的对象:

    • debug: Boolean. When 'true' all incoming and outgoing trafic on serial interface will be logged to console.

sendCommand(data, cb)

发送命令

使用此方法,您可以向 OTGW输入

  • :数据:具有有效 OTGW 串行命令。 例如:“PR=A”

  • cb:当发送命令收到响应时将调用的回调函数。 使用以下参数调用回调函数:

    • err: Object containing the error encountered.
    • response: The response from the OTGW on the send command.

decode(data)

使用此方法,您可以解码从 OTGW 接收的数据、消息。

输入:

  • data: String with the message received from the OTGW.

输出:

  • 带有解码消息的对象或错误时为空。 对象将具有以下属性:

    • 状态:指定消息生成内容的字符。

      • "R": "Gateway to boiler"
      • "B": "From boiler"
      • "T": "From thermostat"
      • "A": "Gateway to thermostat"
    • direction: 字符串,说明是什么生成了消息。

    • msgType:指定消息类型的十六进制代码。

    • msgTypeStr:msgType 的字符串。 目前只有:“Read-Ack”或“Read-Data”。

    • id:十六进制代码,指定值来自哪个 opentherm id。

    • idStr:带有 id 解释的字符串。 当 id 未知时,这将被设置为“UNKNOWN”。

    • val1:值第 1 部分的

    • 十六进制代码。 val2:值第 2 部分的十六进制代码。

    • 状态:对象。 仅当 id == "00" (OTGWIDSTATUS) 时。 val1 和 val2 中的每一位都表示不同 opentherm 状态字段的状态。 此对象中的属性具有字段名称和位的布尔值。 设置 (1) 为真,未设置 (0) 为假。

    • StatusStr:对象。 Status 对象的人类可读版本。

    • :根据 id,这是一个数字(浮点数)、数字(整数)、字符串(“”)

事件:

以下事件由班级:

  • error: This is emitted when there is an error anywhere.
  • exception: This is emitted when we receive a response for a command which was already answered.
  • connected: When succesfully connected to OTGW.
  • initialized: When succesfully communicated with the OTGW and received the response to following commands: PR=A (Get about), PR=M (Get mode)) and PR=W (Get if domestic hot water is enabled).
  • inError: When a message is received from OTGW but we cannot decode it.
  • otgwData: When data is received and decoded from OTGW.
  • otgwError: When the OTGW reported and error. This happens when a wrong command was given, a wrong formatted command value was specified or something in the opentherm communication for the gateway went wrong.
  • printSummary: When the Print Summary mode command "PS=1" is send this event will follow it.

This is a NodeJS modules to be able to connect to an Opentherm Gateway (OTGW).

How to use: See openthermgw_example.js

Install

npm install @1st-setup/openthermgateway

Usage:

Listening to traffic coming from OTGW:

const openthermGatway = require('@1st-setup/openthermgateway');

var myOTGW = new openthermGatway("/dev/ttyUSB0",null, {debug:true});
myOTGW.on("error", (err) => {
    console.error(err.toString());
});

myOTGW.on("exception", (err) => {
    console.error(err.toString());
});

myOTGW.on("inError", (err) => {
    console.error(err.toString());
});

myOTGW.on("otgwError", (err) => {
    console.error(JSON.stringify(err,null,"\t"));
});

myOTGW.on("initialized",() => {
    console.log("Initialized");
    myOTGW.sendCommand("PS=0",(err, response) => {

    });
})

myOTGW.on("connected",() => {
    console.log("Connected");
})

myOTGW.on("otgwData",(data) => {
    console.log("otgw >> "+JSON.stringify(data,null,"\t"));
    console.log("otgw.data >> "+JSON.stringify(myOTGW.data,null,"\t"));
})

myOTGW.on("printSummary",(data) => {
    console.log("printSummary >> "+JSON.stringify(data,null,"\t"));
})

Sending commands to OTGW (see: OTGW Serial commands):

const openthermGatway = require('@1st-setup/openthermgateway');

var myOTGW = new openthermGatway("/dev/ttyUSB0",null, {debug:true});

// To get About opentherm gateway (prints the welcome message) 
myOTGW.sendCommand("PR=A", (err, response) => {
    if (err) {
        console.error(`Error sending command: Error:${err}`);
    }
    else {
        console.log(`Response to command PR=A: ${response}`);
    }
})

Class openthermGatway

Methods:

Constructor(serialDevice, serialOptions, otgwOptions)

Called when you use new to create a new openthermGateway object

Input:

  • serialDevice: String containing ful path to serial device. E.g.: "/dev/ttyUSB0"

  • serialOptions: Object containing openOptions for the 'serialport' module.

  • otgwOptions: Object with following properties:

    • debug: Boolean. When 'true' all incoming and outgoing trafic on serial interface will be logged to console.

sendCommand(data, cb)

With this method you can send a command to the OTGW

Input:

  • data: String with valid OTGW Serial command. E.g.: "PR=A"

  • cb: Callback function which will be called when response is received on send command. Callback function is called with following arguments:

    • err: Object containing the error encountered.
    • response: The response from the OTGW on the send command.

decode(data)

With this method you can decode data, messages, received from the OTGW.

Input:

  • data: String with the message received from the OTGW.

Output:

  • Object with decoded message or null on error. Object will have following properties:

    • status: Character specifying what genereated the message.

      • "R": "Gateway to boiler"
      • "B": "From boiler"
      • "T": "From thermostat"
      • "A": "Gateway to thermostat"
    • direction: String telling what generated the message.

    • msgType: Hex code specifying the type of message.

    • msgTypeStr: String for msgType. Currently only: "Read-Ack" or "Read-Data".

    • id: Hex code specifying from which opentherm id the values are.

    • idStr: String with explanation of id. When id is not known this will be set to "UNKNOWN".

    • val1: Hex code for value part 1.

    • val2: Hex code for value part 2.

    • Status: Object. Only when id == "00" (OTGWIDSTATUS). Each bit in val1 and val2 tells the status of different opentherm status fields. The properties in this object have the name of the field and the boolean value for the bit. True for set (1) and false when not set (0).

    • StatusStr: Object. Human readable version of Status object.

    • <idStr>: Depending on the id this is a Number (float), Number (integer), String ("<val1> <val2>")

Events:

Following event are emitted by the class:

  • error: This is emitted when there is an error anywhere.
  • exception: This is emitted when we receive a response for a command which was already answered.
  • connected: When succesfully connected to OTGW.
  • initialized: When succesfully communicated with the OTGW and received the response to following commands: PR=A (Get about), PR=M (Get mode)) and PR=W (Get if domestic hot water is enabled).
  • inError: When a message is received from OTGW but we cannot decode it.
  • otgwData: When data is received and decoded from OTGW.
  • otgwError: When the OTGW reported and error. This happens when a wrong command was given, a wrong formatted command value was specified or something in the opentherm communication for the gateway went wrong.
  • printSummary: When the Print Summary mode command "PS=1" is send this event will follow it.
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文