Metadata-Version: 2.4
Name: iot-daemonize
Version: 0.1.0
Summary: A small framework for IOT xyz2mqtt daemons
Author-email: Gerrit Beine <mail@gerritbeine.com>
Maintainer-email: Gerrit Beine <mail@gerritbeine.com>
License: Copyright (c) 2016-2025, Gerrit Beine
        All rights reserved.
        
        Redistribution and use in source and binary forms, with or without
        modification, are permitted provided that the following conditions are met:
        
        * Redistributions of source code must retain the above copyright notice, this
          list of conditions and the following disclaimer.
        
        * Redistributions in binary form must reproduce the above copyright notice,
          this list of conditions and the following disclaimer in the documentation
          and/or other materials provided with the distribution.
        
        * Neither the name of fronius2mqtt nor the names of its
          contributors may be used to endorse or promote products derived from
          this software without specific prior written permission.
        
        THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
        AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
        IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
        DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
        FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
        DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
        SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
        CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
        OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
        OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
        
Project-URL: Homepage, https://c0d3.sh/smarthome/python-iot-daemonize
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: BSD License
Classifier: Programming Language :: Python :: 3.8
Classifier: Topic :: Home Automation
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE.md
Requires-Dist: bottle
Requires-Dist: paho-mqtt
Dynamic: license-file

# iot-daemon

A daemon framework for handling different xyz2mqtt applications.

## Usage

Using

```python
import iot_daemonize
import iot_daemonize.configuration as configuration
```

it is possible to configure the framework.

The class configuration.Configuration uses command line arguments and a configuration file.
The configuration file overrides the command line arguments.

A default configuration for MQTT services is provided as `MqttDaemonConfiguration`.

It can be used as follows:

```python
config = configuration.MqttDaemonConfiguration(program ='example2mqtt', description ='Send data to MQTT broker')
# the following line will parse the command line arguments
config.parse_args()
# the following line will parse the configuration file provided as commmand line argument
config.parse_config(config.config)
# print the internal state of configuration values
print(config._config_values)
```

The framework services can be initialized based on the configuration:

```python
# Initialize MQTT and multi-threading daemon
iot_daemonize.init(config, mqtt = True, daemonize = True)

# Add tasks to the daemon, must be declared as functions
iot_daemonize.daemon.add_task(task1)
iot_daemonize.daemon.add_task(task2)

# Run the framework, this will start the MQTT client and the daemon (for HTTP see below)
iot_daemonize.run()
```

To run an HTTP server, use the following code:

```python
from bottle import run

def http_server(stop):
    run(server=iot_daemonize.http_server)

# Initialize HTTP and multi-threading daemon
iot_daemonize.init(config, http = True, daemonize = True)

# Add HTTP server task to the daemon
iot_daemonize.daemon.add_task(http_server)

# Run the framework, this will start the HTTP server and the daemon
iot_daemonize.run()
```
