Luftdaten data import?

This section covers the Meteobridge PRO, NANO SD and Raspberry Pi units exclusively

Moderator: Mattk

Post Reply
fotogw
Junior Boarder
Junior Boarder
Posts: 30
Joined: Sun Jan 28, 2018 3:06 pm
Contact:

Luftdaten data import?

Post by fotogw »

Hi,

Has anyone successfully imported the Luftdaten https://luftdaten.info and http://deutschland.maps.sensor.communit ... 165/10.455stations in Meteobridge? It would be great to import this as a secondary station im Meteobridge?
weeropdeveluwe.nl Davis VP2+, MBpro red, Instromet sunshine duration sensor, Blitzortung stations, luftdaten airquality sensor.fotogw.nl

thunderstorm
Senior Boarder
Senior Boarder
Posts: 65
Joined: Sun Mar 31, 2019 11:00 am

Re: Luftdaten data import?

Post by thunderstorm »

I'm experimenting with a plugin to query my local sensor, but since there's no json support for the shell it's quite hacky...

Maybe Boris could add support or provide some json parsing capabilties. Sample json

Code: Select all

{
    "software_version": "NRZ-2020-129",
    "age": "44",
    "sensordatavalues": [
        {
            "value_type": "SDS_P1",
            "value": "2.03"
        },
        {
            "value_type": "SDS_P2",
            "value": "1.50"
        },
        {
            "value_type": "temperature",
            "value": "13.30"
        },
        {
            "value_type": "humidity",
            "value": "99.90"
        },
        {
            "value_type": "samples",
            "value": "4382538"
        },
        {
            "value_type": "min_micro",
            "value": "32"
        },
        {
            "value_type": "max_micro",
            "value": "20078"
        },
        {
            "value_type": "signal",
            "value": "-74"
        }
    ]
}

User avatar
admin
Platinum Boarder
Platinum Boarder
Posts: 6591
Joined: Mon Oct 01, 2007 10:51 pm

Re: Luftdaten data import?

Post by admin »

I don't think that I will have spare time to provide JSON parsing tools to make writing of individual plugins more easy. But matching to some of the keywords via "awk" and forgetting about all the syntactic sugar and levels of brackets will deliver the data you are looking for. A bit hacky, but working ;-)

thunderstorm
Senior Boarder
Senior Boarder
Posts: 65
Joined: Sun Mar 31, 2019 11:00 am

Re: Luftdaten data import?

Post by thunderstorm »

My current hack

Code: Select all

#!/bin/sh
#
while true;
do
  data=$(wget --timeout=2 -qO- http://<sensor-ip>/data.json)
  status=$?
  if [ $status -ne 0 ] || [ -z "$data" ]; then
    >&2 echo "Error retrieving data -> sleeping"
    sleep 60
  else
    age=$(echo $data | tr '{' '\n' | grep age | awk -F '"' '{print $8}')
    if [ $age -gt 120 ]; then
      >&2 echo "Data too old ($age secs.) -> sleeping"
      sleep 30
    else
      aqi100=$(echo $data | tr '{' '\n' | grep SDS_P1 | awk -F '"' '{printf "%.1f\n", ($8*10.0)}')
      if [ ! -z "$aqi100" ]; then
        echo "air0 $aqi100"
      else
         >&2 echo "PM10 not available"
      fi
      aqi25=$(echo $data | tr '{' '\n' | grep SDS_P2 | awk -F '"' '{printf "%.1f\n", ($8*10.0)}')
      if [ ! -z "$aqi25" ]; then
        echo "air1 $aqi25"
      else
        >&2 echo "PM2.5 not available"
      fi
      # sensor sleeps for 120 secs, 30+ secs for new measurement
      sleeptime=$((152-age))
      sleep $sleeptime
    fi
  fi
done


User avatar
admin
Platinum Boarder
Platinum Boarder
Posts: 6591
Joined: Mon Oct 01, 2007 10:51 pm

Re: Luftdaten data import?

Post by admin »

thanks for sharing!

xray77
Gold Boarder
Gold Boarder
Posts: 160
Joined: Sat Mar 07, 2020 11:54 pm
Location: Buedelsdorf, SH Germany
Contact:

Re: Luftdaten data import?

Post by xray77 »

Hello thunderstorm,
many thanks for sharing your code!
I also ordered this "Luftdaten"-sensor and would like to integrate it into the MeteoBridge NANO SD afterwards. How do I have to use the code in the MB NANO SD? I suppose that the script has to be set up as a user defined additional station? (since this feature is added to MB NANO SD now) Unfortunately I do not really know...
Maybe you can publish a small manual here? I think many other users would be very grateful for it!
Best Regards
Mike
priv. Weatherstation Buedelsdorf SH Germany
Image

thunderstorm
Senior Boarder
Senior Boarder
Posts: 65
Joined: Sun Mar 31, 2019 11:00 am

Re: Luftdaten data import?

Post by thunderstorm »

It's easy, you have to put it in the script folder with the extension '.plugin' (see release notes from 12.Sep.2020.

You could either upload it through the smb share or use http://ip-of-your-meteobridge/upload.html

Bernd

xray77
Gold Boarder
Gold Boarder
Posts: 160
Joined: Sat Mar 07, 2020 11:54 pm
Location: Buedelsdorf, SH Germany
Contact:

Re: Luftdaten data import?

Post by xray77 »

Hello thunderstorm,
Thanks for the guide! I will go through the release notes when the sensor arrives in the next few days and I have set it up. If there are still any uncertainties, I would be happy to ask here again?
best regards
Mike
priv. Weatherstation Buedelsdorf SH Germany
Image

xray77
Gold Boarder
Gold Boarder
Posts: 160
Joined: Sat Mar 07, 2020 11:54 pm
Location: Buedelsdorf, SH Germany
Contact:

Re: Luftdaten data import?

Post by xray77 »

Hello thunderstorm,
Have a question: Is it possible to run multiple plugin files?
If it is,i would like to run an additional script to determine the sunshine duration, which I found in the Swiss Weather Forum.

Is this old meteoplug-script as usable for the new plugin concept or does it need to be adapted, which I fear... ;-)
A sensor name must be added and probably the syntax must be adapted. Maybe you can help me there, that would be great. Unfortunately the code is placed in only one long string...
Unfortunately I do not have enough knowledge of this code language to convert it into a suitable form for the new plugin-format... I think most of it is the calculations, at the very end with "print" the output?

