This is the service that I wrote and I put it in bin/user, I plan to write 
this up when I get the. time but this 
<https://s3.eu-west-2.amazonaws.com/s3-archive.revittmk.aws.co.uk/useful-guides/weewx-guides/rasberry-pi/read-cpu-temp.html>
 
will give you an idea of how I add the service.

My Ecowitt uploads to /var/www/html/ecowitt

I then read every file in the directory, deleting all but the most recent 
which I then read

I parse the file and insert the data into the database fields, and as there 
is not a extraHumid3 I used extraHumid1 instead.

Hope this helps

On Friday, January 15, 2021 at 10:25:03 AM UTC [email protected] wrote:

> Mike,
> I would be very interested to see that code you have written to insert 
> data into the database. I am currently using FilePile but always interested 
> in looking at alternative ways. 
> Ian
>
> On Fri, 15 Jan 2021 at 09:56, Mike Revitt <[email protected]> wrote:
>
>> Thank you both for your advice and input.
>>
>> In the end I have taken a bit of advice from both you you and some other 
>> information I found online, and in the interests of keeping things simple 
>> have managed to get my Ecowitt uploading data files to a directory on the 
>> raspberry Pi and have written a small python script that reads these and 
>> inserts them into the database, and this is run as a service very similar 
>> to the way I insert the CPU temperature
>>
>> One thing I am keen to try is using the config file to define the 
>> directory as you show above Vince, but that will have to wait till I have 
>> time to experiment on my "spare" raspberry Pi. Not trying that on my live 
>> system. So for the time being the directory is defined as a constant
>>
>>
>> On Wednesday, January 13, 2021 at 6:45:37 PM UTC vince wrote:
>>
>>> On Wednesday, January 13, 2021 at 3:09:29 AM UTC-8 [email protected] 
>>> wrote:
>>>
>>>> That sounds interesting, is there some documentation that shows how to 
>>>> control where the data goes when running it as a service?
>>>>
>>>>
>>> There is - see 
>>> https://github.com/gjr80/weewx-gw1000/wiki/Available-config-options
>>>
>>> Here's the mapping I use as a driver, FWIW.   Works great.   You'd 
>>> probably want to also override the inside temp and inside humidity items to 
>>> extraTempN and extraHumidN for your scenario where you want the Ecowitt 
>>> items to add to your Davis measurements.  Maybe more items such as the 
>>> battery status as I did below.
>>>
>>> I'd lean toward disagree with Ian's suggestion to use a secondary db, as 
>>> it's not really needed, but there are lots of ways to get there.
>>>
>>> I specify the gateway ip address since it's on a different subnet than 
>>> the weewx pi.
>>>
>>> # Options for 'GW1000'
>>> [GW1000]
>>>     driver = user.gw1000
>>>     ip_address = 192.168.2.20
>>>     port = 45000
>>>     poll_interval = 20
>>>
>>>     #--- the defaults map inTemp, inHumidity, outTemp, outHumidity
>>>     #--- and the extraTemp1-8 and soilMostN items automagically
>>>     #--- but we need to add the battery status mappings
>>>     [[field_map_extensions]]
>>>         # outTemp
>>>         outTempBatteryStatus = wh26_batt
>>>         # extraTemp1-8
>>>         batteryStatus1 = wh31_ch1_batt
>>>         batteryStatus2 = wh31_ch2_batt
>>>         # soilMost1 = channel autoselects on first use
>>>         batteryStatus8 = wh51_ch1_batt
>>>
>>>
>>>
>>> -- 
>> 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/31fa642d-b923-4acc-a8d1-8fafad463493n%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/weewx-user/31fa642d-b923-4acc-a8d1-8fafad463493n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
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/51b53da8-6550-46cd-b4ab-1a0e393b0460n%40googlegroups.com.
#!/bin/env python3
#-----------------------------------------------------------------------------------------------------------------------------------
# Routine Name: ecowitt.py
# Author:       Mike Revitt
# Date:         14/01/2021
#------------------------------------------------------------------------------------------------------------------------------------
# Revision History    Push Down List
# -----------------------------------------------------------------------------------------------------------------------------------
# Date        | Name        | Description
# ------------+-------------+--------------------------------------------------------------------------------------------------------
#             |             |
# 14/01/2021  | M Revitt    | Initial version
#-------------+-------------+--------------------------------------------------------------------------------------------------------
# Description:  Reads the Temperature and Humidity from and ECOWITT_PATH which is where the Ecwitt weather station places the data files
#               Converts all data into Celcius then populates the WeeWX database
#
# Issues:       None
#
# ***********************************************************************************************************************************
# Copyright 2021 Mike Revitt <[email protected]>. All Rights Reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
# (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,
# merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# ***********************************************************************************************************************************
"""Gets the temperatures and humidy from Ecowitt"""

import  os
import  weewx
from    weewx.engine  import  StdService
from    stat          import  S_ISREG, ST_MTIME, ST_MODE

ECOWITT_PATH  = '/var/www/html/ecowitt'

class AddEcowittData(StdService):

    def __init__(self, engine, config_dict):

      # Initialize my superclass first:
      super(AddEcowittData, self).__init__(engine, config_dict)

      # Bind to any new archive record events:
      self.bind(weewx.NEW_ARCHIVE_RECORD, self.new_archive_record)

    def new_archive_record(self, event):

        lEcowittFiles =  (os.path.join(ECOWITT_PATH, sFiles)  for sFiles          in os.listdir(ECOWITT_PATH))
        lEcowittFiles = ((os.stat(sFullPath), sFullPath)      for sFullPath       in lEcowittFiles)
        lEcowittFiles = ((stat[ST_MTIME],     sFullPath)      for stat, sFullPath in lEcowittFiles if S_ISREG(stat[ST_MODE]))
        sDelFile      = ''

        for cDate, sFullPath in sorted(lEcowittFiles, reverse=False):
            if os.path.exists(sDelFile):
                os.remove(sDelFile)
                sDelFile = sFullPath
            else:
                sDelFile = sFullPath

        dEcowittData = {}
        ecowittData  = open(sFullPath, 'r')
        for sLineIn in ecowittData:
            if "[" in sLineIn:
                sKey    = sLineIn.split('[',  1)[1].split(']', 1)[0]
                sValue  = sLineIn.split('=>', 1)[1].strip()
                dEcowittData[sKey] = sValue

        ecowittData.close()

        event.record['extraTemp3']  = float(dEcowittData['tempinf'])
        event.record['extraHumid1'] = float(dEcowittData['humidityin'])
        event.record['extraTemp2']  = float(dEcowittData['tempf'])
        event.record['extraHumid2'] = float(dEcowittData['humidity'])

Reply via email to