@@ -7,7 +7,7 @@ Software License: BSD-3.
77 Copyright (c) 2017, Stroud Water Research Center (SWRC)
88 and the EnviroDIY Development Team
99
10- This example sketch is written for ModularSensors library version 0.21.4
10+ This example sketch is written for ModularSensors library version 0.22.5
1111
1212This sketch is an example of logging data to an SD card and sending the data to
1313both the EnviroDIY data portal as should be used by groups involved with
@@ -28,7 +28,7 @@ THIS CODE IS PROVIDED "AS IS" - NO WARRANTY IS GIVEN.
2828// Data Logger Settings
2929// ==========================================================================
3030// The library version this example was written for
31- const char *libraryVersion = " 0.21.4 " ;
31+ const char *libraryVersion = " 0.22.5 " ;
3232// The name of this file
3333const char *sketchName = " DWRI_CitSci.ino" ;
3434// Logger ID, also becomes the prefix for the name of the data file on SD card
@@ -62,77 +62,31 @@ ProcessorStats mcuBoard(mcuBoardVersion);
6262
6363
6464// ==========================================================================
65- // Wifi/Cellular Modem Main Chip Selection
65+ // Wifi/Cellular Modem Settings
6666// ==========================================================================
6767
68- #define TINY_GSM_MODEM_SIM800 // Select for a SIM800, SIM900, or variant thereof
69-
70-
71- // ==========================================================================
72- // Modem Pins
73- // ==========================================================================
74-
75- const int8_t modemVccPin = -2 ; // MCU pin controlling modem power (-1 if not applicable)
76- const int8_t modemSleepRqPin = 23 ; // MCU pin used for modem sleep/wake request (-1 if not applicable)
77- const int8_t modemStatusPin = 19 ; // MCU pin used to read modem status (-1 if not applicable)
78-
79-
80- // ==========================================================================
81- // TinyGSM Client
82- // ==========================================================================
83-
84- #define TINY_GSM_YIELD () { delay (2 ); } // Use to counter slow (9600) baud rate
85-
86- // Include TinyGSM for the modem
87- // This include must be included below the define of the modem name!
88- #include < TinyGsmClient.h>
89-
9068// Create a reference to the serial port for the modem
9169HardwareSerial &modemSerial = Serial1; // Use hardware serial if possible
9270
93- // Create a new TinyGSM modem to run on that serial port and return a pointer to it
94- TinyGsm *tinyModem = new TinyGsm(modemSerial);
95-
96- // Create a TCP client on that modem
97- TinyGsmClient *tinyClient = new TinyGsmClient(*tinyModem);
98-
99-
100- // ==========================================================================
101- // Specific Modem On-Off Methods
102- // ==========================================================================
103-
104- // THIS ONLY APPLIES TO A SODAQ GPRSBEE R6!!!
105- // Describe the physical pin connection of your modem to your board
106- const long modemBaud = 9600 ; // Communication speed of the modem
107- const bool modemStatusLevel = HIGH; // The level of the status pin when the module is active (HIGH or LOW)
108-
109- // Create the wake and sleep methods for the modem
110- // These can be functions of any type and must return a boolean
111- bool modemWakeFxn (void )
112- {
113- digitalWrite (modemSleepRqPin, HIGH);
114- digitalWrite (redLED, HIGH); // A light just for show
115- return true ;
116- }
117- bool modemSleepFxn (void )
118- {
119- digitalWrite (modemSleepRqPin, LOW);
120- digitalWrite (redLED, LOW);
121- return true ;
122- }
123- void extraModemSetup (void ){}
124- // ==========================================================================
125- // Network Information and LoggerModem Object
126- // ==========================================================================
127- #include < LoggerModem.h>
71+ // Modem Pins - Describe the physical pin connection of your modem to your board
72+ const int8_t modemVccPin = -2 ; // MCU pin controlling modem power (-1 if not applicable)
73+ const int8_t modemStatusPin = 19 ; // MCU pin used to read modem status (-1 if not applicable)
74+ const int8_t modemSleepRqPin = 23 ; // MCU pin used for modem sleep/wake request (-1 if not applicable)
75+ const int8_t modemLEDPin = redLED; // MCU pin connected an LED to show modem status (-1 if unconnected)
12876
12977// Network connection information
130- const char *apn = " hologram" ; // The APN for the gprs connection, unnecessary for WiFi
78+ const char *apn = " hologram" ; // The APN for the gprs connection
13179
132- // Create the loggerModem instance
133- // A "loggerModem" is a combination of a TinyGSM Modem, a Client, and functions for wake and sleep
134- loggerModem modem (modemVccPin, modemStatusPin, modemStatusLevel, modemWakeFxn, modemSleepFxn, tinyModem, tinyClient, apn);
135- // ^^ Use this for cellular
80+ // For the Sodaq 2GBee R6 and R7 based on the SIMCom SIM800
81+ // NOTE: The Sodaq GPRSBee doesn't expose the SIM800's reset pin
82+ #include < modems/Sodaq2GBeeR6.h>
83+ const long modemBaud = 9600 ; // SIM800 does auto-bauding by default
84+ Sodaq2GBeeR6 modem2GB (&modemSerial,
85+ modemVccPin, modemStatusPin,
86+ modemSleepRqPin,
87+ apn);
88+ // Create an extra reference to the modem by a generic name (not necessary)
89+ Sodaq2GBeeR6 modem = modem2GB;
13690
13791
13892// ==========================================================================
@@ -145,12 +99,12 @@ MaximDS3231 ds3231(1);
14599
146100
147101// ==========================================================================
148- // CAMPBELL OBS 3 / OBS 3+ Analog Turbidity Sensor
102+ // Campbell OBS 3 / OBS 3+ Analog Turbidity Sensor
149103// ==========================================================================
150104#include < sensors/CampbellOBS3.h>
151105
152106const int8_t OBS3Power = sensorPowerPin; // Pin to switch power on and off (-1 if unconnected)
153- const uint8_t OBS3numberReadings = 10 ;
107+ const uint8_t OBS3NumberReadings = 10 ;
154108const uint8_t ADSi2c_addr = 0x48 ; // The I2C address of the ADS1115 ADC
155109// Campbell OBS 3+ Low Range calibration in Volts
156110const int8_t OBSLowADSChannel = 0 ; // The ADS channel for the low range output
@@ -159,7 +113,7 @@ const float OBSLow_B = 1.000E+00; // The "B" value (X) from the low range calib
159113const float OBSLow_C = 0.000E+00 ; // The "C" value from the low range calibration
160114
161115// Create a Campbell OBS3+ LOW RANGE sensor object
162- CampbellOBS3 osb3low (OBS3Power, OBSLowADSChannel, OBSLow_A, OBSLow_B, OBSLow_C, ADSi2c_addr, OBS3numberReadings );
116+ CampbellOBS3 osb3low (OBS3Power, OBSLowADSChannel, OBSLow_A, OBSLow_B, OBSLow_C, ADSi2c_addr, OBS3NumberReadings );
163117
164118
165119// Campbell OBS 3+ High Range calibration in Volts
@@ -169,7 +123,7 @@ const float OBSHigh_B = 1.000E+00; // The "B" value (X) from the high range cal
169123const float OBSHigh_C = 0.000E+00 ; // The "C" value from the high range calibration
170124
171125// Create a Campbell OBS3+ HIGH RANGE sensor object
172- CampbellOBS3 osb3high (OBS3Power, OBSHighADSChannel, OBSHigh_A, OBSHigh_B, OBSHigh_C, ADSi2c_addr, OBS3numberReadings );
126+ CampbellOBS3 osb3high (OBS3Power, OBSHighADSChannel, OBSHigh_A, OBSHigh_B, OBSHigh_C, ADSi2c_addr, OBS3NumberReadings );
173127
174128
175129// ==========================================================================
@@ -178,12 +132,12 @@ CampbellOBS3 osb3high(OBS3Power, OBSHighADSChannel, OBSHigh_A, OBSHigh_B, OBSHig
178132#include < sensors/DecagonCTD.h>
179133
180134const char *CTDSDI12address = " 1" ; // The SDI-12 Address of the CTD
181- const uint8_t CTDnumberReadings = 6 ; // The number of readings to average
135+ const uint8_t CTDNumberReadings = 6 ; // The number of readings to average
182136const int8_t SDI12Power = sensorPowerPin; // Pin to switch power on and off (-1 if unconnected)
183137const int8_t SDI12Data = 7 ; // The SDI12 data pin
184138
185139// Create a Decagon CTD sensor object
186- DecagonCTD ctd (*CTDSDI12address, SDI12Power, SDI12Data, CTDnumberReadings );
140+ DecagonCTD ctd (*CTDSDI12address, SDI12Power, SDI12Data, CTDNumberReadings );
187141
188142
189143// ==========================================================================
@@ -197,7 +151,7 @@ Variable *variableList[] = {
197151 new DecagonCTD_Depth (&ctd, " 12345678-abcd-1234-efgh-1234567890ab" ),
198152 new CampbellOBS3_Turbidity (&osb3low, " 12345678-abcd-1234-efgh-1234567890ab" , " TurbLow" ),
199153 new CampbellOBS3_Turbidity (&osb3high, " 12345678-abcd-1234-efgh-1234567890ab" , " TurbHigh" ),
200- new ProcessorStats_Batt (&mcuBoard, " 12345678-abcd-1234-efgh-1234567890ab" ),
154+ new ProcessorStats_Battery (&mcuBoard, " 12345678-abcd-1234-efgh-1234567890ab" ),
201155 new MaximDS3231_Temp (&ds3231, " 12345678-abcd-1234-efgh-1234567890ab" ),
202156 new Modem_RSSI (&modem, " 12345678-abcd-1234-efgh-1234567890ab" ),
203157 new Modem_SignalPercent (&modem, " 12345678-abcd-1234-efgh-1234567890ab" ),
@@ -228,7 +182,7 @@ const char *samplingFeature = "12345678-abcd-1234-efgh-1234567890ab"; // Sam
228182
229183// Create a data publisher for the EnviroDIY/WikiWatershed POST endpoint
230184#include < publishers/EnviroDIYPublisher.h>
231- EnviroDIYPublisher EnviroDIYPOST (dataLogger, registrationToken, samplingFeature);
185+ EnviroDIYPublisher EnviroDIYPOST (dataLogger, &modem.gsmClient, registrationToken, samplingFeature);
232186
233187
234188// ==========================================================================
@@ -311,15 +265,16 @@ void setup()
311265 digitalWrite (modemSleepRqPin, LOW);
312266 }
313267
314- // Set the timezone and offsets
268+ // Set the timezones for the logger/data and the RTC
315269 // Logging in the given time zone
316- Logger::setTimeZone (timeZone);
317- // Offset is the same as the time zone because the RTC is in UTC
318- Logger::setTZOffset (timeZone );
270+ Logger::setLoggerTimeZone (timeZone);
271+ // It is STRONGLY RECOMMENDED that you set the RTC to be in UTC (UTC+0)
272+ Logger::setRTCTimeZone ( 0 );
319273
320274 // Attach the modem and information pins to the logger
321275 dataLogger.attachModem (modem);
322- dataLogger.setLoggerPins (wakePin, sdCardSSPin, sensorPowerPin, buttonPin, greenLED);
276+ modem.setModemLED (modemLEDPin);
277+ dataLogger.setLoggerPins (wakePin, sdCardSSPin, sdCardPwrPin, buttonPin, greenLED);
323278
324279 // Begin the logger
325280 dataLogger.begin ();
@@ -330,19 +285,24 @@ void setup()
330285 {
331286 modem.modemPowerUp ();
332287 modem.wake ();
288+ modem.setup ();
333289
334290 // At very good battery voltage, or with suspicious time stamp, sync the clock
335291 // Note: Please change these battery voltages to match your battery
336292 if (getBatteryVoltage () > 3.8 ||
337293 dataLogger.getNowEpoch () < 1546300800 || /* Before 01/01/2019*/
338- dataLogger.getNowEpoch () > 1735689600 ) /* Before 1/1/2025*/
294+ dataLogger.getNowEpoch () > 1735689600 ) /* After 1/1/2025*/
339295 {
340296 // Synchronize the RTC with NIST
341- Serial.println (F (" Attempting to synchronize RTC with NIST" ));
297+ Serial.println (F (" Attempting to connect to the internet and synchronize RTC with NIST" ));
342298 if (modem.connectInternet (120000L ))
343299 {
344300 dataLogger.setRTClock (modem.getNISTTime ());
345301 }
302+ else
303+ {
304+ Serial.println (F (" Could not connect to internet for clock sync." ));
305+ }
346306 }
347307 }
348308
@@ -369,6 +329,7 @@ void setup()
369329 }
370330
371331 // Call the processor sleep
332+ Serial.println (F (" Putting processor to sleep" ));
372333 dataLogger.systemSleep ();
373334}
374335
@@ -394,6 +355,6 @@ void loop()
394355 // If the battery is good, send the data to the world
395356 else
396357 {
397- dataLogger.logDataAndSend ();
358+ dataLogger.logDataAndPublish ();
398359 }
399360}
0 commit comments