Online thermometer with local backup: Difference between revisions
(10 intermediate revisions by the same user not shown) | |||
Line 9: | Line 9: | ||
https://learn.adafruit.com/dht/connecting-to-a-dhtxx-sensor | https://learn.adafruit.com/dht/connecting-to-a-dhtxx-sensor | ||
https://learn.adafruit.com/dht-humidity-sensing-on-raspberry-pi-with-gdocs-logging/python-setup | |||
Wires: | Wires: | ||
Line 16: | Line 20: | ||
*Ground - black wire. 4rd on left or first on right. [Green-yellow -> black] | *Ground - black wire. 4rd on left or first on right. [Green-yellow -> black] | ||
=== Raspi | === Raspi 2B === | ||
I have an old Raspi (not the plus version). The pins are | |||
I have an old Raspi 2B (not the plus version). The pins are shown here: https://www.megaleecher.net/raspberry_pi_gpio_pinout_helper | |||
== Theory == | == Theory == | ||
=== Get the data === | === Get the data using Python=== | ||
First install the Adafruit Python DHT software. The detailed instructions are eg at https://thepihut.com/blogs/raspberry-pi-tutorials/am2302-temp-humidity-sensor. I needed to install <code inline>setuptools</code> and <code> inline python3-dev</code> via apt. Also, the examples use Python2, but running the directly using python3 works. | |||
=== Save the data to local or online database securely === | === Save the data to local or online database securely === | ||
Need to install MariaDB or MySQL server on Raspi. It is straightforward. Find the tutorials using [https://duckduckgo.com/?q=raspberry+pi+setup+mysql+mariadb&ia=web ddg]. | |||
To check if internet connection is established, ping to a secure website, e.g. <code inline>ping 8.8.8.8</code> will ping to DNS server provided by google. | |||
Use mysqldump to transfer data from local server to online. | |||
=== Set the location === | === Set the location === |
Latest revision as of 20:44, 22 August 2021
Introduction
We use AM2302 (wired DHT22) temperature-humidity sensor with Raspberry Pi. Pi is set up to measure temperature and humidity every minutes (perhaps 5min), and the is securely sent to online web server if possible. If not, the will be saved to local database and transferred when RPi is online.
The data is visualized using D3.js library with zoom and pan. The current location of RPi can be changed online, and the location is shown on the visualization page.
AM2302 Sensor
https://learn.adafruit.com/dht/connecting-to-a-dhtxx-sensor
https://learn.adafruit.com/dht-humidity-sensing-on-raspberry-pi-with-gdocs-logging/python-setup
Wires:
- VCC - red wire Connect to 3.3 - 5V power. 1st on left. [Brown -> yellow]
- Data out - white or yellow wire. 2nd on left. [Blue -> black]
- Not connected
- Ground - black wire. 4rd on left or first on right. [Green-yellow -> black]
Raspi 2B
I have an old Raspi 2B (not the plus version). The pins are shown here: https://www.megaleecher.net/raspberry_pi_gpio_pinout_helper
Theory
Get the data using Python
First install the Adafruit Python DHT software. The detailed instructions are eg at https://thepihut.com/blogs/raspberry-pi-tutorials/am2302-temp-humidity-sensor. I needed to install setuptools
and inline python3-dev
via apt. Also, the examples use Python2, but running the directly using python3 works.
Save the data to local or online database securely
Need to install MariaDB or MySQL server on Raspi. It is straightforward. Find the tutorials using ddg.
To check if internet connection is established, ping to a secure website, e.g. ping 8.8.8.8
will ping to DNS server provided by google.
Use mysqldump to transfer data from local server to online.