Giter Site home page Giter Site logo

rkoshak / sensorreporter Goto Github PK

View Code? Open in Web Editor NEW
104.0 16.0 42.0 594 KB

A python based service that receives sensor inputs and publishes them in various ways.

License: Apache License 2.0

Python 92.31% Shell 7.69%
bluetooth gpio mqtt openhab rest-api

sensorreporter's People

Contributors

1technophile avatar aherstein avatar bgilmer77 avatar danieldecker avatar florian-h05 avatar lennysh avatar markrad avatar mgarciate avatar msw1970 avatar paillom avatar reddevil156 avatar rhyssman avatar rkoshak avatar urmel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sensorreporter's Issues

Not Really an Issue

Hi @rkoshak,

I often see you in the OpenHab community forum and I saw mention of this project in one of your posts. First off this is a great idea. I love the idea of being able to deploy a sensor with just an ini file.

However, it did not meet all my needs.

First, I would really appreciate it if you would integrate the DHT22 code that you have waiting.

Second, I really needed event detection for a motion sensor. I forked your code and added that functionality (for the Pi sensor only). The other issue that I had is that my original code used an LED to indicate motion. I could have pushed the value to OpenHab and then have it return a value to turn on the LED but that really didn't meet my needs. I want the LED to tell me the local code is working. Pushing it to OpenHab has too many failure points so I wouldn't know if OpenHab was down, my network connection was bad or my code monitoring the sensor was not running.

To address this, I added an option in the sensor options to dynamically load a script that is called when the pin changes state. Here is a snippet of my ini file:

[Sensor2]
; Native Raspberry Pi Library
Class: rpiGPIOSensor.rpiGPIOSensor
Pin: 12
Connection: MQTT
Destination: sensor2/topic
PUD: DOWN
EventDetection: BOTH
StateCallback: switchLed
StateCallbackArgs: Actuator_Unoccupied,Actuator_Occupied
Poll: -1

Here is a sample StateCallback function (switchLed.py):

occupiedPin = None
unoccupiedPin = None

def init(params):
    global occupiedPin
    global unoccupiedPin
    
    pins = params('StateCallbackArgs').split(',')
    occupiedPin = pins[0]
    unoccupiedPin = pins[1]

def stateChange(state, params, actuators):
    global occupiedPin
    global unoccupiedPin
    
    if (state == 1):
        actuators[occupiedPin].on_direct_message("ON")
        actuators[unoccupiedPin].on_direct_message("OFF")
    else:
        actuators[occupiedPin].on_direct_message("OFF")
        actuators[unoccupiedPin].on_direct_message("ON")

In my scenario I have a RGB LED which I turn on the red LED when no motion is detected and the blue LED when motion is detected. If this is of interest to you then I will send you a pull request. You can check out the code at https://github.com/markrad/sensorReporter.

Anyway, thanks for all your hard work. It works very well.

And by the way, I fixed a couple of bugs too. Toggle was broken, it always came out true and the GPIO was set to low if the msg payload was ON which seemed like it was the wrong way round to me.

M.

active_low

Would be nice to have an option to swap the ON/OFF value coming from openHAB.
Or am I missing a setting somewhere? :$

ps love this script! Works perfectly ...

Request to update GPIO Readme

Sorry if this is the wrong format for this suggestion. I could submit the proposed changes via PR if that is preferred.

The Python file rpi_gpio.py sets the GPIO mode to "BCM". A lot of the examples that I have been following use "BOARD", which caused a great deal of confusion when I was trying to figure out why the sensorReporter was logging PIN 15 as DOWN.

Consider adding a row for Pin under the table in gpio.rpi_gpio.RpiGpioSensor of the Readme file, which explains that the GPIO mode is set to "BCM" and to use the Pinout command to find the correct pin in the configuration file.

GPIO.setmode(GPIO.BCM)

Convert to a module

Raspberry Pi OS bookwork has tightened down the installation of libraries and all but requires a virtualenv.

In order to install this as a module requires a restructuring of the folders and creation of some new files.

Log level set on class level [bug?]

I came across that setting the level in the config e.g. for a connection will be applied to all connections.
Example config:

[Logging]
Syslog = YES
Level = INFO

[Connection1]
Class = openhab_rest.rest_conn.OpenhabREST
Name = openHAB
URL = http://localhost:8080
RefreshItem = Test_Refresh

[Connection2]
Class = openhab_rest.rest_conn.OpenhabREST
Name = openHAB2
URL = http://192.168.1.1:8080
RefreshItem = Test_Refresh
Level = DEBUG

In above configuration all connections will be set to log level DEBUG. For sensors and actuators it is the same.
Is this behavior intended?

sensor actuator evaluation [enhancement]

I think there is a need for some kind of logic processing to trigger several actuators with multiple sensors.
Example: A room with 2 motion detectors and 3 lights, all lights should switch on if either motion detector triggers. Only if both motion detectors are off the lights should switch off.

Currently there is no way to trigger several actuators with on sensor or like in the example above connect many sensors with many actuators. I would implement this with a new pseudo actuator, which will receive the sensor states and trigger the configured actuators.
What do you think about the idea?

Fresh Install On RPi3 Causes IndentationError

I'm attempting to use sensorReporter to deliver info into OpenHAB using the REST API... When I try to launch sensorReporter using sudo python sensorReporter.py sensorReporter.ini I get the following error..

Starting...
Loading sensorReporter.ini
Configuring logger: file = /var/log/sensorReporter.log size = 67108864 num = 10
Traceback (most recent call last):
File "sensorReporter.py", line 207, in
main()
File "sensorReporter.py", line 71, in main
loadConfig(sys.argv[1])
File "sensorReporter.py", line 194, in loadConfig
createConnection(config, section)
File "sensorReporter.py", line 173, in createConnection
MyConn = getattr(importlib.import_module(module_name), class_name)
File "/usr/lib/python2.7/importlib/init.py", line 37, in import_module
import(name)
File "/opt/sensorReporter/restConn.py", line 41
def publish(self, message, destination):
^
IndentationError: unexpected indent

I've checked restConn.py for indentation errors but I can't find any..

Bad Command Actuator

Actuator 0 does not work for me . If Toggle is left TRUE system toggles the actuator like expected. If i set FALSE for the toggle setting it still toggles regardless of the command sent to the topic. If i leave the Toggle setting blank the logs show that the toggle setting is set to false but i get the error Bad command ON and or Bad command OFF when trying to send either or to the topic.

[Logging]
Syslog = YES
Level = INFO

[Connection1]
Class = mqtt.mqtt_conn.MqttConnection
Name = MQTT
Client = Fishtank
User = xxxxxxx
Password = xxxxxx
Host = x.x.x.x
Port = 1883
Keepalive = 10
RootTopic = fishtank
TLS = NO
Level = DEBUG

[Actuator0]
Class = gpio.rpi_gpio.RpiGpioActuator
Connection = MQTT
CommandSrc = light/switch
Pin = 24
InitialState = OFF
Toggle =
Level = DEBUG

