diff --git a/.vs/OurWeatherWeatherPlus/v16/.suo b/.vs/OurWeatherWeatherPlus/v16/.suo new file mode 100644 index 0000000..dd28ace Binary files /dev/null and b/.vs/OurWeatherWeatherPlus/v16/.suo differ diff --git a/.vs/OurWeatherWeatherPlus/v16/Browse.VC.db b/.vs/OurWeatherWeatherPlus/v16/Browse.VC.db new file mode 100644 index 0000000..9871772 Binary files /dev/null and b/.vs/OurWeatherWeatherPlus/v16/Browse.VC.db differ diff --git a/.vs/ProjectSettings.json b/.vs/ProjectSettings.json new file mode 100644 index 0000000..0cf5ea5 --- /dev/null +++ b/.vs/ProjectSettings.json @@ -0,0 +1,3 @@ +{ + "CurrentProjectSetting": "No Configurations" +} \ No newline at end of file diff --git a/.vs/VSWorkspaceState.json b/.vs/VSWorkspaceState.json new file mode 100644 index 0000000..5e8a94c --- /dev/null +++ b/.vs/VSWorkspaceState.json @@ -0,0 +1,7 @@ +{ + "ExpandedNodes": [ + "" + ], + "SelectedNode": "\\SDL_ESP8266_WeatherPlus.ino", + "PreviewInSolutionExplorer": false +} \ No newline at end of file diff --git a/.vs/slnx.sqlite b/.vs/slnx.sqlite new file mode 100644 index 0000000..9849354 Binary files /dev/null and b/.vs/slnx.sqlite differ diff --git a/SDL_ESP8266_WeatherPlus.ino b/SDL_ESP8266_WeatherPlus.ino index b3f2928..c5cc96c 100644 --- a/SDL_ESP8266_WeatherPlus.ino +++ b/SDL_ESP8266_WeatherPlus.ino @@ -3,31 +3,25 @@ // SwitchDoc Labs, LLC // +// edit in Atom 0549 06232019..xx // -// - -#define WEATHERPLUSESP8266VERSION "035" +#include "constants.h" +#define WEATHERPLUSESP8266VERSION "033" #define WEATHERPLUSPUBNUBPROTOCOL "OURWEATHER035" // define DEBUGPRINT to print out lots of debugging information for WeatherPlus. #undef DEBUGPRINT - #undef PUBNUB_DEBUG - #undef DEBUGBLYNK - #define BLYNK_NO_BUILTIN - #define BLYNK_PRINT Serial // Defines the object that is used for printing #undef BLYNK_DEBUG #define BLYNK_USE_128_VPINS - #include - // Change this to undef if you don't have the OLED present #define OLED_Present @@ -138,13 +132,6 @@ String getValue(String data, char separator, int index) char channel1[] = "OWIOT1"; char uuid[] = WEATHERPLUSPUBNUBPROTOCOL; - - - - - - - #include #include //needed for Serial.println @@ -155,11 +142,7 @@ char uuid[] = WEATHERPLUSPUBNUBPROTOCOL; #include "MaREST.h" -#include - - - - +#include // display modes #define DISPLAY_POWERUP 0 @@ -196,15 +179,9 @@ String RestTimeStamp; String RestDataString; String Version; - - - - - //---------------------------------------------------------------------- //Local WiFi - int WiFiSetupFlag = 0; String APssid; @@ -231,10 +208,7 @@ aREST rest = aREST(); // commands are functions that get called by the webserver framework // they can read any posted data from client, and they output to server - - - -#include "elapsedMillis.h" +#include "elapsedmillis.h" elapsedMillis timeElapsed; //declare global if you don't want it reset every time loop @@ -275,10 +249,12 @@ RtcDS3231 Rtc; float AM2315_Temperature; float AM2315_Humidity; float dewpoint; +double heatIndex{}; +bool heatIndexValid{ false }; +String heatIndexLevel[5]{ "Caution", "Extreme caution", "Danger", "Extreme danger", "not defined" }; #include "SDL_ESP8266_HR_AM2315.h" - SDL_ESP8266_HR_AM2315 am2315; float dataAM2315[2]; //Array to hold data returned by sensor. [0,1] => [Humidity, Temperature] @@ -294,7 +270,6 @@ const char *monthName[12] = { // ThunderBoard AS3935 from SwitchDoc Labs AS3935 as3935(0x02, 3); - // lightning state variables as3935 String as3935_LastLightning = ""; @@ -391,17 +366,8 @@ void setAS3935Parameters() as3935.setTuningCapacitor(as3935_TuneCap); // set to 1/2 - middle - you can calibrate on an Arduino UNO and use the value from there (pf/8) - - - - - - - // lightning state variables as3935 - - // first let's turn on disturber indication and print some register values from AS3935 // tell AS3935 we are indoors, for outdoors use setOutdoors() function if (as3935_Indoor == true) @@ -436,7 +402,6 @@ void setAS3935Parameters() uint16_t getWatchdogThreshold(void); uint16_t setWatchdogThreshold(uint16_t wdth); - as3935.setSpikeRejection(as3935_SpikeDetection); as3935.setWatchdogThreshold(as3935_WatchdogThreshold); @@ -507,11 +472,6 @@ SDL_RasPiGraphLibrary windDirectionGraph(10, SDL_MODE_LABELS); char windSpeedBuffer[150]; // wind speed graph char windGustBuffer[150]; // wind speed graph char windDirectionBuffer[150]; // wind speed graph - - - - - // WeatherRack // LED connected to digital GPIO 0 @@ -626,7 +586,7 @@ float SolarPanelCurrent; // WXLink Support -#include "Crc16.h" +#include "crc16.h" //Crc 16 library (XModem) Crc16 crc; @@ -1401,20 +1361,27 @@ void setup() { Blynk.virtualWrite(V8, "Metric"); writeToBlynkStatusTerminal("Units set to Metric "); - - - + + + } } // end setup - -// -// -// loop() +double calcHeatIndex(float AM2315_Humidity, float AM2315_Temperature) { + double heatIndex{}; + heatIndex = constants::hIc1C + constants::hIc2C * AM2315_Temperature + constants::hIc3C * AM2315_Humidity + constants::hIc4C * AM2315_Temperature * AM2315_Humidity + + constants::hIc5C * AM2315_Temperature * AM2315_Temperature + constants::hIc6C * AM2315_Humidity * AM2315_Humidity + + constants::hIc7C * AM2315_Temperature * AM2315_Temperature * AM2315_Humidity + constants::hIc8C * AM2315_Temperature * AM2315_Humidity * AM2315_Humidity + + constants::hIc9C * AM2315_Temperature * AM2315_Temperature * AM2315_Humidity * AM2315_Humidity; + return heatIndex; + } // // +// loop() *********************************************** +// ****************************************************** +// ****************************************************** void loop() { @@ -1503,6 +1470,14 @@ void loop() { AM2315_Temperature = dataAM2315[1]; AM2315_Humidity = dataAM2315[0]; dewpoint = AM2315_Temperature - ((100.0 - AM2315_Humidity) / 5.0); + if (AM2315_Temperature > 27) { + heatIndex = calcHeatIndex(AM2315_Humidity, AM2315_Temperature); + heatIndexValid = true; + } + else { + heatIndex = 0; + heatIndexValid = false; + } Serial.print("Temp: "); Serial.println(AM2315_Temperature); Serial.print("Hum: "); Serial.println(AM2315_Humidity); @@ -1858,7 +1833,14 @@ void loop() { // calculate dewpoint dewpoint = AM2315_Temperature - ((100.0 - AM2315_Humidity) / 5.0); - + if (AM2315_Temperature > 27) { + heatIndex = calcHeatIndex(AM2315_Humidity, AM2315_Temperature); + heatIndexValid = true; + } + else { + heatIndex = 0; + heatIndexValid = false; + } // set up solar status and message ID for screen @@ -1890,22 +1872,10 @@ void loop() { Serial.println(""); */ - - - } - - - } - - - - - - Serial.print("windSpeedMin ="); Serial.print(windSpeedMin); Serial.print(" windSpeedMax ="); @@ -1973,7 +1943,6 @@ void loop() { RestDataString += String(LoadVoltage, 2) + ","; RestDataString += String(LoadCurrent, 2) + ","; - RestDataString += String(WXBatteryVoltage, 2) + ","; RestDataString += String(WXBatteryCurrent, 2) + ","; RestDataString += String(WXSolarPanelVoltage, 2) + ","; @@ -1991,12 +1960,10 @@ void loop() { } invalidTemperatureFound = false; - // Restart WiFi in case of connected, then lost connection if (WiFiPresent == true) { if (WiFi.status() != WL_CONNECTED) - { //Restart Access Point with the specified name WiFiManager wifiManager; @@ -2004,7 +1971,6 @@ void loop() { Serial.println("--->Restarting Connection connect and setting"); wifiManager.setTimeout(600); - Serial.print("OurWeather IP Address:"); Serial.println(myConnectedIp); @@ -2013,9 +1979,7 @@ void loop() { Serial.print("OurWeather subnet Mask:"); Serial.println(myConnectedMask); - wifiManager.setSTAStaticIPConfig( myConnectedIp, myConnectedGateWay, myConnectedMask); - //and goes into a blocking loop awaiting configuration if (!wifiManager.justConnect(APssid.c_str())) { Serial.println("->Restarting Connection but hit timeout"); @@ -2028,13 +1992,8 @@ void loop() { Serial.println("->Connection Restarted"); } - - - } } - - if (WXLastMessageGood == true) { RestDataString += "WXLMG ,"; @@ -2044,8 +2003,7 @@ void loop() { RestDataString += "WXLMB ,"; } - RestDataString += String(pubNubEnabled) + ","; - + RestDataString += String(pubNubEnabled) + ","; // index # 34 if (AS3935Present == true) { @@ -2066,12 +2024,8 @@ void loop() { Serial.print("as3935 irqSource: "); Serial.println(irqSource, BIN); - - - if (irqSource > 0) { - printAS3935Registers(); as3935_LastReturnIRQ = irqSource; // returned value is bitmap field, bit 0 - noise level too high, bit 2 - disturber detected, and finally bit 3 - lightning! @@ -2079,7 +2033,6 @@ void loop() { { Serial.println("INT_NH Interrupt: Noise level too high, try adjusting noise floor"); writeToBlynkStatusTerminal("ThunderBoard-Noise level too high"); - as3935_LastEvent = "Noise Level too high"; RtcDateTime now = Rtc.GetDateTime(); as3935_LastEventTimeStamp = returnDateTime(now); @@ -2109,7 +2062,6 @@ void loop() { as3935_LastLightningDistance = strokeDistance; as3835_LightningCountSinceBootup++; - Serial.print("INT_L Interrupt: Lightning Detected. Stroke Distance:"); Serial.print(strokeDistance); Serial.println(" km"); @@ -2124,13 +2076,8 @@ void loop() { delay(3000); updateDisplay(DISPLAY_LIGHTNING_DISPLAY); delay(3000); - - - - } } - } // Lightning REST variable as3935_FullString = ""; @@ -2141,20 +2088,17 @@ void loop() { as3935_FullString += as3935_LastEventTimeStamp + ","; as3935_FullString += String(as3835_LightningCountSinceBootup); - // Lighting Rest RestDataString += as3935_LastLightning + ","; RestDataString += as3935_LastLightningTimeStamp + ","; RestDataString += String(as3935_LastLightningDistance) + ","; RestDataString += as3935_LastEvent + ","; RestDataString += as3935_LastEventTimeStamp + ","; - RestDataString += String(as3835_LightningCountSinceBootup); + RestDataString += String(as3835_LightningCountSinceBootup) + ","; // index # 40 if (timeElapsed300Seconds > 300000) // 5 minutes { - - String lastBootTimeString; lastBootTimeString = returnDateTime(lastBoot); @@ -2164,11 +2108,8 @@ void loop() { timeElapsed300Seconds = 0; // update rain - - add60MinuteRainReading(rainTotal - lastRain); lastRain = rainTotal; - RtcDateTime now = Rtc.GetDateTime(); if (now.Day() == lastDay) @@ -2182,8 +2123,26 @@ void loop() { rainCalendarDay = 0.0; startOfDayRain = rainTotal; } - - + RestDataString += String(rainCalendarDay, 2) + ","; // index # 41 + RestDataString += lastBootTimeString + ","; // index # 42 + RestDataString += String(heatIndex, 0) + ","; // index # 43 + RestDataString += String(heatIndexValid) + ","; // index #44 + if (heatIndex <= 27) { + RestDataString += heatIndexLevel[4] + ","; + } + else if (heatIndex > 27 && heatIndex <= 32) { + RestDataString += heatIndexLevel[0] + ","; + } + else if (heatIndex > 32 && heatIndex <= 41) { + RestDataString += heatIndexLevel[1] + ","; + } + else if (heatIndex > 41 && heatIndex <= 54) { + RestDataString += heatIndexLevel[2] + ","; + } + else if (heatIndex > 54) { + RestDataString += heatIndexLevel[3] + ","; + } + else RestDataString += " unknown "; // index # 45 bool dataStale; dataStale = false; diff --git a/SDL_Weather_80422.cpp b/SDL_Weather_80422.cpp index 152040d..61b2f19 100644 --- a/SDL_Weather_80422.cpp +++ b/SDL_Weather_80422.cpp @@ -10,7 +10,7 @@ #include "Arduino.h" -#include +#include "TimeLib.h" #include "SDL_Weather_80422.h"