Author Topic: Incoming node data parsing [RX/TX wires were swapped...]  (Read 2694 times)

beckerdo

  • NewMember
  • *
  • Posts: 8
Incoming node data parsing [RX/TX wires were swapped...]
« on: January 13, 2016, 03:19:47 PM »
Hello all,
Great work with the RaspberryPi Gateway code! I have been running with a Pi2 and moteino receiver, but I was writing my own Python code for gathering, storing and serving my data. I am going to give the Gateway code a try with my motetino transmitter nodes.

One question. I am a newbie to JavaScript, I want my Gateway to receive and parse my moteino node data. My nodes have the moteino weather shield, but they also have additional sensors such a luminosity and uV index (five in all). Is there a place in the GitHub repo or in the docs that shows the data format the Gateway parses from the nodes? I am sure I can change the transmit format or add something to the receiving gateway code.

Right now my data that I save in the receiving moteino log sketch looks like this (where tid is the transmitter ID, sid is the sensor ID, tf is temperature in fahrenheit, hp is humidity percent, pi is barometer pressure inches, etc.). At the end ts is the time stamp which is provided by the receiving unit.
R[1][2] "tid=t1, sid=s0, tf=68.1, hp=72, vvr=5.44, tm=594" - ack ts=2015-03-19 09:51:45
R[2][2] "tid=t1, sid=s1, tf=67.2, pia=29.03, pir=29.94" - ack ts=2015-03-19 09:51:55
R[3][2] "tid=t1, sid=s2, vis=260, ir=253, uvi=0.02" - ack ts=2015-03-19 09:52:05
R[4][2] "tid=t1, sid=s3, vl=0.01" - ack ts=2015-03-19 09:52:10
R[5][2] "tid=t1, sid=s4, uvW=0.01" - ack ts=2015-03-19 09:52:15

Any suggestions? Thanks.
« Last Edit: January 18, 2016, 04:08:27 PM by Felix »

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: Incoming node data parsing
« Reply #1 on: January 13, 2016, 04:28:36 PM »
Hi,
First you will need to reformat your string that you pass to the gateway.js app:

"token token token ... token"

Where token can be anything except spaces.
Each token is then matched against the list of metrics defined in metrics.js.
There you can define your own metrics in order to have them show up in the UI.
Also please see this video on more details about metrics:

beckerdo

  • NewMember
  • *
  • Posts: 8
Re: Incoming node data parsing
« Reply #2 on: January 13, 2016, 06:30:09 PM »
Good stuff, thanks for the pointer!

beckerdo

  • NewMember
  • *
  • Posts: 8
Re: Incoming node data parsing
« Reply #3 on: January 14, 2016, 06:41:01 PM »
Just to be sure I understand this, please let me summarize, and perhaps you can tell me if I am correct or not.

1) My Moetino transmitter node sends some data elements that have a key and a value. This is from the RFM69 WeatherNode.ino example:
Code: [Select]
sprintf(buffer, "BAT:%sv F:%d H:%d P:%s", BATstr, weatherShield_SI7021.getFahrenheitHundredths(), weatherShield_SI7021.getHumidityPercent(), Pstr);
sendLen = strlen(buffer);
radio.sendWithRetry(GATEWAYID, buffer, sendLen, 1); //retry one time

2) The RaspberryPi-Gateway attempts to grab these values in metrics.js by matching some regular expressions:
Code: [Select]
  //WeatherShield metrics
  F : { name:'F', regexp:/F\:(-?\d+\.\d+)/i, value:'', unit:'°', pin:1, graph:1, graphValSuffix:'F', graphOptions:{ legendLbl:'Temperature', lines: { lineWidth:1 } }},
  H : { name:'H', regexp:/H\:([\d\.]+)/i, value:'', unit:'%', pin:1, graph:1, graphOptions:{ legendLbl:'Humidity', lines: { lineWidth:1 }}},
  P : { name:'P', regexp:/P\:([\d\.]+)/i, value:'', unit:'"', pin:1, },

3) For my other sensors in my data example above (for example vis=260, ir=253, uvi=0.02,  vl=0.01,  uvW=0.01), I need to add some regular expressions to parse for the keys, and some graphOptions to save and graph the data.

Does this process sound correct?
Thanks, beckerdo
« Last Edit: January 14, 2016, 07:00:08 PM by Felix »

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: Incoming node data parsing
« Reply #4 on: January 14, 2016, 06:59:34 PM »
Sounds right yes.
I suggest following the existing token pattern of key:value with space separation between tokens. Sometimes there is no key, like MOTION, see the metrics definition for that. The graphed metrics are always numeric, cannot store a non numeric value.

beckerdo

  • NewMember
  • *
  • Posts: 8
Re: Incoming node data parsing
« Reply #5 on: January 18, 2016, 01:44:32 PM »
I've updated my transmitting and receiving Moteinos to provide data in the key:value format. I've also updated the Gateway metrics.js file to detect my new metrics.

When I run my receiving Moteino on codebender, I see the console log showing the metrics it is receiving from the radio. They look like this now in the console log (the actual messages are in parens):
Code: [Select]
R[99][2] "TID:t1 SID:s0 TF:177.3 HP:54 VVR:6.44 TM:3" - ack
R[100][2] "TID:t1 SID:s1 TF2:71.9 PIA:29.44 PIR:30.37" - ack
However, when I connect my receiving Moteino to the Raspberry Pi, I don't see any events or log info in the gateway.sys.log. I do see events in gateway.sys.log when I run the Moteino Gateway Dashbord in my browser and click various buttons so it seems the node and rest of the software stack is working.

Are there any statements in gateway.js I should add or uncomment to help debug talk between Gateway and the Moetino? Any Linux commands I can use to see if the Raspberry Pi is talking properly with the receiving Moteino serial port? Thanks!



beckerdo

  • NewMember
  • *
  • Posts: 8
Re: Incoming node data parsing
« Reply #6 on: January 18, 2016, 01:56:21 PM »
Never mind all! After more debugging of the hardware, it appears I mixed the send and receive wires from the Moetino serial pins to the Raspberry Pi GPIO header. A simple wire swap, and now I see data coming into my Raspberry Pi gateway!