/***************************************************************************** logging_to_EnviroDIY.ino Written By: Sara Damiano (sdamiano@stroudcenter.org) Development Environment: PlatformIO 3.2.1 Hardware Platform: EnviroDIY Mayfly Arduino Datalogger Software License: BSD-3. Copyright (c) 2017, Stroud Water Research Center (SWRC) and the EnviroDIY Development Team This sketch is an example of logging data to an SD card and sending the data to the EnviroDIY data portal. DISCLAIMER: THIS CODE IS PROVIDED "AS IS" - NO WARRANTY IS GIVEN. *****************************************************************************/ // Some define statements #define STANDARD_SERIAL_OUTPUT Serial // Without this there will be no output // Select your modem chip, comment out all of the others // #define TINY_GSM_MODEM_SIM800 // Select for a SIM800, SIM900, or varient thereof // #define TINY_GSM_MODEM_A6 // Select for a AI-Thinker A6 or A7 chip // #define TINY_GSM_MODEM_M590 // Select for a Neoway M590 // #define TINY_GSM_MODEM_U201 // Select for a U-blox U201 // #define TINY_GSM_MODEM_ESP8266 // Select for an ESP8266 using the DEFAULT AT COMMAND FIRMWARE #define TINY_GSM_MODEM_XBEE // Select for Digi brand WiFi or Cellular XBee's // ========================================================================== // Include the base required libraries // ========================================================================== #include // The base Arduino library #include // for external and pin change interrupts #include // ========================================================================== // Basic Logger Settings // ========================================================================== // The name of this file const char *sketchName = "logging_to_EnviroDIY.ino"; // Logger ID, also becomes the prefix for the name of the data file on SD card const char *LoggerID = "MayflyV0.5b"; // How frequently (in minutes) to log data int loggingInterval = 1; // Your logger's timezone. const int timeZone = -5; // Create a new logger instance LoggerEnviroDIY EnviroDIYLogger; // ========================================================================== // Primary Arduino-Based Board and Processor // ========================================================================== #include const long serialBaud = 57600; // Baud rate for the primary serial port for debugging const int greenLED = 8; // Pin for the green LED (-1 if unconnected) const int redLED = 9; // Pin for the red LED (-1 if unconnected) const int buttonPin = 21; // Pin for a button to use to enter debugging mode (-1 if unconnected) const int wakePin = A7; // Interrupt/Alarm pin to wake from sleep // Set the wake pin to -1 if you do not want the main processor to sleep. // In a SAMD system where you are using the built-in rtc, set wakePin to 1 const int sdCardPin = 12; // SD Card Chip Select/Slave Select Pin (must be defined!) // Create the processor "sensor" const char *MFVersion = "v0.5"; ProcessorStats mayfly(MFVersion) ; // ========================================================================== // Modem/Internet connection options // ========================================================================== HardwareSerial &ModemSerial = Serial1; // The serial port for the modem - software serial can also be used. const int modemSleepRqPin = 23; // Modem SleepRq Pin (for sleep requests) (-1 if unconnected) const int modemStatusPin = 19; // Modem Status Pin (indicates power status) (-1 if unconnected) const int modemVCCPin = -1; // Modem power pin, if it can be turned on or off (-1 if unconnected) ModemSleepType ModemSleepMode = held; // How the modem is put to sleep // Use "held" if the DTR pin is held HIGH to keep the modem awake, as with a Sodaq GPRSBee rev6. // Use "pulsed" if the DTR pin is pulsed high and then low to wake the modem up, as with an Adafruit Fona or Sodaq GPRSBee rev4. // Use "reverse" if the DTR pin is held LOW to keep the modem awake, as with all XBees. // Use "always_on" if you do not want the library to control the modem power and sleep or if none of the above apply. const long ModemBaud = 9600; // Modem baud rate const char *apn = "xxxxx"; // The APN for the gprs connection, unnecessary for WiFi const char *wifiId = "xxxxx"; // The WiFi access point, unnecessary for gprs const char *wifiPwd = "xxxxx"; // The password for connecting to WiFi, unnecessary for gprs // Create the loggerModem instance // A "loggerModem" is a combination of a TinyGSM Modem, a TinyGSM Client, and an on/off method loggerModem modem; // ========================================================================== // Maxim DS3231 RTC (Real Time Clock) // ========================================================================== #include MaximDS3231 ds3231(1); // The array that contains all variables to be logged // ========================================================================== Variable *variableList[] = { new ProcessorStats_Batt(&mayfly, "12345678-abcd-1234-efgh-1234567890ab"), new ProcessorStats_FreeRam(&mayfly, "12345678-abcd-1234-efgh-1234567890ab"), // new YOUR_variableName_HERE(&) }; int variableCount = sizeof(variableList) / sizeof(variableList[0]); // ========================================================================== // 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 // ========================================================================== // Working Functions // ========================================================================== // Flashes the LED's on the primary board void greenredflash(int numFlash = 4, int rate = 75) { for (int i = 0; i < numFlash; i++) { digitalWrite(greenLED, HIGH); digitalWrite(redLED, LOW); delay(rate); digitalWrite(greenLED, LOW); digitalWrite(redLED, HIGH); delay(rate); } digitalWrite(redLED, LOW); } // ========================================================================== // Main setup function // ========================================================================== void setup() { // Start the primary serial connection Serial.begin(serialBaud); // Start the serial connection with the modem ModemSerial.begin(ModemBaud); // Start the stream for the modbus sensors // modbusSerial.begin(9600); // Start the SoftwareSerial stream for the sonar // sonarSerial.begin(9600); // Allow interrupts for software serial #if defined SoftwareSerial_ExtInts_h enableInterrupt(SonarData, SoftwareSerial_ExtInts::handle_interrupt, CHANGE); #endif // Set up pins for the LED's pinMode(greenLED, OUTPUT); pinMode(redLED, OUTPUT); // Blink the LEDs to show the board is on and starting up greenredflash(); // Print a start-up note to the first serial port Serial.print(F("Now running ")); Serial.print(sketchName); Serial.print(F(" on Logger ")); Serial.println(LoggerID); // Set the timezone and offsets // 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); // Initialize the logger EnviroDIYLogger.init(sdCardPin, wakePin, variableCount, variableList, loggingInterval, LoggerID); EnviroDIYLogger.setAlertPin(greenLED); // Setup the logger modem #if defined(TINY_GSM_MODEM_XBEE) || defined(TINY_GSM_MODEM_ESP8266) modem.setupModem(&ModemSerial, modemVCCPin, modemStatusPin, modemSleepRqPin, ModemSleepMode, wifiId, wifiPwd); #else modem.setupModem(&ModemSerial, modemVCCPin, modemStatusPin, modemSleepRqPin, ModemSleepMode, apn); #endif // Attach the modem to the logger EnviroDIYLogger.attachModem(modem); // Set up the connection with EnviroDIY EnviroDIYLogger.setToken(registrationToken); EnviroDIYLogger.setSamplingFeatureUUID(samplingFeature); // Set up the connection with DreamHost #ifdef DreamHostPortalRX EnviroDIYLogger.setDreamHostPortalRX(DreamHostPortalRX); #endif // Begin the logger EnviroDIYLogger.begin(); // Check for debugging mode EnviroDIYLogger.checkForTestingMode(buttonPin); } // ========================================================================== // Main loop function // ========================================================================== void loop() { // Log the data EnviroDIYLogger.log(); }