Introduction: Raspberry PI and DHT22 Temperature and Humidity Logger With LAMP and Email Warnings
Instructable "archived" - no active development taking place at the moment by originator.
14.7.2018 UPDATE
Quite long time has passed since this instructable was first published and a lot has changed during this time. As comments indicate, some of the packages have changed along the way and that has been causing some issues for finishing this instructable. I decided to give an update for the whole instructable in order to get everything back in order.
Biggest change is that OS is now changing from previous Wheezy to Raspbian Stretch Lite. Everyting else, is pretty much as used to.
25.4.2018 UPDATE
DHT22-TemperatureLogger code used for collecting sensor data to database and for mail sending, has gone through some serious refactoring. This was done to add some features and to fix some minor bugs.
If you have finished this instructable prior this update, but want to update the code. Jump to page 10, download the DHT22Logger code again, setup revised config.json and you are good to go.
Few examples about what changed:
Logging added. Execution of the code now creates rotating log files to DHT22-TemperatureLogger/Debugger/Logs/. Handy in case that something goes wrong.
Added support for 1-n sensors. First version supported only 1-2 sensors, now there can be as many as Raspberry pi has gpios. Attach sensor to RPI and add sensor configuration to config.json and it is taken into account when executed.
Code refactored from first "quick and dirty" implementation to separate logical components. Hopefully easier to understand and to extend or refactor for your personal use
Configurations renamed and rearranged for easier understanding e.g. connection check is now weekly averages as it actually sends weekly average temperatures (intention for this that rpi is reporting weekly that it is still alive)
Added configurable timeoutfor mail sending so that user can decide how long Logger waits before sending warnings after previously sended mail. Previously hardcoded value was used and that found out to be little inconvenient
Sql backup dump is no longer daily, user sets day when dump is taken. 0 is daily, 1-7 is from Monday to Sunday.
Weekly average temperatures sending is now also configurable. Works with same pattern as sql dump above. 0 is daily, 1-7 is from Monday to Sunday. Note that it will always count 7 days backwards and send average from those.
Possibility to choose from Fahrenheits or Celsius
And some more minor tweaks and fixes.
---------------------------------------------------------------------------------------
This is an Raspberry Pi based temperature and humidity logger that uses Adafruit DHT22 sensors for measurements. You might have seen similar kind of instructions before, but this one has a twist. It doesn't just read temperature and humidity from sensors, but it stores data to database and provides means to read that temperature data with any web enabled device (computer, phone, tablet) web browser. This logger also allows you to set limits for temperatures and is able to send email if sensor temperature or humidity exceeds set limits...this neat feature can be for example used to alarm when it is time to set heating on in your house / carage / greenhouse / you name it.
To complete this instructable, you will need following:
- Raspberry PI (I used Raspberry PI 1 model B+, but should be doable with other models as well)
- Power supply for the pi. (I used old Nokia microusb telephone charger which gives about 880mA)
- SD memory card. Note that you might need adapter. (I used 8Gb and had 4.1Gb available after installing everything)
- Ethernet cable or USB wlan dongle that is supported by Raspberry Pi (google can help with this)
- DHT22 sensor/s and 4.7 kOhm resistors. Instructable supports 1-n sensors. https://www.adafruit.com/products/385
- Cables and breakout for connection https://www.adafruit.com/products/914
- Computer where you set up the SD card for the raspberry PI and from where you can connect and do the configurations. (NOTE: this instruction uses PC)
- Optional: Breadboard. Test assembly is easier to be created on this, than by connecting wires directly to sensors: http://thepihut.com/products/raspberry-pi-breadbo...
Internet connection is also require in location where you are going to set the raspberry logger. Either via ethernet or wlan dongle.
Keyboard + display are needed as well while installing and configuring the Wheezy OS. But once installations are finished, network is up and SSH enabled, it is possible to use connect raspberry pi remotely from PC and keyboard + display can be put aside.
Step 1: Sensor and RPI Assembly
Create assembly as instructed in attached image. Image instructs how you can connect two DHT22's to the Raspberry Pi, but if you have only one available just ignore another one and add one. And vice versa, if you have more sensors add them to free ground, power and gpio pins.
Notable here is that you can connect sensors to any GPIO you like. I had mine connected in GPIO22 and GPIO23. Both sensors also need +3.3Volts and ground. Resistor is set between +3.3V line and GPIO line.
When assembly is ready, prepare SD card and go to next step.
Step 2: OS for the RPI
Previously Wheezy was selected OS for this instructable. But that has long since changed and the link was dead as well. Instead, get Raspbian-Stretch-Lite image from here to your computer https://www.raspberrypi.org/downloads/raspbian/
And get also Win32 Disk Imager http://sourceforge.net/projects/win32diskimager/
Start Win32 Disk Imager and set the location of the downloaded Os image (.img file) to "Image File". Select the drive where your SD card is and select "Write".
Imager asks to Confirm Overwrite. Double check that drive is correct and select "Yes". Wait for write to finish. When Disk Imager informs that write is completed and successful press "OK", close the Disk Imager and eject the SD card from computer.
Place the card to your Raspberry Pi and go to next step.
Step 3: Setting Up Raspberry Pi
Set SD card to Raspberry Pi and power it up by plugging the power supply to Raspberry Pi's micro-usb. (Remember to attach keyboard and display before you insert power supply).
Rasperry Pi starts to boot up and will prompt for username and password.
By default those are:
username: pi
password: raspberry
After boot up finished start the configuration tool by typing
sudo raspi-config
In configuration tool, do the following:
1. Change your password and give new password to Raspberry Pi
2. Open network options -> 2.1 Change name if you want to -> 2.2 Enter wi-fi information (ssid, password)
3. Make sure that Raspberry Pi boots to console by selecting option 1, console.
4.This is optional, but it is advised that you set up locale information correctly. If you want to change internationalization options e.g. keyboard layout, timezone.
5. From interfacing options, select P2 - SSH and enable it This allows you to connect to RPI with SSH from your computer. This way you don't need display or keyboard on RPI to use it
6.Don't do anything
7. Open advanced options -> 7.1 Expand filesystem
8. Optional
Finally go to "Finish" and restart RPI by typing
sudo reboot
Configuration is now ready. Next step is to check how it can be connected remotely from PC.
Step 4: Connect Your Raspberry Pi From PC Part 1
Raspberry Pi is now configured and booted up. You should be able connect it via PuTTY from your PC now. PuTTY can be downloaded from http://www.chiark.greenend.org.uk/~sgtatham/putty...
When you start up the PuTTY you will notice that Host name or IP is required in order to connect to your Raspberry PI. To obtain the Raspberry Pi's IP address. Type the following to Raspberry Pi and press enter
Ifconfig
This will list you network adapters and information from them (check image). If you are connected with Ethernet (like I was at this point) you should see inet addr:xxx.xxx.xxx.xxx in eth0. by typing this inet address to PuTTY's host name line you should be able to connect Raspberry Pi remotely.
If you set up Wlan in previous step, you should also see wlan0 information, inet addr: etc. You can connect using those as well.
There is also manual way to configure WLAN. It was used earlier with Wheezy OS and it is described in next page. If you have network setup already, you can skip it and continue with how to connect with PuTTY.
Step 5: Optional: Wlan Configuration to Raspberry Pi
Manual way of adding Raspberry Pi WLAN settings.
You need to set wlan ssid and password to configuration so that Raspberry Pi can connect it.To start type following and press enter.
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
Add network section and configurations to the end of the file (check above image for reference):
Network={
ssid="yourssid"
psk="passwordtoyourwlan"
}
Save with Ctrl+X and select "Y" to confirm save.
Now restart Raspberry Pi. Type following and press enter.
sudo reboot
Once booted up and logged in, type following and press enter.
Ifconfig
You should now see that also wlan0 has inet addr available.
Step 6: Connect Your Raspberry Pi From PC Part 2
Now the IP (ethernet or wlan) address is known. You can now connect via PuTTY from your windows desktop. To do so, open putty, type in IP address and port 22 and select open.
Say yes to security alert and command line opens up in PuTTY.
Type in login name and password and now you should be in pi's command prompt. This means that you can now disconnect keyboard and display from Raspberry Pi and do all the rest of the steps from your pc via PuTTY. To shutdown pi (just in case when disconnecting keyboard and display) type following and press enter.
sudo shutdown -h now
Raspberry Pi will shut down. Once you have disconnected keyboard and display disconnect power supply and put it back in to boot up the Raspberry Pi. Wait for a moment (so Raspberry Pi boots up) and then try to connect again via PuTTY, if everything works like it should you should be now able to login...if you get timeout at first, wait for a moment and try again.
NOTE: IP address can change if your routers DHCP gives new IP address to the Raspberry Pi during bootup / reset and therefore you should know the new IP in order to connect again via PuTTY.
To avoid this problem, you have option to set in static ip address for the Raspberry Pi…there is few guides how to do that. E.g. try this http://www.modmypi.com/blog/tutorial-how-to-give-...
Or then you can do like I did (if your router allows it), add address reservation to Raspberry Pi's wlan adapter MAC address in router configurations. I have tplink router so i added MAC address and reserved currently assigned IP address for it. For this trick, you need both, IP address and MAC. Againy type following and press enter.
ifconfig
Take note from hwaddr (this is the Mac and inet addr which is the IP)Then create address reservation to your DHCP / address reseravtion list. Check your routers user guide to see how this can be done in your own router. I have TPLink so Address Reservation looks exactly like in attached image.
Now everything is set up and we can get to the fun part.
Step 7: Installing DHT22 Sensor Libraries
Start by updating and upgrading the Raspberry Pi. Type following and press enter.
sudo apt-get update
This updates software sources then type following and press enter.
sudo apt-get upgrade
This updates to everything to latest version. If prompted to continue press "Y".
When these are finished, it is time to install Adafruit Python code. You will need this code in order to get readings from DHT22 sensors. This will also allow you to test that your assembly works in first place.
At first, get compiler and python library. For that type following and press enter
sudo apt-get install build-essential python-dev python-openssl
Then, make sure that you are in folder where you want to install the Adafruit code, by default i would suggest /home/. For that type following and press enter.
cd /home/pi
In stretch lite, you also need to install Git separately as it is not included by default. To do so, type:
sudo apt-get install git
Now clone the git repository. Type following and press enter.
git clone https://github.com/adafruit/Adafruit_Python_DHT.g...
Go to folder.Type following and press enter.
cd Adafruit_Python_DHT
And finally install the Adafruit library. Type following and press enter.
sudo python setup.py install
Then it is time to test your assembly...
Step 8: Testing the DHT22's
Now that installation is completed you can test the connected sensor/s and see that you get reading from them. Go to folder where you cloned the Adafruit_Python_DHT and then to examples folder. Type following and press enter.
cd /home/pi/Adafruit_Python_DHT/examples
You remember the gpio/s where you plugged the sensor/s? Good, then type sudo ./AdafruitDHT.py and press enter. I had gpio 22 and 23 so I tested with
sudo ./AdafruitDHT.py 22 22
sudo ./AdafruitDHT.py 22 23
If your sensor and assembly is ok, you should get back temperature and humidity from the sensor/s. Like seen in attached image.
NOTE:
If you see "Failed to get reading. Try again!", then try again few times.
If still nothing, re-check that you typed in the right GPIO.
If gpio is for sure right, check your assembly again. E.g. DHT22 gets power, ground and resistor is connected correctly.
If all above are right, try to connect your sensor to another GPIO and see if you get reading from that
If nothing from above works, it is always possible that your DHT22 is broken. :(
Libraries for DHT22 sensors are now installed and you can get the readings from sensor/s. Time to set up database for holding that data.
Step 9: Setting Up the MySql for Storing the Temperature Data
Get Mysql/MariaDb and required addons for it. To do that type following and press enter.
sudo apt-get install mysql-server python-mysqldb
Note: You won't be queried for password for ROOT user anymore during the installation. This is empty by default.
After installation completed. It is time to set up the actual database and tables for storing the data. This need to be done in mysql console. To get into console type in the following and press enter.
sudo mysql -u root -p -h localhost
Hit enter (empty) for password and you should be in MariaDb console
In console
First, create database called temperatures. Type following and press enter.
CREATE DATABASE temperatures;
Select the created database by typing following and pressing enter.
USE temperatures;
Next you need to create database user and grant access to database . (Change password to something else if you like).To do that type in the following lines separately and after each press enter (check reference image 2).
CREATE USER 'logger'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON temperatures.* TO 'logger'@'localhost';
FLUSH PRIVILEGES;
Now the user has been created and privileges added. Time to change user from root to this new logger. Log out by typing following and pressing enter.
quit
And log back in with this new user by typing following and pressing enter
sudo mysql -u logger -p -h localhost
And give password that you assigned after IDENTIFIED BY when creating the user (by default it was password).
Now it is time to create two tables. Temperaturedata for storing sensor information and time of measurement and also mailsendlog that holds information when temperature limit trigged mail warnings have been sent. Mailsendlog is used in code to check when last warning was sent and it has been restricted that warning can be sent only within mail sending timeout limit set in configurations. This restriction is required so that mailbox is not flooded in cases where measurements are done frequently, e.g. every minute and every measurement causes warning.
However there is little exception when this check is ignored and that is in cases when temperature or humidity increases or decreases more than sensor limits allow, between measurements. Think of the case when you are logging home temperature via this logger and there is suddenly huge drop in temperature between measurements, it would be nice to get information about that even if set mail sending time out has not passed yet.
Some warnings, like sensor cannot be read, or database insert failed are send every time when they occur. These warning indicate that there is something wrong with Raspberry Pi or sensors and should be checked right away.
To start creating tables, type in the following and press enter.
USE temperatures;
Create first table with columns dateandtime, sensor, temperature and humidity. To do that type in the following and press enter.
CREATE TABLE temperaturedata (dateandtime DATETIME, sensor VARCHAR(32), temperature DOUBLE, humidity DOUBLE);
Create second table with columns dateandtime, triggedsensor, triggedlimit and lasttemperature. To do that type in the following and press enter.
CREATE TABLE mailsendlog (mailsendtime DATETIME, triggedsensor VARCHAR(32), triggedlimit VARCHAR(10), lasttemperature VARCHAR(10));
You can confim, that empty sets are present by typing in the following and pressing enter.
SELECT * FROM mailsendlog;
SELECT * FROM temperaturedata;
If tables exist, you should see "Empty Set (0.00 sec)"
Database and tables are now setup, exit the MySql console by typing in the following and pressing enter.
quit
Then restart mysql to changes take effect. To do that type in the following and press enter
sudo /etc/init.d/mysql restart
Thats it, mysql and database is ready. Next thing is to download the DHT22-TemperatureLogger for reading sensors, and inserting data to these new tables.
Step 10: Set Up the Temperature Logger Code
TemperatureLogger Python code can also be found from github, just like the Adafruit DHT22 codes.
NOTE: If this is first time you are doing this, you can skip to "Setting up" few lines below. But if you already have done this step earlier and now there is fixes/update in github that is wanted on your setup as well, you need to fetch the code again.
Folder can either be removed and cloned again or fetched and reseted with Git. Either way, first backup configurations json file, backup also SQL backups from DHT22-TemperatureLogger/Backups folder, then remove DHT-TemperatureLogger folder.
To remove and re-clone the folder make sure you are on the folder that contains DHT22-TemperatureLogger. e.g. type:
cd /home/pi
and remove the folder by typing
sudo rm -r DHT22-TemperatureLogger/
Now you can re-clone from GIT and reset the configurations with the steps mentioned below in "Setting up". Notable is that if there were changes also to configurations json file (e.g. new configurations), you cannot copy the backed up old file back as is.
For Git fetch and reset
Go to DHT22-TemperatureLogger/ folder
type git remote -v and you should see something similar like this:
origin https://github.com/jjposio/DHT22-TemperatureLogger.git (fetch)
origin https://github.com/jjposio/DHT22-TemperatureLogger.git (push)
Fetch latest version with git fetch --all
and reset folder to match latest version with git reset --hard
If Git approach didn't work, you can always just delete and re-clone as mentioned above.
Setting up.
Make sure that you are in folder where you want to install the DHT22-TemperatureLogger, by default i would suggest /home/pi/. Type in the folder and press enter.
cd /home/pi
Now clone git repository by typing
git clone https://github.com/jjposio/DHT22-TemperatureLogger.git
Type
ls
and press enter. And you should see that TemperatureLogger is unpacked to new DHT22-TemperatureLogger folder (image attached). Now to get this to work with Adafruit code and your MySql database that was just created, some configurations are needed. Start by editing the settings. To do this go to DHT22-TemperatureLogger folder by typing following and pressing enter
cd /home/pi/DHT22-TemperatureLogger
Now open config.json in editor. Type in the following and press enter.
sudo nano config.json
Configuration file opens up in editor (reference image attached).
Start going through the configurations and make them match your configurations.
mysql: Change mysql part to match what was created in mysql creation phase.
sensors: Create configurations for sensors attached to your RPI. Notable is that each sensor need to have own configuration line.
name: Set names for your sensors, e.g. outside, inside, livingroom, kitchen and so on. Where that sensor is going to be located or how you want to name it in log. Also add GPIO from where sensor is found. Other values are triggerlimits.
SensorType: Keep this as 22 with dht22 sensor, this is here in case that i will later add support for other sensors as well. (However I think that DHT11 should work, but haven't tested it. Try it out...)
Temperature low and high are limits for triggering email warnings. E.g. if sensor low liimit is 0 and temperature on that location drops below 0, you will receive warning to email address that you assign later. Same goes with high limit. If temperature gets higher than set limit. Warning is sent.
Humidity limits works exactly like temperature limits, but send warnings if humidity received from sensor doesn't fit between the limits
Threshold is used for measuring if temperature or humidity drops more than set limit between 2 measurements. As example, TemperatureThreshold is set to 5, last measurement was 10 and on next measurement you get 0. This means that 5 or 15 would be ok, but anything below or above that is more than threshold and email warning is triggered. Use case for this is to follow if temperature raises or drops too quickly in monitored location.
NOTE: There is two example rows here for two sensors. If you want to attach more, just copy and paste more lines and edit values.
mailInfo: This is for sending those email warnings. (I created new gmail just for this purpose) NOTE CURRENTLY ONLY GMAIL IS SUPPORTED
Senderaddress: This is shown in receivers inbox as sender
Receiveraddress: Where do you want to sent these warnings
Username: username for sender email
Password: password for sender email
subjectMessage: Can be changed if you want to, this is subject of the sended email in normal case
subjectWarning: This can also be changed, this is sended in case that warning is triggered (e.g. temperature is below triggerlimit)
sqlBackupDump: Backup dumps are either once a week or daily now.
BackupDumpEnabled y/n indicates if backup dumps are wanted in first place.
backupDay is day of the week when dump is taken. 1-7 (Monday to Sunday) 0 daily.
backupHour is the hour of the day when dump is taken- 0-24
backupDumpPath is the path where dump is stored. By default it is in Backups folder.
Every dump is automatically created to own datetime folder in this directory. Note that this folder isn't automatically backed up to any location. You need to copy it manually every now and then.
weeklyAverages: Used to define if weekly average temperatures are sent and on which day. This is done in order that you can be sure that logger is up and running even though warnings haven't been sent recently.
weeklyAveragesSendingEnabled: y means enabled, anything else means it is disabled.
weekDayForSendingAverages: is day of the week when dump is taken. 1-7 (Monday to Sunday)
hourOfTheDayForSendingAverages: is the hour of the day when dump is taken 0-24.
useFahrenheits: y enabled, n disabled. Note that if you change to fahrenheits and back to celsius "on the fly", you might get some warning mails about exceeded threshold limits or broke limits.
mailSendingTimeoutInFullHours: 0-x
Used to reduce spam. If set to 0, logger will send mail from every warning. Bigger values allow it to send warnings only once per hour. Used so that mailbox doesn't get flooded in case that measurements are done frequently and every measurement causes mail notification to be sent.
adafruitPath: This is the path where Adafruit_Python_DHT was downloaded from Git in beginning. By default it was /home/pi/Adafruit_Python_DHT/ Script AdafruitDHT.py This is important as it is used to get readings from each connected sensor.
Once settings are set, press Ctrl+x and save when prompted with "Y". Now test that readings are written to database correctly In DHT22-TemperatureLogger folder, type following and press enter.
python DHT22logger.py
If everything goes as planned, Raspberry executes the python script, gets readings from sensor/s and writes them to database. If you cant see any errors, all seems to be working. Now check database that data is inserted. Go to mysql console by typing following and pressing enter.
sudo mysql -u logger -p -h localhost
And log in with your password. In mysql console type following and press enter.
use temperatures;
And then type (and press enter)
select * from temperaturedata;
And check that readings were saved to table (reference image)
If everything seems to be in order and you can see the readings, exit mysql by typing following and pressing enter
quit
Note that mailsendlog table is empty at this point as no warning mails have been send. However, if you have only one sensor attached, but in configs sensor amount setting is more than 1, you will get email indicating that sensor couldn't be read. These kind of warnings are send always if they occur and are not logged.
Step 11: Automatical Sensor Reading
Now that temperature logger seem to be working, you probably want to take measurements automatically every n minutes all the time when Raspberry is powered on. To do so add timed event to crontab scheduler
Type following and press enter.
crontab -e
Rpi will prompt that "no crontab for pi - using empty one" and gives options to selecting editor.
Select option 2. /bin/nano and crontab should open up.
Add the following line at the end of the file (check reference image). This will run the script every 15 minutes.
*/15 * * * * python /home/pi/DHT22-TemperatureLogger/DHT22logger.py
More information about setting the crontab job can be found from here http://www.thesitewizard.com/general/set-cron-job...
Quit and save with Ctrl+x and select "Y" when prompted
Wait for 15-20 minute (or reduce time to wait less) and check that new inserts are done to mysql table. If yes, everything is now set up…and logger is working automatically and inserting data to MySql & sending mails.
Next thing thing is to set up LAMP (Linux, Apache, MySQL, PHP) and serve MySql information to web page. This way you can check the current readings with any web enabled device.
Step 12: LAMP (Linux, Apache, MySQL, PHP) and Data to Web Page
First type in
sudo apt-get update
to update again. After update finished. Install apache2 web-server (and addons) so that you can serve temperaturelogger web page to client.
sudo apt-get install
apache2 php7.0 php7.0-curl php7.0-gd php7.0-imap php7.0-json php7.0-mcrypt php7.0-mysql php7.0-opcache php7.0-xmlrpc libapache2-mod-php7.0
After install finished restart apache server by typing
sudo /etc/init.d/apache2 restart
Now the web server is ready and can serve your first web-page.
On your PC web-browser type in the IP address of the raspberrypi and you shdould see the apache landing page. (same as in attached picture)
Good, now change html page to PHP and get data for the page from temperatures database. Go to location from where the index.html page is served. Type
cd /var/www/html/
Note: location used to be /var/www/ but has since changed to /var/www/html/
Check that you are in correct folder and actually have the index.html in this folder by typing
ls
You should see that there is index.html in this page (attached reference image 2)
Create the index.php page and copy following code section to it. Type in.
sudo nano index.php
Editor opens up. Copy the code from attached index.php.txt file to the editor. Remember to change settings to match your MySql settings. And you can also change how many hours backwards temperatures are seen in web page by editing $hours variable.
When ready Exit with Ctrl+X and save with "Y" when prompted
Now remove the index.html, so that next time page is loaded index.php is used by typing
sudo rm index.html
Then once again, on your PC web-browser type in the IP address of the raspberrypi and you should see the page, but this time with temperature information from your MySql database (attached image as reference).
Good, you are almost finished. Last thing to do is installing dynamic DNS so that you can connect this page with www. instead of IP.
Attachments
Step 13: Installing Dynamic DNS
As dynamic DNS I have been using no-ip as it is free to use and quite simple to set up. To use this, first you need to create account to No-Ip. Go to www.noip.com and sign up. NOTE: remember the account information as it is needed also during the installation in Raspberry Pi.
Once you have account and access to no-ip and have signed in, it is time to create host.
1. Select add a host
2. Givee hostname. Hostname is the name of your site, e.g. mylogger.ddns.net. After the setup, when you write this to your browser, it connects to temperaturelogger index.php page. Good part is that you don't need to know Raspberry Pi's IP address anymore.
3. When ready, save with "add host"
Now go back to you Raspberry Pi terminal and create folder for the noip by typing
mkdir /home/pi/noip
Go to that folder by typing
cd /home/pi/noip
Get the software package
wget http://www.no-ip.com/client/linux/noip-duc-linux....
You noticed that software is packed and need to be extract. For extracting, type:
tar vzxf noip-duc-linux.tar.gz
Now select the noip folder that was extracted. This folder changes along with version changes. Easiest way to select latest is to type
cd ./n and press tab and then enter to select
Now compile and install the noip software from the extracted source. Type
sudo make && sudo make install
During the install, you will be asked for the no-ip account information and after that everything is set.
Check that you can access the page with hostname you gave (e.g.. mylogger.ddns.net) by typing it to web browser.
You should again see the temperaturelogger temperature data. Notice that you can now check temperatures with any web enabled device by just setting that host name to your web page e.g. try it with your phone.
Now everything is set, but remember that if you restart your Raspberry Pi, no-ip need to be started manually by typing.
sudo /usr/local/bin/noip2
However this can be easily tweaked so that no-ip is automatically run on a startup. For doing that you can follow this tutorial: http://www.stuffaboutcode.com/2012/06/raspberry-p...
That's all for this instructable. Thank you for reading it all the way through and congratulations for finishing it. I hope you had as fun following it through as I had while putting it all together. In case you have some questions, please don't hesitate to leave question or contact me.
Thanks and best regards,
JJ
163 Comments
Question 4 years ago
sudo apt-get
install mysql-server python-mysqldb
step
I got the following error.
sudo:
unable to resolve host PIMFG01: Name or service not known
Reading
package lists... Done
Building
dependency tree
Reading
state information... Done
Package
mysql-server is not available, but is referred to by another package.
This
may mean that the package is missing, has been obsoleted, or
is
only available from another source
However
the following packages replace it:
mariadb-server-10.0
E:
Package 'mysql-server' has no installation candidate
So in
turn I did
Sudo
apt-get install mariadb-server
Now
when I attempt to do the
python
DHT22logger.py
I
get
Traceback
(most recent call last):
File
"DHT22logger.py", line 37, in <module>
from
Utility.WeeklyAverages import WeeklyAverages
File
"/home/pi/DHT22-TemperatureLogger/Utility/WeeklyAverages.py",
line 1, in <module>
from
Database.DbActionController import DbController
File
"/home/pi/DHT22-TemperatureLogger/Database/DbActionController.py",
line 5, in <module>
from
DbActions import DbActions
File
"/home/pi/DHT22-TemperatureLogger/Database/DbActions.py",
line 1, in <module>
import
MySQLdb
ImportError:
No module named MySQLdb
What
can I do to fix this issue?
Answer 1 year ago
I resolve installing this packet:
apt-get install python-mysqldb
1 year ago
Hi there!
Sending warning emails over Gmail SMTP doesn`t work for me, something about username/password mismatch, although it`s all correct...
File "/usr/lib/python2.7/smtplib.py", line 623, in login
raise SMTPAuthenticationError(code, resp)
SMTPAuthenticationError: (535, '5.7.8 Username and Password not accepted. Learn more at\n5.7.8 https://support.google.com/mail/?p=BadCredentials p3sm3284871ejo.61 - gsmtp')
Question 2 years ago on Step 8
I have a DHT22 (just with three PINs -> +,-, out) and Raspberry Pi 4 model B.
I'm struggling at step 8: testing the DHT22.
The sensors do not output any value. Always appears "Failed to get reading. Try again!"
"Out" is plugged in on Pin 7 - GPIO 4
What i tried:
sudo ./AdafruitDHT.py 2302 4
sudo ./AdafruitDHT.py 22 4
change Pin to 15/16 GPIO 22/23
Can someone help me?
Answer 2 years ago
I had this problem when I was using soldered connections on the DHT22 - this seems to run the risk of damaging the device. I switched to a new DHT22 with a push connector and the resistor soldered to the connector leads. This worked fine. The pins I use are pin 1 +ve, pin 2 connected to GPIO 22, pin 3 -ve.
2 years ago
Hey!! Very nice job!! But, i have a problem. 7 or 8 times a day, i receive an alert email with bad readings. Can you help me? Thanks a lot!
Question 2 years ago
I just created this one as my first temperature reader and I'm heaving a few issues. My temps are reading as XX.X but in the database they loose the decimal place. Any suggestions why? I'm also looking to create the nice graph, but no success so far. I've never use SQL before so lots to learn!!! Pete
3 years ago on Step 13
I am receiving the following error in step 10:
pi@raspberrypi:~/DHT22-TemperatureLogger $ python DHT22logger.py
Logger initialization started
Check if directory for storing logs is writeable
Directory is writeable
Logger initialized
22-11-20 20:26:00 INFO root DHT22logger execution started
22-11-20 20:26:00 INFO Configurations.ConfigHandler ConfigHandler instantiation started
22-11-20 20:26:00 INFO Configurations.ConfigHandler Instantiate ConfigReader
22-11-20 20:26:00 INFO Configurations.ConfigReader ConfigReader instantiation started
22-11-20 20:26:00 INFO Configurations.ConfigReader Loading configurations from config.json
22-11-20 20:26:00 INFO Configurations.ConfigReader ConfigReader instantiated
22-11-20 20:26:00 INFO Configurations.ConfigHandler Read configurations
22-11-20 20:26:00 INFO Configurations.ConfigHandler Configurations read succesfully
22-11-20 20:26:00 INFO Configurations.ConfigAdapter ConfigAdapter instantiation started
22-11-20 20:26:00 INFO Utility.TimeFormatHelper TimeFormat instantiation started
22-11-20 20:26:00 INFO Utility.TimeFormatHelper TimeFormat instantiated
22-11-20 20:26:00 INFO Configurations.ConfigAdapter ConfigAdapter instantiated
22-11-20 20:26:00 INFO Configurations.ConfigHandler ConfigHandler instantiated
22-11-20 20:26:00 INFO Configurations.ConfigHandler Get full configuration adaptation
22-11-20 20:26:00 INFO Configurations.ConfigAdapter Creating dictionary for full configurations
22-11-20 20:26:00 INFO Configurations.ConfigAdapter Configuration dictionary created
22-11-20 20:26:00 INFO Database.DbActionController DbController instantiation started
22-11-20 20:26:00 INFO Database.DbActions DBActions instantiation started
22-11-20 20:26:00 INFO Database.DbActions DBActions instantiated
22-11-20 20:26:00 INFO Database.DbActionController DbController instantiated
22-11-20 20:26:00 INFO Utility.MailSender MailSender instantiation started
22-11-20 20:26:00 INFO Utility.TimeFormatHelper TimeFormat instantiation started
22-11-20 20:26:00 INFO Utility.TimeFormatHelper TimeFormat instantiated
22-11-20 20:26:00 INFO Utility.MailSender MailSender instantiation finished
22-11-20 20:26:00 INFO Sensors.SensorDataHandler SensorDataHandler instantiation started
22-11-20 20:26:00 INFO Sensors.SensorReader SensorReader instantiation started
22-11-20 20:26:00 INFO Sensors.SensorReader SensorReader instantiated
22-11-20 20:26:00 INFO Utility.MeasurementCompare MeasurementCompare instantiation started
22-11-20 20:26:00 INFO Utility.MeasurementCompare Instantiation done
22-11-20 20:26:00 INFO Sensors.SensorDataHandler SensorDataHandler instantiated
22-11-20 20:26:00 INFO Sensors.SensorReader Starting to collect temperature and humidity data from the the sensors
22-11-20 20:26:00 INFO Sensors.SensorReader Collecting data for sensor: Inside
22-11-20 20:26:00 INFO Sensors.SensorReader Get readings for the sensor Inside
22-11-20 20:26:00 INFO Sensors.SensorReader Start reading values for sensor type 22 in gpio 4
22-11-20 20:26:01 INFO Sensors.SensorReader Values from sensor: Temp=28.0* Humidity=74.9%
22-11-20 20:26:01 INFO Sensors.SensorReader Check is measured temperature negative or positive
22-11-20 20:26:01 INFO Sensors.SensorReader Value is positive
22-11-20 20:26:01 INFO Sensors.SensorReader Read humidity readings
22-11-20 20:26:01 INFO Sensors.SensorReader Cast temperature and humidity readings to float
22-11-20 20:26:01 INFO Sensors.SensorReader Sensor value reading finished
22-11-20 20:26:01 INFO Sensors.SensorReader Sensor temperature values as celsius
22-11-20 20:26:01 INFO Sensors.SensorReader Readings: Temperature: 28.0 , Humidity: 74.9. Store sensor readings for handling
22-11-20 20:26:01 INFO Sensors.SensorReader Temperature and humidity data from sensor Inside collected
22-11-20 20:26:01 INFO Sensors.SensorReader Checking when last mail regarding this sensor was sent out. Sensor=Inside
22-11-20 20:26:01 INFO Database.DbActionController getLastSensorMailSentTime
22-11-20 20:26:01 INFO Database.DbActions Executing Sql SELECT
22-11-20 20:26:01 ERROR Sensors.SensorReader Failed to get entry when last mail regarding this sensor was sent out.
Traceback (most recent call last):
File "/home/pi/DHT22-TemperatureLogger/Sensors/SensorReader.py", line 93, in getSensorReadings
mailSentTime = self.dbControl.getLastSensorMailSentTime(sensorName)
File "/home/pi/DHT22-TemperatureLogger/Database/DbActionController.py", line 29, in getLastSensorMailSentTime
data = self.dbActions.sqlSelect(sqlQuery)
File "/home/pi/DHT22-TemperatureLogger/Database/DbActions.py", line 32, in sqlSelect
db = MySQLdb.connect(self.host,self.user,self.password,self.database)
File "/usr/lib/python2.7/dist-packages/MySQLdb/__init__.py", line 86, in Connect
return Connection(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/MySQLdb/connections.py", line 204, in __init__
super(Connection, self).__init__(*args, **kwargs2)
OperationalError: (1045, "Access denied for user ' logger'@'localhost' (using password: YES)")
22-11-20 20:26:01 ERROR Sensors.SensorDataHandler Sensor reading raised exception
Traceback (most recent call last):
File "/home/pi/DHT22-TemperatureLogger/Sensors/SensorDataHandler.py", line 31, in readAndStoreSensorReadings
self.readingsFromSensors, self.failedSensors = self.sensorReader.getSensorReadings()
File "/home/pi/DHT22-TemperatureLogger/Sensors/SensorReader.py", line 93, in getSensorReadings
mailSentTime = self.dbControl.getLastSensorMailSentTime(sensorName)
File "/home/pi/DHT22-TemperatureLogger/Database/DbActionController.py", line 29, in getLastSensorMailSentTime
data = self.dbActions.sqlSelect(sqlQuery)
File "/home/pi/DHT22-TemperatureLogger/Database/DbActions.py", line 32, in sqlSelect
db = MySQLdb.connect(self.host,self.user,self.password,self.database)
File "/usr/lib/python2.7/dist-packages/MySQLdb/__init__.py", line 86, in Connect
return Connection(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/MySQLdb/connections.py", line 204, in __init__
super(Connection, self).__init__(*args, **kwargs2)
OperationalError: (1045, "Access denied for user ' logger'@'localhost' (using password: YES)")
22-11-20 20:26:01 ERROR root Sensor data handling failed:
Traceback (most recent call last):
File "DHT22logger.py", line 82, in main
SensorDataHandler(configurations,dbControl,mailSender).readAndStoreSensorReadings()
File "/home/pi/DHT22-TemperatureLogger/Sensors/SensorDataHandler.py", line 31, in readAndStoreSensorReadings
self.readingsFromSensors, self.failedSensors = self.sensorReader.getSensorReadings()
File "/home/pi/DHT22-TemperatureLogger/Sensors/SensorReader.py", line 93, in getSensorReadings
mailSentTime = self.dbControl.getLastSensorMailSentTime(sensorName)
File "/home/pi/DHT22-TemperatureLogger/Database/DbActionController.py", line 29, in getLastSensorMailSentTime
data = self.dbActions.sqlSelect(sqlQuery)
File "/home/pi/DHT22-TemperatureLogger/Database/DbActions.py", line 32, in sqlSelect
db = MySQLdb.connect(self.host,self.user,self.password,self.database)
File "/usr/lib/python2.7/dist-packages/MySQLdb/__init__.py", line 86, in Connect
return Connection(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/MySQLdb/connections.py", line 204, in __init__
super(Connection, self).__init__(*args, **kwargs2)
OperationalError: (1045, "Access denied for user ' logger'@'localhost' (using password: YES)")
22-11-20 20:26:01 INFO Utility.MailSender sendWarningEmail called
22-11-20 20:26:01 INFO Utility.MailSender _sendMail called. Sending mail...
22-11-20 20:26:02 ERROR Utility.MailSender Failed to send mail
Traceback (most recent call last):
File "/home/pi/DHT22-TemperatureLogger/Utility/MailSender.py", line 69, in sendWarningEmail
self._sendMail(messageOut)
File "/home/pi/DHT22-TemperatureLogger/Utility/MailSender.py", line 106, in _sendMail
server.login(self.username,self.password)
File "/usr/lib/python2.7/smtplib.py", line 623, in login
raise SMTPAuthenticationError(code, resp)
SMTPAuthenticationError: (534, '5.7.9 Application-specific password required. Learn more at\n5.7.9 https://support.google.com/mail/?p=InvalidSecondF... 23sm8266723pgs.19 - gsmtp')
22-11-20 20:26:02 ERROR root Sending warning mail failed
Traceback (most recent call last):
File "DHT22logger.py", line 87, in main
mailSender.sendWarningEmail("Error with sensor data handling.\nError message: {0}".format(e.message))
File "/home/pi/DHT22-TemperatureLogger/Utility/MailSender.py", line 69, in sendWarningEmail
self._sendMail(messageOut)
File "/home/pi/DHT22-TemperatureLogger/Utility/MailSender.py", line 106, in _sendMail
server.login(self.username,self.password)
File "/usr/lib/python2.7/smtplib.py", line 623, in login
raise SMTPAuthenticationError(code, resp)
SMTPAuthenticationError: (534, '5.7.9 Application-specific password required. Learn more at\n5.7.9 https://support.google.com/mail/?p=InvalidSecondF... 23sm8266723pgs.19 - gsmtp')
22-11-20 20:26:02 INFO root Check if weekly averages need to be sended
22-11-20 20:26:02 INFO Configurations.ConfigHandler Get configuration for sending weekly average temperatures
22-11-20 20:26:02 INFO Configurations.ConfigAdapter Creating dictionary for backup dump configurations
22-11-20 20:26:02 INFO Configurations.ConfigAdapter Configuration dictionary created
22-11-20 20:26:02 INFO Configurations.ConfigHandler Check if weekly averages sending is enabled
22-11-20 20:26:02 INFO Configurations.ConfigHandler Yes
22-11-20 20:26:02 INFO Configurations.ConfigHandler Is it time to perform requested action
22-11-20 20:26:02 INFO Configurations.ConfigHandler No
22-11-20 20:26:02 INFO Configurations.ConfigHandler Get configuration for backup dump
22-11-20 20:26:02 INFO Configurations.ConfigAdapter Creating dictionary for backup dump configurations
22-11-20 20:26:02 INFO Configurations.ConfigAdapter Configuration dictionary created
22-11-20 20:26:02 INFO Configurations.ConfigHandler Check if dump is enabled
22-11-20 20:26:02 INFO Configurations.ConfigHandler Yes
22-11-20 20:26:02 INFO Configurations.ConfigHandler Is it time to perform requested action
22-11-20 20:26:02 INFO Configurations.ConfigHandler No
22-11-20 20:26:02 INFO root DHT22logger execution finished
Can you please suggest as where I am going wrong
3 years ago
Just installed Raspbian Buster and found the following changes were required to complete the install:
Step 9
sudo apt-get install mariadb-server python-mysqldb
Step 12
sudo apt-get install apache2 php7.1 php7.1-curl php7.1-gd php7.1-imap php7.1-json php7.1-mcrypt php7.1-mysql php7.1-opcache php7.1-xmlrpc libapache2-mod-php7.1
Mike
Tip 5 years ago
Hi All,
When using only one DHT22, delete one of the sensor configuration lines, making sure to leave the two "[[" and "]]" around the remaining line. If the outer '[' and ']' are missing, the program will report 0 data.
If the last ']' is missing, the DHT22logger.py breaks and gives several errors and ends with "ValueError: Expecting , delimiter: line 10 column 11 (char 345)".
If you wish to use a DHT11, change "DHT22" to "DHT11" in each of the sensor configuration lines of config.json. One line for each sensor.
The DHT22 aka AM2302, comes in two forms, sensor and module.
The sensor with four legs protruding from it's plastic cover, that requires the use of a "pull up" resistor.
The module, is the DHT22 sensor mounted on a PCB and has three legs with a "pull up" resistor and "ripple filter" capacitor on the PCB.
The DHT11 also comes in both sensor and module forms.
Hopefully these tips will guide you in completing this project,
Shane
Thank you jjpfin for this project and knowledge.
Reply 3 years ago
Thank you, you helped me a lot
Question 4 years ago
Hey Guys . Very nice site and project . I get the attached errors. Pease help or advice where to start looking
Answer 3 years ago
In that screenshot, look for the line that begins with "OperationalError: (1054....". It looks like you have a misnamed column of triggedsensor or something like that.
Question 4 years ago on Step 13
following all the instructions, the system works locally. xxx.local brings up the data. However, the NOIP portion seems incomplete. When the noip address is entered into a web browser, the router login appears. What additional instructions are needed to get to the temperature data?
A second question... Is the database purged of old data after email is sent? If not, how could the data be purged? The system is running on small memory.
thank you
Answer 3 years ago
A quick solution that I have is to set up a cron job to purge the data from the database periodically.
Question 3 years ago
For the DHT22-TemperatureLogger code base, could you add in an option to use a different port to connect to the MySQL server? It appears to use the default port of 3306. I'm actually logging this data to a different server within my network that is on MariaDB and that uses 3307 by default. It would be nice to have this as a config option instead of being able to only use 3306.
4 years ago
great project. I appreciate the update. I picked up a pair of sensors off of amazon. One i ran a fair distance away. I mounted the rpi on my network rack and probably have a 50ft cable run going over to my exhaust fan. I could never get the 2nd sensor to work reliably. I saw a post in an amazon thread about running it at 5v, so i put the second sensor on a 5v rail, and then it operated correctly, and reliably. just a YMMV thing. Dont know if it was the distance, or what, but it works now.
4 years ago
Hy, I have a problem with an execution time about 2,5 minutes. My mysql table consist of about 2300 row. I marked this BLOND. What is the reason of this? Thanks your answer.
pi@gregohun ~/DHT22-TemperatureLogger $ python DHT22logger.py
Logger initialization started
Check if directory for storing logs is writeable
Directory is writeable
Logger initialized
11-06-19 10:05:53 INFO root DHT22logger execution started
11-06-19 10:05:53 INFO Configurations.ConfigHandler ConfigHandler instantiation started
11-06-19 10:05:53 INFO Configurations.ConfigHandler Instantiate ConfigReader
11-06-19 10:05:53 INFO Configurations.ConfigReader ConfigReader instantiation started
11-06-19 10:05:53 INFO Configurations.ConfigReader Loading configurations from config.json
11-06-19 10:05:53 INFO Configurations.ConfigReader ConfigReader instantiated
11-06-19 10:05:53 INFO Configurations.ConfigHandler Read configurations
11-06-19 10:05:53 INFO Configurations.ConfigHandler Configurations read succesfully
11-06-19 10:05:53 INFO Configurations.ConfigAdapter ConfigAdapter instantiation started
11-06-19 10:05:53 INFO Utility.TimeFormatHelper TimeFormat instantiation started
11-06-19 10:05:53 INFO Utility.TimeFormatHelper TimeFormat instantiated
11-06-19 10:05:53 INFO Configurations.ConfigAdapter ConfigAdapter instantiated
11-06-19 10:05:53 INFO Configurations.ConfigHandler ConfigHandler instantiated
11-06-19 10:05:53 INFO Configurations.ConfigHandler Get full configuration adaptation
11-06-19 10:05:53 INFO Configurations.ConfigAdapter Creating dictionary for full configurations
11-06-19 10:05:53 INFO Configurations.ConfigAdapter Configuration dictionary created
11-06-19 10:05:53 INFO Database.DbActionController DbController instantiation started
11-06-19 10:05:53 INFO Database.DbActions DBActions instantiation started
11-06-19 10:05:53 INFO Database.DbActions DBActions instantiated
11-06-19 10:05:53 INFO Database.DbActionController DbController instantiated
11-06-19 10:05:53 INFO Utility.MailSender MailSender instantiation started
11-06-19 10:05:53 INFO Utility.TimeFormatHelper TimeFormat instantiation started
11-06-19 10:05:53 INFO Utility.TimeFormatHelper TimeFormat instantiated
11-06-19 10:05:53 INFO Utility.MailSender MailSender instantiation finished
11-06-19 10:05:53 INFO Sensors.SensorDataHandler SensorDataHandler instantiation started
11-06-19 10:05:53 INFO Sensors.SensorReader SensorReader instantiation started
11-06-19 10:05:53 INFO Sensors.SensorReader SensorReader instantiated
11-06-19 10:05:53 INFO Utility.MeasurementCompare MeasurementCompare instantiation started
11-06-19 10:05:53 INFO Utility.MeasurementCompare Instantiation done
11-06-19 10:05:53 INFO Sensors.SensorDataHandler SensorDataHandler instantiated
11-06-19 10:05:53 INFO Sensors.SensorReader Starting to collect temperature and humidity data from the the sensors
11-06-19 10:05:53 INFO Sensors.SensorReader Collecting data for sensor: Inside
11-06-19 10:05:53 INFO Sensors.SensorReader Get readings for the sensor Inside
11-06-19 10:05:53 INFO Sensors.SensorReader Start reading values for sensor type 22 in gpio 4
11-06-19 10:05:54 INFO Sensors.SensorReader Values from sensor: Temp=25.7* Humidity=77.7%
11-06-19 10:05:54 INFO Sensors.SensorReader Check is measured temperature negative or positive
11-06-19 10:05:54 INFO Sensors.SensorReader Value is positive
11-06-19 10:05:54 INFO Sensors.SensorReader Read humidity readings
11-06-19 10:05:54 INFO Sensors.SensorReader Cast temperature and humidity readings to float
11-06-19 10:05:54 INFO Sensors.SensorReader Sensor value reading finished
11-06-19 10:05:54 INFO Sensors.SensorReader Sensor temperature values as celsius
11-06-19 10:05:54 INFO Sensors.SensorReader Readings: Temperature: 25.7 , Humidity: 77.7. Store sensor readings for handling
11-06-19 10:05:54 INFO Sensors.SensorReader Temperature and humidity data from sensor Inside collected
11-06-19 10:05:54 INFO Sensors.SensorReader Checking when last mail regarding this sensor was sent out. Sensor=Inside
11-06-19 10:05:54 INFO Database.DbActionController getLastSensorMailSentTime
11-06-19 10:05:54 INFO Database.DbActions Executing Sql SELECT
11-06-19 10:05:55 INFO Database.DbActions Executing Sql SELECT finished
11-06-19 10:05:55 WARNING Sensors.SensorReader No entry for last mail sent
11-06-19 10:05:55 INFO Sensors.SensorReader Collecting previously measured values for sensor=Inside
11-06-19 10:05:55 INFO Database.DbActionController Start reading last sensor measurements
11-06-19 10:05:55 INFO Database.DbActions Executing Sql SELECT
11-06-19 10:08:30 INFO Database.DbActions Executing Sql SELECT finished
11-06-19 10:08:30 INFO Sensors.SensorReader Previously measured values collected
11-06-19 10:08:30 INFO Sensors.SensorReader Sensor readings collected
11-06-19 10:08:30 INFO Sensors.SensorDataHandler Successfully read: 1 sensors. Failed to read: 0 sensor(s)
11-06-19 10:08:30 INFO Sensors.SensorDataHandler Start persisting data for sensor Inside
11-06-19 10:08:30 INFO Database.DbActionController Starting to persist sensor readings to database
11-06-19 10:08:30 INFO Database.DbActions Executing Sql INSERT
11-06-19 10:08:31 INFO Database.DbActions Executing Sql INSERT finished
11-06-19 10:08:31 INFO Sensors.SensorDataHandler Data persisting finished for sensor Inside
11-06-19 10:08:31 INFO Sensors.SensorDataHandler Data persisted
11-06-19 10:08:31 INFO Sensors.SensorDataHandler Starting measurement comparison against set threshold for sensor Inside
11-06-19 10:08:31 INFO Sensors.SensorDataHandler Last measured temperature to compare to: 25.6 and Last measured humidity to compare to: 77.4
11-06-19 10:08:31 INFO Sensors.SensorDataHandler Execute measurement compare against set threshold
11-06-19 10:08:31 INFO Utility.MeasurementCompare Set sensor data to begin measurements
11-06-19 10:08:31 INFO Utility.MeasurementCompare Data set
11-06-19 10:08:31 INFO Utility.MeasurementCompare Comparing temperature change against set threshold
11-06-19 10:08:31 INFO Utility.MeasurementCompare Checking if previous temperature is available...
11-06-19 10:08:31 INFO Utility.MeasurementCompare Previous temperature is available, execute comparison
11-06-19 10:08:31 INFO Utility.MeasurementCompare Measured temperature = 25.7, previously measured temperature 25.6, temperature treshold 10.0
11-06-19 10:08:31 INFO Utility.MeasurementCompare Comparison done
11-06-19 10:08:31 INFO Utility.MeasurementCompare Comparing humidity change against set threshold
11-06-19 10:08:31 INFO Utility.MeasurementCompare Checking if previous humidity value is available...
11-06-19 10:08:31 INFO Utility.MeasurementCompare Previous humidity is available, execute comparison
11-06-19 10:08:31 INFO Utility.MeasurementCompare Measured humidity = 77.7, previously measured humidity 77.4, humidity treshold 10.0
11-06-19 10:08:31 INFO Utility.MeasurementCompare Comparison done
11-06-19 10:08:31 INFO Sensors.SensorDataHandler Threshold comparison done for sensor Inside
11-06-19 10:08:31 INFO Sensors.SensorDataHandler Perform delta check compare against previously measured results for sensor Inside
11-06-19 10:08:31 INFO Utility.MeasurementCompare Set sensor data to begin measurements
11-06-19 10:08:31 INFO Utility.MeasurementCompare Data set
11-06-19 10:08:31 INFO Utility.MeasurementCompare Comparing measured temperature against set limit
11-06-19 10:08:31 INFO Utility.MeasurementCompare Comparison done
11-06-19 10:08:31 INFO Utility.MeasurementCompare Comparing measured humidity against set limit
11-06-19 10:08:31 INFO Utility.MeasurementCompare Comparison done
11-06-19 10:08:31 INFO root Check if weekly averages need to be sended
11-06-19 10:08:31 INFO Configurations.ConfigHandler Get configuration for sending weekly average temperatures
11-06-19 10:08:31 INFO Configurations.ConfigAdapter Creating dictionary for backup dump configurations
11-06-19 10:08:31 INFO Configurations.ConfigAdapter Configuration dictionary created
11-06-19 10:08:31 INFO Configurations.ConfigHandler Check if weekly averages sending is enabled
11-06-19 10:08:31 INFO Configurations.ConfigHandler No
11-06-19 10:08:31 INFO Configurations.ConfigHandler Get configuration for backup dump
11-06-19 10:08:31 INFO Configurations.ConfigAdapter Creating dictionary for backup dump configurations
11-06-19 10:08:31 INFO Configurations.ConfigAdapter Configuration dictionary created
11-06-19 10:08:31 INFO Configurations.ConfigHandler Check if dump is enabled
11-06-19 10:08:31 INFO Configurations.ConfigHandler No
11-06-19 10:08:31 INFO root DHT22logger execution finished
4 years ago
I've get this messages from the Debug.Log
16-05-19 14:30:54 ERROR Utility.MailSender Failed to send mail
Traceback (most recent call last):
File "/home/pi/DHT22-TemperatureLogger/Utility/MailSender.py", line 69, in se$
self._sendMail(messageOut)
File "/home/pi/DHT22-TemperatureLogger/Utility/MailSender.py", line 104, in _$
server = smtplib.SMTP('smtp.gmail.com',587)
File "/usr/lib/python2.7/smtplib.py", line 256, in __init__
(code, msg) = self.connect(host, port)
File "/usr/lib/python2.7/smtplib.py", line 316, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "/usr/lib/python2.7/smtplib.py", line 291, in _get_socket
return socket.create_connection((host, port), timeout)
File "/usr/lib/python2.7/socket.py", line 575, in create_connection
raise err
error: [Errno 101] Network is unreachable
16-05-19 14:30:54 ERROR root Sending warning mail failed
16-05-19 14:30:54 ERROR root Sending warning mail failed
Traceback (most recent call last):
File "/home/pi/DHT22-TemperatureLogger/DHT22logger.py", line 87, in main
mailSender.sendWarningEmail("Error with sensor data handling.\nError messag$
File "/home/pi/DHT22-TemperatureLogger/Utility/MailSender.py", line 69, in se$
self._sendMail(messageOut)
File "/home/pi/DHT22-TemperatureLogger/Utility/MailSender.py", line 104, in _$
server = smtplib.SMTP('smtp.gmail.com',587)
File "/usr/lib/python2.7/smtplib.py", line 256, in __init__
(code, msg) = self.connect(host, port)
File "/usr/lib/python2.7/smtplib.py", line 316, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "/usr/lib/python2.7/smtplib.py", line 291, in _get_socket
return socket.create_connection((host, port), timeout)
File "/usr/lib/python2.7/socket.py", line 575, in create_connection
raise err
error: [Errno 101] Network is unreachable
what the next step should i do
4 years ago
I have updated PHP scripting for displaying temperature and humidity values on a chart that is PHP 7.0 compatible. However, I'm having difficulty posting a properly formatted version. Reply to this message if the attached code is too mangled.
=====
<?php
// settings
// host, user and password settings
$host = "localhost";
$user = "logger";
$password = “<insert your password>“;
$database = "temperatures";
$sensor1 = "Water Heater";
$sensor2 = "Garage";
$type1 = "Temp";
$type2 = "Humidity";
//how many hours backwards do you want results to be shown in web page.
$hours = 168;
// make connection to database
$con = mysql_connect($host,$user,$password,$database);
// sql command that selects all entires from current time and X hours backwards
//NOTE: If you want to show all entries stored in the database, comment out the line that starts with
// "AND t1.dateandtime..." by inserting a "#" at the beginning of that line
$sql="SELECT year(t1.dateandtime) AS year, month(t1.dateandtime) AS month, day(t1.dateandtime) AS day,
hour(t1.dateandtime) AS hour, minute(t1.dateandtime) AS minute,
t1.sensor AS sensor1, t1.temperature AS temp1, t1.humidity AS hum1,
t2.sensor AS sensor2, t2.temperature AS temp2, t2.humidity AS hum2
FROM temperaturedata AS t1
INNER join temperaturedata AS t2
ON t1.dateandtime = t2.dateandtime AND t2.sensor = '" . $sensor1 . "'
WHERE t1.sensor = '" . $sensor2 . "'
AND t1.dateandtime >= (NOW() - INTERVAL $hours HOUR)
ORDER BY t1.dateandtime";
// set query to variable
$data = mysqli_query($con, $sql);
// format current time for display
$today = date("D M j, Y G:i:s T");
// create content to web-page
?>
<html>
<head>
<!-- Comment out the following line to disable auto-refresh every 15 minutes -->
<meta http-equiv="refresh" content="900"> <!-- Refresh every 15 minutes -->
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('datetime', 'Datetime');
data.addColumn('number', '<?php echo $sensor1 . " " . $type1 ?>');
data.addColumn('number', '<?php echo $sensor1 . " " . $type2 ?>');
data.addColumn('number', '<?php echo $sensor2 . " " . $type1 ?>');
data.addColumn('number', '<?php echo $sensor2 . " " . $type2 ?>');
data.addRows([
<?php
// loop all the results that were read from database and "draw" to web page
while ($row=mysqli_fetch_assoc($data)) {
echo " [ ";
echo "new Date(".$row['year'].", ";
echo ($row['month']-1).", "; // adjust month from mysql to javascript format
echo $row['day'].", ";
echo $row['hour'].", ";
echo $row['minute']."), ";
echo $row['temp1'].", ";
echo $row['temp2'].", ";
echo $row['hum1'].", ";
echo $row['hum2']." ";
echo "],\n";
}
mysqli_free_result($data);
?>
]);
var options = {
title: 'Bakersfield Home - <?php echo $today ?>',
width: 1000,
height: 600,
curveType: 'function',
legend: { position: 'bottom' },
crosshair: { trigger: 'both' },
series: {
0: { targetAxisIndex: 0 },
1: { targetAxisIndex: 0 },
2: { targetAxisIndex: 1 },
3: { targetAxisIndex: 1 }
},
vAxes: {
0: {
title: '\u00B0Fahrenheit',
viewWindowMode: 'explicit',
viewWindow: {
max: 135,
min: 35
}
},
1: {
title: '%Humidity',
viewWindowMode: 'explicit',
viewWindow: {
max: 100,
min: 0
}
}
},
hAxis: { title: 'Time of Day' }
};
var chart = new google.visualization.LineChart(document.getElementById('curve_chart'));
chart.draw(data, options);
}
</script>
</head>
<body>
<div id="curve_chart" style="width: 1200px; height: 500px"></div>
</body>
</html>
<?php
mysqli_close($con);
?>