/DHTpubmqttDaemon

A daemon reading the data of an DHT22 connected to an Raspberry PI. The read data is transfered to an MQTT server with a given topic.

Primary LanguageCOtherNOASSERTION

DHTpubMqttDaemon for Raspberry PI

A daemon written in C for reading data of an DHT22 sensor connected to an Raspberry PI. The read data will be published to an MQTT server with a given topic.

Getting Started

These instructions will get you a copy of the project up and running on your local machine.

Hardware prerequisites

You need a Raspberry PI board and a DHT22 sensor connected to Pin 7 (GPIO4) of the Raspberry to use this daemon.

Wiring

Software prerequisites

The daemon uses 3 non standard libraries which must be installed first:

libconfig-dev - This library allows parsing, manipulating and writing structured configuration files.

apt-get install libconfig-dev

libmosquitto-dev - Library for implementing MQTT version 3.1/3.1.1 clients.

apt-get install libmosquitto-dev

wiringpi - Wiring Pi GPIO Interface library for the Raspberry Pi

apt-get install wiringpi 

MQTT server - MQTT server running and reachable form the Raspberry.

Installing

  1. Build the executable file by running "make"
cd ~/dhtpubmqttd
make
  1. Edit the config file dhtpubmqttd.conf according to your needs
nano dhtpubmqttd.conf
  1. Copy the binary dhtpubmqttd and the config file dhtpubmqttd.conf to /opt/dhtpubmqttd/
sudo mkdir /opt/dhtpubmqttd
sudo cp dhtpubmqttd /opt/dhtpubmqttd
sudo cp dhtpubmqttd.conf /opt/dhtpubmqttd
  1. Copy the service configuration file dhtpubmqttd.service to /lib/systemd/system/
sudo cp dhtpubmqttd.service /lib/systemd/system/
  1. Enable DHTpubMqttDaemon service
sudo systemctl enable dhtpubmqttdaemon.service
  1. Start DHTpubMqttDaemon.service
sudo systemctl start dhtpubmqttd.service
  1. check syslog for errors
sudo tail -f /var/log/syslog
  1. Start an MQTT client and subscripe the topic configured in the config file. You should get a string in JSON format with the read data.
{"Humidity":"42.00","Temperature":"20.10"}

License

This project is licensed under the GNU General Public License - see the LICENSE file for details