Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RuuviTagSensor.get_datas looses data from sensors when running via a docker container after a few hours #120

Closed
emmanuel-bv opened this issue Jan 22, 2021 · 1 comment
Labels

Comments

@emmanuel-bv
Copy link

Describe the bug
RuuviTag python library looses some sensors when running through a docker container for a few hours.

Environment:

  • HW: Raspberry Pi 3 B+
  • OS: Raspbian Stretch
  • ruuvitag_sensor package version: ruuvitag-sensor==1.1.0
  • RuuviTag firmware version: latest stable
  • Data format: 5

When running this simple Python script on the host, it works as expected and collects data from all the sensors over long period of time:

import logging
import os
import sys
import time

from ruuvitag_sensor.ruuvi import RuuviTagSensor

# A map of sensors' MAC to device id.
# All devices need to be pre-created in IoT Hub.
authorized_devices = {"FE:36:EA:1E:62:AF": "sensor_1",
                      "E4:F2:81:30:8D:52": "sensor_2"}

logging.basicConfig(
    format='%(asctime)s %(levelname)-8s %(message)s',
    level=logging.DEBUG,
    datefmt='%Y-%m-%d %H:%M:%S')


def log_messages(mac, payload):
    """ The callback for when a message is received from a sensor.
    """

    # This check for authorized devices should not be needed
    # given that it should already be enforced by the ruuvitag library
    if mac in authorized_devices:
        device_id = authorized_devices[mac]
        logging.info("publishing message for %s [%s]: {%s}." %(device_id, mac, str(payload)))
    else:
        logging.warning("ignoring message from an unknown sensor (MAC address: {%s})."%(mac))


def main():

    def callback(data):
        log_messages(data[0], data[1])

    # listening for sensors data.
    logging.info("listening for sensors data.")
    RuuviTagSensor.get_datas(callback, list(authorized_devices.keys()))

    logging.info("exiting.")


if __name__ == "__main__":
    main()

However when running the same code in a docker container on the same raspberry pi hardware, it will initially start by collecting data from all sensors but then miss data from sensor 2 after a couple hours.

Here is here is the docker file used:

COPY requirements.txt ./
RUN pip install -r requirements.txt

COPY app .

# For demo purposes, started as root to make sure 
# there are no permission issues.
USER root

CMD [ "python3", "-u", "./main.py" ]

and the requirements file:
ruuvitag-sensor==1.1.0

And here is the docker run command used:
sudo docker run --rm --network host --privileged arm32v7_container

@ttu
Copy link
Owner

ttu commented Mar 20, 2022

Hi @ebertrams!

Sorry that didn't get back to you regarding this issue. Hope that you got the situation sorted out.

If you are still using RuuviTag and you have this same issue, could you provie me more logging data. You can write all logs to file by changing file_handler's log level, e.g.

import logging
from ruuvitag_sensor.log import log
from ruuvitag_sensor.ruuvi import RuuviTagSensor

for handler in log.handlers:
    if isinstance(handler, logging.FileHandler):
        handler.setLevel(logging.DEBUG)

if __name__ == "__main__":
    RuuviTagSensor.get_data_for_sensors()

Sorry once again, that I ignored this issue :(

@ttu ttu closed this as completed Mar 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants