Thank you I'll get that going

On Wednesday, August 14, 2019 at 6:52:01 AM UTC-5, mwall wrote:
>
> 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
>

-- 
You received this message because you are subscribed to the Google Groups 
"weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to weewx-user+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/weewx-user/cc975a33-0f32-4991-88b5-9336a571d08b%40googlegroups.com.

Reply via email to