Socketlogger error while starting.

98 views
Skip to first unread message

richard effsec

unread,
Jul 7, 2020, 2:19:56 AM7/7/20
to weewx-user
Hello,

I installed weewx with a WS1200 weatherstation. I used socketlogger to gather weather data using method 2 in https://obrienlabs.net/redirecting-weather-station-data-from-observerip/
Ncat is working and I got readings at port 2999 like:

outTemp=60.6,outHumidity=84,dewpoint=55.8,windchill=60.6,windDir=107,windSpeed=0.00,windGust=2.24,dailyrain=0.00,radiation=34.46,UV=1,inTemp=-9999,inHumidity=-9999,barometer=-9999,epoch=1594102395,txBatteryStatus=0
outTemp=60.6,outHumidity=84,dewpoint=55.8,windchill=60.6,windDir=51,windSpeed=0.67,windGust=1.12,dailyrain=0.00,radiation=36.61,UV=1,inTemp=-9999,inHumidity=-9999,barometer=-9999,epoch=1594102422,txBatteryStatus=0

Weewx does not pick up the information, the readings are like there is no connection to the weatherstation. The syslog shows that socketlogger.py has errors at line 67.

Jul  6 23:21:47 raspberrypi systemd[1]: Starting LSB: weewx weather system...
Jul  6 23:21:47 raspberrypi weewx[22535] INFO __main__: Initializing weewx version 4.1.1
Jul  6 23:21:47 raspberrypi weewx[22535] INFO __main__: Using Python 3.7.3 (default, Dec 20 2019, 18:57:59) #012[GCC 8.3.0]
Jul  6 23:21:47 raspberrypi weewx[22535] INFO __main__: Platform Linux-4.19.118-v7+-armv7l-with-debian-10.4
Jul  6 23:21:47 raspberrypi weewx[22535] INFO __main__: Locale is 'en_US.UTF-8'
Jul  6 23:21:47 raspberrypi weewx[22535] INFO __main__: PID file is /var/run/weewx.pid
Jul  6 23:21:47 raspberrypi weewx[22539] INFO __main__: Using configuration file /etc/weewx/weewx.conf
Jul  6 23:21:47 raspberrypi weewx[22539] INFO __main__: Debug is 0
Jul  6 23:21:47 raspberrypi weewx[22539] INFO weewx.engine: Loading station type SocketLogger (user.socketlogger)
Jul  6 23:21:47 raspberrypi weewx[22539] CRITICAL __main__: Caught unrecoverable exception:
Jul  6 23:21:47 raspberrypi weewx[22539] CRITICAL __main__:     ****  invalid syntax (socketlogger.py, line 67)
Jul  6 23:21:47 raspberrypi weewx[22539] CRITICAL __main__:     ****  Traceback (most recent call last):
Jul  6 23:21:47 raspberrypi weewx[22539] CRITICAL __main__:     ****    File "/usr/share/weewx/weewxd", line 148, in main
Jul  6 23:21:47 raspberrypi weewx[22539] CRITICAL __main__:     ****      engine = weewx.engine.StdEngine(config_dict)
Jul  6 23:21:47 raspberrypi weewx[22539] CRITICAL __main__:     ****    File "/usr/share/weewx/weewx/engine.py", line 69, in __init__
Jul  6 23:21:47 raspberrypi weewx[22539] CRITICAL __main__:     ****      self.setupStation(config_dict)
Jul  6 23:21:47 raspberrypi weewx[22539] CRITICAL __main__:     ****    File "/usr/share/weewx/weewx/engine.py", line 92, in setupStation
Jul  6 23:21:47 raspberrypi weewx[22539] CRITICAL __main__:     ****      __import__(driver)
Jul  6 23:21:47 raspberrypi weewx[22539] CRITICAL __main__:     ****    File "/usr/share/weewx/user/socketlogger.py", line 67
Jul  6 23:21:47 raspberrypi weewx[22539] CRITICAL __main__:     ****      except (socket.error, socket.timeout, socket.herror), ex:
Jul  6 23:21:47 raspberrypi weewx[22539] CRITICAL __main__:     ****                                                          ^
Jul  6 23:21:47 raspberrypi weewx[22539] CRITICAL __main__:     ****  SyntaxError: invalid syntax
Jul  6 23:21:47 raspberrypi weewx[22539] CRITICAL __main__:     ****  Exiting.
Jul  6 23:21:47 raspberrypi weewx[22523]: Starting weewx weather system: weewx.

