diff --git a/README.md b/README.md index e9ac911..0cb3f20 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ The package provide a single custom node __Bme280__ that can be used directly in ## Installation -Under your node-red working directory. +Under your node-red (typically ``$HOME/.node-red``) working directory. `` npm install node-red-contrib-bme280 @@ -35,25 +35,25 @@ After installation place your Bme280 node in any of your flow and configure the 1. __Name:__ Select the name of your sensor for easy identification. 2. __Bus ID:__ Select the I2C bus to which the sensor is connected. Depending on your wiring and SBC can be different. 3. __I2C address:__ I2C address (7-bit) hexdecimal address(0x##). BMP/BME280 sensor have fixed 0x77 or 0x76. You can check your sensor id by using i2c-tools typing ``i2cdetect -y `` -4. __Topic:__ Topic field set on the input message. If this field is empty topic will not be included in the output msg. By configuring the node this input msg topic will be reused. +4. __Topic:__ Topic field set on the output message. If this field is empty, topic will not be included in the output msg. By configuring the node this way input msg topic will be reused. 4. __Extra:__ Check box to indicate the node to compute extra information each time a read is requested. After configuration and deployment the node will init the sensor and will identify if BME280 or BMP280 variant is detected. ### Reading Sensor Data -As in other node-red nodes the actual measurement of sensor data require that an input msg arrive to the node. The input called __Trigger__ will start the reading of sensor data will send the data in the node's output. +As in other node-red nodes the actual measurement of sensor data require that an input msg arrive to the node. The input called __Trigger__ will start the reading of sensor data will send the data in the node's output. The input __msg is reused__ so any property on the input msg (with the exception of payload and topic if set) will be redirected without modification to the output. The __output__ will have the following format: ``` msg = { - _id: , + _msgid: , topic: , payload: { model: "BME280" or "BMP280", temperature_C: , - humidity: , + humidity: , // Only present if model == "BME280" pressure_hPa: } } @@ -62,15 +62,15 @@ msg = { payload: { .... - heatIndex: , - dewPoint_C= , + heatIndex: , // Only present if model == "BME280" + dewPoint_C= , // Only present if model == "BME280" altitude_M= , temperature_F= pressure_Hg= } ``` -__Note__: BMP280 version __WILL NOT__ report humidity information the sensor do not provide this information. humidity will be always be read as __0__. +__Note__: BMP280 version __WILL NOT__ report humidity information the sensor do not provide this information. humidity, heatIndex & dewPoint_C will not be __present__ in the payload. ## Notes @@ -87,5 +87,7 @@ BPM280 & BME280 has been tested using different breakout from cheap providers. O - Topic configurable to help MQTT integration - Input msg will be reused to enable better HTTP node integration. - Documentation improvements + - Added some examples. + * 0.0.2 Solved npm repository name. * 0.0.1 First version diff --git a/bme280.html b/bme280.html index 952c927..47c93ba 100644 --- a/bme280.html +++ b/bme280.html @@ -47,7 +47,7 @@ return this.name ? this.name : "Bme280"; }, labelStyle: function() { return this.name ? "node_label_italic" : "";}, - outputLabels: ["Incoming Payloads"], + outputLabels: ["Sensor reads"], inputLabels: ["Trigger"] }); diff --git a/bme280.js b/bme280.js index 9a1f5b4..73e9c9d 100644 --- a/bme280.js +++ b/bme280.js @@ -35,11 +35,14 @@ module.exports = function(RED) { //var msg={_msgid:RED.util.generateId(),topic:"bme280",payload:data}; _msg.payload=data; data.model=node.type; + if(node.type != "BME280" && _msg.payload.humidity !== undefined) delete _msg.payload.humidity; if(node.topic !== undefined && node.topic != "") _msg.topic=node.topic; if(node.extra) { - var pl=msg.payload; - pl.heatIndex=BME280.calculateHeatIndexCelcius(data.temperature_C,data.humidity); - pl.dewPoint_C=BME280.calculateDewPointCelcius(data.temperature_C,data.humidity); + var pl=_msg.payload; + if(node.type == "BME280") { + pl.heatIndex=BME280.calculateHeatIndexCelcius(data.temperature_C,data.humidity); + pl.dewPoint_C=BME280.calculateDewPointCelcius(data.temperature_C,data.humidity); + } pl.altitude_M=BME280.calculateAltitudeMeters(data.pressure_hPa,0); pl.temperature_F=BME280.convertCelciusToFahrenheit(data.temperature_C); pl.pressure_Hg=BME280.convertHectopascalToInchesOfMercury(data.pressure_hPa); diff --git a/examples/http_html.json b/examples/http_html.json new file mode 100644 index 0000000..fb4080d --- /dev/null +++ b/examples/http_html.json @@ -0,0 +1 @@ +[{"id":"17646079.863cc","type":"http in","z":"9b546cc2.584d9","name":"","url":"bme280","method":"get","upload":false,"swaggerDoc":"","x":90,"y":860,"wires":[["56ddef05.a245c"]]},{"id":"12587b55.d46e65","type":"http response","z":"9b546cc2.584d9","name":"","statusCode":"200","headers":{},"x":600,"y":860,"wires":[]},{"id":"2a13956c.f3379a","type":"template","z":"9b546cc2.584d9","name":"メインHTML","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"BME280 DATA:
\n
\nTEMPERATURE: {{payload.temperature_C}}
\nPRESSURE: {{payload.pressure_hPa}}
\nHUMIDITY: {{payload.humidity}}
\n
","output":"str","x":430,"y":860,"wires":[["12587b55.d46e65"]]},{"id":"56ddef05.a245c","type":"Bme280","z":"9b546cc2.584d9","name":"","bus":"1","address":"0x76","topic":"bme280","extra":false,"x":260,"y":860,"wires":[["2a13956c.f3379a"]]}] diff --git a/examples/http_json.json b/examples/http_json.json new file mode 100644 index 0000000..74227ff --- /dev/null +++ b/examples/http_json.json @@ -0,0 +1 @@ +[{"id":"17646079.863cc","type":"http in","z":"9b546cc2.584d9","name":"","url":"bme280json","method":"get","upload":false,"swaggerDoc":"","x":110,"y":860,"wires":[["56ddef05.a245c"]]},{"id":"12587b55.d46e65","type":"http response","z":"9b546cc2.584d9","name":"","statusCode":"200","headers":{},"x":720,"y":860,"wires":[]},{"id":"56ddef05.a245c","type":"Bme280","z":"9b546cc2.584d9","name":"","bus":"1","address":"0x76","topic":"bme280","extra":false,"x":280,"y":860,"wires":[["46a48ddd.381ca4"]]},{"id":"46a48ddd.381ca4","type":"json","z":"9b546cc2.584d9","name":"","property":"payload","action":"","pretty":false,"x":410,"y":860,"wires":[["7dc41cd6.f34034"]]},{"id":"7dc41cd6.f34034","type":"template","z":"9b546cc2.584d9","name":"plain json","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{payload}}","output":"str","x":560,"y":860,"wires":[["12587b55.d46e65"]]}]