Some logs
root@fishtank:/opt/sensorReporter# systemctl restart sensor_reporter.service
root@fishtank:/opt/sensorReporter# journalctl -f -u sensor_reporter.service
-- Logs begin at Tue 2021-06-22 15:34:52 BST. --
Jun 22 17:30:22 fishtank python3[12010]: INFO - [sensor_reporter] Creating device for Actuator0
Jun 22 17:30:22 fishtank python3[12010]: DEBUG - [MqttConnection] on_subscribe: Successfully subscribed <paho.mqtt.client.Client object at 0x76588f90>, None, 1, (0,)
Jun 22 17:30:22 fishtank python3[12010]: INFO - [MqttConnection] Registering for messages on 'fishtank/light/switch'
Jun 22 17:30:22 fishtank python3[12010]: INFO - [RpiGpioActuator] Configued RpoGpuiActuator: pin 24 on destination light/switch with toggle False
Jun 22 17:30:22 fishtank python3[12010]: INFO - [PollManager] Starting polling loop
Jun 22 17:30:22 fishtank python3[12010]: DEBUG - [MqttConnection] on_subscribe: Successfully subscribed <paho.mqtt.client.Client object at 0x76588f90>, None, 4, (0,)
Jun 22 17:30:22 fishtank python3[12010]: DEBUG - [MqttConnection] on_subscribe: Successfully subscribed <paho.mqtt.client.Client object at 0x76588f90>, None, 5, (0,)
Jun 22 17:30:22 fishtank python3[12010]: DEBUG - [MqttConnection] Received message client <paho.mqtt.client.Client object at 0x76588f90> userdata None and msg <paho.mqtt.client.MQTTMessage object at 0x760926f0>
Jun 22 17:30:22 fishtank python3[12010]: INFO - [RpiGpioActuator] Received command on light/switch: OFF
Toggle = False Pin = 24
Jun 22 17:30:22 fishtank python3[12010]: ERROR - [RpiGpioActuator] Bad command OFF
Jun 22 17:30:52 fishtank python3[12010]: DEBUG - [MqttConnection] Received message client <paho.mqtt.client.Client object at 0x76588f90> userdata None and msg <paho.mqtt.client.MQTTMessage object at 0x760926f0>
Jun 22 17:30:52 fishtank python3[12010]: INFO - [RpiGpioActuator] Received command on light/switch: ON
Toggle = False Pin = 24
Jun 22 17:30:52 fishtank python3[12010]: ERROR - [RpiGpioActuator] Bad command ON
Jun 22 17:31:00 fishtank python3[12010]: DEBUG - [MqttConnection] Received message client <paho.mqtt.client.Client object at 0x76588f90> userdata None and msg <paho.mqtt.client.MQTTMessage object at 0x760926f0>
Jun 22 17:31:00 fishtank python3[12010]: INFO - [RpiGpioActuator] Received command on light/switch: ON
Toggle = False Pin = 24
Jun 22 17:31:00 fishtank python3[12010]: ERROR - [RpiGpioActuator] Bad command ON
Jun 22 17:31:05 fishtank python3[12010]: DEBUG - [MqttConnection] Received message client <paho.mqtt.client.Client object at 0x76588f90> userdata None and msg <paho.mqtt.client.MQTTMessage object at 0x760926f0>
Jun 22 17:31:05 fishtank python3[12010]: INFO - [RpiGpioActuator] Received command on light/switch: ON
Toggle = False Pin = 24
Jun 22 17:31:05 fishtank python3[12010]: ERROR - [RpiGpioActuator] Bad command ON

Any thoughts?

ConfigParser.NoOptionError: No option 'syslog' in section: 'Logging'

[23:57:15] openhabian@openHABianPi:/opt/sensorReporter$ sudo python /opt/sensorReporter/sensorReporter.py /opt/sensorReporter/sensorReporter.ini
Starting...
Loading /opt/sensorReporter/sensorReporter.ini
Traceback (most recent call last):
  File "/opt/sensorReporter/sensorReporter.py", line 199, in <module>
    main()
  File "/opt/sensorReporter/sensorReporter.py", line 71, in main
    loadConfig(sys.argv[1])
  File "/opt/sensorReporter/sensorReporter.py", line 181, in loadConfig
    config.get("Logging", "Syslog"))
  File "/usr/lib/python2.7/ConfigParser.py", line 618, in get
    raise NoOptionError(option, section)
ConfigParser.NoOptionError: No option 'syslog' in section: 'Logging'

The problem surely comes from me, but for several hours I have been looking for a solution. Can you help me? Thanks

[Logging]
File: /var/log/mqttReporter.log
MaxSize: 67108864
NumFiles: 10

Deprecate and remove gpioSensor.py

WebIOPi has long since gone away and rpiGPIOSensor replaces that functionality and then some. Rather than keeping this extension up to date we should just get rid of it.

Heartbeat.py does not send frequent messages

Hi, by using /device/getUpdate i get messages back of /status/heartbeat and /status/hearbeatstr (there is a typo) but normally i should get it every hr (3600000ms) but it does not work. I always need to ask.

ds18x20 configuration

I opened this issue because there seems to be a bug with the ds18x20 sensor and I think its better to discuss it here rather than in a merged PR #105

The original/old configuration did not work due to the MQTT Homie changes, so if both should, we need to fix this.

Originally posted by @florian-h05 in #105 (comment)

I wrote:

I deliberately designed the Homie support that way, that the config for a sensor with single output doesn't need to specify the channel. So sensorReporter will assume that the given StateDest is reverencing the only available channel.
So, in my opinion, both configurations (with and without channel) are correct in this case.

To clarify, this is nothing Homie specific, I was wrong in the comment above. The sensor channel structure it related to the yaml configuration and the way it is read.
After reviewing the code again, I must also state, that there is no auto selection for sensors with single output. There are single output sensors that don't require the channel to be defined and I took this for auto selection.

Actually it depends on the sensor implementation if a channel must be specified or not. taken from exec_sensor:

self._send(self.results, self.comm)

In the example above are only two arguments specified, the third argument which defines the trigger (channel) is omitted so there is no need to define a channel in the config.
In the ds18x20 sensor this looks as following

OUT_TEMP = "Temperature"
self._send(to_send, self.comm, OUT_TEMP)

Since the "trigger argument" is set to "Temperature" the configuration must specify this channel.

So there are two approaches:

  1. change the ds18x20 code and documentation, so that no extra channel is needed in the configuration. This would be consistent with the other sensors
  2. leave the ds18x20 code and documentation unchanged

For the sake of completeness:
If the sensor implementation uses the trigger argument in the send command configure_device_channel must also specify the channel via output_name:

configure_device_channel(self.comm, is_output=True, output_name=OUT_TEMP,
                                 datatype=ChanType.FLOAT, name="temperatur reading",
                                 unit="°" + self.temp_unit)

[rpiGPIOActuator.py] ON and OFF msg commands do not work

Sending any message to the topic for the actuator causes a toggle if toggle is set to true. Setting toggle to false and then sending either NO or YES to the MQTT topic causes a message such as, 2018-03-23 15:00:50,987 ERROR - Bad input <paho.mqtt.client.MQTTMessage object at 0xb66014b0>
Problem appears to be that the IF statements such as:
if msg == "ON"

