Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

try parseFloat mqtt payload in order to be able to format number with… #442

Open
wants to merge 1 commit into
base: angular13
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions server/runtime/devices/mqtt/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,18 @@ function MQTTclient(_data, _logger, _events) {
for (var i = 0; i < topicsMap[topicAddr].length; i++) {
var id = topicsMap[topicAddr][i].id;
var oldvalue = data.tags[id].value;
data.tags[id].value = msg.toString();
let val = parseFloat(msg.toString());
if (Number.isNaN(val)) {
// maybe boolean
val = Number(value);
// maybe string
if (Number.isNaN(val)) {
val = value;
}
} else {
val = parseFloat(val.toFixed(5));
}
data.tags[id].value = val;
data.tags[id].timestamp = new Date().getTime();
data.tags[id].changed = true;
if (data.tags[id].type === 'json' && data.tags[id].options && data.tags[id].options.subs && data.tags[id].memaddress) {
Expand Down Expand Up @@ -574,4 +585,4 @@ module.exports = {
create: function (data, logger, events) {
return new MQTTclient(data, logger, events);
}
}
}