No description
Find a file
2017-10-18 16:01:40 +02:00
.idea added relative path to PCM-temperature offset file 2017-07-14 14:52:21 +02:00
LICENSE.txt LICENSE change to GPL 2017-06-20 10:59:05 +02:00
PCM-Sensoren-Verlegung.png * changed one sensor in RL because of faulty data 2017-07-20 13:54:48 +02:00
PCM-Temp-Sensor-Corrections.csv * changed one sensor in RL because of faulty data 2017-07-20 13:54:48 +02:00
PCM_temperature_publisher.py * changed one sensor in RL because of faulty data 2017-07-20 13:54:48 +02:00
PCM_temperature_subscriber.py updates influxdb for ESHL 2017-10-18 16:01:40 +02:00
PCM_temperature_tester.py updates: 2017-06-13 15:48:53 +02:00
README.md Update 'README.md' 2017-09-26 23:48:08 +02:00

This repository is designed for a Raspberry Pi3 running raspbian (June 2017) and contains:

  • A script to gather DS18B20 sensor values and send them to a WAMP server.
  • A script to receive DS18B20 and other sensor values via WAMP and send them to a MySQL-DB or InfluxDB

Prerequisites

To install the necessary prerequisites on the Pi, do

    sudo sudo apt-get install -y build-essential libssl-dev libffi-dev python-dev htop screen git
    sudo pip3 install w1thermsensor crossbar PyMySQL influxdb

        #enable w1 bus on GPIO 7
    sudo tee /boot/config.txt << EOF
        dtoverlay=w1-gpio
    EOF

Download

Just fetch the scripts via

cd ~ # go to home directory
git clone https://gogs.univ-exp.com/ESHL/PCM-temperature.git

Running the sensor-data sending script

Start the sending script with:

./PCM_temperature_publisher.py

Be aware to configure all the sensors which should be monitored in PCM-Temp-Sensor-Corrections.csv The file sould look like:

UUID,Correction,Location,Room
000008fdb09d,0.31,middle of room,main room
0004314d2eff,-0.03,south of room,main room
0000080a7e33,-0.0620,middle of room,east room
0000080b24e7,-0.6870,middle of room,west room
0000080b45e5,0,on desktop,east room

At the beginning of the script set the corresponding variables for WAMP:

  • wamp_URL = "String"
  • wamp_realm = "String"
  • wamp_topic = "String"
  • wamp_write_interval = INTEGER in seconds

also check the variables

  • sensor_read_interval = INTEGER in seconds default 10
  • sensors_csv_list = "String" default 'PCM-Temp-Sensor-Corrections.csv'

The script will automatically detect new sensors on the bus. Only detected and configured sensors will be published to WAMP. The loss of a sensor conection will also be handled, so just plug and play with the sensors ;-)

sensor-data structure