Does anybody know what this means and how to solve this?

Tom Keffer

unread,
Jul 7, 2020, 7:32:55 AM7/7/20
to weewx-user
I don't know anything about socketlogger, but it looks like it has not been ported to Python 3. Try running under Python 2.7

--
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+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-user/c7fc7ba0-91b0-4642-b32e-e2a881d3f724o%40googlegroups.com.

richard effsec

unread,
Jul 7, 2020, 3:21:50 PM7/7/20
to weewx-user
THanks, I found the weewx-interceptor and installed it in listening mode. Now everything works fine.

klm3...@gmail.com

unread,
Nov 21, 2021, 8:30:51 AM11/21/21
to weewx-user
I just found out that I had the same problem when upgrading my weewx 3.9.2 to the latest 4.5.1. socketlogger is giving the same error as the original reporter. 

I used the 2to3 tool of python to translate the socketlogger.py. Here the version for python 3.

-----------------

#
#    Copyright (c) 2012 Tom Keffer <tke...@gmail.com>
#
#    See the file LICENSE.txt for your full rights.
#
#    $Revision: 1 $
#    $Author: pobrien $
#    $Date: 2016-01-14 08:00:00 -0500 (Thu, 14 Jan 2016) $
#
""" This driver connects to a socket (typically on localhost) and waits
    for packet data. Once a new line comes into the socket, this will process
    the data and submit the packet back to weewx.

    Based on the hackulink driver, which was based on the weewx wmr100 driver
"""

import socket
import syslog
import time

import weedb
import weewx.drivers
import weeutil.weeutil
import weewx.wxformulas

def logmsg(dst, msg):
    syslog.syslog(dst, 'SocketLogger: %s' % msg)

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

def logerror(msg):
    logmsg(syslog.LOG_ERROR, msg)

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

def loader(config_dict, engine):
    station = SocketLogger(**config_dict['SocketLogger'])
    return station

