This is a weather station based on ESP32 and MicroPython.
Here is a list of main features:
- Measuring temperature and humidity with DHT22 sensor
- Measuring temperature, humidity and barometric pressure with BME280 sensor
- Sending data to a Google sheet
- Supporting Google OAuth 2.0 service to get access to the sheet
- Configuring the device via web browser
The sheet doesn't need to be publicly available on the Internet. The device doesn't require any middleman such as PushingBox or IFTTT.
Below is a brief description how the project can be built. More details can be found in the following articles:
Here is a circuit and a breadboard view.
The project uses MicroPython 1.11. Older or newer versions may also work. The project uses the following tools:
esptool
for flashing ESP32mpfshell
for uploading files to ESP32minicom
for connecting to ESP32 for debugging purposesopenssl
andrsa
package for reading cryptographic keys
To access a Google sheet, the project needs a service account:
- Follow the instructions and create a service account
- Create a key
- Download a JSON file with the key
The key is encoded in PKCS1 format. Unfortunately the project doesn't support PKCS1 yet. You need to convert the key to the format which the project undrstand:
$ cd scripts
$ sh extract_key.sh ../google_key.json ../key.json
You'll need key.json
and an email for the sercvice account.
Create a Google sheet and extract its ID from the URL
https://docs.google.com/spreadsheets/d/<ID_is_here>/edit#gid=0
The following function, when added to the google sheet (Tools > Script editor) allows the
formula uploaded in the dt
variable (see measure(self)
) to calculate a local timestamp
from the epoch value loaded in column A of the inserted row
function TIMESTAMP_TO_DATE(value) {
return new Date(value * 1000);
}
Share the sheet with your service account. The sheet doesn't need to be publicly accessible from the Internet.
main.conf
contains a configuration for the device. Provide the following parameters:
ssid
andpassword
are credentials for your Wi-Figoogle_service_account_email
is an email for the Google's service accountgoogle_sheet_id
is the Google's sheet IDmeasurement_interval
is a mesurement interval inXh Ym Zs
format, for example,1h 2m 3s
- Pins that are used by switches, sensors, etc. Actual pin numbers may depend on a particular board. Mare sure that you update the config to contain right pin numbers for your board.
The following scripts may be used to upload MicroPython to ESP32:
$ sh scripts/erase.sh
$ sh scripts/flash.sh
$ sh scripts/verify.sh
You can run sh scripts/upload.sh
to upload the code, the configuration file and the key.
Then, you can connect to the board with sh scripts/minicon.sh
command to check if everything works fine.
The switch turns on the configuration mode. In this mode the device sets up a Wi-Fi access point, and start an HTTP server on http://192.168.4.1. The server provides a web page for updating the configuration of the device.
- The implementation of RSA signing is based on python-rsa package
- The implementation of NTP client is based on ntptime.py
- The implementation of BME280 micropython driver is based on this
Here is a list of possbile enhancements: