Trends and message change
This commit is contained in:
parent
52726c263c
commit
ccd03735ea
252
src/main.cpp
252
src/main.cpp
@ -7,6 +7,7 @@
|
|||||||
#include <WiFiUdp.h>
|
#include <WiFiUdp.h>
|
||||||
#include <Adafruit_GFX.h>
|
#include <Adafruit_GFX.h>
|
||||||
#include <Adafruit_SSD1306.h>
|
#include <Adafruit_SSD1306.h>
|
||||||
|
#include <EEPROM.h>
|
||||||
#include "bitmaps.h"
|
#include "bitmaps.h"
|
||||||
#include "netman.h"
|
#include "netman.h"
|
||||||
|
|
||||||
@ -37,6 +38,7 @@ void initSystems() {
|
|||||||
pinMode(PIN_BUZZER, OUTPUT);
|
pinMode(PIN_BUZZER, OUTPUT);
|
||||||
pinMode(LED_BUILTIN, OUTPUT);
|
pinMode(LED_BUILTIN, OUTPUT);
|
||||||
digitalWrite(LED_BUILTIN, HIGH);
|
digitalWrite(LED_BUILTIN, HIGH);
|
||||||
|
EEPROM.begin(512);
|
||||||
Wire.begin(); // Initialize I2C
|
Wire.begin(); // Initialize I2C
|
||||||
Wire.setClock(400000L); // Set I2C to Fast Mode (400 kHz)
|
Wire.setClock(400000L); // Set I2C to Fast Mode (400 kHz)
|
||||||
display.ssd1306_command(SSD1306_SETCONTRAST);
|
display.ssd1306_command(SSD1306_SETCONTRAST);
|
||||||
@ -174,6 +176,32 @@ void powerSaveCheck() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float prevTemperature = 0.0;
|
||||||
|
int prevHumidity = 0;
|
||||||
|
float prevPressure = 0.0;
|
||||||
|
float prevWindSpeed = 0.0;
|
||||||
|
|
||||||
|
void saveWeatherData() {
|
||||||
|
|
||||||
|
// Store float values as bytes (4 bytes for each float)
|
||||||
|
EEPROM.put(0, prevTemperature);
|
||||||
|
EEPROM.put(4, prevHumidity);
|
||||||
|
EEPROM.put(8, prevPressure);
|
||||||
|
EEPROM.put(12, prevWindSpeed);
|
||||||
|
|
||||||
|
// Commit changes to EEPROM
|
||||||
|
EEPROM.commit(); // Write changes to flash
|
||||||
|
}
|
||||||
|
|
||||||
|
void loadWeatherData() {
|
||||||
|
// Read the data from EEPROM (addresses correspond to where they were saved)
|
||||||
|
|
||||||
|
EEPROM.get(0, prevTemperature);
|
||||||
|
EEPROM.get(4, prevHumidity);
|
||||||
|
EEPROM.get(8, prevPressure);
|
||||||
|
EEPROM.get(12, prevWindSpeed);
|
||||||
|
}
|
||||||
|
|
||||||
int icon = 0;
|
int icon = 0;
|
||||||
String weatherState;
|
String weatherState;
|
||||||
float temperature;
|
float temperature;
|
||||||
@ -188,6 +216,16 @@ String getRandomMessage(const String messages[], int size) {
|
|||||||
return messages[random(size)];
|
return messages[random(size)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String generateTrendMessage(float current, float previous, const String& parameter) {
|
||||||
|
if (current > previous) {
|
||||||
|
return parameter + " rising ";
|
||||||
|
} else if (current < previous) {
|
||||||
|
return parameter + " falling ";
|
||||||
|
} else {
|
||||||
|
return parameter + " stable ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool fetchWeatherData() {
|
bool fetchWeatherData() {
|
||||||
// Get current time
|
// Get current time
|
||||||
time_t epochTime = timeClient.getEpochTime();
|
time_t epochTime = timeClient.getEpochTime();
|
||||||
@ -207,115 +245,117 @@ bool fetchWeatherData() {
|
|||||||
|
|
||||||
if (!deserializeJson(doc, payload)) {
|
if (!deserializeJson(doc, payload)) {
|
||||||
String mainWeather = doc["weather"][0]["main"].as<String>();
|
String mainWeather = doc["weather"][0]["main"].as<String>();
|
||||||
String description = doc["weather"][0]["description"].as<String>();
|
|
||||||
|
|
||||||
// Define 10 messages for each weather condition
|
|
||||||
if (mainWeather == "Clear") {
|
|
||||||
String clearMessages[] = {
|
|
||||||
"Solar intensity optimal. Prepare for a day of high visibility.",
|
|
||||||
"Sky is clear, perfect for horizon scanning protocols.",
|
|
||||||
"Bright skies detected. Enjoy the solar boost!",
|
|
||||||
"All systems go. Solar power at full capacity.",
|
|
||||||
"Clear skies engaged. Optimal light detected for maximum efficiency.",
|
|
||||||
"Visibility: crystal-clear. Time to explore the open landscape.",
|
|
||||||
"Atmospheric clarity confirmed. Solar shields inactive.",
|
|
||||||
"The sky is pristine. Energy absorption at max.",
|
|
||||||
"Clear skies overhead. Pathfinding ideal for visual systems.",
|
|
||||||
"No obstructions above. Horizon detection is in prime mode."
|
|
||||||
};
|
|
||||||
weatherState = getRandomMessage(clearMessages, 10);
|
|
||||||
} else if (mainWeather == "Clouds") {
|
|
||||||
String cloudMessages[] = {
|
|
||||||
"Cloud cover detected. Sky shield engaged for mild solar filtering.",
|
|
||||||
"Overcast overhead. Perfect ambiance for low-light operations.",
|
|
||||||
"Clouds in the atmosphere. System monitoring for breaks in cover.",
|
|
||||||
"Skies are shaded - ideal for thermal conservation.",
|
|
||||||
"Cloud barrier active. Solar input reduced for optimal temperature.",
|
|
||||||
"Cloud density increasing. Adjusting light sensitivity.",
|
|
||||||
"Partial shade above. Charging might be slower.",
|
|
||||||
"A mild cover blankets the sky. Solar intake downscaled.",
|
|
||||||
"Gray layers up high. Vision systems compensating.",
|
|
||||||
"Cloudscape in progress. Ideal time for internal diagnostics."
|
|
||||||
};
|
|
||||||
weatherState = getRandomMessage(cloudMessages, 10);
|
|
||||||
} else if (mainWeather == "Rain") {
|
|
||||||
String rainMessages[] = {
|
|
||||||
"Precipitation incoming. Deploy waterproof systems if venturing outside.",
|
|
||||||
"Raindrops detected. External surfaces advised to stay dry.",
|
|
||||||
"Rain detected. Surface moisture levels increasing rapidly.",
|
|
||||||
"Incoming rainstorm - caution advised for all outdoor units.",
|
|
||||||
"Prepare for water influx. Systems on standby for slippery terrain.",
|
|
||||||
"Moisture levels spiking. External sensors on alert.",
|
|
||||||
"Rainfall in progress. Hydration of external units possible.",
|
|
||||||
"Drips from the sky. Activate surface protection measures.",
|
|
||||||
"Rain warning: path may be slippery. Engage traction mode.",
|
|
||||||
"Rain detected. Outdoor activity may face hydration challenges."
|
|
||||||
};
|
|
||||||
weatherState = getRandomMessage(rainMessages, 10);
|
|
||||||
} else if (mainWeather == "Drizzle") {
|
|
||||||
String drizzleMessages[] = {
|
|
||||||
"Micro-droplets detected. Light atmospheric moisture active.",
|
|
||||||
"Atmosphere in drizzle mode. Surface wetting minimal.",
|
|
||||||
"Drizzle detected: gentle hydration for the surroundings.",
|
|
||||||
"Light rain mode activated - atmospheric refresh in progress.",
|
|
||||||
"Tiny droplets detected. Surroundings entering gentle wet mode.",
|
|
||||||
"Drizzle overhead. Water levels rising at a slow pace.",
|
|
||||||
"Mist-level rain. Surface dampness increasing slightly.",
|
|
||||||
"Fine mist in the air. Slight hydration for surfaces detected.",
|
|
||||||
"Low-intensity rain. Cooling effect minimal.",
|
|
||||||
"Drizzle detected. Perfect time for a smooth power cycle."
|
|
||||||
};
|
|
||||||
weatherState = getRandomMessage(drizzleMessages, 10);
|
|
||||||
} else if (mainWeather == "Thunderstorm") {
|
|
||||||
String thunderstormMessages[] = {
|
|
||||||
"Warning: Electrical storm approaching. Secure sensitive devices.",
|
|
||||||
"Severe storm alert. Brace for lightning and thunder activity.",
|
|
||||||
"System warning: Thunderstorm detected. High voltage hazard active.",
|
|
||||||
"Thunderstorm detected. Power up shields and secure electronics.",
|
|
||||||
"Electrical interference detected - storm protocol activated.",
|
|
||||||
"Heavy storm active. Electrical currents elevated.",
|
|
||||||
"Thunder and lightning detected. External energy sensors triggered.",
|
|
||||||
"Storm intensity rising. Secure pathways advised.",
|
|
||||||
"High-energy weather detected. Storm protection measures on.",
|
|
||||||
"Electrical storm in progress. Surge protection engaged."
|
|
||||||
};
|
|
||||||
weatherState = getRandomMessage(thunderstormMessages, 10);
|
|
||||||
} else if (mainWeather == "Snow") {
|
|
||||||
String snowMessages[] = {
|
|
||||||
"Cryo-precipitation alert: Snowfall active. Surface stability may be reduced.",
|
|
||||||
"Snowfall detected. Thermal insulation advised for all systems.",
|
|
||||||
"Cryogenic conditions active. Snow accumulation possible.",
|
|
||||||
"System temperature cooling due to snowfall. Low-traction alert.",
|
|
||||||
"External temperature dropping rapidly. Snow detected - proceed cautiously.",
|
|
||||||
"Icy precipitation confirmed. Outdoor conditions less stable.",
|
|
||||||
"Snow alert: Prepare for reduced surface traction.",
|
|
||||||
"Snow detected. Temperature protocols active.",
|
|
||||||
"Heavy snow warning: Surface coating likely.",
|
|
||||||
"Snowfall registered. External mobility may be impacted."
|
|
||||||
};
|
|
||||||
weatherState = getRandomMessage(snowMessages, 10);
|
|
||||||
} else if (mainWeather == "Mist" || mainWeather == "Fog") {
|
|
||||||
String mistMessages[] = {
|
|
||||||
"Low-visibility alert: Mist/fog detected. Navigation systems advised.",
|
|
||||||
"Foggy conditions active - visibility restricted, adjust pathfinding.",
|
|
||||||
"Atmospheric opacity high mist encountered. Slow travel recommended.",
|
|
||||||
"Dense mist detected. Sensor accuracy may be affected.",
|
|
||||||
"Atmosphere shrouded in mist. Low-visibility protocols recommended.",
|
|
||||||
"Fog cover detected. Vision range significantly reduced.",
|
|
||||||
"High density fog. Calibrate sensors for low-light conditions.",
|
|
||||||
"Environmental opacity increased. Proceed with caution.",
|
|
||||||
"Fog barrier detected. Slow-moving navigation optimal.",
|
|
||||||
"Mist detected - navigating carefully for minimal interference."
|
|
||||||
};
|
|
||||||
weatherState = getRandomMessage(mistMessages, 10);
|
|
||||||
} else {
|
|
||||||
weatherState = "Atmospheric anomaly detected: " + description + ". Monitoring closely.";
|
|
||||||
}
|
|
||||||
|
|
||||||
temperature = doc["main"]["temp"].as<float>() - 273.15;
|
temperature = doc["main"]["temp"].as<float>() - 273.15;
|
||||||
humidity = doc["main"]["humidity"];
|
humidity = doc["main"]["humidity"];
|
||||||
pressure = doc["main"]["pressure"].as<float>() / 1000;
|
pressure = doc["main"]["pressure"].as<float>() / 1000;
|
||||||
wind_speed = doc["wind"]["speed"].as<float>();
|
wind_speed = doc["wind"]["speed"].as<float>();
|
||||||
|
// Define 10 messages for each weather condition
|
||||||
|
if (mainWeather == "Clear") {
|
||||||
|
String clearMessages[] = {
|
||||||
|
"All systems nominal. Atmospheric clearance detected.",
|
||||||
|
"Clear skies confirmed. Solar energy levels stable for ship systems.",
|
||||||
|
"Sky conditions optimal for external scan. Proceed with visual sweep.",
|
||||||
|
"Visibility restored. All monitoring systems active and secure.",
|
||||||
|
"Open space ahead. Prepare for normal operations.",
|
||||||
|
"Solar reflection steady. Systems running at full capacity.",
|
||||||
|
"Clear. No interference detected. Navigation optimal.",
|
||||||
|
"Visible space clear. Proceed with standard operations.",
|
||||||
|
"Skies unclouded. No anomalies detected.",
|
||||||
|
"No obstructions in sight. Navigation systems operating normally."
|
||||||
|
};
|
||||||
|
weatherState = generateTrendMessage(temperature, prevTemperature, "Temperature") + generateTrendMessage(pressure, prevPressure, "Atmospheric pressure") + generateTrendMessage(humidity, prevHumidity, "Humidity") + generateTrendMessage(wind_speed, prevWindSpeed, "Wind speed") + getRandomMessage(clearMessages, 10);
|
||||||
|
} else if (mainWeather == "Clouds") {
|
||||||
|
String cloudMessages[] = {
|
||||||
|
"Cloud cover detected. Light interference on visual systems.",
|
||||||
|
"Overcast conditions observed.",
|
||||||
|
"Shadows overhead. Adjusting sensitivity on light filters.",
|
||||||
|
"Moderate cloud formation detected. System performance normal.",
|
||||||
|
"Atmospheric interference present. Monitoring light levels.",
|
||||||
|
"Cloud coverage rising. Operational impact minimal.",
|
||||||
|
"Low-visibility overhead. Preparing for reduced solar input.",
|
||||||
|
"Sensors report cloud patterns. Adjusting visibility protocols.",
|
||||||
|
"Clouds forming in surrounding space. Adjusting navigational parameters.",
|
||||||
|
"Light cloud cover detected. No operational impact expected."
|
||||||
|
};
|
||||||
|
weatherState = generateTrendMessage(temperature, prevTemperature, "Temperature") + generateTrendMessage(pressure, prevPressure, "Atmospheric pressure") + generateTrendMessage(humidity, prevHumidity, "Humidity") + generateTrendMessage(wind_speed, prevWindSpeed, "Wind speed") + getRandomMessage(cloudMessages, 10);
|
||||||
|
} else if (mainWeather == "Rain") {
|
||||||
|
String rainMessages[] = {
|
||||||
|
"Precipitation incoming. Shielding activated.",
|
||||||
|
"Rain detected. External moisture levels rising, activating water barriers.",
|
||||||
|
"Surface moisture increasing. Prepare for external wet conditions.",
|
||||||
|
"Rainstorm detected. External protection systems online.",
|
||||||
|
"Raindrops detected. Surface conditions becoming slick.",
|
||||||
|
"Incoming water influx. Prepare external surfaces for wet conditions.",
|
||||||
|
"Rain detected. Traction systems engaged for slippery terrain.",
|
||||||
|
"Wet conditions approaching. Hydration protocols for external units activated.",
|
||||||
|
"Raindrops increasing. Proceed with caution on exterior surfaces.",
|
||||||
|
"Heavy rain in the vicinity. External equipment may require adjustment."
|
||||||
|
};
|
||||||
|
weatherState = generateTrendMessage(temperature, prevTemperature, "Temperature") + generateTrendMessage(pressure, prevPressure, "Atmospheric pressure") + generateTrendMessage(humidity, prevHumidity, "Humidity") + generateTrendMessage(wind_speed, prevWindSpeed, "Wind speed") + getRandomMessage(rainMessages, 10);
|
||||||
|
} else if (mainWeather == "Drizzle") {
|
||||||
|
String drizzleMessages[] = {
|
||||||
|
"Light drizzle detected. Surface moisture rising, minimal impact.",
|
||||||
|
"Low-intensity rain detected. External systems functioning normally.",
|
||||||
|
"Fine mist detected. Prepare for minor surface wetting.",
|
||||||
|
"Gentle drizzle. Light hydration of external units detected.",
|
||||||
|
"Atmospheric moisture levels rising slowly. Proceed with minor caution.",
|
||||||
|
"Minor drizzle detected. No immediate impact on operations.",
|
||||||
|
"Drizzle detected. Adjusting exterior temperature controls.",
|
||||||
|
"Light rain confirmed. Surface conditions remain stable.",
|
||||||
|
"Drizzle present. External activity unaffected.",
|
||||||
|
"Micro-droplets detected. Surface wetting minimal."
|
||||||
|
};
|
||||||
|
weatherState = generateTrendMessage(temperature, prevTemperature, "Temperature") + generateTrendMessage(pressure, prevPressure, "Atmospheric pressure") + generateTrendMessage(humidity, prevHumidity, "Humidity") + generateTrendMessage(wind_speed, prevWindSpeed, "Wind speed") + getRandomMessage(drizzleMessages, 10);
|
||||||
|
} else if (mainWeather == "Thunderstorm") {
|
||||||
|
String thunderstormMessages[] = {
|
||||||
|
"Warning: Severe storm approaching. High-voltage hazard detected.",
|
||||||
|
"Electrical storm detected in proximity. Shielding and surge protection engaged.",
|
||||||
|
"Thunderstorm alert: Prepare for sudden power fluctuations.",
|
||||||
|
"Storm in progress. Lightning detected. Surge protection active.",
|
||||||
|
"Electrical interference detected. Recalibrating external sensors.",
|
||||||
|
"Thunderstorm imminent. High-energy levels detected. Activating surge protocols.",
|
||||||
|
"Power surge imminent. Warning: high-voltage storm detected.",
|
||||||
|
"Electrical storm approaching. Brace for system disturbances.",
|
||||||
|
"Warning: Lightning detected. Secure sensitive systems immediately.",
|
||||||
|
"Severe atmospheric storm approaching. Power systems primed for protection."
|
||||||
|
};
|
||||||
|
weatherState = generateTrendMessage(temperature, prevTemperature, "Temperature") + generateTrendMessage(pressure, prevPressure, "Atmospheric pressure") + generateTrendMessage(humidity, prevHumidity, "Humidity") + generateTrendMessage(wind_speed, prevWindSpeed, "Wind speed") + getRandomMessage(thunderstormMessages, 10);
|
||||||
|
} else if (mainWeather == "Snow") {
|
||||||
|
String snowMessages[] = {
|
||||||
|
"Cryogenic conditions detected. Snowfall in progress.",
|
||||||
|
"Snow accumulation imminent. External traction systems engaged.",
|
||||||
|
"Freezing precipitation confirmed. Temperature control systems adjusting.",
|
||||||
|
"Snow falling. Low-traction surfaces detected. Proceed with caution.",
|
||||||
|
"Heavy snowfall recorded. Thermal systems operating at full capacity.",
|
||||||
|
"Snowstorm imminent. Prepare for reduced external mobility.",
|
||||||
|
"Temperature drop confirmed. Snow accumulation expected.",
|
||||||
|
"Snow detected. De-icing systems online.",
|
||||||
|
"Cryogenic particles in atmosphere. Surface stability compromised.",
|
||||||
|
"Snowfall detected. All external movement restricted."
|
||||||
|
};
|
||||||
|
weatherState = generateTrendMessage(temperature, prevTemperature, "Temperature") + generateTrendMessage(pressure, prevPressure, "Atmospheric pressure") + generateTrendMessage(humidity, prevHumidity, "Humidity") + generateTrendMessage(wind_speed, prevWindSpeed, "Wind speed") + getRandomMessage(snowMessages, 10);
|
||||||
|
} else if (mainWeather == "Mist" || mainWeather == "Fog") {
|
||||||
|
String mistMessages[] = {
|
||||||
|
"Low-visibility conditions. Activate infrared scanning systems.",
|
||||||
|
"Fog detected. Navigation systems recalibrating for low-visibility operation.",
|
||||||
|
"Atmospheric opacity confirmed. Proceed with caution at reduced speed.",
|
||||||
|
"Dense mist detected. Visibility dropped to critical levels.",
|
||||||
|
"Fog levels increasing. Adjusting pathfinding parameters for accuracy.",
|
||||||
|
"Dense fog detected. Slowing navigation to safe speeds.",
|
||||||
|
"Increased fog density. Visual systems recalibrated.",
|
||||||
|
"Low visibility confirmed. Proceed with extreme caution.",
|
||||||
|
"Mist detected in sector. Visual enhancement systems engaged.",
|
||||||
|
"Fog detected. Reduced visibility affecting sensor accuracy."
|
||||||
|
};
|
||||||
|
weatherState = generateTrendMessage(temperature, prevTemperature, "Temperature") + generateTrendMessage(pressure, prevPressure, "Atmospheric pressure") + generateTrendMessage(humidity, prevHumidity, "Humidity") + generateTrendMessage(wind_speed, prevWindSpeed, "Wind speed") + getRandomMessage(mistMessages, 10);
|
||||||
|
} else {
|
||||||
|
weatherState = generateTrendMessage(temperature, prevTemperature, "Temperature") + generateTrendMessage(pressure, prevPressure, "Atmospheric pressure") + generateTrendMessage(humidity, prevHumidity, "Humidity") + generateTrendMessage(wind_speed, prevWindSpeed, "Wind speed") + "Unspecified weather anomaly detected. Conditions unstable. Monitoring closely.";
|
||||||
|
}
|
||||||
|
prevTemperature = temperature;
|
||||||
|
prevHumidity = humidity;
|
||||||
|
prevPressure = pressure;
|
||||||
|
prevWindSpeed = wind_speed;
|
||||||
|
saveWeatherData();
|
||||||
http.end();
|
http.end();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -382,7 +422,6 @@ void displayWeatherData() {
|
|||||||
// If the text has completely scrolled off, reset scroll position to start from the right
|
// If the text has completely scrolled off, reset scroll position to start from the right
|
||||||
if (scrollPos < -stateWidth) {
|
if (scrollPos < -stateWidth) {
|
||||||
scrollPos = SCREEN_WIDTH;
|
scrollPos = SCREEN_WIDTH;
|
||||||
delay(4000);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -421,6 +460,7 @@ void setup(void) {
|
|||||||
netman.start();
|
netman.start();
|
||||||
timeClient.begin();
|
timeClient.begin();
|
||||||
timeClient.update();
|
timeClient.update();
|
||||||
|
loadWeatherData();
|
||||||
fetchWeatherData();
|
fetchWeatherData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user