Skip to content

Commit

Permalink
Merge pull request #153 from EnviroDIY/calcVar
Browse files Browse the repository at this point in the history
Implemented real calculated variables.
Also fix to Sonar results instability due to buffer not being cleared.
aufdenkampe authored Sep 6, 2018
2 parents 67955c4 + 6892a0f commit 9e8100e
Showing 88 changed files with 2,113 additions and 1,736 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -31,7 +31,6 @@ install:
- git rm library.json
- pip install -U platformio
- pio upgrade
- pio update
- pio lib -g install 2079 # DS3231
- pio lib -g install 311 # EnableInterrupt
- pio lib -g install 322 # SdFat
@@ -53,6 +52,6 @@ install:
- pio lib -g install https://github.com/PaulStoffregen/AltSoftSerial.git # #73, but need the git until Paul S. has a new release
- pio lib -g install https://github.com/EnviroDIY/SoftwaterSerial_ExternalInts.git
# - pio lib -g install https://github.com/todbot/SoftI2CMaster.git
- pio lib -g update
- pio update

script: make travis-build
195 changes: 100 additions & 95 deletions README.md

Large diffs are not rendered by default.

47 changes: 16 additions & 31 deletions examples/DRWI_CitSci/DRWI_CitSci.ino
Original file line number Diff line number Diff line change
@@ -30,27 +30,24 @@ THIS CODE IS PROVIDED "AS IS" - NO WARRANTY IS GIVEN.
#include <LoggerDreamHost.h>

// ==========================================================================
// Basic Logger Settings
// Data Logger Settings
// ==========================================================================
// The name of this file
const char *sketchName = "DWRI_CitSci.ino";

// Logger ID, also becomes the prefix for the name of the data file on SD card
const char *LoggerID = "XXXX";
const char *LoggerID = "XXXXX";
// How frequently (in minutes) to log data
const uint8_t loggingInterval = 5;
// Your logger's timezone.
const int8_t timeZone = -5;
// Create a new logger instance
LoggerDreamHost EnviroDIYLogger;


// ==========================================================================
// Primary Arduino-Based Board and Processor
// ==========================================================================
#include <ProcessorStats.h>

const long serialBaud = 57600; // Baud rate for the primary serial port for debugging
const long serialBaud = 115200; // Baud rate for the primary serial port for debugging
const int8_t greenLED = 8; // Pin for the green LED (-1 if unconnected)
const int8_t redLED = 9; // Pin for the red LED (-1 if unconnected)
const int8_t buttonPin = 21; // Pin for a button to use to enter debugging mode (-1 if unconnected)
@@ -59,7 +56,7 @@ const int8_t wakePin = A7; // Interrupt/Alarm pin to wake from sleep
// In a SAMD system where you are using the built-in rtc, set wakePin to 1
const int8_t sdCardPin = 12; // SD Card Chip Select/Slave Select Pin (must be defined!)

// Create the processor "sensor"
// Create and return the processor "sensor"
const char *MFVersion = "v0.5b";
ProcessorStats mayfly(MFVersion) ;

@@ -125,6 +122,8 @@ DecagonCTD ctd(*CTDSDI12address, SDI12Power, SDI12Data, CTDnumberReadings);
// ==========================================================================
// The array that contains all variables to be logged
// ==========================================================================
// Create pointers for all of the variables from the sensors
// at the same time putting them into an array
Variable *variableList[] = {
new ProcessorStats_Batt(&mayfly, "12345678-abcd-1234-efgh-1234567890ab"),
new MaximDS3231_Temp(&ds3231, "12345678-abcd-1234-efgh-1234567890ab"),
@@ -136,7 +135,12 @@ Variable *variableList[] = {
new Modem_RSSI(&modem, "12345678-abcd-1234-efgh-1234567890ab"),
new Modem_SignalPercent(&modem, "12345678-abcd-1234-efgh-1234567890ab"),
};
// Count up the number of pointers in the array
int variableCount = sizeof(variableList) / sizeof(variableList[0]);
// Create the VariableArray object
VariableArray varArray(variableCount, variableList);
// Create a new logger instance
LoggerDreamHost EnviroDIYLogger(LoggerID, loggingInterval, sdCardPin, wakePin, &varArray);


// ==========================================================================
@@ -195,18 +199,15 @@ void setup()
// Offset is the same as the time zone because the RTC is in UTC
Logger::setTZOffset(timeZone);

// Initialize the logger
EnviroDIYLogger.init(sdCardPin, wakePin, variableCount, variableList,
loggingInterval, LoggerID);
EnviroDIYLogger.setAlertPin(greenLED);

// Setup the logger modem
modem.setupModem(&ModemSerial, modemVCCPin, modemStatusPin, modemSleepRqPin, ModemSleepMode, apn);

// Attach the modem to the logger
EnviroDIYLogger.attachModem(&modem);
// Attach the modem and information pins to the logger
EnviroDIYLogger.attachModem(modem);
EnviroDIYLogger.setAlertPin(greenLED);
EnviroDIYLogger.setTestingModePin(buttonPin);

// Set up the connection with EnviroDIY
// Enter the tokens for the connection with EnviroDIY
EnviroDIYLogger.setToken(registrationToken);
EnviroDIYLogger.setSamplingFeatureUUID(samplingFeature);

@@ -215,22 +216,6 @@ void setup()

// Begin the logger
EnviroDIYLogger.begin();

// Hold up for 10-seconds to allow immediate entry into sensor testing mode
// EnviroDIYLogger.checkForTestingMode(buttonPin);

// Set up an interrupt on a pin to enter sensor testing mode at any time
pinMode(buttonPin, INPUT_PULLUP);
enableInterrupt(buttonPin, Logger::testingISR, CHANGE);
Serial.print(F("Push button on pin "));
Serial.print(buttonPin);
Serial.println(F(" at any time to enter sensor testing mode."));

// Blink the LEDs really fast to show start-up is done
greenredflash(6, 25);

// Sleep
EnviroDIYLogger.systemSleep();
}