never match.

MQTT does not reconnect if the remote broker is restarted

I have rPi Zero on which the sensorReporter is running, and the MQTT broker is running on 2nd rPI. If the rPi running the broker is restarted, the sensorReporter doesn't reconnect:

`pi@raspberrypizero:~ $ sudo systemctl status sensor_reporter.service
● sensor_reporter.service - Reports status and sensor readings over MQTT and openHAB REST
   Loaded: loaded (/etc/systemd/system/sensor_reporter.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2021-01-07 14:25:26 CET; 2 days ago
 Main PID: 26660 (python3)
    Tasks: 1 (limit: 881)
   CGroup: /system.slice/sensor_reporter.service
           └─26660 /usr/bin/python3 sensor_reporter.py sensor_reporter.ini

Jan 09 23:52:12 raspberrypizero python3[26660]: WARNING - [MqttConnection] MQTT is not currently connected! Ignoring message
Jan 09 23:52:12 raspberrypizero python3[26660]: WARNING - [MqttConnection] MQTT is not currently connected! Ignoring message`


MQTT Communicator not consistently publishing

I noticed that for a couple of weeks I've not been getting updates on my door status changes and only one of three installs are publishing heartbeat messages.

The communicator itself is working because I do get that first message published for each sensor when sensorReporter first starts up. That also shows that the sensors are configured to use that communicator.

But after that point nothing gets published. From looking at the logs it is detecting that the doors are opening and closing, it's just not publishing that fact.

And the heartbeat sensor is only publishing at all on two of my three instances with one simply never publishing at all.

In summary.

  • govee sensor
  • Heartbeat works on two out of three deployments
  • RPI GPIO Sensor only publishes during startup and never again, but it does sense the state changes on the pins

I'm still researching but configs seem to be the same for the heartbeat stuff so it's strange that it doesn't work.

Do not publish actuators from PollManager report

@DanielDecker, before I submit a PR to take care of this I want to make sure I understand what's going on.

This morning at 06:24 my sensorReporter restarted. During startup PollMgr.report was called and your new additions to publish the states of Actuators ran. So far, so good. But I think there is a bug in rpi_gpio.py.

    def publish_actuator_state(self):
        """Publishes the current state of the actuator."""
        msg = "ON" if self.current_state else "OFF"

        #publish own state, make sure the echo gets filtered
        self._publish(msg, self.cmd_src, filter_echo=True)

Shouldn't that publish to self.destination instead of self.cmd_src? By publishing to cmd_src it's causing the actuator to trigger which, at least in this one case, is absolutely not desirable. It make sense to report the current state, but not trigger the action.

add support for sensor pushbuttons

As I understand it the standard use case for a sensor in this project is a switch which stays on or off. In a smart home a light might be switched via a button or a rule. The button might be pressed for a short duration to toggle the light or for a long duration to activate a smart home scene. I'd like to implement optional param's to define location (to publish) and duration for for short and long press events so the destination doesn't need to handle that. @rkoshak are you interested in that feature?

What would be the best approach to make toggle for a actor using the local and mqtt connection possible?

More about TLS

Hi Richard,

I use you project to detect by bluetooth who is present in my house or elsewhere. Thank you for that it's working as I would with my rpi 3.

As usually, I try to secure my installation.

It seems the TLS part is incomplete in your project if I understand well.

May I suggest you to add some more options in your config file ?

For example about TLS:

TLS = YES # YES or NO as before
TLS Protocol version = 1.2 # here you can allow 1.0 (the default in paho mqtt) or 1.1 or 1.2
TLS certs directory = /opt/sensorReporter # no comment
Check TLS subject name = False

For this new option you will need:

self.client.tls_set("/opt/sensorReporter/certs/ca.crt","/opt/sensorReporter/certs/OH_secu.crt","/opt/sensorReporter/certs/OH_secu.key",tls_version=ssl.PROTOCOL_TLSv1_1)

Have to adapt the path to certs directory and change for tls version the last number. Beware if tls_version is not present it's TLS version 1 which is used by default.

As usually for a tls connection, you need the certificate authority, and client certificate (key and crt)

self.client.tls_insecure_set(True)
Is used to check if subject name in certificate match. If used with false this is ignored.

Add in mqttConn.py: import ssl

What do you think about that ? I'm using it and it's functional. It's better too have a secure connection, no ?

Gilles.

connect mutliple sensor_reporter via mqtt

Connecting eg. two raspberry pi's via sensor_reporter and mqtt seams to be useful for low level automation. Eg. sensor1 on pi A triggers actor2 on pi B. As I understand it using openHAB to translate such simple actions is a bad idea. So I was wondering if using mqtt for such cases is a better solution?

