Forum Replies Created
-
AuthorPosts
-
@vogelrnws Ok, thank you. If you need my email, zholloman54@gmail.com
@vogelrnws I was spending some time looking at the cellular stuff and I decided I’d try to use the python example you used, but I can’t seem to access the files through the Google Drive. Also, I don’t think I currently have a python editor. What is a good one that you would suggest? Thanks
@neilh20 Ok, that sounds good. I just sent the details to your email. Let me know if it still works.
@vogelrnws Thank you for sending that. I’ll be sure to take a look at it if ThingSpeak doesn’t work.
@neilh20 I tried running the code with your ModularSensors library, and it still didn’t work. The apn I’m using is hologram. If I am using a Hologram SIM card, is that correct, or should I change the source to something else? Also, what is Tera-term with Timestamp, and is that something I should consider using?And also, one more question. Is ThingSpeak with API different that ThingSpeak with MQTT? Right now, it looks like I’m using the MQTT connection.
Hi there @vogelrnws. Honestly, It’d be awesome if you could send that code. I’m still considering my options on the method to publish the data, but that could be helpful!
@neilh20, ok! I’ll try that. For some reason (not really sure why), the code all of a sudden started saying that it couldn’t connect to the internet for clock sync. I’m looking into that, so I’ll get back to you once I fix that. Thank you again!Hey @neilh20. I just had a thought. The fact that the software works with the Digi WiFi S6B. Do you think that means its an issue with the actual cellular connection as opposed to the code?
Hi there @neilh20. Thanks for your response, sorry I couldn’t get to it until now. I spent some time on the code, and I tried the code with the 0.28.5 version of the EnviroDIY ModularSensors library just to see if anything changed. It still isn’t uploading to ThingSpeak though. I tried the 0.30.0 version of the ModularSensors library, alongside the StreamDebugger as well, here’s the output of the code (excluding the ThingSpeak data). It doesn’t look that much different.
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.Try the new cross-platform PowerShell https://aka.ms/pscore6
PS C:\Users\waked\OneDrive – East Carolina University\Documents\PlatformIO\Projects\LearnEnviroDIYcode-master> pio device monitor –port COM10 –baud 115200
— Available filters and text transformations: colorize, debug, default, direct, hexlify, log2file, nocontrol, printable, send_on_enter, time
— More details at http://bit.ly/pio-monitor-filters
— Miniterm on COM10 115200,8,N,1 —
— Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H —
Now running logging_to_thingspeak5.ino on Logger loggerUsing ModularSensors Library version TinyGSM Library version 0.11.4
Current RTC time is: 2021-08-02T12:16:53-05:00
CTDcond has a non-unique UUID!
CTDtemp has a non-unique UUID!
CTDdepth has a non-unique UUID!
Battery has a non-unique UUID!
12345678-abcd-1234-ef00-1234567890ab -> CTDcond
12345678-abcd-1234-ef00-1234567890ab -> CTDtemp
12345678-abcd-1234-ef00-1234567890ab -> CTDdepth
12345678-abcd-1234-ef00-1234567890ab -> Battery
12345678-abcd-1234-ef00-1234567890ab -> decibelMiliWattThis logger has a variable array with 5 variables, of which 4 come from 2 sensors and 1 are calculated.
Setting up sensors…
Attempting to connect to the internet and synchronize RTC with NIST
This may take up to two minutes!
OKCN163.97.697.6
OKCN163.97.6
OKCN163.97.6
OKCN163.97.6
OKCN163.97.6Clock already within 5 seconds of time.
Putting modem to sleep
Setting up file on SD card
Data will be saved as logger_2021-08-02.csv
Putting processor to sleep
——————————————\/—- Line Saved to SD Card —-\/
2021-08-02 12:20:00,0.0,22.40,-3.2,4.897,-81OKCN3.23.121
Sending data to [ 0 ] mqtt.thingspeak.com
MQTT connection failed with state: -4: MQTT_CONNECTION_TIMEOUT——————————————
——————————————
\/—- Line Saved to SD Card —-\/
2021-08-02 12:21:00,0.0,22.40,-2.7,4.897,0OKCN3.23.121
Sending data to [ 0 ] mqtt.thingspeak.com
MQTT connection failed with state: -4: MQTT_CONNECTION_TIMEOUTAdditionally, here’s the updated version of the code with the StreamDebugger stuff.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356/** =========================================================================* @file logging_to_ThingSpeak.ino* @brief Example logging data and publishing to ThingSpeak.** @author Sara Geleskie Damiano <sdamiano@stroudcenter.org>* @copyright (c) 2017-2020 Stroud Water Research Center (SWRC)* and the EnviroDIY Development Team* This example is published under the BSD-3 license.** Build Environment: Visual Studios Code with PlatformIO* Hardware Platform: EnviroDIY Mayfly Arduino Datalogger** DISCLAIMER:* THIS CODE IS PROVIDED "AS IS" - NO WARRANTY IS GIVEN.* ======================================================================= */// ==========================================================================// Defines for the Arduino IDE// NOTE: These are ONLY needed to compile with the Arduino IDE.// If you use PlatformIO, you should set these build flags in your// platformio.ini// ==========================================================================/** Start [defines] */#ifndef TINY_GSM_RX_BUFFER#define TINY_GSM_RX_BUFFER 64#endif#ifndef TINY_GSM_YIELD_MS#define TINY_GSM_YIELD_MS 2#endif#ifndef MQTT_MAX_PACKET_SIZE#define MQTT_MAX_PACKET_SIZE 240#endif#define TINY_GSM_MODEM_XBEE/** End [defines] */// ==========================================================================// Include the libraries required for any data logger// ==========================================================================/** Start [includes] */// The Arduino library is needed for every Arduino program.#include <Arduino.h>// EnableInterrupt is used by ModularSensors for external and pin change// interrupts and must be explicitly included in the main program.#include <EnableInterrupt.h>// To get all of the base classes for ModularSensors, include LoggerBase.// NOTE: Individual sensor definitions must be included separately.#include <LoggerBase.h>#include <StreamDebugger.h>/** End [includes] */// ==========================================================================// Data Logging Options// ==========================================================================/** Start [logging_options] */// The name of this program fileconst char* sketchName = "logging_to_thingspeak5.ino";// Logger ID, also becomes the prefix for the name of the data file on SD cardconst char* LoggerID = "logger";// How frequently (in minutes) to log dataconst uint8_t loggingInterval = 1;// Your logger's timezone.const int8_t timeZone = -5; // Eastern Standard Time// NOTE: Daylight savings time will not be applied! Please use standard time!// Set the input and output pins for the logger// NOTE: Use -1 for pins that do not applyconst int32_t serialBaud = 115200; // Baud rate for debuggingconst int8_t greenLED = 8; // Pin for the green LEDconst int8_t redLED = 9; // Pin for the red LEDconst int8_t buttonPin = 21; // Pin for debugging mode (ie, button pin)const int8_t wakePin = A7; // MCU 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 1const int8_t sdCardPwrPin = -1; // MCU SD card power pinconst int8_t sdCardSSPin = 12; // SD card chip select/slave select pinconst int8_t sensorPowerPin = 22; // MCU pin controlling main sensor power/** End [logging_options] */// ==========================================================================// Wifi/Cellular Modem Options// ==========================================================================/** Start [xbee_cell_transparent] */// For any Digi Cellular XBee's// NOTE: The u-blox based Digi XBee's (3G global and LTE-M global) can be used// in either bypass or transparent mode, each with pros and cons// The Telit based Digi XBees (LTE Cat1) can only use this mode.#if defined STREAMDEBUGGER_DBG#include <StreamDebugger.h>#include <modems/DigiXBeeCellularTransparent.h>// NOTE: Extra hardware and software serial ports are created in the "Settings// for Additional Serial Ports" sectionHardwareSerial& modemSerial = Serial1; // Use hardware serial if possibleconst int32_t modemBaud = 9600; // All XBee's use 9600 by defaultStreamDebugger modemDebugger(modemSerial, STANDARD_SERIAL_OUTPUT);#define modemSerHw modemDebugger#else#define modemSerHw modemSerial#endif // STREAMDEBUGGER_DBG// Modem Pins - Describe the physical pin connection of your modem to your board// NOTE: Use -1 for pins that do not apply// The pin numbers here are for a Digi XBee with a Mayfly and LTE adapter// For options https://github.com/EnviroDIY/LTEbee-Adapter/edit/master/README.mdconst int8_t modemVccPin = -1; // MCU pin controlling modem power// Option: modemVccPin = A5, if Mayfly SJ7 is// connected to the ASSOC pinconst int8_t modemStatusPin = 13; // MCU pin used to read modem status// NOTE: If possible, use the <code>STATUS/SLEEP_not</code> (XBee pin 13) for status, but// the CTS pin can also be used if necessaryconst bool useCTSforStatus = false; // Flag to use the CTS pin for statusconst int8_t modemResetPin = 20; // MCU pin connected to modem reset pinconst int8_t modemSleepRqPin = 23; // MCU pin for modem sleep/wake requestconst int8_t modemLEDPin = redLED; // MCU pin connected an LED to show modem// status// Network connection informationconst char* apn = "hologram"; // APN for GPRS connection// Create the modem objectDigiXBeeCellularTransparent modemXBCT(&modemSerHw, modemVccPin, modemStatusPin,useCTSforStatus, modemResetPin,modemSleepRqPin, apn);// Create an extra reference to the modem by a generic nameDigiXBeeCellularTransparent modem = modemXBCT;/** End [xbee_cell_transparent] */// ==========================================================================// ==========================================================================// Using the Processor as a Sensor// ==========================================================================/** Start [processor_sensor] */#include <sensors/ProcessorStats.h>// Create the main processor chip "sensor" - for general metadataconst char* mcuBoardVersion = "v0.5b";ProcessorStats mcuBoard(mcuBoardVersion);/** End [processor_sensor] */// ==========================================================================// Maxim DS3231 RTC (Real Time Clock)// ==========================================================================/** Start [ds3231] */#include <sensors/MaximDS3231.h>// Create a DS3231 sensor objectMaximDS3231 ds3231(1);/** End [ds3231] */// ==========================================================================// Meter Hydros 21 Conductivity, Temperature, and Depth Sensor// ==========================================================================/** Start [decagon_ctd] */#include <sensors/DecagonCTD.h>const char* CTDSDI12address = "1"; // The SDI-12 Address of the CTDconst uint8_t CTDNumberReadings = 6; // The number of readings to averageconst int8_t SDI12Power = sensorPowerPin; // Power pin (-1 if unconnected)const int8_t SDI12Data = 7; // The SDI12 data pin// Create a Decagon CTD sensor objectDecagonCTD ctd(*CTDSDI12address, SDI12Power, SDI12Data, CTDNumberReadings);/** End [decagon_ctd] */// ==========================================================================// Creating the Variable Array[s] and Filling with Variable Objects// ==========================================================================/** Start [variable_arrays] */Variable* variableList[] = {new DecagonCTD_Cond(&ctd, "12345678-abcd-1234-ef00-1234567890ab"),new DecagonCTD_Temp(&ctd, "12345678-abcd-1234-ef00-1234567890ab"),new DecagonCTD_Depth(&ctd, "12345678-abcd-1234-ef00-1234567890ab"),new ProcessorStats_Battery(&mcuBoard,"12345678-abcd-1234-ef00-1234567890ab"),new Modem_RSSI(&modem, "12345678-abcd-1234-ef00-1234567890ab")};// Count up the number of pointers in the arrayint variableCount = sizeof(variableList) / sizeof(variableList[0]);// Create the VariableArray objectVariableArray varArray;/** End [variable_arrays] */// ==========================================================================// The Logger Object[s]// ==========================================================================/** Start [loggers] */// Create a logger instanceLogger dataLogger;/** End [loggers] */// ==========================================================================// Creating Data Publisher[s]// ==========================================================================// Create a channel with fields on ThingSpeak in advance// The fields will be sent in exactly the order they are in the variable array.// Any custom name or identifier given to the field on ThingSpeak is irrelevant.// No more than 8 fields of data can go to any one channel. Any fields beyond// the eighth in the array will be ignored.const char* thingSpeakMQTTKey ="thingSpeakMQTTKey"; // Your MQTT API Key from Account > MyProfile.const char* thingSpeakChannelID ="thingSpeakChannelID"; // The numeric channel id for your channelconst char* thingSpeakChannelKey ="thingSpeakChannelKey"; // The Write API Key for your channel// Create a data publisher for ThingSpeak#include <publishers/ThingSpeakPublisher.h>ThingSpeakPublisher TsMqtt;/** End [loggers] */// ==========================================================================// Working Functions// ==========================================================================/** Start [working_functions] */// Flashes the LED's on the primary boardvoid greenredflash(uint8_t numFlash = 4, uint8_t rate = 75) {for (uint8_t i = 0; i < numFlash; i++) {digitalWrite(greenLED, HIGH);digitalWrite(redLED, LOW);delay(rate);digitalWrite(greenLED, LOW);digitalWrite(redLED, HIGH);delay(rate);}digitalWrite(redLED, LOW);}// Reads the battery voltage// NOTE: This will actually return the battery level from the previous update!float getBatteryVoltage() {if (mcuBoard.sensorValues[0] == -9999) mcuBoard.update();return mcuBoard.sensorValues[0];}/** End [working_functions] */// ==========================================================================// Arduino Setup Function// ==========================================================================/** Start [setup] */void setup() {// Start the primary serial connectionSerial.begin(serialBaud);// Print a start-up note to the first serial portSerial.print(F("Now running "));Serial.print(sketchName);Serial.print(F(" on Logger "));Serial.println(LoggerID);Serial.println();Serial.print(F("Using ModularSensors Library version "));//Serial.println(MODULAR_SENSORS_VERSION);Serial.print(F("TinyGSM Library version "));Serial.println(TINYGSM_VERSION);Serial.println();// Start the serial connection with the modemmodemSerial.begin(modemBaud);// Set up pins for the LED'spinMode(greenLED, OUTPUT);digitalWrite(greenLED, LOW);pinMode(redLED, OUTPUT);digitalWrite(redLED, LOW);// Blink the LEDs to show the board is on and starting upgreenredflash();// Set the timezones for the logger/data and the RTC// Logging in the given time zoneLogger::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 loggerdataLogger.attachModem(modem);modem.setModemLED(modemLEDPin);dataLogger.setLoggerPins(wakePin, sdCardSSPin, sdCardPwrPin, buttonPin,greenLED);// Begin the variable array[s], logger[s], and publisher[s]varArray.begin(variableCount, variableList);dataLogger.begin(LoggerID, loggingInterval, &varArray);TsMqtt.begin(dataLogger, &modem.gsmClient, thingSpeakMQTTKey,thingSpeakChannelID, thingSpeakChannelKey);// Note: Please change these battery voltages to match your battery// Set up the sensors, except at lowest battery levelif (getBatteryVoltage() > 3.4) {Serial.println(F("Setting up sensors..."));varArray.setupSensors();}// Sync the clock if it isn't valid or we have battery to spareif (getBatteryVoltage() > 3.55 || !dataLogger.isRTCSane()) {// Synchronize the RTC with NIST// This will also set up the modemdataLogger.syncRTC();}// Create the log file, adding the default header to it// Do this last so we have the best chance of getting the time correct and// all sensor names correct// Writing to the SD card can be power intensive, so if we're skipping// the sensor setup we'll skip this too.if (getBatteryVoltage() > 3.4) {Serial.println(F("Setting up file on SD card"));dataLogger.turnOnSDcard(true); // true = wait for card to settle after power updataLogger.createLogFile(true); // true = write a new headerdataLogger.turnOffSDcard(true); // true = wait for internal housekeeping after write}// Call the processor sleepSerial.println(F("Putting processor to sleep"));dataLogger.systemSleep();}/** End [setup] */// ==========================================================================// Arduino Loop Function// ==========================================================================/** Start [loop] */// Use this short loop for simple data logging and sendingvoid loop() {// Note: Please change these battery voltages to match your battery// At very low battery, just go back to sleepif (getBatteryVoltage() < 3.4) {dataLogger.systemSleep();}// At moderate voltage, log data but don't send it over the modemelse if (getBatteryVoltage() < 3.55) {dataLogger.logData();}// If the battery is good, send the data to the worldelse {dataLogger.logDataAndPublish();}}/** End [loop] */That’s very strange that the code worked with the Digi Wifi module. Any other suggestions are greatly appreciated! And if you see anything that I did wrong with the code, please let me know! I’m still rather new to this.
Hi @neilh20, thanks for all your help! Yeah, I think I replaced the channel key in the trace with the thingSpeakChannelKey for the forum. I’m looking at the Topic [41] thing and I see the key in the topic channels/…
Here’s the platformIO file.
[platformio]
src_dir = src/logging_to_thingspeak
;src_dir = src/LTExBee_FirstConnectiondescription = ModularSensors example intended for DRWI users with CTD, turbidity, and 2G signal
[env:mayfly]
monitor_speed = 115200
board = mayfly
platform = atmelavr
framework = arduino
lib_ldf_mode = deep+
lib_ignore =
RTCZero
Adafruit NeoPixel
Adafruit GFX Library
Adafruit SSD1306
Adafruit ADXL343
Adafruit STMPE610
Adafruit TouchScreen
Adafruit ILI9341
build_flags =
-DSDI12_EXTERNAL_PCINT
-DNEOSWSERIAL_EXTERNAL_PCINT
-DMQTT_MAX_PACKET_SIZE=240
-DTINY_GSM_RX_BUFFER=64
-DTINY_GSM_YIELD_MS=2
-DMS_DATAPUBLISHERBASE_DEBUG
-DMS_THINGSPEAKPUBLISHER_DEBUG
lib_deps =
envirodiy/EnviroDIY_ModularSensorsHi there! Yeah I registered the MQTT device via ThingSpeak. I used the MQTT Explorer you suggested and I was able to post some data to Thingspeak by typing literal values into the Explorer. This leads me to think that it’s an issue with the Mayfly code.
@neilh20 I’m curious as to how you set up the ThingSpeak using POST. I’m not really committed to the MQTT platform, and I’m curious how you set your’s up.Hey @neilh20. Thanks for looking at. Yeah, I already had the keys and the channel ID in the code, I just took them out for the forum. Sorry, I understand that could have been confusing. Other than that, is there anything else you could see it being?
-
AuthorPosts