theengs / gateway

Multi platform Multi devices BLE Bluetooth to MQTT gateway leveraging Theengs Decoder
https://gateway.theengs.io
GNU General Public License v3.0
111 stars 31 forks source link

TypeError: %d format: a real number is required, not ReasonCode #262

Closed ArjanM83 closed 3 months ago

ArjanM83 commented 4 months ago

A couple of days ago I started using TheengsGateway using Docker on a RPi 2 (32-bit):

docker run -d \
    --restart on-failure \
    --privileged \
    -e MQTT_HOST=192.168.86.6 \
    -e MQTT_USERNAME=user1 \
    -e MQTT_PASSWORD=password \
    -e MQTT_PUB_TOPIC=home/TheengsGatewayClient1/messages \
    -e MQTT_SUB_TOPIC=home/TheengsGateway/Client1/commands \
    -e PUBLISH_ALL=true \
    -e SCAN_TIME=60 \
    -e TIME_BETWEEN=0 \
    -e LOG_LEVEL=WARNING \
    -e HASS_DISCOVERY=false \
    -e GENERAL_PRESENCE=false \
    -e DISCOVERY=false \
    -e DISCOVERY_TOPIC=hello/topic \
    -e SCANNING_MODE=active \
    -v /var/run/dbus:/var/run/dbus \
    --name Theengs_Gateway \
    theengs/gateway:latest

During the night I noticed the same error multiple times, see below. Also it stopped sending messages to the MQTT broker, not sure yet if it's the broker or Theengs Gateway that failed. The broker is also using Docker (eclipse-mosquitto version 2.0.18).

Error:

--- Logging error ---
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/logging/__init__.py", line 1110, in emit
    msg = self.format(record)
          ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/logging/__init__.py", line 953, in format
    return fmt.format(record)
           ^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/logging/__init__.py", line 687, in format
    record.message = record.getMessage()
                     ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/logging/__init__.py", line 377, in getMessage
    msg = msg % self.args
          ~~~~^~~~~~~~~~~
TypeError: %d format: a real number is required, not ReasonCode
Call stack:
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/opt/venv/lib/python3.11/site-packages/TheengsGateway/__main__.py", line 5, in <module>
    main()
  File "/opt/venv/lib/python3.11/site-packages/TheengsGateway/__init__.py", line 55, in main
    run(configuration, config_path)
  File "/opt/venv/lib/python3.11/site-packages/TheengsGateway/ble_gateway.py", line 683, in run
    gw.client.loop_forever()
  File "/opt/venv/lib/python3.11/site-packages/paho/mqtt/client.py", line 2291, in loop_forever
    rc = self._loop(timeout)
  File "/opt/venv/lib/python3.11/site-packages/paho/mqtt/client.py", line 1680, in _loop
    rc = self.loop_read()
  File "/opt/venv/lib/python3.11/site-packages/paho/mqtt/client.py", line 2096, in loop_read
    return self._loop_rc_handle(rc)
  File "/opt/venv/lib/python3.11/site-packages/paho/mqtt/client.py", line 3042, in _loop_rc_handle
    self._do_on_disconnect(packet_from_broker=False, v1_rc=rc)
  File "/opt/venv/lib/python3.11/site-packages/paho/mqtt/client.py", line 4378, in _do_on_disconnect
    on_disconnect(
  File "/opt/venv/lib/python3.11/site-packages/TheengsGateway/ble_gateway.py", line 163, in on_disconnect
    logger.error(
Message: 'Disconnected from MQTT broker with reason code = %d'
Arguments: (ReasonCode(Disconnect, 'Unspecified error'),)

Since I'm using the Docker version, what can I do to retrieve more useful information?

ArjanM83 commented 3 months ago

Since I moved the docker container to another RPi, I haven't seen this issue anymore. Perhaps the older RPi 2 just had issues. I will close this issue for now.