Hello,
i want to read my out my electric meter over serial, and store it into a MySqlDatabase.
I get datas from the meter, but i dont now how i can seperate the values.
Serial output give me lines, the information that i need is in line 10,11,12 and 13.
I want to seperate it.
Many Thanks,
Markus
Hi Markus,
Just out of curiousity - what hardware did you use to get the reading out of the SMART meter?
Well that looks like a string but it is hard to tell what is behind the red box. Please copy and post the debug data to a reply.
you could try this. Add a change node after where the data comes out and select the jsonata option and add in $substring(payload,6,11) - note you may have to play with the offsets
Oh after you extract the data, you may want to change it to a number - since it is a string - depending on how you want to use it.
i need the value after "1.8.1" and "1.8.2" and "2.8.1" and "2.8.2" as number to an output
for example "1.8.2" (00005760.291) output 5760.291
thanks
And did you try what I suggested?
Yes, this works sorry i have forget to set the "to" to expression.
the serial output give me lines, how can i count these lines to sort out what i want?
or better to find for example "1.8.1"
Using @hotNipi function, take a look at the switch node and see if that will help.
many thanks, to you (zenofmud and hotNipi)
final funktion
var parts = msg.payload.split("(");
msg.key = parts[0];
if (msg.key == "1.8.1")
{
msg.val = parseFloat(parts[1]);
return msg;
}
This example is crying for a Regex solution, imo...
var parts = msg.payload.match(/([\d.]+)\(([\d.]+)\*(\w+)\)/);
msg.payload = {
id: parts[1],
value: parseFloat(parts[2]),
units: parts[3]
};
return msg;
With the incoming data listed above, the output payload will be:
{
"id": "1.8.2",
"value": 5760.291,
"units": "kWh"
}
@shrickus regex makes my head hurt - I never spend enougth time with it so each time is like starting over again and again and ...
Heh heh, you are not alone... I've always suspected that I'm wired differently, but since my sweet-spots seem to be things like xslt, map-reduce, jsonata, and regex -- well, it's pretty obviously true!
BTW, so as not to disappoint -- here is the equivalent JSONata expression:
payload.$match(/([\d.]+)\(0*([\d.]+)\*(\w+)\)/) {
"id": groups[0],
"value": $number(groups[1]),
"units": groups[2]
}
Hi Steve,
I was waiting patiently for the JSONata to appear - and then, as if by magic, it did.
Happy New Year from Dynamic Dave in the UK
Can anyone help me pull data out of the below string? I need Address, deviceid maxADU, segmentation, vendorid, object type, vendorid.
msg : Object
object
payload: string
vendorId----------> 7
pi : TTY=unknown ; PWD=/home/pi ; USER=root ; COMMAND=/usr/bin/node-red-log 1
pam_unix(sudo:session): session opened for user root by (uid=0)
1 Oct 13:54:19 - [error] [change:b5f40521.772738] Invalid JSONata expression: Argument 1 of function "substring" does not match function signature
root : TTY=unknown ; PWD=/home/pi ; USER=root ; COMMAND=/bin/journalctl -f -n 25 -u nodered -o cat
pam_unix(sudo:session): session opened for user root by (uid=0)
1 Oct 13:55:04 - [info] Stopping flows
1 Oct 13:55:04 - [info] Stopped flows
1 Oct 13:55:04 - [info] Starting flows
1 Oct 13:55:06 - [info] Started flows
1 Oct 13:55:08 - [info] Stopping flows
1 Oct 13:55:08 - [info] Stopped flows
1 Oct 13:55:08 - [info] Starting flows
1 Oct 13:55:10 - [info] Started flows
address----------> 192.168.251.55
deviceId----------> 55
maxApdu----------> 1476
segmentation----------> 0
vendorId----------> 7
object type----------> 7
vendorId----------> 7
pi : TTY=un...
socketid: "7E5dLH4WdG_0NLzKAAAA"
_msgid: "17d752ed.11c22d"
Please make your own topic, and make sure to copy the debug output from the browser.
shrickus:
Regex solution
Hello shrickus,
That looks nice!
But I get error messages.
What goes wrong?
See printout