The script will send a JSON object to the specified WAMP-router (default ws://wamp-router:8080/ws) and address (default `eshl.pcm.v1). The Data structure is as follows:

[
    {
        # ==> UUID of sensor
        "0000080a0826": {
            # ==> timestamp of sensor value
            "timestamp": 1500293373.8427284,
            # ==> mean temperature (°C) over 10 measurements
            # to ignore value fluctuation
            "mean-temperature": 18.32;
            # ==> location of sensor in the room
            "location": "SW",
            # ==> location of sensor at the building
            "room": "Raum rechts",
            # ==> last measured temperature (°C). be aware
            # it might be fluctuating, so use mean-temperature
            "temperature": 18.388
        },
        "0000080b45e5": {
            "timestamp": 1500293373.762908,
            "mean-temperature": 18.525,
            "location": "SO",
            "room": "Raum links",
            "temperature": 18.525000000000002
        },

        # ...
        # more entries
        # ...

        "0000080a22a7": {
            "timestamp": 1500293373.9128275,
            "mean-temperature": 18.668,
            "location": "SE",
            "room": "Hauptraum",
            "temperature": 18.677
        }
    }
]

Be aware to use mean-temperature instead of temperaturebecause it is the mean-value over the last 10 measurements to prevent fluctuation of measured values.

Running the sensor-data receiving script

Start the receiving script with:

./PCM_temperature_subscriber.py [--OPTIONS]

At the beginning of the script set the corresponding variables for WAMP:

  • wamp_URL = "String"
  • wamp_realm = "String"
  • wamp_topic_$SENSOR_TYPE = "String"
  • wamp_write_interval = INTEGER in seconds

and for the Databases InfluxDB and MySQL:

  • influx_host = "String"
  • influx_port = INTEGER
  • influx_user = "String"
  • influx_password = "String"
  • influx_dbname = "String"
  • influx_update_interval = INTEGER in seconds, default 5
  • mysql_host = "String"
  • mysql_port = INTEGER
  • mysql_user = "String"
  • mysql_password = "String"
  • mysql_dbname = "String"
  • mysql_update_interval = INTEGER in seconds, default 10

With the option --help you'll get the following options:

-h, --help            show this help message and exit
--PCM                 collect PCM sensor data
--Enocean             collect Enocean sensor data
--Bacnet              collect Bacnet sensor data
--KNX                 collect KNX sensor data
--Dachs               collect Dachs sensor data
--WAGO                collect Dachs sensor data
--OpenweathermapCurrent
                    collect current openweathermap sensor data
--InfluxDB            send collected sensor data to InfluxDB
--MySQL               send collected sensor data to MySQL-DB
--MySQL_delete        delete all sensor data in MySQL-DB

The Script will analyze all received sensors, except the $SENSORreader class has a room_list or location_list. Then the $SENSORReader class will only analyze those sensors defined there. See the $SensorReader's parse_sensor_entry_thread(...)-method for details.

Running the scripts as a system service

For the ESHL you might want to start the scripts automatically as a service.

The sensor-data sending script

Just paste the following to a terminal. Be aware that you might change the location of the script in ExecStart, depending on the user you have downloaded it with. For debugging just comment out the second ExecStart and use the firt one. This will generate a Logfile of the output which might become rather big.

    # generate the systemd file
sudo tee  /etc/systemd/system/PCM-Publisher.service << EOF
[Unit]
Description=PCM Sensor Publisher daemon
After=multi-user.target

[Service]
Type=idle
# with log
#ExecStart=/usr/bin/python3 /home/pi/PCM-temperature/PCM_temperature_publisher.py  > /home/pi/PCM-temperature/PCM_temperature_publisher.log 2>&1
# without log, default
ExecStart=/usr/bin/python3 /home/pi/PCM-temperature/PCM_temperature_publisher.py

ExecStop=/usr/bin/pkill -f  PCM_temperature_publisher.py

Restart=always

[Install]
WantedBy=multi-user.target
EOF

    # update systemd
sudo systemctl daemon-reload
    # enable the file for autostart
sudo systemctl enable PCM-Publisher.service
    # start the daemon
sudo systemctl start PCM-Publisher.service

The sensor-data receiving script

Just paste the following to a terminal. Be aware that you might change the location of the script in ExecStart, depending on the user you have downloaded it with. Also this daemon will only gather the PCM-Sensor data and push it to a MySQL-DB (standard for ESHL). For debugging just comment out the second ExecStart and use the firt one. This will generate a Logfile of the output which might become rather big.

    # generate the systemd file
sudo tee  /etc/systemd/system/PCM-Subscriber.service << EOF
[Unit]
Description=PCM Sensor Subscriber daemon
After=multi-user.target

[Service]
Type=idle
# with log
#ExecStart=/usr/bin/python3 /home/pi/PCM-temperature/PCM_temperature_subscriber.py --PCM --MySQL > /home/pi/PCM-temperature/PCM_temperature_subscriber.log 2>&1
# without log, default
ExecStart=/usr/bin/python3 /home/pi/PCM-temperature/PCM_temperature_subscriber.py --PCM --MySQL

ExecStop=/usr/bin/pkill -f PCM_temperature_subscriber.py

Restart=always

[Install]
WantedBy=multi-user.target
EOF

    # update systemd
sudo systemctl daemon-reload
    # enable the file for autostart
sudo systemctl enable PCM-Subscriber.service
    # start the daemon
sudo systemctl start PCM-Subscriber.service

Running the sensor testing-script

Start the receiving script with:

./PCM_temperature_tester.py

The script loops over measure_ierations = 10iterations and in each iteration over all detected sensors. It calculates the difference for each sensor to a given target_temperature and measures the mean measuring time for one sensor and all sensors (over a for loop).

Be aware to keep the pause between measurings sleep_between_measurements > 2 with default of 5 because of the self-heating of the sensors during measurement.

Overview for ESHL

This is how the sensors and receiving raspberrypi are located at ESHL

PCM-Verlegung PCM-Sensor locations

Password for the users pi and root is well known (the same as for sparta). The pullup resistor between 3,3V and w1 was fwas reduced to 392 Ω because sensor 0000080a0826 always had problems.

License

Author Stefan Maier

Licence GNU GPLv3

Ressources