Node-Red, Want to truncate results from BME280 Sensor
Node-Red question here.
I have hooked a BME280 sensor (Temp, Pressure, Humidity) up to my Raspberry Pi 3B for a side project I am doing in work. I downloaded the BME280 Node and it connects without issue. I then pipe the output through a JSON node to convert it to a standard that my dashboard uses (Freeboard dashboard).
The output is as follows:
{ temperature: 20.75, pressure: 1020.4576451979732, humidity: 43.76235104765547 }
The question is:
How do I truncate the extra decimal places? 14 decimal places are killing my gauges!
I've already tried using Math.Trunc in a function Node between the output and the Dashboard but... well, I'm a beginner coder so I could really do with a little help.
Apologies if this has already been asked before.
Mere
Edit:
The code I've already tried:
Math.Trunc("Pressure:", toFixed(2)); - not sure about this one
Math.Round("Pressure:" * 100) / 100;
I've also tried.
parseFloat("Pressure").toFixed(2) - found on this site
I guess this is where my inexperience really shows.
javascript node-red
add a comment |
Node-Red question here.
I have hooked a BME280 sensor (Temp, Pressure, Humidity) up to my Raspberry Pi 3B for a side project I am doing in work. I downloaded the BME280 Node and it connects without issue. I then pipe the output through a JSON node to convert it to a standard that my dashboard uses (Freeboard dashboard).
The output is as follows:
{ temperature: 20.75, pressure: 1020.4576451979732, humidity: 43.76235104765547 }
The question is:
How do I truncate the extra decimal places? 14 decimal places are killing my gauges!
I've already tried using Math.Trunc in a function Node between the output and the Dashboard but... well, I'm a beginner coder so I could really do with a little help.
Apologies if this has already been asked before.
Mere
Edit:
The code I've already tried:
Math.Trunc("Pressure:", toFixed(2)); - not sure about this one
Math.Round("Pressure:" * 100) / 100;
I've also tried.
parseFloat("Pressure").toFixed(2) - found on this site
I guess this is where my inexperience really shows.
javascript node-red
Show us the code you tried and somebody will help you fix it. (Edit the question to include it, don't try and add as a comment)
– hardillb
Mar 13 '17 at 15:21
add a comment |
Node-Red question here.
I have hooked a BME280 sensor (Temp, Pressure, Humidity) up to my Raspberry Pi 3B for a side project I am doing in work. I downloaded the BME280 Node and it connects without issue. I then pipe the output through a JSON node to convert it to a standard that my dashboard uses (Freeboard dashboard).
The output is as follows:
{ temperature: 20.75, pressure: 1020.4576451979732, humidity: 43.76235104765547 }
The question is:
How do I truncate the extra decimal places? 14 decimal places are killing my gauges!
I've already tried using Math.Trunc in a function Node between the output and the Dashboard but... well, I'm a beginner coder so I could really do with a little help.
Apologies if this has already been asked before.
Mere
Edit:
The code I've already tried:
Math.Trunc("Pressure:", toFixed(2)); - not sure about this one
Math.Round("Pressure:" * 100) / 100;
I've also tried.
parseFloat("Pressure").toFixed(2) - found on this site
I guess this is where my inexperience really shows.
javascript node-red
Node-Red question here.
I have hooked a BME280 sensor (Temp, Pressure, Humidity) up to my Raspberry Pi 3B for a side project I am doing in work. I downloaded the BME280 Node and it connects without issue. I then pipe the output through a JSON node to convert it to a standard that my dashboard uses (Freeboard dashboard).
The output is as follows:
{ temperature: 20.75, pressure: 1020.4576451979732, humidity: 43.76235104765547 }
The question is:
How do I truncate the extra decimal places? 14 decimal places are killing my gauges!
I've already tried using Math.Trunc in a function Node between the output and the Dashboard but... well, I'm a beginner coder so I could really do with a little help.
Apologies if this has already been asked before.
Mere
Edit:
The code I've already tried:
Math.Trunc("Pressure:", toFixed(2)); - not sure about this one
Math.Round("Pressure:" * 100) / 100;
I've also tried.
parseFloat("Pressure").toFixed(2) - found on this site
I guess this is where my inexperience really shows.
javascript node-red
javascript node-red
edited Mar 13 '17 at 18:17
hardillb
24.6k73160
24.6k73160
asked Mar 13 '17 at 15:13
MeremortalMeremortal
13
13
Show us the code you tried and somebody will help you fix it. (Edit the question to include it, don't try and add as a comment)
– hardillb
Mar 13 '17 at 15:21
add a comment |
Show us the code you tried and somebody will help you fix it. (Edit the question to include it, don't try and add as a comment)
– hardillb
Mar 13 '17 at 15:21
Show us the code you tried and somebody will help you fix it. (Edit the question to include it, don't try and add as a comment)
– hardillb
Mar 13 '17 at 15:21
Show us the code you tried and somebody will help you fix it. (Edit the question to include it, don't try and add as a comment)
– hardillb
Mar 13 '17 at 15:21
add a comment |
3 Answers
3
active
oldest
votes
You can use toFixed() function. For example if you want only 2 digits after the comma you can use toFixed(2). For example
var t = 10.122345355
t.toFixed(2) // "10.12"
toFixed will convert it to string so you need to parse it as a float afterward
add a comment |
Try something like this in a function node:
var pres = msg.payload.pressure;
var temp = msg.payload.temperature;
var humidity = msg.payload.humidity;
msg.payload = {
pressure: pres.toFixed(2),
temperature : temp.toFixed(2),
humidity: humidity.toFixed(2)
};
return msg;
Thank you so much! I tried this and it worked straight away. And I'd also like to say thanks for helping me see the way I need to structure my code.
– Meremortal
Mar 14 '17 at 10:36
stackoverflow.com/help/someone-answers
– hardillb
Mar 14 '17 at 10:49
add a comment |
Although this has been idle for a while, here is some more info for the next person to come across it on how to parse the data from the BME280 in Node Red.
The data object delivered looks like this:
temperature_C: 24.54
humidity: 48.00285972066518
pressure_hPa: 1008.9618686461673
model: "BME280"
heatIndex: 25.624424558111855
dewPoint_C: 12.810600563041554
altitude_M: 35.74196949170104
temperature_F: 76.172
pressure_Hg: 29.79463137918758
Note that to get all this data you need to check the Extra Data box in the BME280 node otherwise you only get this:
temperature_C: 24.45
humidity: 48.38705227965796
pressure_hPa: 1009.0013733960975
model: "BME280"
Extract the data you want and truncate it in a function node like this:
var pres = msg.payload.pressure_hPa;
var temp = msg.payload.temperature_C;
var humidity = msg.payload.humidity;
msg.payload = {
pressure: pres.toFixed(2),
temperature : temp.toFixed(2),
humidity: humidity.toFixed(2)
};
return msg;
Cool, I had no idea that this extra information was available. Thanks again for updating this and I'm off now to update my project!
– Meremortal
Nov 25 '18 at 10:15
@Meremortal : For more details, go to the Node Red Discourse site. I posted a working flow there just today: link
– jm in TX
Nov 27 '18 at 6:57
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f42767087%2fnode-red-want-to-truncate-results-from-bme280-sensor%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can use toFixed() function. For example if you want only 2 digits after the comma you can use toFixed(2). For example
var t = 10.122345355
t.toFixed(2) // "10.12"
toFixed will convert it to string so you need to parse it as a float afterward
add a comment |
You can use toFixed() function. For example if you want only 2 digits after the comma you can use toFixed(2). For example
var t = 10.122345355
t.toFixed(2) // "10.12"
toFixed will convert it to string so you need to parse it as a float afterward
add a comment |
You can use toFixed() function. For example if you want only 2 digits after the comma you can use toFixed(2). For example
var t = 10.122345355
t.toFixed(2) // "10.12"
toFixed will convert it to string so you need to parse it as a float afterward
You can use toFixed() function. For example if you want only 2 digits after the comma you can use toFixed(2). For example
var t = 10.122345355
t.toFixed(2) // "10.12"
toFixed will convert it to string so you need to parse it as a float afterward
answered Mar 13 '17 at 15:27
pm.calabresepm.calabrese
366610
366610
add a comment |
add a comment |
Try something like this in a function node:
var pres = msg.payload.pressure;
var temp = msg.payload.temperature;
var humidity = msg.payload.humidity;
msg.payload = {
pressure: pres.toFixed(2),
temperature : temp.toFixed(2),
humidity: humidity.toFixed(2)
};
return msg;
Thank you so much! I tried this and it worked straight away. And I'd also like to say thanks for helping me see the way I need to structure my code.
– Meremortal
Mar 14 '17 at 10:36
stackoverflow.com/help/someone-answers
– hardillb
Mar 14 '17 at 10:49
add a comment |
Try something like this in a function node:
var pres = msg.payload.pressure;
var temp = msg.payload.temperature;
var humidity = msg.payload.humidity;
msg.payload = {
pressure: pres.toFixed(2),
temperature : temp.toFixed(2),
humidity: humidity.toFixed(2)
};
return msg;
Thank you so much! I tried this and it worked straight away. And I'd also like to say thanks for helping me see the way I need to structure my code.
– Meremortal
Mar 14 '17 at 10:36
stackoverflow.com/help/someone-answers
– hardillb
Mar 14 '17 at 10:49
add a comment |
Try something like this in a function node:
var pres = msg.payload.pressure;
var temp = msg.payload.temperature;
var humidity = msg.payload.humidity;
msg.payload = {
pressure: pres.toFixed(2),
temperature : temp.toFixed(2),
humidity: humidity.toFixed(2)
};
return msg;
Try something like this in a function node:
var pres = msg.payload.pressure;
var temp = msg.payload.temperature;
var humidity = msg.payload.humidity;
msg.payload = {
pressure: pres.toFixed(2),
temperature : temp.toFixed(2),
humidity: humidity.toFixed(2)
};
return msg;
answered Mar 13 '17 at 22:22
hardillbhardillb
24.6k73160
24.6k73160
Thank you so much! I tried this and it worked straight away. And I'd also like to say thanks for helping me see the way I need to structure my code.
– Meremortal
Mar 14 '17 at 10:36
stackoverflow.com/help/someone-answers
– hardillb
Mar 14 '17 at 10:49
add a comment |
Thank you so much! I tried this and it worked straight away. And I'd also like to say thanks for helping me see the way I need to structure my code.
– Meremortal
Mar 14 '17 at 10:36
stackoverflow.com/help/someone-answers
– hardillb
Mar 14 '17 at 10:49
Thank you so much! I tried this and it worked straight away. And I'd also like to say thanks for helping me see the way I need to structure my code.
– Meremortal
Mar 14 '17 at 10:36
Thank you so much! I tried this and it worked straight away. And I'd also like to say thanks for helping me see the way I need to structure my code.
– Meremortal
Mar 14 '17 at 10:36
stackoverflow.com/help/someone-answers
– hardillb
Mar 14 '17 at 10:49
stackoverflow.com/help/someone-answers
– hardillb
Mar 14 '17 at 10:49
add a comment |
Although this has been idle for a while, here is some more info for the next person to come across it on how to parse the data from the BME280 in Node Red.
The data object delivered looks like this:
temperature_C: 24.54
humidity: 48.00285972066518
pressure_hPa: 1008.9618686461673
model: "BME280"
heatIndex: 25.624424558111855
dewPoint_C: 12.810600563041554
altitude_M: 35.74196949170104
temperature_F: 76.172
pressure_Hg: 29.79463137918758
Note that to get all this data you need to check the Extra Data box in the BME280 node otherwise you only get this:
temperature_C: 24.45
humidity: 48.38705227965796
pressure_hPa: 1009.0013733960975
model: "BME280"
Extract the data you want and truncate it in a function node like this:
var pres = msg.payload.pressure_hPa;
var temp = msg.payload.temperature_C;
var humidity = msg.payload.humidity;
msg.payload = {
pressure: pres.toFixed(2),
temperature : temp.toFixed(2),
humidity: humidity.toFixed(2)
};
return msg;
Cool, I had no idea that this extra information was available. Thanks again for updating this and I'm off now to update my project!
– Meremortal
Nov 25 '18 at 10:15
@Meremortal : For more details, go to the Node Red Discourse site. I posted a working flow there just today: link
– jm in TX
Nov 27 '18 at 6:57
add a comment |
Although this has been idle for a while, here is some more info for the next person to come across it on how to parse the data from the BME280 in Node Red.
The data object delivered looks like this:
temperature_C: 24.54
humidity: 48.00285972066518
pressure_hPa: 1008.9618686461673
model: "BME280"
heatIndex: 25.624424558111855
dewPoint_C: 12.810600563041554
altitude_M: 35.74196949170104
temperature_F: 76.172
pressure_Hg: 29.79463137918758
Note that to get all this data you need to check the Extra Data box in the BME280 node otherwise you only get this:
temperature_C: 24.45
humidity: 48.38705227965796
pressure_hPa: 1009.0013733960975
model: "BME280"
Extract the data you want and truncate it in a function node like this:
var pres = msg.payload.pressure_hPa;
var temp = msg.payload.temperature_C;
var humidity = msg.payload.humidity;
msg.payload = {
pressure: pres.toFixed(2),
temperature : temp.toFixed(2),
humidity: humidity.toFixed(2)
};
return msg;
Cool, I had no idea that this extra information was available. Thanks again for updating this and I'm off now to update my project!
– Meremortal
Nov 25 '18 at 10:15
@Meremortal : For more details, go to the Node Red Discourse site. I posted a working flow there just today: link
– jm in TX
Nov 27 '18 at 6:57
add a comment |
Although this has been idle for a while, here is some more info for the next person to come across it on how to parse the data from the BME280 in Node Red.
The data object delivered looks like this:
temperature_C: 24.54
humidity: 48.00285972066518
pressure_hPa: 1008.9618686461673
model: "BME280"
heatIndex: 25.624424558111855
dewPoint_C: 12.810600563041554
altitude_M: 35.74196949170104
temperature_F: 76.172
pressure_Hg: 29.79463137918758
Note that to get all this data you need to check the Extra Data box in the BME280 node otherwise you only get this:
temperature_C: 24.45
humidity: 48.38705227965796
pressure_hPa: 1009.0013733960975
model: "BME280"
Extract the data you want and truncate it in a function node like this:
var pres = msg.payload.pressure_hPa;
var temp = msg.payload.temperature_C;
var humidity = msg.payload.humidity;
msg.payload = {
pressure: pres.toFixed(2),
temperature : temp.toFixed(2),
humidity: humidity.toFixed(2)
};
return msg;
Although this has been idle for a while, here is some more info for the next person to come across it on how to parse the data from the BME280 in Node Red.
The data object delivered looks like this:
temperature_C: 24.54
humidity: 48.00285972066518
pressure_hPa: 1008.9618686461673
model: "BME280"
heatIndex: 25.624424558111855
dewPoint_C: 12.810600563041554
altitude_M: 35.74196949170104
temperature_F: 76.172
pressure_Hg: 29.79463137918758
Note that to get all this data you need to check the Extra Data box in the BME280 node otherwise you only get this:
temperature_C: 24.45
humidity: 48.38705227965796
pressure_hPa: 1009.0013733960975
model: "BME280"
Extract the data you want and truncate it in a function node like this:
var pres = msg.payload.pressure_hPa;
var temp = msg.payload.temperature_C;
var humidity = msg.payload.humidity;
msg.payload = {
pressure: pres.toFixed(2),
temperature : temp.toFixed(2),
humidity: humidity.toFixed(2)
};
return msg;
answered Nov 24 '18 at 3:31
jm in TXjm in TX
64
64
Cool, I had no idea that this extra information was available. Thanks again for updating this and I'm off now to update my project!
– Meremortal
Nov 25 '18 at 10:15
@Meremortal : For more details, go to the Node Red Discourse site. I posted a working flow there just today: link
– jm in TX
Nov 27 '18 at 6:57
add a comment |
Cool, I had no idea that this extra information was available. Thanks again for updating this and I'm off now to update my project!
– Meremortal
Nov 25 '18 at 10:15
@Meremortal : For more details, go to the Node Red Discourse site. I posted a working flow there just today: link
– jm in TX
Nov 27 '18 at 6:57
Cool, I had no idea that this extra information was available. Thanks again for updating this and I'm off now to update my project!
– Meremortal
Nov 25 '18 at 10:15
Cool, I had no idea that this extra information was available. Thanks again for updating this and I'm off now to update my project!
– Meremortal
Nov 25 '18 at 10:15
@Meremortal : For more details, go to the Node Red Discourse site. I posted a working flow there just today: link
– jm in TX
Nov 27 '18 at 6:57
@Meremortal : For more details, go to the Node Red Discourse site. I posted a working flow there just today: link
– jm in TX
Nov 27 '18 at 6:57
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f42767087%2fnode-red-want-to-truncate-results-from-bme280-sensor%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Show us the code you tried and somebody will help you fix it. (Edit the question to include it, don't try and add as a comment)
– hardillb
Mar 13 '17 at 15:21