Ah, you are running WeeWX v4 and this driver uses WeeWX v3 (legacy) 
logging, hence the lack of control. Try this version of bme280wx.py, I've 
changed the logging to v4 logging and changed the offending loginf to logdbg. 
Rename your old bme280wx.py to say bme280wx_orig.py and then copy the 
attached bme280wx.py in its place. Restart WeeWX and you should have a 
quieter log, if you want to turn on the debug logging to see the bme28 data 
in the log just set debug = 1 in weewx.conf and restart WeeWX.

If the driver fails because of an error on my behalf you can revert to the 
copy you just made.

Gary
On Saturday, 23 January 2021 at 12:43:02 UTC+10 mksm...@gmail.com wrote:

> Yes. debug =0 in weewx.conf
>
> anytime I do changes to a driver I follow these steps
>
> sudo /etc/init.d/weewx stop
>
> *make the changes and save*
>
> sudo /etc/init.d/weewx start
>
> On Saturday, January 23, 2021 at 5:36:12 AM UTC+3 gjr80 wrote:
>
>> Did you have debug = 0 in weewx.conf and did you restart WeeWX?
>>
>> Gary
>>
>> On Saturday, 23 January 2021 at 12:26:55 UTC+10 mksm...@gmail.com wrote:
>>
>>> I am realy sorry I missed to mention that changing line 78
>>>
>>>         loginf('BME280 data %s' % bme280data)
>>> to
>>>         logdbg('BME280 data %s' % bme280data)
>>>
>>> did not work
>>>
>>> On Saturday, January 23, 2021 at 4:50:58 AM UTC+3 gjr80 wrote:
>>>
>>>> Not sure why you are thanking me, you took no notice of what I 
>>>> suggested. Commenting out log lines is a poor choice, in future if you 
>>>> ever 
>>>> want to troubleshoot you have no means of obtaining any meaningful log 
>>>> info 
>>>> unless you again modify source code. A better solution is to change the 
>>>> log 
>>>> level of the noisy log output as i suggested so that it is only logged 
>>>> when 
>>>> you run WeeWX with debug = 1. 
>>>>
>>>> Gary
>>>> On Saturday, 23 January 2021 at 11:37:31 UTC+10 mksm...@gmail.com 
>>>> wrote:
>>>>
>>>>> Commenting out line 78 or line 107 only did not work, but Commenting 
>>>>> out (line 78 & 107) did the trick. no more unnecessary writing to 
>>>>> (/var/log)
>>>>>
>>>>> Thank you *vince & gjr80*
>>>>>
>>>>> On Saturday, January 23, 2021 at 3:16:42 AM UTC+3 gjr80 wrote:
>>>>>
>>>>>> If it's this one 
>>>>>> <https://gitlab.com/wjcarpenter/bme280wx/-/blob/master/bin/user/bme280wx.py>
>>>>>>  
>>>>>> then the only change that is needed is to change the loginf() call 
>>>>>> at line 78 to logdbg(). Everything else should be left untouched. 
>>>>>> Commenting out logging to fix a chatty log is really a case of cutting 
>>>>>> off 
>>>>>> your nose to spite your face. Just like restarting WeeWX daily, far 
>>>>>> better 
>>>>>> to engineer out the problem.
>>>>>>
>>>>>> Gary
>>>>>>
>>>>>> On Saturday, 23 January 2021 at 10:06:06 UTC+10 vince wrote:
>>>>>>
>>>>>>> We'd have to see 'exactly' what code you have installed now in order 
>>>>>>> to help.   At this point we've seen so many partial descriptions that 
>>>>>>> it's 
>>>>>>> impossible to know what exactly you're currently running and what error 
>>>>>>> messages you are seeing when you run that code.
>>>>>>>
>>>>>>>

-- 
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/8811f877-ccde-405c-a497-116f84853ceen%40googlegroups.com.
#!/usr/bin/env python
"""
bme280wx
"""
import smbus2
import bme280
import weewx
from weewx.engine import StdService
import weeutil

# import/setup logging, WeeWX v3 is syslog based but WeeWX v4 is logging based,
# try v4 logging and if it fails use v3 logging
try:
    # WeeWX4 logging
    import logging

    log = logging.getLogger(__name__)

    def logdbg(msg):
        log.debug(msg)

    def loginf(msg):
        log.info(msg)

    def logerr(msg):
        log.error(msg)