Btw. right now sensor_reporter logs an error when mapping an sensor to an actor via mqtt (open/close doesn't match on/off obviously)

local polling sensor for Connector online state

I think a sensor which can forward the online state of Connectors would be useful. This way an online status indicator or a fallback action can be configured in case a Connector goes offline.
The idea is to check every X seconds (configured polling interval) if the named Connector(s) is / are online. If offline for a certain time, send a command to a local actuator (e.g. on / off).

To make such a sensor possible I would add a new function to the connection class for requesting information about the connection (e.g. kind=local/remote, state=online/offline).

@rkoshak: what do you think of this proposal?

Enhancement to rpiGPIOSensor

  • Allow class rpiGPIOSensor to report ON / OFF as well as OPEN / CLOSED.
  • Add functionality to control if it is considered as active high or low. Eg. a magnetic door contact would be active LOW (indicating open door)

Q: BT detection of paired devices?

Hi there!

Currently, I'm trying to detect wether a BT adapter for my stereo is online. At first it went great using an openHAB binding as suggested here. Later I noticed, that the adapter will be marked as offline, if paired with my laptop. For me, this is unwanted behavior.

While searching for solutions, I found this repository (e.g. here). To save some time installing, configuring etc. I wanted to ask beforhand:
Is it possible to detect BT devices wich are paired with other devices?

I'd be grateful for a short reply.
Kind regards,

Hinrich

Support BLE

As far as I understand, sensorReporter can scan for legacy bluetooth devices. It would be nice to also include BLE in order to support low energy BLE tags.

I own a few attached to keys or objetcs and I use them for presence detection.

debounce possible?

Hi. SensorReporter is working fine for me. But I'm missing the debounce feature. Some of my sensors show some bouncing while going from off to on.

Is it possible to implement this?

Kinds

Goove Sensor do not work. Logs show that modules are missing

syslog:
Error creating device Sensor0: Traceback (most recent call last):#12 File "sensor_reporter.py", line 160, in create_device#012 device = getattr(importlib.import_module(module_name), class_name)#12 File "/usr/lib/python3.7/importlib/init.py", line 127, in import_module#012 return _bootstrap._gcd_import(name[level:], package, level)#12 File "", line 1006, in _gcd_import#012 File "", line 983, in _find_and_load#012 File "", line 953, in _find_and_load_unlocked#012 File "", line 219, in _call_with_frames_removed#012 File "", line 1006, in _gcd_import#012 File "", line 983, in _find_and_load#012 File "", line 965, in _find_and_load_unlocked#012ModuleNotFoundError: No module named 'govee'

python3 sensor_reporter.py configuration.ini
Traceback (most recent call last):
File "sensor_reporter.py", line 253, in
main()
File "sensor_reporter.py", line 244, in main
poll_mgr = create_poll_manager(config_file)
File "sensor_reporter.py", line 184, in create_poll_manager
init_logger(config)
File "sensor_reporter.py", line 103, in init_logger
set_log_level(lambda key: config.get("Logging", key), root_logger)
File "/opt/sensor_reporter/core/utils.py", line 20, in set_log_level
level = params("Level")
File "sensor_reporter.py", line 103, in
set_log_level(lambda key: config.get("Logging", key), root_logger)
File "/usr/lib/python3.7/configparser.py", line 780, in get
d = self._unify_values(section, vars)
File "/usr/lib/python3.7/configparser.py", line 1146, in _unify_values
raise NoSectionError(section) from None
configparser.NoSectionError: No section: 'Logging'

MQTT — Retain Messages

I am using MQTT to publish message information about a sensor. I see that the "retain" parameter is hardcoded to False. This is causing issues as the sensor reporter code only publishes to MQTT when there's been a change in status for a sensor. This means that anything consuming the topic will have no idea of the status of the sensor should it disconnect and reconnect later. Is this the intended behavior? What are your thoughts on possibly supplying an optional Retain1 parameter to go along with the Address1 and Destination1 parameters for a sensor?

Typing error in bluetoothScanner.py

Line 164:
for conn in self.publisher:

should be
for conn in self.publish:

Error message:
bash-4.4# python /opt/sensorReporter/sensorReporter.py /opt/sensorReporter/sensorReporter.ini
Starting...
Loading /opt/sensorReporter/sensorReporter.ini
Configuring logger: file = /var/log/mqttReporter.log size = 67108864 num = 10
Traceback (most recent call last):
File "/opt/sensorReporter/sensorReporter.py", line 207, in
main()
File "/opt/sensorReporter/sensorReporter.py", line 71, in main
loadConfig(sys.argv[1])
File "/opt/sensorReporter/sensorReporter.py", line 199, in loadConfig
sensors[section] = createDevice(config, section)
File "/opt/sensorReporter/sensorReporter.py", line 158, in createDevice
d = MyDevice(devConns, logger, params, sensors, actuators)
File "/opt/sensorReporter/bluetoothScanner.py", line 62, in init
self.publishState()
File "/opt/sensorReporter/bluetoothScanner.py", line 164, in publishState
for conn in self.publisher:

Inconsistent startup

Only about 50% of the time does sensorReporter come up when the computer reboots. I suspect there is a dependency that isn't running sometimes when it tries to start.

Python Thread Error

Hi

I've recently updated using git pull and now I'm seeing sensorReporter stopping with the following error showing in the logs..

`● sensorReporter.service - Reports status and sensor readings over MQTT and REST
Loaded: loaded (/etc/systemd/system/sensorReporter.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2018-11-22 22:41:12 GMT; 10min ago
Main PID: 4582 (python)
CGroup: /system.slice/sensorReporter.service
└─4582 /usr/bin/python /opt/sensorReporter/sensorReporter.py /opt/sensorReporter/sensorReporter.ini

Nov 22 22:45:23 WGB01AP1002 python[4582]: Published message 'OFF' to 'Mark_Phone_Bluetooth'
Nov 22 22:45:23 WGB01AP1002 python[4582]: Published message 'OFF' to 'Jo_Phone_Bluetooth'
Nov 22 22:45:23 WGB01AP1002 python[4582]: Traceback (most recent call last):
Nov 22 22:45:23 WGB01AP1002 python[4582]: File "/opt/sensorReporter/sensorReporter.py", line 207, in
Nov 22 22:45:23 WGB01AP1002 python[4582]: main()
Nov 22 22:45:23 WGB01AP1002 python[4582]: File "/opt/sensorReporter/sensorReporter.py", line 82, in main
Nov 22 22:45:23 WGB01AP1002 python[4582]: Thread(target=check, args=(sensors[s],)).start()
Nov 22 22:45:23 WGB01AP1002 python[4582]: File "/usr/lib/python2.7/threading.py", line 736, in start
Nov 22 22:45:23 WGB01AP1002 python[4582]: _start_new_thread(self.__bootstrap, ())
Nov 22 22:45:23 WGB01AP1002 python[4582]: thread.error: can't start new thread
`
I"m struggling to see why this would suddenly start happening.

Any clues?

sensorReporter 2.0 and Homie Support

This is an issue to track the effort to support the Homie MQTT topic standard which will allow automatic discovery of MQTT Things with the openHAB MQTT 2.4 binding (and others). However, this is going to require a significant reworking of the whole structure of sensorReporter so this issue will follow both.

I've created a homie branch to do this work in.

Tasks:

  • Done: Separate the add-ons into their own folders and use requirements.txt in each folder to capture needed third party libraries
  • Done: Add a separate README.md for each add-on
  • Started: Create base classes for sensors, actuators, connections and scripts and change existing add-ons to inherit from these base classes. Move all the common code possible to the base classes.
  • Separate the bluetooth add-on into three separate bindings
  • Move polling to the new sensor subclass to allow add-ons to manage their own threads (need to think about whether this is a good idea or not). Many already have to be in their own thread because they block or are event driven (e.g. GPIO, dash)
  • Normalize naming conventions
  • Create a Homie communicator that handles publishing and subscribing according to the Homie 3.0 standard.

The big difference with Homie is that the sensors and actuators can no longer arbitrarily define their MQTT topics. Furthermore, each node needs to be added to the Homie communicators because part of the standard is publishing metadata about what sensors are available and their data formats and such. I'm not yet positive how cleanly I can retain the existing communicators and also support Homie but I think Homie support is important enough to break some eggs.

Any questions, comments, and discussion are appreciated.

Syslog

Make the Syslog parameter optional and make sure it is documented in default.ini.

GPIO Actuator always works in "TOGGLE" Mode, steady state output is not possible

See issue title
In the readme file the TOGGLE is described as optional setting, but without it the sensor reporter logs an error.

Additionally maybe a good idea is to change the name of ÏnitialState" to "InvertOutput", which should create pulse with duration of 0,5s opposite on the "InitialState". For Example if the initial state is ON (because as in my case the relay board inputs are inverted), one might need to create pulse "ON-OFF-ON"

Config.ini:

[Logging]
 Syslog = YES
 Level = DEBUG

 [Connection1]
 Class = openhab_rest.rest_conn.OpenhabREST
 Name = openHAB
 URL = http://192.168.4.227:8080
 RefreshItem = RefreshSprinklers
 Level = DEBUG

 [Connection2]
 Class = mqtt.mqtt_conn.MqttConnection
 Name = MQTTSprinklers
 Client = rPiZero
 User = ****
 Password = ****
 Host = 192.168.4.227
 Port = 1883
 Keepalive = 10
 RootTopic = sensor_reporter
 TLS = NO
 Level = DEBUG

 [Sensor1]
 Class = heartbeat.heartbeat.Heartbeat
 Connection = MQTTSprinklers
 Poll = 60
 Num-Dest = heartbeat/num
 Str-Dest = heartbeat/str

 [Actuator0]
 Class = gpio.rpi_gpio.RpiGpioActuator
 Connection = MQTTSprinklers, openHAB
 CommandSrc  = SprinklersTerraceCmd
 InitialState = ON
 Pin = 26
 Level = DEBUG

 [Actuator1]
 Class = gpio.rpi_gpio.RpiGpioActuator
 Connection = MQTTSprinklers, openHAB
 CommandSrc = SprinklersGardenHouseCmd
 InitialState = ON
 Pin = 19
 Level = DEBUG

 [Actuator2]
 Class = gpio.rpi_gpio.RpiGpioActuator
 Connection = MQTTSprinklers, openHAB
 CommandSrc = SprinklersEntranceCmd
 InitialState = ON
 Pin = 13
 Level = DEBUG

 [Actuator3]
 Class = gpio.rpi_gpio.RpiGpioActuator
 Connection = MQTTSprinklers, openHAB
 CommandSrc = SprinklersFrontCmd
 InitialState = ON
 Pin = 6
 Level = DEBUG

 [Actuator4]
 Class = gpio.rpi_gpio.RpiGpioActuator
 Connection = MQTTSprinklers, openHAB
 CommandSrc = DripHoseCmd
 InitialState = ON
 Pin = 5
 Level = DEBUG

 [Actuator5]
 Class = gpio.rpi_gpio.RpiGpioActuator
 Connection = MQTTSprinklers, openHAB
 CommandSrc = SprinkerPumpCmd
 InitialState = ON
 Pin = 0
 Level = DEBUG

 [Actuator6]
 Class = gpio.rpi_gpio.RpiGpioActuator
 Connection = MQTTSprinklers, openHAB
 CommandSrc = SprinklerPiRelay7Cmd
 InitialState = ON
 Pin = 11
 Level = DEBUG

 [Actuator7]
 Class = gpio.rpi_gpio.RpiGpioActuator
 Connection = MQTTSprinklers, openHAB
 CommandSrc = SprinklerPiRelay8Cmd
 InitialState = ON
 Pin = 9
 Level = DEBUG

Log output:


 Dec 21 18:59:15 raspberrypizero INFO - [MqttConnection] Disconnected from MQTT broker with client <paho.mqtt.client.Client object at 0xb653d330>, userdata None, and code 0
Dec 21 18:59:15 raspberrypizero python3[5954]: /opt/sensor_reporter/gpio/rpi_gpio.py:140: RuntimeWarning: This channel is already in use, continuing anyway.  Use GPIO.setwarnings(False) to disable warnings.
Dec 21 18:59:15 raspberrypizero python3[5954]:   GPIO.setup(self.pin, GPIO.OUT)
Dec 21 18:59:15 raspberrypizero python3[5954]: Exception in thread Thread-1:
Dec 21 18:59:15 raspberrypizero python3[5954]: Traceback (most recent call last):
Dec 21 18:59:15 raspberrypizero python3[5954]:   File "/usr/lib/python3.7/threading.py", line 917, in _bootstrap_inner
Dec 21 18:59:15 raspberrypizero python3[5954]:     self.run()
Dec 21 18:59:15 raspberrypizero python3[5954]:   File "/usr/lib/python3.7/threading.py", line 865, in run
Dec 21 18:59:15 raspberrypizero python3[5954]:     self._target(*self._args, **self._kwargs)
Dec 21 18:59:15 raspberrypizero python3[5954]:   File "/usr/local/lib/python3.7/dist-packages/paho/mqtt/client.py", line 3452, in _thread_main
Dec 21 18:59:15 raspberrypizero python3[5954]:     self.loop_forever(retry_first_connection=True)
Dec 21 18:59:15 raspberrypizero python3[5954]:   File "/usr/local/lib/python3.7/dist-packages/paho/mqtt/client.py", line 1779, in loop_forever
Dec 21 18:59:15 raspberrypizero python3[5954]:     rc = self.loop(timeout, max_packets)
Dec 21 18:59:15 raspberrypizero python3[5954]:   File "/usr/local/lib/python3.7/dist-packages/paho/mqtt/client.py", line 1181, in loop
Dec 21 18:59:15 raspberrypizero python3[5954]:     rc = self.loop_read(max_packets)
Dec 21 18:59:15 raspberrypizero python3[5954]:   File "/usr/local/lib/python3.7/dist-packages/paho/mqtt/client.py", line 1572, in loop_read
Dec 21 18:59:15 raspberrypizero python3[5954]:     rc = self._packet_read()
Dec 21 18:59:15 raspberrypizero python3[5954]:   File "/usr/local/lib/python3.7/dist-packages/paho/mqtt/client.py", line 2310, in _packet_read
Dec 21 18:59:15 raspberrypizero python3[5954]:     rc = self._packet_handle()
Dec 21 18:59:15 raspberrypizero python3[5954]:   File "/usr/local/lib/python3.7/dist-packages/paho/mqtt/client.py", line 2936, in _packet_handle
Dec 21 18:59:15 raspberrypizero python3[5954]:     return self._handle_publish()
Dec 21 18:59:15 raspberrypizero python3[5954]:   File "/usr/local/lib/python3.7/dist-packages/paho/mqtt/client.py", line 3216, in _handle_publish
Dec 21 18:59:15 raspberrypizero python3[5954]:     self._handle_on_message(message)
Dec 21 18:59:15 raspberrypizero python3[5954]:   File "/usr/local/lib/python3.7/dist-packages/paho/mqtt/client.py", line 3429, in _handle_on_message
Dec 21 18:59:15 raspberrypizero python3[5954]:     callback(self, self._userdata, message)
Dec 21 18:59:15 raspberrypizero python3[5954]:   File "/opt/sensor_reporter/mqtt/mqtt_conn.py", line 147, in on_message
Dec 21 18:59:15 raspberrypizero python3[5954]:     handler(msg.payload.decode("utf-8"))
Dec 21 18:59:15 raspberrypizero python3[5954]:   File "/opt/sensor_reporter/gpio/rpi_gpio.py", line 159, in on_message
Dec 21 18:59:15 raspberrypizero python3[5954]:     self.cmd_src, msg, self.toggle, self.pin)
Dec 21 18:59:15 raspberrypizero python3[5954]: AttributeError: 'RpiGpioActuator' object has no attribute 'toggle'
Dec 21 18:59:15 raspberrypizero systemd[1]: sensor_reporter.service: Succeeded.
Dec 21 18:59:15 raspberrypizero systemd[1]: Stopped Reports status and sensor readings over MQTT and openHAB REST.
Dec 21 18:59:19 raspberrypizero systemd[1]: Started Reports status and sensor readings over MQTT and openHAB REST.
Dec 21 18:59:20 raspberrypizero INFO - [sensor_reporter] Setting logging level to DEBUG
Dec 21 18:59:20 raspberrypizero INFO - [sensor_reporter] Creating connection MQTTSprinklers
Dec 21 18:59:20 raspberrypizero INFO - [MqttConnection] Initializing MQTT Connection...
Dec 21 18:59:20 raspberrypizero INFO - [MqttConnection] Attempting to connect to MQTT broker at 192.168.4.227:1883
Dec 21 18:59:20 raspberrypizero INFO - [MqttConnection] Connection to MQTT is successful
Dec 21 18:59:20 raspberrypizero INFO - [MqttConnection] LWT topic is sensor_reporter/status, subscribing to refresh topic sensor_reporter/refresh
Dec 21 18:59:20 raspberrypizero INFO - [MqttConnection] Registering for messages on 'sensor_reporter/refresh'
Dec 21 18:59:20 raspberrypizero DEBUG - [MqttConnection] Published message ONLINE to sensor_reporter/status retain=True
Dec 21 18:59:20 raspberrypizero DEBUG - [sensor_reporter] 1 connections created
Dec 21 18:59:20 raspberrypizero INFO - [sensor_reporter] Creating device for Actuator0
Dec 21 18:59:20 raspberrypizero INFO - [MqttConnection] Connected with client <paho.mqtt.client.Client object at 0xb64e6330>, userdata None, flags {'session present': 0}, and result code 0. Subscribing to refresh command topic sensor_reporter/refresh
Dec 21 18:59:20 raspberrypizero DEBUG - [MqttConnection] Published message ONLINE to sensor_reporter/status retain=True
Dec 21 18:59:20 raspberrypizero INFO - [MqttConnection] on_connect: Resubscribing to sensor_reporter/refresh
Dec 21 18:59:21 raspberrypizero INFO - [sensor_reporter] Received a request for current sensor states before poll_mgr has been created, ignoring.
Dec 21 18:59:21 raspberrypizero DEBUG - [MqttConnection] on_publish: Successfully published message <paho.mqtt.client.Client object at 0xb64e6330>, None, 2
Dec 21 18:59:21 raspberrypizero DEBUG - [MqttConnection] on_publish: Successfully published message <paho.mqtt.client.Client object at 0xb64e6330>, None, 3
Dec 21 18:59:21 raspberrypizero DEBUG - [MqttConnection] on_subscribe: Successfully subscribed <paho.mqtt.client.Client object at 0xb64e6330>, None, 1, (0,)
Dec 21 18:59:21 raspberrypizero DEBUG - [MqttConnection] on_subscribe: Successfully subscribed <paho.mqtt.client.Client object at 0xb64e6330>, None, 4, (0,)
Dec 21 18:59:21 raspberrypizero INFO - [MqttConnection] Registering for messages on 'sensor_reporter/SprinklersTerraceCmd'
Dec 21 18:59:21 raspberrypizero DEBUG - [MqttConnection] on_subscribe: Successfully subscribed <paho.mqtt.client.Client object at 0xb64e6330>, None, 5, (0,)
Dec 21 18:59:21 raspberrypizero ERROR - [sensor_reporter] Error creating device Actuator0: Traceback (most recent call last):#012  File "/usr/lib/python3.7/configparser.py", line 788, in get#012    value = d[option]#012  File "/usr/lib/python3.7/collections/__init__.py", line 914, in __getitem__#012    return self.__missing__(key)            # support subclasses that define __missing__#012  File "/usr/lib/python3.7/collections/__init__.py", line 906, in __missing__#012    raise KeyError(key)#012KeyError: 'toggle'#012#012During handling of the above exception, another exception occurred:#012#012Traceback (most recent call last):#012  File "sensor_reporter.py", line 170, in create_device#012    return device(dev_conns, params)#012  File "/opt/sensor_reporter/gpio/rpi_gpio.py", line 149, in __init__#012    self.toggle = bool(params("Toggle"))#012  File "sensor_reporter.py", line 161, in <lambda>#012    params = lambda key: config.get(section, key)#012  File "/usr/lib/python3.7/configparser.py", line 791, in get#012    raise NoOptionError(option, section)#012configparser.NoOptionError: No option 'toggle' in section: 'Actuator0'
Dec 21 18:59:21 raspberrypizero INFO - [sensor_reporter] Creating device for Actuator1
Dec 21 18:59:21 raspberrypizero INFO - [MqttConnection] Registering for messages on 'sensor_reporter/SprinklersGardenHouseCmd'
Dec 21 18:59:21 raspberrypizero DEBUG - [MqttConnection] on_subscribe: Successfully subscribed <paho.mqtt.client.Client object at 0xb64e6330>, None, 6, (0,)
Dec 21 18:59:21 raspberrypizero ERROR - [sensor_reporter] Error creating device Actuator1: Traceback (most recent call last):#012  File "/usr/lib/python3.7/configparser.py", line 788, in get#012    value = d[option]#012  File "/usr/lib/python3.7/collections/__init__.py", line 914, in __getitem__#012    return self.__missing__(key)            # support subclasses that define __missing__#012  File "/usr/lib/python3.7/collections/__init__.py", line 906, in __missing__#012    raise KeyError(key)#012KeyError: 'toggle'#012#012During handling of the above exception, another exception occurred:#012#012Traceback (most recent call last):#012  File "sensor_reporter.py", line 170, in create_device#012    return device(dev_conns, params)#012  File "/opt/sensor_reporter/gpio/rpi_gpio.py", line 149, in __init__#012    self.toggle = bool(params("Toggle"))#012  File "sensor_reporter.py", line 161, in <lambda>#012    params = lambda key: config.get(section, key)#012  File "/usr/lib/python3.7/configparser.py", line 791, in get#012    raise NoOptionError(option, section)#012configparser.NoOptionError: No option 'toggle' in section: 'Actuator1'
Dec 21 18:59:21 raspberrypizero INFO - [sensor_reporter] Creating device for Actuator2
Dec 21 18:59:21 raspberrypizero INFO - [MqttConnection] Registering for messages on 'sensor_reporter/SprinklersEntranceCmd'
Dec 21 18:59:21 raspberrypizero DEBUG - [MqttConnection] on_subscribe: Successfully subscribed <paho.mqtt.client.Client object at 0xb64e6330>, None, 7, (0,)
Dec 21 18:59:21 raspberrypizero ERROR - [sensor_reporter] Error creating device Actuator2: Traceback (most recent call last):#012  File "/usr/lib/python3.7/configparser.py", line 788, in get#012    value = d[option]#012  File "/usr/lib/python3.7/collections/__init__.py", line 914, in __getitem__#012    return self.__missing__(key)            # support subclasses that define __missing__#012  File "/usr/lib/python3.7/collections/__init__.py", line 906, in __missing__#012    raise KeyError(key)#012KeyError: 'toggle'#012#012During handling of the above exception, another exception occurred:#012#012Traceback (most recent call last):#012  File "sensor_reporter.py", line 170, in create_device#012    return device(dev_conns, params)#012  File "/opt/sensor_reporter/gpio/rpi_gpio.py", line 149, in __init__#012    self.toggle = bool(params("Toggle"))#012  File "sensor_reporter.py", line 161, in <lambda>#012    params = lambda key: config.get(section, key)#012  File "/usr/lib/python3.7/configparser.py", line 791, in get#012    raise NoOptionError(option, section)#012configparser.NoOptionError: No option 'toggle' in section: 'Actuator2'
Dec 21 18:59:21 raspberrypizero INFO - [sensor_reporter] Creating device for Actuator3
Dec 21 18:59:21 raspberrypizero INFO - [MqttConnection] Registering for messages on 'sensor_reporter/SprinklersFrontCmd'
Dec 21 18:59:21 raspberrypizero DEBUG - [MqttConnection] on_subscribe: Successfully subscribed <paho.mqtt.client.Client object at 0xb64e6330>, None, 8, (0,)
Dec 21 18:59:21 raspberrypizero ERROR - [sensor_reporter] Error creating device Actuator3: Traceback (most recent call last):#012  File "/usr/lib/python3.7/configparser.py", line 788, in get#012    value = d[option]#012  File "/usr/lib/python3.7/collections/__init__.py", line 914, in __getitem__#012    return self.__missing__(key)            # support subclasses that define __missing__#012  File "/usr/lib/python3.7/collections/__init__.py", line 906, in __missing__#012    raise KeyError(key)#012KeyError: 'toggle'#012#012During handling of the above exception, another exception occurred:#012#012Traceback (most recent call last):#012  File "sensor_reporter.py", line 170, in create_device#012    return device(dev_conns, params)#012  File "/opt/sensor_reporter/gpio/rpi_gpio.py", line 149, in __init__#012    self.toggle = bool(params("Toggle"))#012  File "sensor_reporter.py", line 161, in <lambda>#012    params = lambda key: config.get(section, key)#012  File "/usr/lib/python3.7/configparser.py", line 791, in get#012    raise NoOptionError(option, section)#012configparser.NoOptionError: No option 'toggle' in section: 'Actuator3'
Dec 21 18:59:21 raspberrypizero INFO - [sensor_reporter] Creating device for Actuator4
Dec 21 18:59:21 raspberrypizero INFO - [MqttConnection] Registering for messages on 'sensor_reporter/DripHoseCmd'
Dec 21 18:59:21 raspberrypizero DEBUG - [MqttConnection] on_subscribe: Successfully subscribed <paho.mqtt.client.Client object at 0xb64e6330>, None, 9, (0,)
Dec 21 18:59:21 raspberrypizero ERROR - [sensor_reporter] Error creating device Actuator4: Traceback (most recent call last):#012  File "/usr/lib/python3.7/configparser.py", line 788, in get#012    value = d[option]#012  File "/usr/lib/python3.7/collections/__init__.py", line 914, in __getitem__#012    return self.__missing__(key)            # support subclasses that define __missing__#012  File "/usr/lib/python3.7/collections/__init__.py", line 906, in __missing__#012    raise KeyError(key)#012KeyError: 'toggle'#012#012During handling of the above exception, another exception occurred:#012#012Traceback (most recent call last):#012  File "sensor_reporter.py", line 170, in create_device#012    return device(dev_conns, params)#012  File "/opt/sensor_reporter/gpio/rpi_gpio.py", line 149, in __init__#012    self.toggle = bool(params("Toggle"))#012  File "sensor_reporter.py", line 161, in <lambda>#012    params = lambda key: config.get(section, key)#012  File "/usr/lib/python3.7/configparser.py", line 791, in get#012    raise NoOptionError(option, section)#012configparser.NoOptionError: No option 'toggle' in section: 'Actuator4'
Dec 21 18:59:21 raspberrypizero INFO - [sensor_reporter] Creating device for Actuator5
Dec 21 18:59:21 raspberrypizero INFO - [MqttConnection] Registering for messages on 'sensor_reporter/SprinkerPumpCmd'
Dec 21 18:59:21 raspberrypizero DEBUG - [MqttConnection] on_subscribe: Successfully subscribed <paho.mqtt.client.Client object at 0xb64e6330>, None, 10, (0,)
Dec 21 18:59:21 raspberrypizero ERROR - [sensor_reporter] Error creating device Actuator5: Traceback (most recent call last):#012  File "/usr/lib/python3.7/configparser.py", line 788, in get#012    value = d[option]#012  File "/usr/lib/python3.7/collections/__init__.py", line 914, in __getitem__#012    return self.__missing__(key)            # support subclasses that define __missing__#012  File "/usr/lib/python3.7/collections/__init__.py", line 906, in __missing__#012    raise KeyError(key)#012KeyError: 'toggle'#012#012During handling of the above exception, another exception occurred:#012#012Traceback (most recent call last):#012  File "sensor_reporter.py", line 170, in create_device#012    return device(dev_conns, params)#012  File "/opt/sensor_reporter/gpio/rpi_gpio.py", line 149, in __init__#012    self.toggle = bool(params("Toggle"))#012  File "sensor_reporter.py", line 161, in <lambda>#012    params = lambda key: config.get(section, key)#012  File "/usr/lib/python3.7/configparser.py", line 791, in get#012    raise NoOptionError(option, section)#012configparser.NoOptionError: No option 'toggle' in section: 'Actuator5'
Dec 21 18:59:21 raspberrypizero INFO - [sensor_reporter] Creating device for Actuator6
Dec 21 18:59:21 raspberrypizero INFO - [MqttConnection] Registering for messages on 'sensor_reporter/SprinklerPiRelay7Cmd'
Dec 21 18:59:21 raspberrypizero ERROR - [sensor_reporter] Error creating device Actuator6: Traceback (most recent call last):#012  File "/usr/lib/python3.7/configparser.py", line 788, in get#012    value = d[option]#012  File "/usr/lib/python3.7/collections/__init__.py", line 914, in __getitem__#012    return self.__missing__(key)            # support subclasses that define __missing__#012  File "/usr/lib/python3.7/collections/__init__.py", line 906, in __missing__#012    raise KeyError(key)#012KeyError: 'toggle'#012#012During handling of the above exception, another exception occurred:#012#012Traceback (most recent call last):#012  File "sensor_reporter.py", line 170, in create_device#012    return device(dev_conns, params)#012  File "/opt/sensor_reporter/gpio/rpi_gpio.py", line 149, in __init__#012    self.toggle = bool(params("Toggle"))#012  File "sensor_reporter.py", line 161, in <lambda>#012    params = lambda key: config.get(section, key)#012  File "/usr/lib/python3.7/configparser.py", line 791, in get#012    raise NoOptionError(option, section)#012configparser.NoOptionError: No option 'toggle' in section: 'Actuator6'
Dec 21 18:59:21 raspberrypizero DEBUG - [MqttConnection] on_subscribe: Successfully subscribed <paho.mqtt.client.Client object at 0xb64e6330>, None, 11, (0,)
Dec 21 18:59:21 raspberrypizero INFO - [sensor_reporter] Creating device for Actuator7
Dec 21 18:59:21 raspberrypizero INFO - [MqttConnection] Registering for messages on 'sensor_reporter/SprinklerPiRelay8Cmd'
Dec 21 18:59:21 raspberrypizero DEBUG - [MqttConnection] on_subscribe: Successfully subscribed <paho.mqtt.client.Client object at 0xb64e6330>, None, 12, (0,)
Dec 21 18:59:21 raspberrypizero ERROR - [sensor_reporter] Error creating device Actuator7: Traceback (most recent call last):#012  File "/usr/lib/python3.7/configparser.py", line 788, in get#012    value = d[option]#012  File "/usr/lib/python3.7/collections/__init__.py", line 914, in __getitem__#012    return self.__missing__(key)            # support subclasses that define __missing__#012  File "/usr/lib/python3.7/collections/__init__.py", line 906, in __missing__#012    raise KeyError(key)#012KeyError: 'toggle'#012#012During handling of the above exception, another exception occurred:#012#012Traceback (most recent call last):#012  File "sensor_reporter.py", line 170, in create_device#012    return device(dev_conns, params)#012  File "/opt/sensor_reporter/gpio/rpi_gpio.py", line 149, in __init__#012    self.toggle = bool(params("Toggle"))#012  File "sensor_reporter.py", line 161, in <lambda>#012    params = lambda key: config.get(section, key)#012  File "/usr/lib/python3.7/configparser.py", line 791, in get#012    raise NoOptionError(option, section)#012configparser.NoOptionError: No option 'toggle' in section: 'Actuator7'
Dec 21 18:59:21 raspberrypizero DEBUG - [sensor_reporter] 0 actuators created
Dec 21 18:59:21 raspberrypizero INFO - [sensor_reporter] Creating device for Sensor1
Dec 21 18:59:21 raspberrypizero INFO - [Heartbeat] Configuing Heartbeat: msec to heartbeat/num and str to heartbeat/str with interval 60.0
Dec 21 18:59:21 raspberrypizero DEBUG - [sensor_reporter] 1 sensors created
Dec 21 18:59:21 raspberrypizero DEBUG - [sensor_reporter] Creating polling manager
Dec 21 18:59:21 raspberrypizero DEBUG - [sensor_reporter] Created, returning polling manager
Dec 21 18:59:21 raspberrypizero INFO - [PollManager] Starting polling loop
Dec 21 18:59:21 raspberrypizero DEBUG - [MqttConnection] on_publish: Successfully published message <paho.mqtt.client.Client object at 0xb64e6330>, None, 13
Dec 21 18:59:21 raspberrypizero DEBUG - [MqttConnection] Published message 18 to sensor_reporter/heartbeat/num retain=False
Dec 21 18:59:21 raspberrypizero DEBUG - [MqttConnection] on_publish: Successfully published message <paho.mqtt.client.Client object at 0xb64e6330>, None, 14
Dec 21 18:59:21 raspberrypizero DEBUG - [MqttConnection] Published message 00:00:00 to sensor_reporter/heartbeat/str retain=False
Dec 21 19:00:21 raspberrypizero DEBUG - [MqttConnection] on_publish: Successfully published message <paho.mqtt.client.Client object at 0xb64e6330>, None, 15
Dec 21 19:00:21 raspberrypizero DEBUG - [MqttConnection] Published message 60122 to sensor_reporter/heartbeat/num retain=False
Dec 21 19:00:21 raspberrypizero DEBUG - [MqttConnection] on_publish: Successfully published message <paho.mqtt.client.Client object at 0xb64e6330>, None, 16
Dec 21 19:00:21 raspberrypizero DEBUG - [MqttConnection] Published message 00:01:00 to sensor_reporter/heartbeat/str retain=False
Dec 21 19:01:21 raspberrypizero DEBUG - [MqttConnection] on_publish: Successfully published message <paho.mqtt.client.Client object at 0xb64e6330>, None, 17
Dec 21 19:01:21 raspberrypizero DEBUG - [MqttConnection] Published message 120224 to sensor_reporter/heartbeat/num retain=False
Dec 21 19:01:21 raspberrypizero DEBUG - [MqttConnection] on_publish: Successfully published message <paho.mqtt.client.Client object at 0xb64e6330>, None, 18
Dec 21 19:01:21 raspberrypizero DEBUG - [MqttConnection] Published message 00:02:00 to sensor_reporter/heartbeat/str retain=False

