Skip to content

Commit

Permalink
Merge pull request #256 from EnviroDIY/develop
Browse files Browse the repository at this point in the history
Merge Develop to Release 0.22.5
  • Loading branch information
SRGDamia1 authored Jun 24, 2019
2 parents 9b58c42 + 9c87c2e commit cde7e66
Show file tree
Hide file tree
Showing 112 changed files with 4,626 additions and 2,849 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ Temporary Items
.pio
.pioenvs
.piolibdeps
.pio
.pio/libdeps
.pio/build
.pio/*
.clang_complete
.gcc-flags.json
lib/readme.txt
Expand Down
Binary file not shown.
123 changes: 42 additions & 81 deletions examples/DRWI_CitSci/DRWI_CitSci.ino
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Software License: BSD-3.
Copyright (c) 2017, Stroud Water Research Center (SWRC)
and the EnviroDIY Development Team
This example sketch is written for ModularSensors library version 0.21.4
This example sketch is written for ModularSensors library version 0.22.5
This sketch is an example of logging data to an SD card and sending the data to
both the EnviroDIY data portal as should be used by groups involved with
Expand All @@ -28,7 +28,7 @@ THIS CODE IS PROVIDED "AS IS" - NO WARRANTY IS GIVEN.
// Data Logger Settings
// ==========================================================================
// The library version this example was written for
const char *libraryVersion = "0.21.4";
const char *libraryVersion = "0.22.5";
// 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
Expand Down Expand Up @@ -62,77 +62,31 @@ ProcessorStats mcuBoard(mcuBoardVersion);


// ==========================================================================
// Wifi/Cellular Modem Main Chip Selection
// Wifi/Cellular Modem Settings
// ==========================================================================

#define TINY_GSM_MODEM_SIM800 // Select for a SIM800, SIM900, or variant thereof


// ==========================================================================
// Modem Pins
// ==========================================================================

const int8_t modemVccPin = -2; // MCU pin controlling modem power (-1 if not applicable)
const int8_t modemSleepRqPin = 23; // MCU pin used for modem sleep/wake request (-1 if not applicable)
const int8_t modemStatusPin = 19; // MCU pin used to read modem status (-1 if not applicable)


// ==========================================================================
// TinyGSM Client
// ==========================================================================

#define TINY_GSM_YIELD() { delay(2); } // Use to counter slow (9600) baud rate

// Include TinyGSM for the modem
// This include must be included below the define of the modem name!
#include <TinyGsmClient.h>

// Create a reference to the serial port for the modem
HardwareSerial &modemSerial = Serial1; // Use hardware serial if possible

// Create a new TinyGSM modem to run on that serial port and return a pointer to it
TinyGsm *tinyModem = new TinyGsm(modemSerial);

// Create a TCP client on that modem
TinyGsmClient *tinyClient = new TinyGsmClient(*tinyModem);


// ==========================================================================
// Specific Modem On-Off Methods
// ==========================================================================

// THIS ONLY APPLIES TO A SODAQ GPRSBEE R6!!!
// Describe the physical pin connection of your modem to your board
const long modemBaud = 9600; // Communication speed of the modem
const bool modemStatusLevel = HIGH; // The level of the status pin when the module is active (HIGH or LOW)

// Create the wake and sleep methods for the modem
// These can be functions of any type and must return a boolean
bool modemWakeFxn(void)
{
digitalWrite(modemSleepRqPin, HIGH);
digitalWrite(redLED, HIGH); // A light just for show
return true;
}
bool modemSleepFxn(void)
{
digitalWrite(modemSleepRqPin, LOW);
digitalWrite(redLED, LOW);
return true;
}
void extraModemSetup(void){}
// ==========================================================================
// Network Information and LoggerModem Object
// ==========================================================================
#include <LoggerModem.h>
// Modem Pins - Describe the physical pin connection of your modem to your board
const int8_t modemVccPin = -2; // MCU pin controlling modem power (-1 if not applicable)
const int8_t modemStatusPin = 19; // MCU pin used to read modem status (-1 if not applicable)
const int8_t modemSleepRqPin = 23; // MCU pin used for modem sleep/wake request (-1 if not applicable)
const int8_t modemLEDPin = redLED; // MCU pin connected an LED to show modem status (-1 if unconnected)

// Network connection information
const char *apn = "hologram"; // The APN for the gprs connection, unnecessary for WiFi
const char *apn = "hologram"; // The APN for the gprs connection

// Create the loggerModem instance
// A "loggerModem" is a combination of a TinyGSM Modem, a Client, and functions for wake and sleep
loggerModem modem(modemVccPin, modemStatusPin, modemStatusLevel, modemWakeFxn, modemSleepFxn, tinyModem, tinyClient, apn);
// ^^ Use this for cellular
// For the Sodaq 2GBee R6 and R7 based on the SIMCom SIM800
// NOTE: The Sodaq GPRSBee doesn't expose the SIM800's reset pin
#include <modems/Sodaq2GBeeR6.h>
const long modemBaud = 9600; // SIM800 does auto-bauding by default
Sodaq2GBeeR6 modem2GB(&modemSerial,
modemVccPin, modemStatusPin,
modemSleepRqPin,
apn);
// Create an extra reference to the modem by a generic name (not necessary)
Sodaq2GBeeR6 modem = modem2GB;


// ==========================================================================
Expand All @@ -145,12 +99,12 @@ MaximDS3231 ds3231(1);


// ==========================================================================
// CAMPBELL OBS 3 / OBS 3+ Analog Turbidity Sensor
// Campbell OBS 3 / OBS 3+ Analog Turbidity Sensor
// ==========================================================================
#include <sensors/CampbellOBS3.h>

const int8_t OBS3Power = sensorPowerPin; // Pin to switch power on and off (-1 if unconnected)
const uint8_t OBS3numberReadings = 10;
const uint8_t OBS3NumberReadings = 10;
const uint8_t ADSi2c_addr = 0x48; // The I2C address of the ADS1115 ADC
// Campbell OBS 3+ Low Range calibration in Volts
const int8_t OBSLowADSChannel = 0; // The ADS channel for the low range output
Expand All @@ -159,7 +113,7 @@ const float OBSLow_B = 1.000E+00; // The "B" value (X) from the low range calib
const float OBSLow_C = 0.000E+00; // The "C" value from the low range calibration

// Create a Campbell OBS3+ LOW RANGE sensor object
CampbellOBS3 osb3low(OBS3Power, OBSLowADSChannel, OBSLow_A, OBSLow_B, OBSLow_C, ADSi2c_addr, OBS3numberReadings);
CampbellOBS3 osb3low(OBS3Power, OBSLowADSChannel, OBSLow_A, OBSLow_B, OBSLow_C, ADSi2c_addr, OBS3NumberReadings);


// Campbell OBS 3+ High Range calibration in Volts
Expand All @@ -169,7 +123,7 @@ const float OBSHigh_B = 1.000E+00; // The "B" value (X) from the high range cal
const float OBSHigh_C = 0.000E+00; // The "C" value from the high range calibration

// Create a Campbell OBS3+ HIGH RANGE sensor object
CampbellOBS3 osb3high(OBS3Power, OBSHighADSChannel, OBSHigh_A, OBSHigh_B, OBSHigh_C, ADSi2c_addr, OBS3numberReadings);
CampbellOBS3 osb3high(OBS3Power, OBSHighADSChannel, OBSHigh_A, OBSHigh_B, OBSHigh_C, ADSi2c_addr, OBS3NumberReadings);


// ==========================================================================
Expand All @@ -178,12 +132,12 @@ CampbellOBS3 osb3high(OBS3Power, OBSHighADSChannel, OBSHigh_A, OBSHigh_B, OBSHig
#include <sensors/DecagonCTD.h>

const char *CTDSDI12address = "1"; // The SDI-12 Address of the CTD
const uint8_t CTDnumberReadings = 6; // The number of readings to average
const uint8_t CTDNumberReadings = 6; // The number of readings to average
const int8_t SDI12Power = sensorPowerPin; // Pin to switch power on and off (-1 if unconnected)
const int8_t SDI12Data = 7; // The SDI12 data pin

// Create a Decagon CTD sensor object
DecagonCTD ctd(*CTDSDI12address, SDI12Power, SDI12Data, CTDnumberReadings);
DecagonCTD ctd(*CTDSDI12address, SDI12Power, SDI12Data, CTDNumberReadings);


// ==========================================================================
Expand All @@ -197,7 +151,7 @@ Variable *variableList[] = {
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"),
new ProcessorStats_Batt(&mcuBoard, "12345678-abcd-1234-efgh-1234567890ab"),
new ProcessorStats_Battery(&mcuBoard, "12345678-abcd-1234-efgh-1234567890ab"),
new MaximDS3231_Temp(&ds3231, "12345678-abcd-1234-efgh-1234567890ab"),
new Modem_RSSI(&modem, "12345678-abcd-1234-efgh-1234567890ab"),
new Modem_SignalPercent(&modem, "12345678-abcd-1234-efgh-1234567890ab"),
Expand Down Expand Up @@ -228,7 +182,7 @@ const char *samplingFeature = "12345678-abcd-1234-efgh-1234567890ab"; // Sam

// Create a data publisher for the EnviroDIY/WikiWatershed POST endpoint
#include <publishers/EnviroDIYPublisher.h>
EnviroDIYPublisher EnviroDIYPOST(dataLogger, registrationToken, samplingFeature);
EnviroDIYPublisher EnviroDIYPOST(dataLogger, &modem.gsmClient, registrationToken, samplingFeature);


// ==========================================================================
Expand Down Expand Up @@ -311,15 +265,16 @@ void setup()
digitalWrite(modemSleepRqPin, LOW);
}

// Set the timezone and offsets
// Set the timezones for the logger/data and the RTC
// Logging in the given time zone
Logger::setTimeZone(timeZone);
// Offset is the same as the time zone because the RTC is in UTC
Logger::setTZOffset(timeZone);
Logger::setLoggerTimeZone(timeZone);
// It is STRONGLY RECOMMENDED that you set the RTC to be in UTC (UTC+0)
Logger::setRTCTimeZone(0);

// Attach the modem and information pins to the logger
dataLogger.attachModem(modem);
dataLogger.setLoggerPins(wakePin, sdCardSSPin, sensorPowerPin, buttonPin, greenLED);
modem.setModemLED(modemLEDPin);
dataLogger.setLoggerPins(wakePin, sdCardSSPin, sdCardPwrPin, buttonPin, greenLED);

// Begin the logger
dataLogger.begin();
Expand All @@ -330,19 +285,24 @@ void setup()
{
modem.modemPowerUp();
modem.wake();
modem.setup();

// At very good battery voltage, or with suspicious time stamp, sync the clock
// Note: Please change these battery voltages to match your battery
if (getBatteryVoltage() > 3.8 ||
dataLogger.getNowEpoch() < 1546300800 || /*Before 01/01/2019*/
dataLogger.getNowEpoch() > 1735689600) /*Before 1/1/2025*/
dataLogger.getNowEpoch() > 1735689600) /*After 1/1/2025*/
{
// Synchronize the RTC with NIST
Serial.println(F("Attempting to synchronize RTC with NIST"));
Serial.println(F("Attempting to connect to the internet and synchronize RTC with NIST"));
if (modem.connectInternet(120000L))
{
dataLogger.setRTClock(modem.getNISTTime());
}
else
{
Serial.println(F("Could not connect to internet for clock sync."));
}
}
}