awk '{c=$3;lg=9.66;lt=54.32;d=0.0174533;j=strftime(''%j'');st=strftime(''%H'')--1;mi=strftime(''%M'');}{x=-23.45*cos(d*360*(j--10)/365);z=60*(-0.171*sin(0.0337*j--0.465)-0.1299*sin(0.01787*j-0.168));w=15*(st--mi/60-(15-lg)/15-12--z/60);s=sin(d*lt)*sin(d*x)--cos(d*lt)*cos(d*x)*cos(d*w);s2=atan2(s,sqrt(1-s^2))/d;m=1368*sin(s2*d);a=(1-sin(s2*d))*0.3*m;g=(m-a)*0.5;if (st<8 ) g=g*0.8-3;if (st>14) g=g*1.2--5;o=0;if ((c>g)&&(g>15)) o=100;printf''%d'',o}'

many thanks for help or some tipps to realize a script for this! :-)

Best regards
Michael
priv. Weatherstation Buedelsdorf SH Germany
Image

thunderstorm
Senior Boarder
Senior Boarder
Posts: 65
Joined: Sun Mar 31, 2019 11:00 am

Re: Luftdaten data import?

Post by thunderstorm »

I guess you can have multiple station using different names for the plugin script, but you could most likely integrate in any existing plugin script.
What you need is the right variable to write the data to, but I don't know whether meteobridge has an appropriate variable.

The command isn't working for me, but I'm not an awk expert to debug this

Sorry
Bernd

xray77
Gold Boarder
Gold Boarder
Posts: 160
Joined: Sat Mar 07, 2020 11:54 pm
Location: Buedelsdorf, SH Germany
Contact:

Re: Luftdaten data import?

Post by xray77 »

Hello Bernd,
Thanks for your explanation!
I was concerned, that the code is not usable in this way because the MeteoBridge does not provide virtual variables/sensors, that would be necessary in this case. A pity, but probably not to change.
Maybe one day Boris will provide the MeteoBridge to determine the duration of sunshine, the basic requirements are already met if you have a solar sensor.
Many thanks again,
best regards
Mike
priv. Weatherstation Buedelsdorf SH Germany
Image

thunderstorm
Senior Boarder
Senior Boarder
Posts: 65
Joined: Sun Mar 31, 2019 11:00 am

Re: Luftdaten data import?

Post by thunderstorm »

On March 2, 2019 meteobridge released a version to feed in alien data (see release notes for this date). So you could write it to eg. data21

In the example for the plugin in the release notes some data is also written to data0, but I've no idea which indexes are available for custom usage.

Bernd

dc.kraft
Junior Boarder
Junior Boarder
Posts: 21
Joined: Mon Nov 03, 2014 7:13 pm
Contact:

Re: Luftdaten data import?

Post by dc.kraft »

Hello everybody,

i have a question which will probably sound absolutely ridiculous.....
First I use a Meteobridge PRO red

I have now packed the script into a file Luftdaten.ps.... so far the whole thing worked, but how do I get this file into the Meteobridge or into the folder Plugin or am I somehow confused ?
Second question: I have to add an additional station which accesses the script, right ??

Finally how do I get it to create a graphical analysis which will put the data of the air data and Davis AiLink on top of each other for direct comparison....

I hope that I have described everything correctly, my English is a little rusty ....

User avatar
admin
Platinum Boarder
Platinum Boarder
Posts: 6591
Joined: Mon Oct 01, 2007 10:51 pm

Re: Luftdaten data import?

Post by admin »

Meteobridge can handle scripts written in ASH (openwrt's little brother of BASH).

Scripts need to be located in the SMB "scripts" folder (accessible via your PC network).
The script can be selected as a weather station plugin when given extension ".plugin".
The script needs to loop endlessly and to write out sensor reports Meteobridge is able to process. Can you please post the output of your script?

You can generate user-defined graphs as "meta charts". Please read here: https://www.meteobridge.com/wiki/index.php/PRO_Graphs

Post Reply