abkfenris / gage-particle

MIT License
0 stars 0 forks source link

gage-particle Codacy Badge

Building a river gage using Particle.io with to incorperate what I learned during my last attempt at building one.

Why

It turns out to be very expensive to have the USGS run a river gage (due to Congressionally set managment standards). This puts setting up a gage on smaller watersheds well past the point of being reasonable for groups of paddlers or environmental organizations to set one up.

My goal with this project is to develop a low cost gage that is simple enough for most groups of paddlers or environmental organizations to be able to set one up.

Current status

Under development. Somewhere between in pieces on my desk, hanging off my porch, or hanging off a sea wall to get a tidal water signal for sensor testing.

Running on my desk

Case

Learnings from last time

Some of the things that I learned last time.

What is all this hardware

Scary

Also:

Currently the parts add up to around \$450 if you already have soldering, cables, and other random (wood) parts laying around for mounting.

Software & Services

The device depends on the Particle cloud console (free with device/cell plan) for management and communication. From there data can be forwared to other services like Ubidots (see the test device dashboard).

The device itself runs a C++ variant called Wiring that was popularized by Arudinos.

Particle has a few tutorials, but perhaps most useful is the device firmware referenece.

Device Software

gage-particle.ino is our devices's entrypoint. I've tried to keep it's file structure as simple as possible so that you can build up an understanding of different parts as you need it.

However there are some key things to know.

Structure

I've largely followed the Runnable class structure found in Arduino the Object Oriented Way. That way the publicly exposed interface for most classes follows the primary constructor, setup() loop() pattern that the main file follows, and internal details on how a sensor works or how often data is sent to the Particle console are taken care of by the internal structure of each class.

Runnable

A Runnable class has at least a void setup() and a void loop(). Almost everything inherits from Runnable.

SettingManager

SettingManager takes care of retrieving and persisting settings data to the EEPROM when the device is powered off. It also sets up Particle.function()s allowing settings to be changed from the Particle Console.

NetworkManager

NetworkManager takes care of managing cellular or wifi status.

DataLogger and DataLog

DataLogger and DataLog expand upon the design of the system LogHandler and Log.

DataLogger subclasses provide mechanisms to log messages or key/value pairs to various systems (Particle console, Serial, Ubidots, microSD, Bluetooth Low Energy UART). A logger may transmit data immediately, or buffer it.

DataLoggers expose 4 key methods.

DataLog is a global/singleton manager that distributes data out to registered DataLoggers.

DataLog should be imported by indivudal sensors or other classes or functions looking to persist data.

DataLog extends the functionality of DataLogger (which it passes to registered loggers) with add_logger(DataLogger &logger) to register the loggers.

Sensor

Sensors follow the Runnable structure, and extend it with a float value() method that immediately returns the key value that it is monitoring.

Mainly however Sensors use DataLog within their loops to directly log values as they are read, and individual loggers control what to do with those values.

Dependencies

There are a few external dependencies.

Particle.io Functions

Various settings controlling the device can be set via the Particle.io console (or via API).

Cloud

The gage depends on the Particle Console to operate, and Ubidots can make displaying data much easier.

Particle Console

Particle console allows you to see latest events, current device status, and send functions to the device.

As events can be forwarded as webhooks, IFFFT, Google Cloud Functions, AWS Lambda, and a ton of other options with HTTP APIs are options for recieving data.

Ubidots

Ubidots offers a free STEM offering which makes for a nice development dashboard.

Burning fingers (aka soldering)

wiring on the Feature doubler

Todo