When the PyPortal starts up, it will first load the aws_splash.bmp image in the images folder on your CIRCUITPY drive. This is a "loading screen" while the code waits for the fonts and display objects load on the screen.

Opening the REPL will help you view what's happening in the code. First, the code attempts to load the PyPortal's graphical interface

Loading AWS IoT Graphics...
Displaying splash screen
Set icon to  /images/aws_splash.bmp
Setting up labels...
Graphics loaded!

Then, the PyPortal's ESP32 will attempt to connect to the WiFi network defined in the secrets.py file. Once connected to a wireless network, the PyPortal will attempt to authenticate with the AWS IOT endpoint with the certificate and private key .

Connecting to WiFi...
Attempting to connect to a39rd7hlvdi9mt-ats.iot.us-east-2.amazonaws.com
Connected to AWS IoT!

Once connected, the MiniMQTT client subscribes to all messages on the device's shadow topic.

Subscribing to shadow updates...
Subscribed to $aws/things/PyPortal/shadow/update/# with QOS level 1

Every SENSOR_DELAY minutes, the PyPortal will read the STEMMA sensor's moisture level and temperature. Then, it'll send it to Amazon AWS IoT.

Moisture Level:  380
Temperature: 61°F
Sending data to AWS IoT...
Data sent!

Since you subscribed to the $aws/things/thingName/shadow/update feed, you'll see a message returned by the message callback signifying that the message has been accepted by the Adafruit AWS device shadow.

Message from $aws/things/PyPortal/shadow/update/accepted: {"state":{"reported":{"temp":"61","moisture":"380"}}

Viewing Sensor Data on PyPortal

You should see the PyPortal display update to display the temperature value and moisture level.

The status indicator at the bottom of the PyPortal will display when it's sending data to AWS IoT. The PyPortal only sends data to AWS IoT every SENSOR_DELAY minutes. Adjust this value in the code to increase or decrease the delay.

Receiving Emails from AWS IoT and Amazon SNS

Once the moisture level dips below 400 (the limit you set earlier), Amazon Simple Notification Service will send an email to you to remind you to water your plant.

Want to change this value? Simply edit the AWS IoT Rule you configured earlier in the guide here.

Remember to Check Your Inbox!

AWS SNS will deliver up to a thousand emails to your inbox, free of charge. After that limit is reached, SNS will charge you $2.00 per 100,000 emails. 

While it's unlikely your PyPortal Plant Monitor will ever reach 1,000 emails per month, it's important to check the email connected to Amazon SNS to ensure your code isn't continuously firing notifications when your plant needs to be watered. You may also want to increase the SENSOR_DELAY in your code to check the plant's vitals every few hours, instead of every fifteen minutes.

Visit the Amazon SNS product page to learn more about its pricing.

This guide was first published on Oct 16, 2019. It was last updated on Apr 24, 2024.

This page (Code Usage) was last updated on Apr 09, 2024.

Text editor powered by tinymce.