It appears that this part of the meteostick driver was never updated to
Python 3.

The crc16() function could work with either Python 2 or 3 until V5.2, at
which point the Python 2 code was removed.

For the moment, replace the file /usr/share/weewx/weewx/crc16.py with the
older version, attached below.

I'll file an issue with the author.

-tk

On Sun, Oct 19, 2025 at 6:16 AM Joe Garcia <[email protected]> wrote:

> Yeah, sorry, the post took awhile to appear so I couldn't update it with
> the full log, whole thing is attached below.  Looking at the repo, there
> was a change to crc16.py 11 months ago that may have caused this:
>
> - def crc16(bytes, crc_start=0):
> + def crc16(byte_buf, crc_start=0):
>
> - return reduce(lambda crc_sum, ch: (_table[(crc_sum >> 8) ^ ch] ^
> (crc_sum << 8)) & 0xffff, byte_buf, crc_start)
> + crc_sum = reduce(lambda crc, ch : (_table[(crc >> 8) ^ ch] ^ (crc << 8))
> & 0xffff, byte_iter, crc_start)
>
> but see my earlier comment about no hablo Python :).
>
> CRITICAL __main__: Caught unrecoverable exception:
> CRITICAL __main__:     ****  unsupported operand type(s) for ^: 'int' and
> 'str'
> CRITICAL __main__:     ****  Traceback (most recent call last):
> CRITICAL __main__:     ****    File "/usr/share/weewx/weewxd.py", line
> 127, in main
> CRITICAL __main__:     ****      engine.run()
> CRITICAL __main__:     ****      ~~~~~~~~~~^^
> CRITICAL __main__:     ****    File "/usr/share/weewx/weewx/engine.py",
> line 204, in run
> CRITICAL __main__:     ****      for packet in
> self.console.genLoopPackets():
> CRITICAL __main__:     ****
>  ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
> CRITICAL __main__:     ****    File "/etc/weewx/bin/user/meteostick.py",
> line 311, in genLoopPackets
> CRITICAL __main__:     ****      data =
> self.station.parse_readings(readings, self.rain_per_tip)
> CRITICAL __main__:     ****    File "/etc/weewx/bin/user/meteostick.py",
> line 638, in parse_readings
> CRITICAL __main__:     ****      data = self.parse_raw(raw,
> CRITICAL __main__:     ****
>  self.channels['iss'],
> CRITICAL __main__:     ****      ...<3 lines>...
> CRITICAL __main__:     ****
>  self.channels['temp_hum_2'],
> CRITICAL __main__:     ****                            rain_per_tip)
> CRITICAL __main__:     ****    File "/etc/weewx/bin/user/meteostick.py",
> line 687, in parse_raw
> CRITICAL __main__:     ****      Meteostick._check_crc(raw_msg_crc, chksum)
> CRITICAL __main__:     ****      ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
> CRITICAL __main__:     ****    File "/etc/weewx/bin/user/meteostick.py",
> line 505, in _check_crc
> CRITICAL __main__:     ****      crc_result = crc16(msg)
> CRITICAL __main__:     ****    File "/usr/share/weewx/weewx/crc16.py",
> line 49, in crc16
> CRITICAL __main__:     ****      return reduce(lambda crc_sum, ch:
> (_table[(crc_sum >> 8) ^ ch] ^ (crc_sum << 8)) & 0xffff,
> CRITICAL __main__:     ****                    byte_buf, crc_start)
> CRITICAL __main__:     ****    File "/usr/share/weewx/weewx/crc16.py",
> line 49, in <lambda>
> CRITICAL __main__:     ****      return reduce(lambda crc_sum, ch:
> (_table[(crc_sum >> 8) ^ ch] ^ (crc_sum << 8)) & 0xffff,
> CRITICAL __main__:     ****                            ~~~~~~~~~~~~~~~^~~~
> CRITICAL __main__:     ****  TypeError: unsupported operand type(s) for ^:
> 'int' and 'str'
> CRITICAL __main__:     ****  Exiting.
> Traceback (most recent call last):
>   File "/usr/share/weewx/weewxd.py", line 226, in <module>
>     main()
>     ~~~~^^
>   File "/usr/share/weewx/weewxd.py", line 127, in main
>     engine.run()
>     ~~~~~~~~~~^^
>   File "/usr/share/weewx/weewx/engine.py", line 204, in run
>     for packet in self.console.genLoopPackets():
>                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
>   File "/etc/weewx/bin/user/meteostick.py", line 311, in genLoopPackets
>     data = self.station.parse_readings(readings, self.rain_per_tip)
>   File "/etc/weewx/bin/user/meteostick.py", line 638, in parse_readings
>     data = self.parse_raw(raw,
>                           self.channels['iss'],
>     ...<3 lines>...
>                           self.channels['temp_hum_2'],
>                           rain_per_tip)
>   File "/etc/weewx/bin/user/meteostick.py", line 687, in parse_raw
>     Meteostick._check_crc(raw_msg_crc, chksum)
>     ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
>   File "/etc/weewx/bin/user/meteostick.py", line 505, in _check_crc
>     crc_result = crc16(msg)
>   File "/usr/share/weewx/weewx/crc16.py", line 49, in crc16
>     return reduce(lambda crc_sum, ch: (_table[(crc_sum >> 8) ^ ch] ^
> (crc_sum << 8)) & 0xffff,
>                   byte_buf, crc_start)
>   File "/usr/share/weewx/weewx/crc16.py", line 49, in <lambda>
>     return reduce(lambda crc_sum, ch: (_table[(crc_sum >> 8) ^ ch] ^
> (crc_sum << 8)) & 0xffff,
>                                               ~~~~~~~~~~~~~~~^~~~
> TypeError: unsupported operand type(s) for ^: 'int' and 'str'
>
> On Sunday, 19 October 2025 at 03:12:18 UTC+13 Tom Keffer wrote:
>
>> I'm sorry but the lines in your snippet are so truncated it's hard to
>> tell what's going on. Can we see the full lines?
>>
>> On Sat, Oct 18, 2025 at 7:02 AM Joe Garcia <[email protected]> wrote:
>>
>>> Another instance of 5.2 breakage, Meteostick support no longer works:
>>>
>>> CRITICAL __main__:     ****    File "/etc/weewx/bin/user/meteostick.py",
>>> l>
>>> CRITICAL __main__:     ****      crc_result = crc16(msg)
>>> CRITICAL __main__:     ****    File "/usr/share/weewx/weewx/crc16.py",
>>> lin>
>>> CRITICAL __main__:     ****      return reduce(lambda crc_sum, ch:
>>> (_table>
>>> CRITICAL __main__:     ****                    byte_buf, crc_start)
>>> CRITICAL __main__:     ****    File "/usr/share/weewx/weewx/crc16.py",
>>> lin>
>>> CRITICAL __main__:     ****      return reduce(lambda crc_sum, ch:
>>> (_table>
>>> CRITICAL __main__:     ****
>>>   >
>>> CRITICAL __main__:     ****  TypeError: unsupported operand type(s) for
>>> ^:>
>>> CRITICAL __main__:     ****  Exiting.
>>>
>>> This may also have come about from an update to Python that occurred at
>>> the same time, not 5.2-specific.  Unfortunately I don't speak Python so I'm
>>> not sure what's required to fix meteostick.py, and the original on Github
>>> hasn't been updated since 2019.
>>>
>>> --
>>> 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 visit
>>> https://groups.google.com/d/msgid/weewx-user/56358b16-66c3-41f6-b500-5cd3e6f9aad6n%40googlegroups.com
>>> <https://groups.google.com/d/msgid/weewx-user/56358b16-66c3-41f6-b500-5cd3e6f9aad6n%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 visit
> https://groups.google.com/d/msgid/weewx-user/eebc86d4-933e-480b-a5d4-6cdb1b49403fn%40googlegroups.com
> <https://groups.google.com/d/msgid/weewx-user/eebc86d4-933e-480b-a5d4-6cdb1b49403fn%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 visit 
https://groups.google.com/d/msgid/weewx-user/CAPq0zEDRJD6BO%3DaNPoCVyzzK-LigSTxzi8uUSGQPeMkKAfG%3DJQ%40mail.gmail.com.
#
#    Copyright (c) 2009-2015 Tom Keffer <[email protected]>
#
#    See the file LICENSE.txt for your full rights.
#
"""Routines for calculating a 16-bit CRC check. """

from functools import reduce

_table=[
0x0000,  0x1021,  0x2042,  0x3063,  0x4084,  0x50a5,  0x60c6,  0x70e7,  # 0x00
0x8108,  0x9129,  0xa14a,  0xb16b,  0xc18c,  0xd1ad,  0xe1ce,  0xf1ef,  # 0x08  
0x1231,  0x0210,  0x3273,  0x2252,  0x52b5,  0x4294,  0x72f7,  0x62d6,  # 0x10
0x9339,  0x8318,  0xb37b,  0xa35a,  0xd3bd,  0xc39c,  0xf3ff,  0xe3de,  # 0x18
0x2462,  0x3443,  0x0420,  0x1401,  0x64e6,  0x74c7,  0x44a4,  0x5485,  # 0x20
0xa56a,  0xb54b,  0x8528,  0x9509,  0xe5ee,  0xf5cf,  0xc5ac,  0xd58d,  # 0x28
0x3653,  0x2672,  0x1611,  0x0630,  0x76d7,  0x66f6,  0x5695,  0x46b4,  # 0x30
0xb75b,  0xa77a,  0x9719,  0x8738,  0xf7df,  0xe7fe,  0xd79d,  0xc7bc,  # 0x38
0x48c4,  0x58e5,  0x6886,  0x78a7,  0x0840,  0x1861,  0x2802,  0x3823,  # 0x40
0xc9cc,  0xd9ed,  0xe98e,  0xf9af,  0x8948,  0x9969,  0xa90a,  0xb92b,  # 0x48
0x5af5,  0x4ad4,  0x7ab7,  0x6a96,  0x1a71,  0x0a50,  0x3a33,  0x2a12,  # 0x50
0xdbfd,  0xcbdc,  0xfbbf,  0xeb9e,  0x9b79,  0x8b58,  0xbb3b,  0xab1a,  # 0x58
0x6ca6,  0x7c87,  0x4ce4,  0x5cc5,  0x2c22,  0x3c03,  0x0c60,  0x1c41,  # 0x60
0xedae,  0xfd8f,  0xcdec,  0xddcd,  0xad2a,  0xbd0b,  0x8d68,  0x9d49,  # 0x68
0x7e97,  0x6eb6,  0x5ed5,  0x4ef4,  0x3e13,  0x2e32,  0x1e51,  0x0e70,  # 0x70
0xff9f,  0xefbe,  0xdfdd,  0xcffc,  0xbf1b,  0xaf3a,  0x9f59,  0x8f78,  # 0x78
0x9188,  0x81a9,  0xb1ca,  0xa1eb,  0xd10c,  0xc12d,  0xf14e,  0xe16f,  # 0x80
0x1080,  0x00a1,  0x30c2,  0x20e3,  0x5004,  0x4025,  0x7046,  0x6067,  # 0x88
0x83b9,  0x9398,  0xa3fb,  0xb3da,  0xc33d,  0xd31c,  0xe37f,  0xf35e,  # 0x90
0x02b1,  0x1290,  0x22f3,  0x32d2,  0x4235,  0x5214,  0x6277,  0x7256,  # 0x98
0xb5ea,  0xa5cb,  0x95a8,  0x8589,  0xf56e,  0xe54f,  0xd52c,  0xc50d,  # 0xA0
0x34e2,  0x24c3,  0x14a0,  0x0481,  0x7466,  0x6447,  0x5424,  0x4405,  # 0xA8
0xa7db,  0xb7fa,  0x8799,  0x97b8,  0xe75f,  0xf77e,  0xc71d,  0xd73c,  # 0xB0
0x26d3,  0x36f2,  0x0691,  0x16b0,  0x6657,  0x7676,  0x4615,  0x5634,  # 0xB8
0xd94c,  0xc96d,  0xf90e,  0xe92f,  0x99c8,  0x89e9,  0xb98a,  0xa9ab,  # 0xC0
0x5844,  0x4865,  0x7806,  0x6827,  0x18c0,  0x08e1,  0x3882,  0x28a3,  # 0xC8
0xcb7d,  0xdb5c,  0xeb3f,  0xfb1e,  0x8bf9,  0x9bd8,  0xabbb,  0xbb9a,  # 0xD0
0x4a75,  0x5a54,  0x6a37,  0x7a16,  0x0af1,  0x1ad0,  0x2ab3,  0x3a92,  # 0xD8
0xfd2e,  0xed0f,  0xdd6c,  0xcd4d,  0xbdaa,  0xad8b,  0x9de8,  0x8dc9,  # 0xE0
0x7c26,  0x6c07,  0x5c64,  0x4c45,  0x3ca2,  0x2c83,  0x1ce0,  0x0cc1,  # 0xE8
0xef1f,  0xff3e,  0xcf5d,  0xdf7c,  0xaf9b,  0xbfba,  0x8fd9,  0x9ff8,  # 0xF0
0x6e17,  0x7e36,  0x4e55,  0x5e74,  0x2e93,  0x3eb2,  0x0ed1,  0x1ef0   # 0xF8
]


def crc16(bytes, crc_start=0):
    """ Calculate CRC16 sum"""

    # We need something that returns integers when iterated over.
    try:
        # Python 2
        byte_iter = [ord(x) for x in bytes]
    except TypeError:
        # Python 3
        byte_iter = bytes

    crc_sum = reduce(lambda crc, ch : (_table[(crc >> 8) ^ ch] ^ (crc << 8)) & 0xffff, byte_iter, crc_start)

    return crc_sum


if __name__ == '__main__' :
    import struct
    # This is the example given in the Davis documentation:
    test_bytes = struct.pack("<HH", 0xCEC6, 0x03A2)
    crc = crc16(test_bytes)
    assert(crc==0xe2b4)

Reply via email to