A multifunctional and modular Firmware for Multitech's mDot based on ARM mBed provides a widerange of functionality for several Sensors such as MAX44009, BME280, MPU9250, SI1143 and uBlox. It allows you to quickly build a Sensornode that measures specific data with its sensors and sends it via LoRaWAN.

Dependencies:   mDot_LoRa_Sensornode_Flowmeter_impl mbed-rtos mbed

LoRa-Sensornode Firmware for Multitech mDot

A multifunctional and modular Firmware for Multitech's mDot which provides a widerange of functionality for several Sensors. It allows you to quickly build a Sensornode that measures specific data with its sensors and sends it via LoRaWAN.

/media/uploads/mitea1/logo-lora-600x370.png /media/uploads/mitea1/mt_mdot_family_642px.png

Supported Sensors

Idea

The Firmware has some predefined Application Modes running different Tasks(Measurements). Each mode can be used in a different Scenario. Application_Modes define which sensors are used, how often they aquire data and how often the data has to be sent via LoRa. Lets say you just want to measure the Light then you choose an Application_Mode (or define one) that only runs TaskLight for light measurement. As a standard all measurements are taken every second and sent via LoRa but you can change that interval depending on your usage Scenario

Committer:
mitea1
Date:
Fri Nov 02 17:01:02 2018 +0000
Revision:
10:4051c38bf73f
Parent:
9:c4e378f4801d
wtf

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mitea1 9:c4e378f4801d 1 /*
mitea1 9:c4e378f4801d 2 * FlowMeter.h
mitea1 9:c4e378f4801d 3 *
mitea1 9:c4e378f4801d 4 * Created on: 23.10.2018
mitea1 9:c4e378f4801d 5 * Author: Adrian
mitea1 9:c4e378f4801d 6 */
mitea1 9:c4e378f4801d 7
mitea1 9:c4e378f4801d 8 #ifndef DRIVERS_FLOWMETER_H_
mitea1 9:c4e378f4801d 9 #define DRIVERS_FLOWMETER_H_
mitea1 9:c4e378f4801d 10 #include "InterruptIn.h"
mitea1 9:c4e378f4801d 11 #include "Ticker.h"
mitea1 9:c4e378f4801d 12 #include "mbed.h"
mitea1 9:c4e378f4801d 13 /**
mitea1 9:c4e378f4801d 14 * FlowSensorProperties
mitea1 9:c4e378f4801d 15 *
mitea1 9:c4e378f4801d 16 * Structure that holds essential information about a flow sensor.
mitea1 9:c4e378f4801d 17 * Stores general sensor properties and calibration points.
mitea1 9:c4e378f4801d 18 *
mitea1 9:c4e378f4801d 19 * See file G34_Flow_rate_to_frequency.jpg for reference.
mitea1 9:c4e378f4801d 20 */
mitea1 9:c4e378f4801d 21 typedef struct {
mitea1 9:c4e378f4801d 22 double capacity; //!< capacity, upper limit of flow rate (in l/min)
mitea1 9:c4e378f4801d 23 double kFactor; //!< "k-factor" (in (pulses/s) / (l/min)), e.g.: 1 pulse/s = kFactor * l/min
mitea1 9:c4e378f4801d 24 double mFactor[10]; //!< multiplicative correction factor near unity, "meter factor" (per decile of flow)
mitea1 9:c4e378f4801d 25 } FlowSensorProperties;
mitea1 9:c4e378f4801d 26
mitea1 9:c4e378f4801d 27 extern FlowSensorProperties UncalibratedSensor; //!< default sensor
mitea1 9:c4e378f4801d 28 extern FlowSensorProperties FS300A; //!< see documentation about FS300A/SEN02141B
mitea1 9:c4e378f4801d 29 extern FlowSensorProperties FS400A; //!< see documentation about FS400A/USN-HS10TA
mitea1 9:c4e378f4801d 30
mitea1 9:c4e378f4801d 31 /**
mitea1 9:c4e378f4801d 32 * FlowMeter
mitea1 9:c4e378f4801d 33 */
mitea1 9:c4e378f4801d 34 class FlowMeter {
mitea1 9:c4e378f4801d 35 public:
mitea1 9:c4e378f4801d 36 /**
mitea1 9:c4e378f4801d 37 * Initializes a new flow meter object.
mitea1 9:c4e378f4801d 38 *
mitea1 9:c4e378f4801d 39 * @param pin The pin that the flow sensor is connected to (has to be interrupt capable, default: INT0).
mitea1 9:c4e378f4801d 40 * @param prop The properties of the actual flow sensor being used (default: UncalibratedSensor).
mitea1 9:c4e378f4801d 41 */
mitea1 9:c4e378f4801d 42 FlowMeter(InterruptIn* pin, FlowSensorProperties prop = UncalibratedSensor);
mitea1 9:c4e378f4801d 43
mitea1 9:c4e378f4801d 44 double getCurrentFlowrate(); //!< Returns the current flow rate since last reset (in l/min).
mitea1 9:c4e378f4801d 45 double getCurrentVolume(); //!< Returns the current volume since last reset (in l).
mitea1 9:c4e378f4801d 46
mitea1 9:c4e378f4801d 47 double getTotalFlowrate(); //!< Returns the (linear) average flow rate in this flow meter instance (in l/min).
mitea1 9:c4e378f4801d 48 double getTotalVolume(); //!< Returns the total volume flown trough this flow meter instance (in l).
mitea1 9:c4e378f4801d 49
mitea1 9:c4e378f4801d 50 /**
mitea1 9:c4e378f4801d 51 * The tick method updates all internal calculations at the end of a measurement period.
mitea1 9:c4e378f4801d 52 *
mitea1 9:c4e378f4801d 53 * We're calculating flow and volume data over time.
mitea1 9:c4e378f4801d 54 * The actual pulses have to be sampled using the count method (i.e. via an interrupt service routine).
mitea1 9:c4e378f4801d 55 *
mitea1 9:c4e378f4801d 56 * Flow sensor formulae:
mitea1 9:c4e378f4801d 57 *
mitea1 9:c4e378f4801d 58 * Let K: pulses per second per unit of measure (i.e. (1/s)/(l/min)),
mitea1 9:c4e378f4801d 59 * f: pulse frequency (1/s),
mitea1 9:c4e378f4801d 60 * Q: flow rate (l/min),
mitea1 9:c4e378f4801d 61 * p: sensor pulses (no dimension/unit),
mitea1 9:c4e378f4801d 62 * t: time since last measurements (s).
mitea1 9:c4e378f4801d 63 *
mitea1 9:c4e378f4801d 64 * K = f / Q | units: (1/s) / (l/min) = (1/s) / (l/min)
mitea1 9:c4e378f4801d 65 * <=> | Substitute p / t for f in order to allow for different measurement intervals
mitea1 9:c4e378f4801d 66 * K = (p / t) / Q | units: ((1/s)/(l/min)) = (1/s) / (l/min)
mitea1 9:c4e378f4801d 67 * <=> | Solve for Q:
mitea1 9:c4e378f4801d 68 * Q = (p / t) / K | untis: l/min = 1/s / (1/s / (l/min))
mitea1 9:c4e378f4801d 69 * <=> | Volume in l:
mitea1 9:c4e378f4801d 70 * V = Q / 60 | units: l = (l/min) / (min)
mitea1 9:c4e378f4801d 71 *
mitea1 9:c4e378f4801d 72 * The property K is sometimes stated in pulses per liter or pulses per gallon.
mitea1 9:c4e378f4801d 73 * In these cases the unit of measure has to be converted accordingly (e.g. from gal/s to l/min).
mitea1 9:c4e378f4801d 74 * See file G34_Flow_rate_to_frequency.jpg for reference.
mitea1 9:c4e378f4801d 75 *
mitea1 9:c4e378f4801d 76 * @param duration The tick duration (in ms).
mitea1 9:c4e378f4801d 77 */
mitea1 9:c4e378f4801d 78 void tick();
mitea1 9:c4e378f4801d 79 void count(void); //!< Increments the internal pulse counter. Serves as an interrupt callback routine.
mitea1 9:c4e378f4801d 80 void reset(); //!< Prepares the flow meter for a fresh measurement. Resets all current values, but not the totals.
mitea1 9:c4e378f4801d 81
mitea1 9:c4e378f4801d 82 /*
mitea1 9:c4e378f4801d 83 * setters enabling continued metering across power cycles
mitea1 9:c4e378f4801d 84 */
mitea1 9:c4e378f4801d 85 FlowMeter* setTotalDuration(unsigned long totalDuration); //!< Sets the total (overall) duration (i.e. after power up).
mitea1 9:c4e378f4801d 86 FlowMeter* setTotalVolume(double totalVolume); //!< Sets the total (overall) volume (i.e. after power up).
mitea1 9:c4e378f4801d 87 FlowMeter* setTotalCorrection(double totalCorrection); //!< Sets the total (overall) correction factor (i.e. after power up).
mitea1 9:c4e378f4801d 88
mitea1 9:c4e378f4801d 89 /*
mitea1 9:c4e378f4801d 90 * convenience methods and calibration helpers
mitea1 9:c4e378f4801d 91 */
mitea1 9:c4e378f4801d 92 InterruptIn* getPin(); //!< Returns the Arduino pin number that the flow sensor is connected to.
mitea1 9:c4e378f4801d 93
mitea1 9:c4e378f4801d 94 unsigned long getCurrentDuration(); //!< Returns the duration of the current tick (in ms).
mitea1 9:c4e378f4801d 95 double getCurrentFrequency(); //!< Returns the pulse rate in the current tick (in 1/s).
mitea1 9:c4e378f4801d 96 double getCurrentError(); //!< Returns the error resulting from the current measurement (in %).
mitea1 9:c4e378f4801d 97
mitea1 9:c4e378f4801d 98 unsigned long getTotalDuration(); //!< Returns the total run time of this flow meter instance (in ms).
mitea1 9:c4e378f4801d 99 double getTotalError(); //!< Returns the (linear) average error of this flow meter instance (in %).
mitea1 9:c4e378f4801d 100
mitea1 9:c4e378f4801d 101 protected:
mitea1 9:c4e378f4801d 102 InterruptIn* pulseInput;
mitea1 9:c4e378f4801d 103 Ticker* ticker;
mitea1 9:c4e378f4801d 104 unsigned long tickDuration_ms;
mitea1 9:c4e378f4801d 105 //unsigned int _pin; //!< connection pin (has to be interrupt capable!)
mitea1 9:c4e378f4801d 106 FlowSensorProperties _properties; //!< sensor properties (including calibration data)
mitea1 9:c4e378f4801d 107
mitea1 9:c4e378f4801d 108 unsigned long _currentDuration; //!< current tick duration (convenience, in ms)
mitea1 9:c4e378f4801d 109 double _currentFrequency; //!< current pulses per second (convenience, in 1/s)
mitea1 9:c4e378f4801d 110 double _currentFlowrate; //!< current flow rate (in l/tick), e.g.: 1 l / min = 1 pulse / s / (pulses / s / l / min)
mitea1 9:c4e378f4801d 111 double _currentVolume; //!< current volume (in l), e.g.: 1 l = 1 (l / min) / (60 * s)
mitea1 9:c4e378f4801d 112 double _currentCorrection; //!< currently applied correction factor
mitea1 9:c4e378f4801d 113
mitea1 9:c4e378f4801d 114 unsigned long _totalDuration; //!< total measured duration since begin of measurement (in ms)
mitea1 9:c4e378f4801d 115 double _totalVolume; //!< total volume since begin of measurement (in l)
mitea1 9:c4e378f4801d 116 double _totalCorrection; //!< accumulated correction factors
mitea1 9:c4e378f4801d 117
mitea1 9:c4e378f4801d 118 volatile unsigned long _currentPulses; //!< pulses within current sample period
mitea1 9:c4e378f4801d 119 };
mitea1 9:c4e378f4801d 120
mitea1 9:c4e378f4801d 121 /**
mitea1 9:c4e378f4801d 122 * FlowSensorCalibration
mitea1 9:c4e378f4801d 123 *
mitea1 9:c4e378f4801d 124 * Convenience class for manipulating sensor properties.
mitea1 9:c4e378f4801d 125 */
mitea1 9:c4e378f4801d 126 class FlowSensorCalibration {
mitea1 9:c4e378f4801d 127 public:
mitea1 9:c4e378f4801d 128 FlowSensorCalibration() {};
mitea1 9:c4e378f4801d 129 FlowSensorCalibration(FlowSensorProperties properties): _properties(properties) {};
mitea1 9:c4e378f4801d 130
mitea1 9:c4e378f4801d 131 FlowSensorCalibration* setProperties(FlowSensorProperties properties) {
mitea1 9:c4e378f4801d 132 this->_properties = properties;
mitea1 9:c4e378f4801d 133 return this;
mitea1 9:c4e378f4801d 134 };
mitea1 9:c4e378f4801d 135
mitea1 9:c4e378f4801d 136 FlowSensorCalibration* setCapacity(double capacity) {
mitea1 9:c4e378f4801d 137 this->_properties.capacity = capacity;
mitea1 9:c4e378f4801d 138 return this;
mitea1 9:c4e378f4801d 139 }
mitea1 9:c4e378f4801d 140
mitea1 9:c4e378f4801d 141 FlowSensorCalibration* setKFactor(double kFactor) {
mitea1 9:c4e378f4801d 142 this->_properties.kFactor = kFactor;
mitea1 9:c4e378f4801d 143 return this;
mitea1 9:c4e378f4801d 144 }
mitea1 9:c4e378f4801d 145
mitea1 9:c4e378f4801d 146 FlowSensorCalibration* setMeterFactorPerDecile(unsigned int decile, unsigned int mFactor) {
mitea1 9:c4e378f4801d 147 this->_properties.mFactor[decile] = mFactor;
mitea1 9:c4e378f4801d 148 return this;
mitea1 9:c4e378f4801d 149 }
mitea1 9:c4e378f4801d 150
mitea1 9:c4e378f4801d 151 FlowSensorProperties getProperties() {
mitea1 9:c4e378f4801d 152 return this->_properties;
mitea1 9:c4e378f4801d 153 }
mitea1 9:c4e378f4801d 154
mitea1 9:c4e378f4801d 155 double getCapacity() {
mitea1 9:c4e378f4801d 156 return this->_properties.capacity;
mitea1 9:c4e378f4801d 157 }
mitea1 9:c4e378f4801d 158
mitea1 9:c4e378f4801d 159 double getKFactor() {
mitea1 9:c4e378f4801d 160 return this->_properties.kFactor;
mitea1 9:c4e378f4801d 161 }
mitea1 9:c4e378f4801d 162
mitea1 9:c4e378f4801d 163 unsigned int getMeterFactorPerDecile(unsigned int decile) {
mitea1 9:c4e378f4801d 164 return this->_properties.mFactor[decile];
mitea1 9:c4e378f4801d 165 }
mitea1 9:c4e378f4801d 166
mitea1 9:c4e378f4801d 167 protected:
mitea1 9:c4e378f4801d 168 FlowSensorProperties _properties;
mitea1 9:c4e378f4801d 169 };
mitea1 9:c4e378f4801d 170
mitea1 9:c4e378f4801d 171 #endif /* DRIVERS_FLOWMETER_H_ */