Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Radically simplified modems in sketches by making a modem parent class #252

Merged
merged 65 commits into from
May 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
7a5d4c8
Starting to separate out modems
SRGDamia1 May 13, 2019
b938068
v1
SRGDamia1 May 13, 2019
9c3fc1f
Digi bees
SRGDamia1 May 13, 2019
ae0d7f0
Using pre-processor macros
SRGDamia1 May 14, 2019
d8f4d19
Added a bunch of modems
SRGDamia1 May 14, 2019
4c3e554
Setup modem pins in setup
SRGDamia1 May 14, 2019
e051526
Added forgotten esp light sleep pins
SRGDamia1 May 14, 2019
e830e4c
Start updating examples
SRGDamia1 May 14, 2019
da97c18
Some cleaning and debug printing
SRGDamia1 May 15, 2019
59c05af
Whew.. updated examples
SRGDamia1 May 15, 2019
08ca9f1
Renamed processor battery var
SRGDamia1 May 16, 2019
4f14b0d
Removed modemStream internal pointer
SRGDamia1 May 16, 2019
e4c94bb
Renamed modem vars and added modem battery and temp
SRGDamia1 May 16, 2019
819edbb
esp
SRGDamia1 May 16, 2019
dc826d8
Removed client from loggerModem parent class
SRGDamia1 May 16, 2019
d9ed608
shortened macro if, fix xbee pointer
SRGDamia1 May 16, 2019
89b8051
All examples have explicit client
SRGDamia1 May 16, 2019
29e73ad
Rename to make it look more different
SRGDamia1 May 16, 2019
250649b
Never let XBee disconnect, even in bypass
SRGDamia1 May 16, 2019
c6842e6
Moved setup check to startMeasurement instead of wake
SRGDamia1 May 16, 2019
c4e6c8e
Setup/wake cleaning
SRGDamia1 May 16, 2019
b89c686
Oops! Mixed up modem battery
SRGDamia1 May 16, 2019
c9cf5db
Debug print out filenames
SRGDamia1 May 16, 2019
2f03efe
Mark header guard
SRGDamia1 May 16, 2019
11137d1
corrected deep debugging
SRGDamia1 May 16, 2019
325c073
Let the modem decide if its wake and sleep should always be run
SRGDamia1 May 16, 2019
d97caaf
Fix XBee sleep, and added a debug print
SRGDamia1 May 16, 2019
4cffdf6
Fixed redefinition warning
SRGDamia1 May 16, 2019
13b4cb8
Added missing destructors
SRGDamia1 May 21, 2019
81975f8
Changed isMeasurementComplete to verifyMeasurementComplete in modems
SRGDamia1 May 21, 2019
881b3b2
Still hunting missing virtual functions crashing linker
SRGDamia1 May 21, 2019
a743ad1
Still the destructor?
SRGDamia1 May 21, 2019
891ee17
Re-implement modem results
SRGDamia1 May 21, 2019
d4bb1a7
Add additional battery stats from modem
SRGDamia1 May 22, 2019
993dd29
Need to compile the modems folder!
SRGDamia1 May 22, 2019
1b36cbc
Version bump
SRGDamia1 May 22, 2019
ac9f611
Correct modem battery units, flash strings
SRGDamia1 May 22, 2019
9766266
case correction
SRGDamia1 May 22, 2019
72192f2
Missed flash strings
SRGDamia1 May 22, 2019
aec109b
Fixed UBeeR410, update gitignore
SRGDamia1 May 23, 2019
93123e3
Fixed R410 to have right modem defined
SRGDamia1 May 23, 2019
80fa4c7
Slightly longer wait when rebooting to bypass
SRGDamia1 May 23, 2019
4544250
Longer wait to get NIST for XBee
SRGDamia1 May 23, 2019
9bc76d2
One less space, one less byte of data
SRGDamia1 May 23, 2019
cf0520c
Added function for a modem hard reset - TBD when and where to use
SRGDamia1 May 23, 2019
86352ba
Fixed hard reset
SRGDamia1 May 24, 2019
479362f
Remembered to initialize client after modem
SRGDamia1 May 24, 2019
32c36ab
Fix other high low high pulses
SRGDamia1 May 24, 2019
9f7bee7
Fix when to run wake
SRGDamia1 May 24, 2019
2d92f6d
Slightly longer waits for status
SRGDamia1 May 25, 2019
bf667dc
Version bump
SRGDamia1 May 25, 2019
a06ce9f
Missing semicolon
SRGDamia1 May 25, 2019
abf34e6
Force restart XBee
SRGDamia1 May 28, 2019
4d7bd7f
Typo
SRGDamia1 May 28, 2019
82f0c55
SIM800 debug off by default
SRGDamia1 May 29, 2019
33e64d0
Always room for debugging
SRGDamia1 May 29, 2019
d855967
Typo
SRGDamia1 May 29, 2019
ab86974
Very minor example changes
SRGDamia1 May 29, 2019
628fc03
Fixed maxbotix debugging
SRGDamia1 May 29, 2019
7c87f73
Increased AT response time for SIM800, also increase wait padding
SRGDamia1 May 30, 2019
3406478
Missing slash
SRGDamia1 May 30, 2019
c7cf822
Increased buffer on status pin reading
SRGDamia1 May 30, 2019
8e6571b
remove some \n's
SRGDamia1 May 30, 2019
13a646e
Version bump, dependency bump
SRGDamia1 May 30, 2019
efde16c
Status pin check
SRGDamia1 May 30, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ Temporary Items
# Atom / PlatformIO
.pioenvs
.piolibdeps
.pio
.pio/libdeps
.pio/build
.pio/*
.clang_complete
.gcc-flags.json
lib/readme.txt
Expand Down
105 changes: 31 additions & 74 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.2

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.2";
// 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 @@ -319,6 +273,7 @@ void setup()

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

// Begin the logger
Expand All @@ -330,12 +285,13 @@ 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"));
Expand Down Expand Up @@ -369,6 +325,7 @@ void setup()
}

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

Expand Down
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