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


On Wednesday, August 14, 2019 at 5:22:01 PM UTC+5:30, 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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/weewx-user/e6356e3c-c7ee-4170-bd72-e4b2d6dd9a06%40googlegroups.com.

Reply via email to