2 changes: 1 addition & 1 deletion examples/DRWI_CitSci/platformio.ini
Original file line number Diff line number Diff line change
@@ -18,6 +18,6 @@ framework = arduino
lib_ldf_mode = deep
lib_ignore = RTCZero
lib_deps =
EnviroDIY_ModularSensors@>=0.11.6
EnviroDIY_ModularSensors@>=0.12.2
https://github.com/PaulStoffregen/AltSoftSerial.git
https://github.com/EnviroDIY/SoftwaterSerial_ExternalInts.git
61 changes: 28 additions & 33 deletions examples/DRWI_NoCellular/DRWI_NoCellular.ino
Original file line number Diff line number Diff line change
@@ -21,28 +21,26 @@ THIS CODE IS PROVIDED "AS IS" - NO WARRANTY IS GIVEN.
#include <EnableInterrupt.h> // for external and pin change interrupts
#include <LoggerBase.h>


// ==========================================================================
// Basic Logger Settings
// Data Logger Settings
// ==========================================================================
// The name of this file
const char *sketchName = "DRWI_NoCellular.ino";

// Logger ID, also becomes the prefix for the name of the data file on SD card
const char *LoggerID = "XXXX";
const char *LoggerID = "XXXXX";
// How frequently (in minutes) to log data
const uint8_t loggingInterval = 5;
// Your logger's timezone.
const int8_t timeZone = -5;
// Create a new logger instance
Logger logger;


// ==========================================================================
// Primary Arduino-Based Board and Processor
// ==========================================================================
#include <ProcessorStats.h>

const long serialBaud = 57600; // Baud rate for the primary serial port for debugging
const long serialBaud = 115200; // Baud rate for the primary serial port for debugging
const int8_t greenLED = 8; // Pin for the green LED (-1 if unconnected)
const int8_t redLED = 9; // Pin for the red LED (-1 if unconnected)
const int8_t buttonPin = 21; // Pin for a button to use to enter debugging mode (-1 if unconnected)
@@ -51,7 +49,7 @@ const int8_t wakePin = A7; // Interrupt/Alarm pin to wake from sleep
// In a SAMD system where you are using the built-in rtc, set wakePin to 1
const int8_t sdCardPin = 12; // SD Card Chip Select/Slave Select Pin (must be defined!)

// Create the processor "sensor"
// Create and return the processor "sensor"
const char *MFVersion = "v0.5b";
ProcessorStats mayfly(MFVersion) ;

@@ -102,16 +100,30 @@ DecagonCTD ctd(*CTDSDI12address, SDI12Power, SDI12Data, CTDnumberReadings);
// ==========================================================================
// The array that contains all variables to be logged
// ==========================================================================
// Create pointers for all of the variables from the sensors
// at the same time putting them into an array
Variable *variableList[] = {
new ProcessorStats_Batt(&mayfly),
new MaximDS3231_Temp(&ds3231),
new DecagonCTD_Cond(&ctd),
new DecagonCTD_Temp(&ctd),
new DecagonCTD_Depth(&ctd),
new CampbellOBS3_Turbidity(&osb3low, "", "TurbLow"),
new CampbellOBS3_Turbidity(&osb3high, "", "TurbHigh"),
new ProcessorStats_Batt(&mayfly, "12345678-abcd-1234-efgh-1234567890ab"),
new MaximDS3231_Temp(&ds3231, "12345678-abcd-1234-efgh-1234567890ab"),
new DecagonCTD_Cond(&ctd, "12345678-abcd-1234-efgh-1234567890ab"),
new DecagonCTD_Temp(&ctd, "12345678-abcd-1234-efgh-1234567890ab"),
new DecagonCTD_Depth(&ctd, "12345678-abcd-1234-efgh-1234567890ab"),
new CampbellOBS3_Turbidity(&osb3low, "12345678-abcd-1234-efgh-1234567890ab", "TurbLow"),
new CampbellOBS3_Turbidity(&osb3high, "12345678-abcd-1234-efgh-1234567890ab", "TurbHigh")
};
// Count up the number of pointers in the array
int variableCount = sizeof(variableList) / sizeof(variableList[0]);
// Create the VariableArray object
VariableArray varArray(variableCount, variableList);
// Create a new logger instance
Logger logger(LoggerID, loggingInterval, sdCardPin, wakePin, &varArray);

