Software apps and online services
This project describes the latest generation of a weather station used by the ThingSpeak team at MathWorks (see ThingSpeak Weather Station & Data Analysis for an earlier version).
This weather station provides the following improvements:
- Optional solar power for locations without power
- Easily repeatable and maintainable packaging and electronics based on the Sentient Things IoT Node
- Updated firmware with micro SD card data logging, store and forwarding of data to overcome communication outages, and optional automatic ThingSpeak channel creation
The first step in the project is to plug the Sentient Things Weather and Level Adapter and the Particle Boron LTE (or similar Feather-based device) into the Adafruit Feather compatible header on the Sentient Things IoT Node as shown below:
The Sentient Things IoT Node is a general purpose board with an Adafruit compatible header that is designed to be the foundation of a wide range of IoT projects. It comes with a hinged water resistant enclosure and the board includes the following features:
- Expandable header that is a super set of the Adafruit Feather header
- Solar or mains with LiPo battery charger
- Optional 3AA/A secondary battery
- A real time clock and calendar with super capacitor backup
- Real time clock power switching capability - i.e. the clock can power off the electronics like a deep sleep mode but with lower power consumption
- Analog watchdog timer
- 256kbit FRAM memory
- micro SD card slot
- Three I/O headers that expose GPIO, serial and I2C (more may be added with additional adapters)
Most importantly, to keep your options open, it does not include a microcontroller. Almost any microcontroller that is compatible with the Feather footprint will work. This project uses the Particle Boron LTE but it is also possible to use a wide range of alternative devices such as the Adafruit HUZZAH32 for example. If you happen to have Particle Photons or Electrons you may use those too with an adapter that converts to the Feather footprint.Step 2 - Mount the temperature and humidity sensor in the solar radiation shield
Assemble the Sentient Things AM2315 Temperature and Humidity Sensor into the solar radiation shield. Note that if you already have an AM2315 sensor you can use it and add your own RJ45 connector following the pinouts described below:
The recommended solar radiation shield fits the AM2315 sensor well as shown below but other shields will work too.
Plug the rain and wind weather meters, AM2315 Temperature and Humidity Sensor and TSL2591 Outdoor Light Sensor into the Sentient Things IoT Node and Weather and Level Adapter connectors. The AM2315 may be plugged into any one of the I/O connectors since they all include the I2C bus. The Wind and the Rain RJ11 connectors are marked on the Weather and Level Adapter and the Voltaic Systems 6V solar panel with extension plugs into the 6V connector. The 6V solar polarity is marked on the board. Also remember to plug a FAT formatted micro SD card into the micro SD slot on the board so that weather data an also be saved locally. Pass the cables through the cable glands as shown. Note that the Weather and Level Adapter includes a MPL3115A2 pressure and altitude sensor so do not make the glands completely airtight to allow the pressure inside the enclosure to equalize with the outside pressure. When finally mounting the enclosure outside make sure that the glands face downwards to prevent water from leaking into the enclosure.
Create a ThingSpeak and a Particle account if you do not have one already. ThingSpeak offers free accounts for non-commercial use and Particle offers a free service level too. Note that if you use the Particle cellular option then there is a monthly fee for the data that you use.
ThingSpeak will be used to collect, display and analyze weather data in the cloud and Particle provides the device hardware, firmware and device connectivity. Particle also provides a Webhooks cloud service (described below) that will be used to minimize the data traffic.
Follow the Particle Quickstart guide to set up your Particle device (associate it with your Particle account and set up WiFi if applicable). Particle offers a handy Android or iOS app for device setup. You will also need to follow Particle's instructions to register your SIM if you are using a cellular device like the Boron LTE.Step 5 - Add Webhooks to your Particle account
ThingSpeak offers both REST and MQTT APIs to send data to ThingSpeak. ThingSpeak also provides a Particle/Arduino compatible library to make it easy to use the APIs. This library is an excellent choice for devices that are connected via WiFi or Ethernet where there are no data charges. In the case of cellular though, it is best to minimize the data traffic by not using REST directly. One of the best ways to do that is to use Particle's (low overhead) COAP protocol to send data to the Particle servers and to have the Particle servers relay the data via REST (http) to ThingSpeak. This is done using Particle Webhooks.
The Sentient Things firmware makes use of the Particle Webhooks listed in the Code section below. Log into your Particle account Console and create three Webhooks under Integrations by pasting the JSON code below into Custom Templates and saving.
Note that for the Webhooks that create and update a ThingSpeak channel you will need to replace XXXXXXXXXXXXXXXX with your 16 character ThingSpeak User API key listed under your account profile on ThingSpeak.Step 6: Program your Particle device and test
The Weather firmware listed below is used to program your Particle device. This may be done using the Particle Web IDE or by using Particle Workbench if you are familiar with the Visual Studio Code based desktop development environment. You may copy and paste the code below into a new project on the Particle Web IDE or simply follow this link to a shared version of the firmware.
You may program or flash your device over the air (at the expense of data usage) or you may flash locally connected to your computer to avoid cellular data charges by following Particle's instructions.
Plug your device into the IoT Node (if it is not there already) and turn the POWER switch on the IoT node to FBAT to supply power to Particle device. The first time your firmware runs with the Particle device plugged into the IoT Node it detects that it is the first time that it is running (by looking for a "magic number" in FRAM) and creates a new ThingSpeak channel using the Particle Webhooks that you created earlier. When you visit ThingSpeak you should see a newly created channel that looks like this:
The firmware saves the channel number and channel Read and Write keys sent back from ThingSpeak in FRAM for future writes to the created channel.
With the firmware running you should see weather data being posted to ThingSpeak every minute.
The firmware prints serial debug messages so if you are having trouble the first step is to connect the USB output of the Particle device to your computer and monitor the serial output. If you have the Particle CLI installed on your computer you will see the Particle device as a COM port. The Particle CLI command:
particle serial monitor --follow
is a handy way to connect to and view the serial debug output from the Particle device.
Note the following code snippet close to the top of the code:
//********CHANGE BELOW AS NEEDED**************
// Set to true and enter TS channel ID and keys AND change firstRunTest to use an existing TS channel
// Set to false if you wish to create a new TS channel the first time the code runs
bool useManualTSChannel = false;
const char *manualTSWriteKey = "XXXXXXXXXXXXXXXX";
const char *manualTSReadKey = "XXXXXXXXXXXXXXXX";
const int manualTSChannel = 895141;
// Change this value to force hard reset and clearing of FRAM when Flashing
// You have to change this value (if you have flashed before) for the TS channel to change
const int firstRunTest = 1122124;
//********CHANGE ABOVE AS NEEDED**************
You may change
bool useManualTSChannel = false;
bool useManualTSChannel = true;
and add your own ThingSpeak keys and channel number to use an existing channel.
Note that you will also need to change the "magic number"
const int firstRunTest = 1122124;
to a different value so that the firmware detects that it is running for the first time to create a new or use an existing channel.Step 7: Install your weather station and analyze the data
Weather station anemometers are best installed away from buildings high off the ground. Options include building your own mast or using a tripod to mount the meters and the rest of the sensors on a rooftop.
ThingSpeak does a wonderful job of displaying your weather data in real-time charts on the Web. It it also possible to analyze and display your data using MATLAB as described in the previous article.
Visit the ThingSpeak weather station at MathWorks for a live demo: