LowPowerLab Forum

Software support => Pi Gateway => Topic started by: Sergegsx on September 24, 2017, 07:20:54 AM

Title: regex help with string
Post by: Sergegsx on September 24, 2017, 07:20:54 AM
Hello,

I would like to know if someone can help me make new metrics based on how my moteinos send the string. These are some examples:
[09-24-17_13:18:14.345] [LOG]   >: [24] up:3542742,power:17,Spower:826593,temp:2587   [RSSI:-82]
[09-24-17_13:18:26.903] [LOG]   >: [31] up:97400,Vcc:3274,temp:2662,bat:4414   [RSSI:-50]
[09-24-17_13:18:28.357] [LOG]   >: [32] up:866892,power:407,Spower:8946559,temp:3062,bat:10208   [RSSI:-78]

also, by I get a wrong reading at the end due to the spaces I guess
[09-24-17_13:18:14.356] [LOG]   post: /home/pi/development/data/db/0024_V.bin[1506251894,2587]

The reason for doing this is that I have not used the moteino gateway in the past, I used my own system. Now I want to give it a try but reflashing all my moteinos would be aweful.

can someone help me with a regex example on how to detect:
this kind of string:
up:866892,power:407,Spower:8946559,temp:3062,bat:10208
up:866892,
power:407,
Spower:8946559,
temp:3062,
bat:10208

thank you!
Title: Re: regex help with string
Post by: Felix on September 25, 2017, 10:29:33 AM
First, very important to note that the tokens have to be space separated not comma separated.
Second, there are various examples in metrics.js that will give you metrics that match numbers.
An example is this:

F : { name:'F', regexp:/\bF\:(-?\d+\.\d+)\b/i, value:'', duplicateInterval:3600, unit:'°', pin:1, graph:1, graphValSuffix:'F', graphOptions:{ legendLbl:'Temperature', lines: { lineWidth:1 } }},

The regexp expression will match F followed by : and then a decimal positive/negative number. If you just want a positive number, no decimals, the expression would be (using your up metric):

up : { name:'up', regexp:/\bup\:(\d+)\b/i, value:'', duplicateInterval:3600, unit:'°', pin:1, graph:1, graphValSuffix:'F', graphOptions:{ legendLbl:'up', lines: { lineWidth:1 } }},

I think you can figure out the rest :)
Try it at www.regexr.com