// ==========================================================================
// Device registration and sampling feature information
// This should be obtained after registration at http://data.envirodiy.org
// ==========================================================================
const char *registrationToken = "12345678-abcd-1234-efgh-1234567890ab"; // Device registration token
const char *samplingFeature = "12345678-abcd-1234-efgh-1234567890ab"; // Sampling feature UUID


// ==========================================================================
@@ -159,29 +171,12 @@ void setup()
// Offset is the same as the time zone because the RTC is in UTC
Logger::setTZOffset(timeZone);

// Initialize the logger
logger.init(sdCardPin, wakePin, variableCount, variableList,
loggingInterval, LoggerID);
// Set pins for alerts and entering testing mode
logger.setAlertPin(greenLED);
logger.setTestingModePin(buttonPin);

// Begin the logger
logger.begin();

// Hold up for 10-seconds to allow immediate entry into sensor testing mode
// EnviroDIYLogger.checkForTestingMode(buttonPin);

// Set up an interrupt on a pin to enter sensor testing mode at any time
pinMode(buttonPin, INPUT_PULLUP);
enableInterrupt(buttonPin, Logger::testingISR, CHANGE);
Serial.print(F("Push button on pin "));
Serial.print(buttonPin);
Serial.println(F(" at any time to enter sensor testing mode."));

// Blink the LEDs really fast to show start-up is done
greenredflash(6, 25);

// Sleep
EnviroDIYLogger.systemSleep();
}


2 changes: 1 addition & 1 deletion examples/DRWI_NoCellular/platformio.ini
Original file line number Diff line number Diff line change
@@ -18,6 +18,6 @@ framework = arduino
lib_ldf_mode = deep
lib_ignore = RTCZero
lib_deps =
EnviroDIY_ModularSensors@>=0.11.6
EnviroDIY_ModularSensors@>=0.12.2
https://github.com/PaulStoffregen/AltSoftSerial.git
https://github.com/EnviroDIY/SoftwaterSerial_ExternalInts.git
8 changes: 4 additions & 4 deletions examples/ReadMe.md
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ To adjust any of these to work with your own sensor arrangements:
14. Program your board!

### single_sensor.ino
This shows making use of the unified set of commands to print data from a MaxBotix ultrasonic range finder to the serial port.
This shows making use of the unified set of commands to print data from a MaxBotix ultrasonic range finder to the serial port. It also shows creating a calculated variable which is the water depth.

### multisensor_print.ino
This shows using an array of sensors to easily update all of them and print all results to the serial port. This example calls on at least one of every single sensor available in this library.
@@ -39,11 +39,11 @@ This is a simplified version of logging_to_EnviroDIY.ino using just the sensors
### DWRI_NoCellular.ino
This is uses just the sensors and equipment standard to the DWRI Citizen Science grant for circumstances where there is no cellular signal.

### baro_rho_correction.ino
This example demonstrates how to work with calculated variables.

### double_logger.ino
This is a more complicated example using two different logger instances to log data at two different intervals, in this case, an AM3215 logging every minute, while checking the battery voltage only every 5 minutes. This showcases both how to use two different logging instances and how to use some of the functions to set up your own logging loop rather than using the log() function.

### baro_rho_correction.ino
Like the double_logger example, this showcases how to set up your own logging loop rather than using the log() function. In this case, though, there is only a single logger, but we are adding some extra calculated variables to the final output.

### data_saving.ino
This is another double logger example, but in this case, both loggers are going at the same interval and the only difference between the loggers is the list of variables. There are two sets of variables, all coming from Yosemitech sensors. Because each sensor outputs temperature and we don't want to waste cellular data sending out multiple nearly identical temperature values, we have one logger that logs every possible variable result to the SD card and another logger that sends only unique results to the EnviroDIY data portal.
2 changes: 1 addition & 1 deletion examples/baro_rho_correction/ReadMe.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Example using the Modular Sensors Library to Calculate Results based on Measured Values and Send Both Measured and Calculated Values to the EnviroDIY Data Portal

Like the double_logger example, this showcases how to set up your own logging loop rather than using the log() function. In this case, though, there is only a single logger, but we are adding some extra calculated variables to the final output.
This example demonstrates how to work with calculated variables.
Loading

0 comments on commit 9e8100e

Please sign in to comment.