Giter VIP home page Giter VIP logo

emqtt's Introduction

emqtt

Receive emails and publish to MQTT. Super simple stuff. Topic will be <configurable_prefix>/<sender_email.replace('@', '')>.

I needed this to make my D-Link camera's motion sensor functionality useful. Available actions on the camera are to send an email or upload an image to an FTP.. This script makes it easier to integrate into automation systems.

It's based on aiosmtpd and paho-mqtt.

I made a docker image because like any hipster dev I like docker. At least it's based on alpine so there's that.

Protip: docker exec emqtt find attachments -type f -ctime +20 -delete

Run it

  1. Create venv and activate it. Or don't.

  2. pip install -r requirements.txt.

  3. Give it some env vars. These are the defaults so omit whatever looks good.

    • SMTP_PORT=1025
    • MQTT_HOST=localhost
    • MQTT_PORT=1883
    • MQTT_USERNAME=""
    • MQTT_PASSWORD=""
    • MQTT_TOPIC=emqtt
    • MQTT_PAYLOAD=ON
    • MQTT_RESET_TIME=300
    • MQTT_RESET_PAYLOAD=OFF
    • SAVE_ATTACHMENTS=True
    • SAVE_ATTACHMENTS_DURING_RESET_TIME=False
    • DEBUG=False
  4. Go.

$ python emqtt.py
2017-11-08 22:36:27,658 - root - INFO - Running

Run it in docker

$ docker build -t emqtt .
$ docker run -d \
    --name emqtt \
    --net host \
    --restart always \
    -e "MQTT_USERNAME=mqtt" \
    -e "MQTT_PASSWORD=mqtt" \
    -e "DEBUG=True" \
    -v /etc/localtime:/etc/localtime:ro \
    -v $PWD/log:/emqtt/log \
    -v $PWD/attachments:/emqtt/attachments \
    emqtt

emqtt's People

Contributors

parberge avatar wicol avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

emqtt's Issues

Fails to build on alpine:latest

I had to add the "py3-pip" to the apk add to get the image to build. I guess pip3 isn't part of python3 package; I'm not sure if it was different before or if it's due to using a Raspberry Pi.

Once it builds, then it doesn't run, but I'll file that as a separate issue.

Fails to run with recent versions of aiosmtpd

Image on docker hub is for linux/amd64; so I locally built this for my Pi4 and it fails to run. I suspect it's due to updated Alpine.

Creating emqtt ... done
Attaching to emqtt
emqtt | 2021-04-10 04:17:31,523 - emqtt - INFO - Setting up a filehandler
emqtt | 2021-04-10 04:17:31,524 - emqtt - INFO - Configured to save attachments
emqtt | Exception in thread Thread-1:
emqtt | Traceback (most recent call last):
emqtt | File "/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner
emqtt | self.run()
emqtt | File "/usr/lib/python3.8/threading.py", line 870, in run
emqtt | self._target(*self._args, **self._kwargs)
emqtt | File "/usr/lib/python3.8/site-packages/aiosmtpd/controller.py", line 169, in _run
emqtt | asyncio.set_event_loop(self.loop)
emqtt | File "/usr/lib/python3.8/asyncio/events.py", line 753, in set_event_loop
emqtt | get_event_loop_policy().set_event_loop(loop)
emqtt | File "/usr/lib/python3.8/asyncio/unix_events.py", line 1365, in set_event_loop
emqtt | super().set_event_loop(loop)
emqtt | File "/usr/lib/python3.8/asyncio/events.py", line 647, in set_event_loop
emqtt | assert loop is None or isinstance(loop, AbstractEventLoop)
emqtt | AssertionError

emqtt errors on publish if MQTT_PORT is defined in docker

Initially I had MQTT_PORT set to its default value 1883 but emqtt then throws the below error from paho when it tries to publish:

TypeError: '<=' not supported between instances of 'str' and 'int'

I don't have the full stack easily on hand now as I already worked around the issue by not defining the port. I assume what happens is that the environment variable is being read as a string and not a number.

Unfortunately I have no python experience so I cannot easily create a PR on this.

Question: Does this change apply to emqtt

mqtt platform in hass was updated recently:

The default availability payloads for the MQTT switch platform have changed from “ON” and “OFF” to “online” and “offline” (in order to match the majority of MQTT platforms that already supported availability reporting). (@DanNixon - #11336) (breaking change)

home-assistant/core#11336

I'm not sure if this mean the PAYLOAD should be "online" and "offline" instead of "ON" and "OFF"

Request: Add proper license

Hi,
your bridge is quite helpful. I'd like to package (and mirror) it; to do so in a legal way I need a license information:

Can you please select a license for your project and add the license file e.g. as LICENSE and with a short copyright + LICENSE note into the actual source code?

Thanks in advance

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.