COMPLETE HARDWARE-SOFTWARE-ASSEMBLY TUTORIAL ON INSTRUCTABLES
IMAGES ARE CC BY 2.0
Component | Image | Store Link | Documentation |
---|---|---|---|
Particle Photon | Particle Store | SparkFun Development Guide | |
[OPTIONAL] 2.4GHz u.FL Antenna | SparkFun | SparkFun Hookup Guide | |
SparkFun OpenLog | SparkFun | SparkFun Hookup Guide | |
SparkFun Photon Weather Shield | SparkFun | SparkFun Hookup Guide | |
SparkFun Weather Meters | SparkFun | SparkFun Hookup Guide | |
Dallas DS18B20 Waterproof Temperature Sensor | SparkFun | Example code by SparkFun on GitHub | |
SparkFun Soil Moisture Sensor | SparkFun | SparkFun Hookup Guide | |
SparkFun Qwiic VEML6075 UV Light Sensor Breakout | SparkFun | SparkFun Hookup Guide | |
SparkFun Sunny Buddy | SparkFun | SparkFun Hookup Guide | |
3.5W solar panel | SparkFun | -- | |
6Ah Li-Ion battery | SparkFun | -- | |
Custom 3D Modelled Stevenson Screen | Thingiverse | -- |
Just clone or fork this repository from https://github.com/ciakkig/pws, and that's it.
Library | Download |
---|---|
SparkFun Photon Weather Shield | GitHub |
OneWire | GitHub |
Dallas DS18B20 | GitHub |
SparkFun VEML6075 | GitHub |
ThingSpeak for Particle | GitHub |
However, all required libraries are already included in the lib
directory.
Additionally, this project was made using Particle Workbench in Visual Studio Code, and while not strictly necessary, using that is warmly recommended.
Otherwise, the code has also been styled (tabbed with 3 spaces) to be consistent with the Particle Build cloud IDE, if that's more your thing.
Set up a new channel on ThingSpeak here, entering your coordinates and elevation, and setting the first 7 fields to the following:
- Temperature
- Humidity
- Pressure
- UV Index
- Rain Rate
- Wind Speed
- Wind Direction
Then, visit the channel's API Keys section and record your credentials to the tsID
and tsAPI
variables in the credentials.h
file.
Set up a personal weather station on WeatherUnderground here, selecting "other" as hardware.
You'll have to enter the station's location again, then record your credentials from the Manage Devices page to the wuID
and wuPASS
varaiables in the credentials.h
file.
Set up a personal weather station on WeatherCloud here, selecting "other" as model.
Once again, you'll have to enter the station's location, but you'll be required to contact WeatherCloud Support to register your device to the API and get the necessary credentials -- but fear not, they don't have any particular requirements you need to satisfy.
You can then record your credentials to the wcID
, wcKEY
and wcAPI
variables in the credentials.h
file.
For all the credentials mentioned in this section, feel free to use templates/calibration_template.h
as a template, but don't forget to copy, rename and mention your file in your .gitignore
if you're planning on redistributing the code to keep your credentials for yourself!
Calibrating sensors is always good practice.
However, the majority of the involved sensors already come factory-calibrated, and calibration methods at the intersection of reliability and affordability are basically non-existent.
Of course, you're free to calibrate as many sensors as you want -- just throw in some more map()
functions -- but please let me know if you manage to find a good way.
As a requirement, however, you'll only have to run calibration on the sensor that needs it the most: the soil moisture sensor.
To do that, as shown in SparkFun's Hookup Guide, put it about three-quarters of its way inside the soil you want to calibrate it for, in a completely dry condition, and record this first raw reading to the smCal0
variable.
Then, wet the soil as much as you can, until it's saturated with water, and record this second raw reading to the smCal100
variable.
Don't worry if the two values happen to be quite close: I had a difference of about 300 -- 9% of my maximum value, and a mere tenth of the difference between my minimum value and the actual 0 recorded in air.
Another element that requires calibration is the Sunny Buddy: while not a sensor, its MPPT (Maximum Power Point Transfer) design needs to be calibrated to that point of maximum power transfer.
To do that, as once again shown in SparkFun's Hookup Guide, connect it to your solar panel on a sunny day, measure the voltage across the SET
and GND
pads, and tweak the nearby potentiometer with a screwdriver until that voltage is about 3V.
- Local compile the project through the Workbench shortcut
- Flash the compiled project over-the-wire through the Workbench shortcut
- Cloud compile the project with
particle compile photon
- Flash the compiled project over-the-air with
particle flash pws pws.bin
I usually prefer to compile locally for more reliability and control over the code, then flash it over the air for a seamless update from wherever I happen to be.
The Particle Cloud API provides a number of useful tools to interface with the Photon through Particle's CLI.
Mainly, the use of Particle Variables, Particle Functions and Particle Events.
You can get
a variable's value by issuing:
particle get var
For example, to get the soilMoisture
variable:
particle get soilMoisture
You can also call
a function with:
particle call device function argument
For example, to call the setSleepAt0
function with argument 0
on your device pws
:
particle call pws setSleepAt0 0
Here's the full list of all variables and functions (with their syntax) exposed through the Particle Cloud API:
Variable | Unit |
---|---|
temperature |
°C |
humidity |
Pa |
pressure |
% |
soilTemperature |
°C |
soilMoisture |
% |
uv |
-- (index) |
rain |
mm/min |
windSpeed |
km/h |
windDirection |
°N |
Function | Arguments | Usage | Returns |
---|---|---|---|
gotoSleepNow |
seconds : > 0 / none for default |
Sends the Photon into deep sleep immediately for the specified seconds . If no value is specified, the code-defined default (currently 300) is used. |
Nothing, as the Photon will be fast asleep. |
setSleepAt0 |
flag : 0 ~ 1 |
Overrides the flag that determines whether the Photon enters deep sleep or stays awake at the end of the loop. | 2-digit integer: ON , made up of the Old flag and New flag. |
setSampleSeconds |
seconds : 1 ~ 300 |
Overrides the value that determines how long the Photon samples the sensors for. If no value is specified, the code-defined default (currently 60) is used as a reset. | 6-digit integer: OLDNEW , made up of OLD time and NEW time. -1 in case of invalid arguments. |
getWeather |
seconds : 1 ~ 300 / none for default |
Polls all sensors for the current weather, sampling in loop for the specified seconds . If no value is specified, the code-defined default (currently 60) is used. |
8-digit integer: TEHUPRES , made up of TEmperature, HUmidity and PRESsure. -1 in case of invalid arguments. |
printData |
-- | Prints the weather data over USB Serial to a PC. | 1 in case of success, -1 in case of failed Serial connection. |
logData |
-- | Logs the weather data over RX-TX Serial to the OpenLog. | 1 in case of success, -1 in case of failed Serial connection. |
publishData |
-- | Publishes the weather data to the Particle Cloud as private Events. | 1 in case of success, nothing or error in case of failed Cloud connection. |
publishThingSpeak |
-- | Publishes the weather data to ThingSpeak. | 1 in case of success, nothing or error in case of failed Internet connection. |
publishWeatherUnderground |
-- | Publishes the weather data to WeatherUnderground. | 1 in case of success, nothing or error in case of failed Internet connection. |
publishWeatherCloud |
-- | Publishes the weather data to WeatherCloud. | 1 in case of success, nothing or error in case of failed Internet connection. |
This program focuses on robustness, debugability and power efficiency on remote deployment, while slightly overlooking the already relatively limited precision introduced by the general-purpose sensors on board. Rather, this is expected to be achieved through a bigger set of data, both through a long, frequent and constant gathering and by averaging a number of samples to measure such data.
By default, the weather station will:
- wake up at every --:-5 minute (i.e. 10:05, 10:15, 10:25, etc.)
- take measurements for each quantity
- do the necessary computations on the measurements
- post the data to the Particle Cloud and to the various weather network websites
- send its sensors to sleep to lower power consumption
- stand by for the next 4-5 minutes to offer a practical window for troubleshooting
- enter deep sleep at every --:-0 minute (i.e. 10:10, 10:20, 10:30, etc.)
- repeat
However, this default cycle can be easily tailored to any particular need for troubleshooting or power saving using the interfaces mentioned above.
Copyright (C) 2020 Giorgio Ciacchella
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License at COPYING
or https://www.gnu.org/licenses/#GPL for more details.