Lua string.match help

2 replies [Last post]
Joined: 28 Feb 2011

I'm looking for some help with Lua , I'm using SciTE for windows to debug my code....

I'm running the following string.match on the HAH to parse some serial data, the code section is a follows

local stnid, outtmp, hum, wndavg, wndgst, wnddir, rain, intmp, baro = data:match("(%d+) (%d+%.%d) (%d+) (%d+%.%d+) (%d+%.%d+) (%w+) (%d+%.%d) (%d+%.%d) (%d+%.%d)")

print (data)

print (stnid, outtmp, hum, wndavg, wndgst, wnddir, rain, intmp, baro )

running the code with SciTE I get:

2686 8.8 63 3.06 6.12 SW 4793.3 25.9 984.1
2686    8.8    63    3.06    6.12    SW    4793.3    25.9    984.1

running xap-plugboard in debug on the HAH I get:

2686 8.9 61 3.40 6.12 NE 4793.3 25.9 984.1
nil     nil     nil     nil     nil     nil     nil     nil     nil

Just don't understand what I'm missing, any help would be appreciated.

Joined: 28 Feb 2011
where's the wood..... I can only see trees

30 + views and no assistance……..Well I have progressed, the string is parsed and have an applet..ish a V.humble applet that will no doubt make one's Lua master eye’s bleed, that parses data to an end point.

My issue is that I do not seem to be able to, and have tried many different contexts, be able to provide an end point for each key or sensor.

Applet is attached, some guidance would be appreciated as I'm more of a hardware guy.

Along with the Applet, if any one is interested I have attached my updated arduino/jeenode OKK code to translate the RF transmissions from a WH1080 fine offset weather station and with a localy installed BMP085 for pressure.

WH1080Applet.lua 1.81 KB
fineofset_wstn_rx.ino_.txt 8.46 KB
Providence, United States
Joined: 9 Jan 2010
I can see you are making

I can see you are making progress - sorry I missed your initial post asking for help.

The callback filter that you wrote is like this:

   f = xap.Filter()

When you construct a filter make sure that you are only going to get data from the TARGET where you opened the serial port.
This filter above would slurp XAP-SERIAL data from ALL xap-serial processes on your network.
Perhaps you only have one and you can get away with it however, from those with >2 its going to bomb badly as it would  grab data from ALL running xap message on the same USB port.  it would be better like this.

  f = xap.Filter()    
  f:add("serial.received","port", port)    

For the rest of the program I see what you are trying to do but your are not quite there. Here is some code that will create all the endpoints and update them based on what is being decoded. This should get you moving.

First you need to setup all these sensor endpoints. This will be in your init() section.

  for _,v in ipairs{'outsidetemp','humidity','windavg','windgust','winddirection','rain','insidetemp','pressure'} do
    sensor[v] = bsc.Endpoint{source="dbzoo.serial.sensor:weather."..v, direction=bsc.INPUT, type=bsc.STREAM}

Next how to update them all? Do that like this:

function update(frame)
  local data = frame:getValue("serial.received","data")
  local stnid, outtmp, hum, wndavg, wndgst, wnddir, rain, intmp, baro = data:match("([^,]*) ([^,]*) ([^,]*) ([^,]*) ([^,]*) ([^,]*) ([^,]*) ([^,]*) ([^,]*)")  
  for s in sensor do

What you should also think about is what happens if you stop receiving data for a while from your arduino? You'll need some sort of REAPER that will set these endpoints to ? after some period. I'll leave that as an excerise for you. hint: use a timer.

NOTE: I did not test any of this I just typed it in   :)


Hardware Info