SIGHUP results in GPIO error [bug]

Sending SIGHUP to sensor_reporter results for me in an delay (closing openHAB connection) and an GPIO error when creating actuator device. The log shows that disconnecting openHAB SSE takes about 8 minutes:

2021-11-28 12:54:43,666     INFO - [sensor_reporter] (SIGHUP) reading configuration: 1 <frame at 0x75876900, file '/opt/sensor_reporter/core/poll_mgr.py', line 71, code start>
2021-11-28 12:54:44,168     INFO - [    PollManager] Waiting for all the polling threads
2021-11-28 12:54:44,170     INFO - [    PollManager] Cleaning up the sensors
2021-11-28 12:54:44,172     INFO - [    PollManager] Cleaning up the actuators
2021-11-28 12:54:44,174     INFO - [    PollManager] Disconnecting from connections
2021-11-28 12:54:44,176     INFO - [    OpenhabREST] Disconnecting from openHAB SSE
2021-11-28 13:03:06,549     INFO - [ MqttConnection] Disconnecting from MQTT

if I comment everything in rest_conn.py > _get_messages() except the for loop, it still takes 8 minutes:

def _get_messages(self):
        """Blocks until stop is set to True. Loops through all the events on the
        SSE subscription and if it's a command to a registered Item, call's that
        Item's handler.
        """
        for event in self.client.events():
            # If we are stopping exit.
            if self.stop:
                return

