Weewx data integration - Dev idea

Hi @ all,

I just managed to hook into the data sent from my affordable weather station and get the data into weewx. It took me quite some time and I read a lot along the way. I am using a raspberry but most things will be similar on other OS https://github.com/weewx/weewx/wiki/Raspberry%20Pi.

I hope I can provide some knowledge base that might encourage others to get their data away from data hogs like wunderground.com (.csv export option was removed recently). Btw I you want to use a awesome community founded weather app and website use windy.com !

But back to Weewx. From the Weewx site http://weewx.com/docs/usersguide.htm#about
WeeWX is software, written in Python, that interacts with a weather station to produce plots, reports, and HTML pages. It can optionally upload the reports to a remote Web server as well as publish to weather services such as WeatherUnderground, CWOP, or PWSweather.com.
Initial development began in the winter of 2008-2009, with the first release in 2009.
The source code is hosted on GitHub, while downloads are available at weewx.com/downloads.
WeeWX is about 13,000 lines of code, plus another 13,000 for the drivers for all the types of supported hardware.

There are many stations that are supported by Weewx drivers while others are not.

If your station is not supported you have several options to get the data.

Question 1: can you set a sever IP and Port or is there only 1 fixed server in the station?

  • if you can set a different IP and Port you are lucky
  • you can install weewx and the interceptor driver https://github.com/matthewwall/weewx-interceptor and use the lister mode
    —> setup
    [Interceptor]
    driver = user.interceptor device_type = observer port = 8000

Problem 1: IP can not be set

Problem 2: IP can not be set

This example assumes two network interfaces on the computer running weewx. 1) Plug the computer into the local network using the first interface (eth0). Plug the device into the second interface (eth1). Bridge the two network interfaces. If you run any web services on the computer, configure them to listen on interface eth0, not eth1. 2) Set parameters in the weewx configuration file. The device has IP address of X.X.X.X [Interceptor] driver = user.interceptor device_type = wu-client mode = sniff iface = eth1 pcap_filter = src X.X.X.X and dst port 80

Problem 3: it still does not work

How do you know you are getting data:

Once everything works fine you might be thinking how great it would be to get the data into farmOS!

So what could be the options to get data into farmOS?
Some ideas not sorted for feasibility:

  1. set a cron job to transfer realtime.txt data into farmOS see here http://landoflinux.com/linux_raspberry_pi_weather_station.html

—> this might be one option to get the data into farmOS however realtime.txt is updated regularly and all old data is overwritten so if a package is dropped its gone

  1. Weewx is hard on SD cards run on PI’s so you can send log files to a remote syslog server
  1. there is also an option to the data to a remote sever via FTP but I cant find it at the moment

I hope this helps the community to either run their own weather station with Weewx or start up the integration of Weewx data into farmOS :slight_smile:

Good resources:

http://landoflinux.com/linux_raspberry_pi_weather_station.html

https://cumuluswiki.wxforum.net/a/Realtime.txt

https://jackstromberg.com/2018/06/setting-up-weewx-with-a-raspberry-pi/

1 Like

Thanks for compiling all of this info @Lars!! Unfortunately I don’t have a weather station so I can’t test anything regarding “getting the data” but interesting to see how that gets setup.

Re: So what could be the options to get data into farmOS?

I just took a look at the WeeWX customization guide. It looks like it might be fairly easy to create a new service (an example here) for farmOS specifically! The integration with wunderground is just a restful_service in the weewx engine. I’m not entirely sure how all of these services work, but there seems to be some sort of hierarchy defined here. It seems like stages earlier in the pipeline will contain more raw and possibly duplicate data. By the time it hits archive_services, resful_services and report_services the data is easier to work with.

In that example the line that sends an email could pretty easily be replaced with a simple

response = session.post(
        headers=headers,
        url=f"{farmos_server_url}/{sensor_public_key}?private_key={sensor_private_key}",
        json=data
    )

Weewx has a really neat way of configuring everything, including services, via weewx.conf. The farmos_server_url, sensor_public_key and sensor_private_key could all be defined in a service config. Additional properties could limit different units that are posted, time intervals, etc.

I’m also curious if this is something we could build into farmOS.py. Even though posting to sensors doesn’t require user authentication with the farmOS server, the farmOS library could simply provide a wrapper around the requests.post I mentioned above (without using farmOS credentials). Because farmOS.py uses the same python ConfigObj configuration as weewx, the config required for farmOS.py might be able to simply be passed through the weewx.conf file. So posting to a sensor would be as easy as client = farmOS("url", "pub key", "private key") and client.sensor.post(data)

(I’m curious what @mstenta thinks about including such a feature in farmOS.py - with the ability to store configs for sensors in a text file, I think this would be very useful!)

2 Likes

I like the idea of being able to use farmOS.py to post to sensors!

Thanks for all this info @Lars! I will have to give my station another shot and see if I can get weewx to detect it…