Skip to main content

Recursively watch a directory for modifications and publish file content to an MQTT broker

Project description

This simple Python program portably watches a directory recursively and publishes the content of newly created and modified files as payload to an MQTT broker. Files which are deleted are published with a NULL payload.

The path to the directory to watch recursively (default .), as well as a list of files to ignore (*.swp, *.o, *.pyc), the broker host (localhost) and port number (1883) must be specified in the program, together with the topic prefix to which to publish to (watch/).

Installation

git clone https://github.com/jpmens/mqtt-watchdir.git
cd mqtt-watchdir
virtualenv watchdir
source watchdir/bin/activate
pip install -e .

Configuration

  • TOPIC_PREFIX is prepended onto the relative path of the file being accessed, and may be None.

Testing

Launch mosquitto_sub:

mosquitto_sub -v -t 'watch/#'

Launch this program and, in another terminal, try something like this:

echo Hello World > message
echo JP > myname
rm myname

whereupon, on the first window, you should see:

watch/message Hello World
watch/myname JP
watch/myname (null)

Requirements

  • watchdog, a Python library to monitor file-system events.

  • Mosquitto’s Python module

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mqtt-watchdir-1.3.tar.gz (4.3 kB view details)

Uploaded Source

File details

Details for the file mqtt-watchdir-1.3.tar.gz.

File metadata

  • Download URL: mqtt-watchdir-1.3.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for mqtt-watchdir-1.3.tar.gz
Algorithm Hash digest
SHA256 59438cc1ecbb1cb6d3c1a3bccf7fd552f4bf4c4247d6d4f15130fed7d7393f81
MD5 4035b26b3bbc2648a6b1a2b316d80527
BLAKE2b-256 8b12a86bcc3451f96673cd3ed417c6f81327e7df7c316356bb2d531d74eacb25

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page