except ImportError:
    # WeeWX legacy (v3) logging via syslog
    import syslog

    def logmsg(level, msg):
        syslog.syslog(level, 'bme280: %s' % msg)

    def logdbg(msg):
        logmsg(syslog.LOG_DEBUG, msg)

    def loginf(msg):
        logmsg(syslog.LOG_INFO, msg)

    def logerr(msg):
        logmsg(syslog.LOG_ERR, msg)


def surely_a_list(innie):
    if isinstance(innie, list):
        return innie
    if innie is None or innie is "":
        return []
    return [innie]  # cross fingers


class Bme280wx(StdService):

    def __init__(self, engine, config_dict):

        # Initialize my superclass first:
        super(Bme280wx, self).__init__(engine, config_dict)
        self.bme280_dict = config_dict.get('Bme280wx', {})
        loginf('bme280wx configuration %s' % self.bme280_dict)

        self.port = int(self.bme280_dict.get('i2c_port', '1'))
        self.address = int(self.bme280_dict.get('i2c_address', '0x76'), base=16)

        self.default_units = self.bme280_dict.get('usUnits', 'US').upper()
        self.default_units = weewx.units.unit_constants[self.default_units]

        self.temperatureKeys = surely_a_list(self.bme280_dict.get('temperatureKeys', 'inTemp'))
        self.temperature_must_have = surely_a_list(
            self.bme280_dict.get('temperature_must_have', []))

        # The conversion from station pressure to MSL barometric pressure depends on the
        # temperature. So, the default is to only provide the pressure value when there
        # is already an outdoor temperature value
        self.pressureKeys = surely_a_list(self.bme280_dict.get('pressureKeys', 'pressure'))
        self.pressure_must_have = surely_a_list(
            self.bme280_dict.get('pressure_must_have', ['outTemp']))

        self.humidityKeys = surely_a_list(self.bme280_dict.get('humidityKeys', 'inHumidity'))
        self.humidity_must_have = surely_a_list(self.bme280_dict.get('humidity_must_have', []))

        self.bus = smbus2.SMBus(self.port)
        # this caches part-speciofic stuff so that a weewx restart is needed
        # if you change the bme280 sensor part; each one is unique
        self.calibration_params = bme280.load_calibration_params(self.bus, self.address)

        loginf('I2C port: %s' % self.port)
        loginf('I2C address: %s' % hex(self.address))
        loginf('fallback default units: %s' % weewx.units.unit_nicknames[self.default_units])

        # This is last to make sure all the other stuff is ready to go
        # (avoid race condition)
        self.bind(weewx.NEW_LOOP_PACKET, self.new_loop_packet)

    def new_loop_packet(self, event):

        packet = event.packet

        # the sample method will take a single reading and return a
        # compensated_reading object
        bme280data = bme280.sample(self.bus, self.address, self.calibration_params)
        logdbg('BME280 data %s' % bme280data)

        if bme280data is None:
            return
        # If there is a declared set of units already, we'll convert to that.
        # If there isn't, we'll accept the configured wisdom.
        if 'usUnits' in packet:
            converter = weewx.units.StdUnitConverters[packet['usUnits']]
        else:
            converter = weewx.units.StdUnitConverters[self.default_units]

        if all(must_have in packet for must_have in self.pressure_must_have):
            pressurePA = (bme280data.pressure, 'mbar', 'group_pressure')
            converted = converter.convert(pressurePA)
            for key in self.pressureKeys:
                packet[key] = converted[0]

        if all(must_have in packet for must_have in self.temperature_must_have):
            temperatureC = (bme280data.temperature, 'degree_C', 'group_temperature')
            converted = converter.convert(temperatureC)
            for key in self.temperatureKeys:
                packet[key] = converted[0]

        if all(must_have in packet for must_have in self.humidity_must_have):
            humidityPCT = (bme280data.humidity, 'percent', 'group_percent')
            converted = converter.convert(humidityPCT)
            for key in self.humidityKeys:
                packet[key] = converted[0]

        logdbg(packet)

Reply via email to