Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 20:10 13 Nov 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Parsing Help please

Author Message
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 07:04pm 08 May 2020
Copy link to clipboard 
Print this post



I'm trying to parse data from the UDP port on my router to collect my Weatherflow data

I've managed to figure out how to get the UDP packets

What I need to parse is the coloured sections in the snippet of what's received below


The obs section contains all the relevant data I need to collect like windspeed, direction temp etc

Can anyone help with telling me how to parse this data?

I "think" it could be done by trying to capture the data starting with serial number
for example
if "serial_number": = "AR-00001937"," then print ,"voltage":
if "serial_number": = "AR-00001937"," then print ,"obs":
if "serial_number": = "SK-00011961," then print ,"voltage":
if "serial_number": = "SK-00011961"," then print ,"obs":

But no idea how to do it
I'm using a Pi-Cromite if it makes a difference



This is the code I used to get the UDP packets
DIM a$,b$,c%
on error skip
udp server 50222
do
  pause 500
  on error skip
  UDP receive a$,b$,c%
  if c%>0 then
    print a$
  end if
loop
on error skip
udp close
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 06:37am 09 May 2020
Copy link to clipboard 
Print this post

What I'm trying to get is the parts coloured below

IF RED then parse the BLUE sections

{"serial_number":"SK-00011961","type":"obs_sky","hub_sn":"HB-00012191","obs":[[1589011848,32799,2.67,0.000000,0.04,0.68,2.01,169,3.34,1,273,null,0,3]],"firmware_revision":43}
{"serial_number":"AR-00001937","type":"obs_air","hub_sn":"HB-00012191","obs":[[1589011895,1002.80,25.05,41,0,0,2.70,1]],"firmware_revision":22}


I would normally be able to do it by doing something like

voltage$=JSON$(a(),"AR-00001937.voltage")'Voltage
I know I can parse the obs bit by using comma parsing but

The problem I have is the UDP port sends out several different packets with different information and I only want the specified bits

Is there a way to do

IF obs_sky then parse obs
IF obs_air then parse obs but I need a way to differentiate the results so I can display them properly

if "SK-00011961","type":"device_status" then parse obs (but identify it as obs_sky)
if "AR-00001937","type":"device_status" then parse obs (but identify it as obs_air)

Can anyone suggest a way to do this?

This is the sections from the obs that I need to parse
  Quote  
type = obs_air
0 Time Epoch Seconds
1 Station Pressure MB
2 Air Temperature C
3 Relative Humidity %
4 Lightning Strike Count
5 Lightning Strike Avg Distance km
6 Battery
7 Report Interval Minutes


type = obs_sky
0 Time Epoch Seconds
1 Illuminance Lux
2 UV Index
3 Rain Accumulated mm
4 Wind Lull (minimum 3 second sample) m/s
5 Wind Avg (average over report interval) m/s
6 Wind Gust (maximum 3 second sample) m/s
7 Wind Direction Degrees
8 Battery Volts
9 Report Interval Minutes
10 Solar Radiation W/m^2
11 Local Day Rain Accumulation mm
12 Precipitation Type 0 = none, 1 = rain, 2 = hail
13 Wind Sample Interval seconds

Edited 2020-05-09 19:02 by lew247
 
PeterB
Guru

Joined: 05/02/2015
Location: Australia
Posts: 655
Posted: 09:01am 09 May 2020
Copy link to clipboard 
Print this post

G'Day Lew

I am sticking my neck out again.
Have you looked at Geoff' GPS software?
If nothing else it will give you something to read while you wait for somebody who knows what they are talking about to come in.

Peter
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 09:03am 09 May 2020
Copy link to clipboard 
Print this post

  lew247 said  What I'm trying to get is the parts coloured below

IF RED then parse the BLUE sections

{"serial_number":"SK-00011961","type":"obs_sky","hub_sn":"HB-00012191","obs":[[1589011848,32799,2.67,0.000000,0.04,0.68,2.01,169,3.34,1,273,null,0,3]],"firmware_revision":43}
{"serial_number":"AR-00001937","type":"obs_air","hub_sn":"HB-00012191","obs":[[1589011895,1002.80,25.05,41,0,0,2.70,1]],"firmware_revision":22}


I know I can parse the obs bit by using comma parsing but

The problem I have is the UDP port sends out several different packets with different information and I only want the specified bits

Is there a way to do

IF obs_sky then parse obs
IF obs_air then parse obs but I need a way to differentiate the results so I can display them properly

if "SK-00011961","type":"obs_sky" then parse obs (but identify it as obs_sky)
if "AR-00001937","type":"obs_air" then parse obs (but identify it as obs_air)

Can anyone suggest a way to do this?

This is the sections from the obs that I need to parse
  Quote  
type = obs_air
0 Time Epoch Seconds
1 Station Pressure MB
2 Air Temperature C
3 Relative Humidity %
4 Lightning Strike Count
5 Lightning Strike Avg Distance km
6 Battery
7 Report Interval Minutes

type = obs_sky
0 Time Epoch Seconds
1 Illuminance Lux
2 UV Index
3 Rain Accumulated mm
4 Wind Lull (minimum 3 second sample) m/s
5 Wind Avg (average over report interval) m/s
6 Wind Gust (maximum 3 second sample) m/s
7 Wind Direction Degrees
8 Battery Volts
9 Report Interval Minutes
10 Solar Radiation W/m^2
11 Local Day Rain Accumulation mm
12 Precipitation Type 0 = none, 1 = rain, 2 = hail
13 Wind Sample Interval seconds

Edited 2020-05-09 21:50 by lew247
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025