ライブラリのインストール
$ npm install influx
node.js
ライブラリの読み込みと、初期設定を行う
const Influx = require('influx')
const influxAircon = new Influx.InfluxDB({
host: '192.168.***.***',
database: 'homedata',
schema: [
{
measurement: 'echonet-Aircon',
tags: [
'addr',
'place'
],
fields: {
status: Influx.FieldType.STRING,
mode: Influx.FieldType.STRING,
modeNum: Influx.FieldType.INTEGER,
setTemp: Influx.FieldType.INTEGER,
measureHumi: Influx.FieldType.INTEGER,
measureTemp: Influx.FieldType.INTEGER,
measureOutdoorTemp: Influx.FieldType.INTEGER
}
}
]
})
データの書き込み
influxAircon.writePoints([
{
measurement: 'echonet-aircon',
tags: { addr: address, place: "aircon" },
fields: {
status: vStatus,
mode: vMode,
modeNum: vModeNum,
setTemp: vSetTemp,
measureHumi: vMeasureHumi,
measureTemp: vMeasureTemp,
measureOutdoorTemp: vMeasureOutdoorTemp
}
}
]).catch(err => {
console.error(`Error saving data to InfluxDB! ${err.stack}`)
})
コメントを投稿