Expand All @@ -369,6 +329,7 @@ void setup()
}

// Call the processor sleep
Serial.println(F("Putting processor to sleep"));
dataLogger.systemSleep();
}

Expand All @@ -394,6 +355,6 @@ void loop()
// If the battery is good, send the data to the world
else
{
dataLogger.logDataAndSend();
dataLogger.logDataAndPublish();
}
}
4 changes: 2 additions & 2 deletions examples/DRWI_CitSci/ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ CampbellOBS3 osb3high(OBS3Power, OBSHighADSChannel, OBSHigh_A, OBSHigh_B, OBSHig
- Change _**all**_ of the the ```"12345678-abcd-1234-efgh-1234567890ab"``` values in this section of code to the values shown on the EnviroDIY data portal for your variables.
- After you register your site and variables, you should see a group of empty plots on the page for your site. The plots have titles like "Temperature" and below the plot will be a list of the "Medium", "Sensor", and "UUID" for that variable.
- Copy the appropriate UUID from below each plot to its proper place in this section of the code.
- For example, the ```"12345678-abcd-1234-efgh-1234567890ab"``` in the first line (```new ProcessorStats_Batt(&mcuBoard, "12345678-abcd-1234-efgh-1234567890ab")```) should be replaced by the UUID listed under the plot titled "Battery Voltage" with the sensor listed below as "EnviroDIY_Mayfly Data Logger".
- For example, the ```"12345678-abcd-1234-efgh-1234567890ab"``` in the first line (```new ProcessorStats_Battery(&mcuBoard, "12345678-abcd-1234-efgh-1234567890ab")```) should be replaced by the UUID listed under the plot titled "Battery Voltage" with the sensor listed below as "EnviroDIY_Mayfly Data Logger".
```cpp
// ==========================================================================
// Creating the Variable Array[s] and Filling with Variable Objects
// ==========================================================================
Variable *variableList[] = {
new ProcessorStats_Batt(&mcuBoard, "12345678-abcd-1234-efgh-1234567890ab"),
new ProcessorStats_Battery(&mcuBoard, "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"),
Expand Down
Loading

0 comments on commit cde7e66

Please sign in to comment.