OurWeather by SwitchDoc

296 views
Skip to first unread message

Chester L. Garrett IV

unread,
Aug 8, 2019, 10:14:09 AM8/8/19
to weewx-user
HI every one,

I am wonder if you can support this hardware or not. I would like to use Weewx to pull data from ourweather using the ip address and using the REST to pull the data. 

Pat

unread,
Aug 8, 2019, 11:40:38 AM8/8/19
to weewx-user
A driver could be written to support this, it will just take someone to invest some time to write it. It's not difficult but without knowing the hardware or the REST data schema there can be challenges. 

weewx operates on a LOOP idea where the weather data is available at specific intervals. Typically it's pushed to weewx, but there can be a pull method as well (using REST). Do you know what interval the data is available at?

Chester L. Garrett IV

unread,
Aug 10, 2019, 12:49:15 PM8/10/19
to weewx-user
Here is more info on REST. I've attached a document on how it works and it tells you how to communicate to it.
OurWeatherAdvancedUsageManual4.0.pdf

Chester L. Garrett IV

unread,
Aug 11, 2019, 1:53:02 PM8/11/19
to weewx-user
I have attached the info on how the REST works. It depends on how often you want to pull the data. It updates underground weather every 5 mins. But if you do it locally it depends on how often you want to pull the data.

Chester L. Garrett IV

unread,
Aug 14, 2019, 7:25:13 AM8/14/19
to weewx-user
Could someone point me in the right direction to get OurWeather by Switch Doc to work with WeeWx.

mwall

unread,
Aug 14, 2019, 7:52:01 AM8/14/19
to weewx-user
On Wednesday, August 14, 2019 at 7:25:13 AM UTC-4, Chester L. Garrett IV wrote:
Could someone point me in the right direction to get OurWeather by Switch Doc to work with WeeWx.

just write a weewx driver that makes a periodic request for the 'FullDataString' URL.  parse the response and emit it as LOOP data.  that's it!

the code will look something like this (error handling is left as an exercise to the reader :)

put this code into the file ourweather.py in the 'user' directory of your weewx installation:

#!/usr/bin/python
import urllib2
import json
import time

import weewx.drivers

DRIVER_NAME = 'OurWeather'
DRIVER_VERSION = "0.1"

def loader(config_dict, engine):
    return OurWeatherDriver(**config_dict[DRIVER_NAME])

class OurWeatherDriver(weewx.drivers.AbstractDevice):

    def __init__(self, **stn_dict):
        # where to find the data
        self.path = stn_dict.get('host', '192.168.0.10')
        # how often to poll the weather data file, seconds
        self.poll_interval = float(stn_dict.get('poll_interval', 10))

    def genLoopPackets(self):
        """request the 'full data string' then parse it.  a 'full data string' looks like this:
{"FullDataString":
"21.30,36.70,25.63,101714.00,620.44,0.00,0.00,0.00,0.70,0.00,0.00,0.00,0.00,0.00,0.00,0,04/2
4/2016 11:56:10,SwitchDoc Labs", "id": "1", "name": "OurWeather", "connected": true}
        """
        while True:
            url = "http://%s/FullDataString' % self.host
            req = urllib2.Request(url=url)
            resp = urllib2.urlopen(req).read()
            resp_json = json.loads(resp)
            parts = resp_json['FullDataString']
            _packet = {
                'dateTime': int(time.time() + 0.5),
                'usUnits': weewx.US,
                'outTemp': parts[0],
                'outHumidity': parts[1],
                # FIXME: fill in the rest of the data here
            }
            yield _packet
            time.sleep(self.poll_interval)

    @property
    def hardware_name(self):
        return "OurWeather"

# To test this driver, run it directly as follows:
#   PYTHONPATH=/home/weewx/bin python /home/weewx/bin/user/ourweather.py
if __name__ == "__main__":
    import weeutil.weeutil
    driver = OurWeatherDriver()
    for packet in driver.genLoopPackets():
        print weeutil.weeutil.timestamp_to_string(packet['dateTime']), packet

then add a stanza to your weewx.conf file:

[OurWeather]
    # ip address or hostname of the weather station
    host = 192.168.5.3
    driver = user.ourweather

and tell weewx to use that driver by modifying the 'station_type' field in the 'Station' stanza:

[Station]
    ...
    station_type = OurWeather

you should run weewx directly until you fix the bugs.  that way you will see data immediately.  after you get to that point you can run weewx as a service/daemon.

for more details, see the customization guide, or any one of the many, many extensions to weewx that are listed in the wiki.

m

Chester L. Garrett IV

unread,
Aug 14, 2019, 4:45:03 PM8/14/19
to weewx-user
Thank you I'll get that going

Avinash H. Duduskar

unread,
Oct 27, 2019, 10:24:03 AM10/27/19
to weewx-user
Hi mwall,

Thanks for the pointers, I have some Qs.
This is what my JSON looks like at http://192.168.1.9/FullDataString:
{"FullDataString": "25.60,89.30,29.42,101926.00,592.16,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,1,2019-10-17 18:39:19,NIBM,0,-1,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,V:1,WXLMB ,0,,,0,,,0", "id": "1", "name": "OurWeather", "hardware": "esp8266", "connected": true}

This station supports Air Quality and Lightning detection sensors which I've currently mapped (to ignore) as extraTemp and soilTemp for now.
The trouble from the JSON is multi-part:

  1. After part14 which is dateTime, the user-configured Station Name is sent for which I don't see an option to specify in https://github.com/weewx/weewx/blob/master/bin/schemas/wview.py
  2. Same issue for these bits towards the end of the JSON: V:1,WXLMB ,0,,,0,,,0", "id": "1", "name": "OurWeather", "hardware": "esp8266", "connected": true which I'm happy to ignore as of now.

Here's the output of me trying to troubleshoot it:

$ PYTHONPATH=/home/weewx/bin python2 /home/weewx/bin/user/ourweather.py
Traceback (most recent call last):
  File "/home/weewx/bin/user/ourweather.py", line 65, in <module>
    for packet in driver.genLoopPackets():
  File "/home/weewx/bin/user/ourweather.py", line 23, in genLoopPackets
    {"FullDataString": "25.60,89.30,29.42,101926.00,592.16,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,1,2019-10-17 18:39:19,NIBM,0,-1,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,V:1,WXLMB ,0,,,0,,,0", "id": "1", "name": "OurWeather", "hardware": "esp8266", "connected": true}
NameError: global name 'true' is not defined

How do I ignore sections of the JSON?
This is what my current ourweather.py looks like, any pointers are appreciated - https://gist.github.com/Strykar/bd7c77c1229af6c8d5bd7ff551a5c541

P.S. I don't know Python, just some Bash.



Thanks,

AD

Chester L. Garrett IV

unread,
Dec 31, 2019, 11:58:12 AM12/31/19
to weewx-user
i am getting this when i put the info for the custom driver. see pic below 

WeeWx drivers.jpg

Matt Pitts

unread,
Apr 19, 2020, 2:11:57 PM4/19/20
to weewx-user
Hi there, did you ever this working with our weather?
Reply all
Reply to author
Forward
0 new messages