I guess self.client.events() needs further analyses. Do you have any idea why it takes so long?
Btw. when no openHAB connection is configured no delay occurs and the connections reestablished right away.
In any case after the reconnect RPi.GPIO complains:

2021-11-28 13:03:06,855    ERROR - [sensor_reporter] Error creating device Actuator_redLED: Traceback (most recent call last):
  File "sensor_reporter.py", line 170, in create_device
    return device(dev_conns, params)
  File "/opt/sensor_reporter/gpio/rpi_gpio.py", line 204, in __init__
    GPIO.setup(self.pin, GPIO.OUT)
RuntimeError: Please set pin numbering mode using GPIO.setmode(GPIO.BOARD) or GPIO.setmode(GPIO.BCM)

Obviously this error occurs for every configured GPIO actuator. I guess this is because:

# Set to use BCM numbering.
GPIO.setmode(GPIO.BCM)

in rpi_gpio.py in line 29 is outside of any class. Would it do any harm to put it into the sensor and actor constructor?

README of openhab folder error

In the table in the openhab README file, there is a class listed as mqtt. I believe this should be openhab. Copy paste error?

BTW, I would like to create a folder with some code to interact using I²C interface. That should allow many sensors or Arduino and related IoT devices. Which folder would you suggest as a template?

Xavier

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.