class SocketLogger(weewx.drivers.AbstractDevice):
    """ Driver for the SocketLogger station. """

    def __init__(self, **stn_dict) :
        """ Initialize an object of type SocketLogger. """

        self.host_ip          = stn_dict.get('host_ip')
        self.host_port        = int(stn_dict.get('host_port'))
        self.timeout          = float(stn_dict.get('timeout'))
        self.station_hardware = stn_dict.get('hardware')

        self.lastrain = None

        self.port = None
        self.openPort()

    def hardware_name(self):
        return self.station_hardware

    def openPort(self):
        try:
            loginf("Connecting to socket on %s port %s" % (self.host_ip, self.host_port) )
            self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            self.socket.settimeout(self.timeout)
            self.socket.connect( (self.host_ip, self.host_port) )
        except (socket.error, socket.timeout, socket.herror) as ex:
            logerror("Socket error while opening port %d to ethernet host %s." % (self.host_port, self.host_ip))
            # Reraise as a weewx I/O error:
            raise weewx.WeeWxIOError(ex)
        except:
            logerror("Unable to connect to host %s on port %d." % (self.host_ip, self.host_port))
            raise
        logdebug("Connected to host %s on port %d" % (self.host_ip, self.host_port))
        self.port = self.socket.makefile()

    def closePort(self):
        self.port.close()

    def check_rain(self, daily_rain_counter):
        # *** DO NOT use the &rainin= data! ***
        # Handle the rain accum by taking the &dailyrainin= reading ONLY.
        # Then submit those minor increments of daily rain to weewx.
        rain = 0.0
        current_rain = float(daily_rain_counter)
        if self.lastrain is not None:
            if (current_rain >= self.lastrain):
                rain = float(current_rain) - float(self.lastrain)
                #loginf("Checking for new rain accumulation")
                #loginf(rain)
        self.lastrain = current_rain
        return rain

    #===============================================================================
    #                         LOOP record decoding functions
    #===============================================================================

    def genLoopPackets(self):
        """ Generator function that continuously returns loop packets """
        for _packet in self.genPackets():
            yield _packet

    def genPackets(self):
        """ Generate measurement packets from the socket. """
        while True:
            try:
                _line = self.port.readline(4096)
                #loginf(_line)
            except (socket.timeout, socket.error) as ex:
                raise weewx.WeeWxIOError(ex)
            if _line == None:
                break
            if _line[0:8] == 'outTemp=':
                #loginf("New line on socket, processing weather data.")
                yield self._process_message(_line)
            else:
                #loginf("New line on socket, but did not start with 'outTemp='. Ignoring line.")
                pass

    def _process_message(self, message):
        _packet = {}

        # Separate line into a dict
        message = message.rstrip() # Strip any newline
        line = message.split(',') # Split by comma
        data = dict( [ i.split( '=' ) for i in line] ) # Create dictionary of the values

        _packet['dateTime'] = int(time.time())
        _packet['usUnits'] = weewx.US
        _packet['outTemp'] = float( data["outTemp"] )
        _packet['outHumidity'] = float( data["outHumidity"] )
        _packet['inTemp'] = float( data["inTemp"] )
        _packet['inHumidity'] = float( data["inHumidity"] )
        _packet['barometer'] = float( data["barometer"] )
        _packet['rain'] = self.check_rain( data["dailyrain"] )
        _packet['windDir'] = float( data["windDir"] )
        _packet['windSpeed'] = float( data["windSpeed"] )
        _packet['windGust'] = float( data["windGust"] )
        _packet['windGustDir'] = float( data["windDir"] )
        _packet['radiation'] = float( data["radiation"] )
        _packet['UV'] = float( data["UV"] )
        _packet['txBatteryStatus'] = float( data["txBatteryStatus"] )
        #loginf(_packet)
        return _packet

---------------------------

i now get:

Nov 21 14:11:30 pi4 systemd[1]: Starting LSB: weewx weather system...
Nov 21 14:11:30 pi4 weewx[3164] INFO __main__: Initializing weewx version 4.5.1
Nov 21 14:11:30 pi4 weewx[3164] INFO __main__: Using Python 3.7.3 (default, Jan 22 2021, 20:04:44) #012[GCC 8.3.0]
Nov 21 14:11:30 pi4 weewx[3164] INFO __main__: Platform Linux-5.10.17-v7l+-armv7l-with-debian-10.10
Nov 21 14:11:30 pi4 weewx[3164] INFO __main__: Locale is 'en_US.UTF-8'
Nov 21 14:11:30 pi4 weewx[3164] INFO __main__: PID file is /var/run/weewx.pid
Nov 21 14:11:30 pi4 weewx[3168] INFO __main__: Using configuration file /etc/weewx/weewx.conf
Nov 21 14:11:30 pi4 weewx[3168] INFO __main__: Debug is 0
Nov 21 14:11:30 pi4 weewx[3168] INFO weewx.engine: Loading station type SocketLogger (user.socketlogger)
Nov 21 14:11:30 pi4 /weewxd: SocketLogger: Connecting to socket on localhost port 2999
Nov 21 14:11:30 pi4 /weewxd: SocketLogger: Connected to host localhost on port 2999
Nov 21 14:11:30 pi4 weewx[3168] INFO weewx.engine: StdConvert target unit is 0x1
Nov 21 14:11:30 pi4 weewx[3152]: Starting weewx weather system: weewx.
Nov 21 14:11:30 pi4 systemd[1]: Started LSB: weewx weather system.
Nov 21 14:11:30 pi4 weewx[3168] INFO weewx.manager: Daily summaries at V2.0. Patching to V4.0
Nov 21 14:11:30 pi4 weewx[3168] INFO weewx.manager: recalculate_weights: Using database 'weewx.sdb'

It took almost 10 minutes, but I have data in weewx again. 

Op dinsdag 7 juli 2020 om 21:21:50 UTC+2 schreef goo...@effsec.nl:
Reply all
Reply to author
Forward
0 new messages