Skip to content

Instantly share code, notes, and snippets.

@Tech500
Last active January 22, 2023 03:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tech500/d3cfb3dee900bd863c24196b5a8f92f1 to your computer and use it in GitHub Desktop.
Save Tech500/d3cfb3dee900bd863c24196b5a8f92f1 to your computer and use it in GitHub Desktop.
//Written entirely on OpenAI using ChatGPT
//See 1st_ChatGPT_Webserver.ino --after debugging and refinement
//by William Lucid 1/21/2023
#include <WiFi.h>
#include <ESPAsyncWebServer.h>
#include "BME280.h"
#include "EnvironmentalCalculations.h"
// Replace with your network credentials
const char* ssid = "yourSSID";
const char* password = "yourPASSWORD7";
// Create an instance of the BME280 sensor
BME280 bme;
// Create an instance of the Environmental Calculations object
EnvironmentalCalculations envCalc;
void setup() {
// Start the serial communication
Serial.begin(115200);
// Connect to Wi-Fi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
// Initialize the BME280 sensor
if (!bme.begin(0x76)) {
Serial.println("Could not find a valid BME280 sensor, check wiring!");
while (1);
}
// Create an instance of the async web server
AsyncWebServer server(80);
// Serve a web page that displays the sensor readings and calculations
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
String html = "<html><body>";
html += "<h1>BME280 Sensor Readings and Calculations</h1>";
// Read the sensor data
float temperature = bme.readTemperature_F();
float humidity = bme.readHumidity();
float pressure = bme.readPressure_inHg();
// Perform calculations
float dewPoint = envCalc.dewPoint(temperature, humidity);
float heatIndex = envCalc.heatIndex(temperature, humidity);
html += "<p>Temperature: " + String(temperature) + " F</p>";
html += "<p>Humidity: " + String(humidity) + " %</p>";
html += "<p>Pressure: " + String(pressure) + " Pa</p>";
html += "<p>Dew Point: " + String(dewPoint) + " C</p>";
html += "<p>Heat Index: " + String(heatIndex) + " C</p>";
html += "</body></html>";
request->send(200, "text/html", html);
});
// Start the server
server.begin();
}
void loop() {
// Perform calculations every 5 minutes
if (millis() % (5 * 60 * 1000) == 0) {
// Read the sensor data
float temperature = bme.readTemperature();
float humidity = bme.readHumidity();
float pressure = bme.readPressure();
// Perform calculations
float dewPoint = envCalc.dewPoint(temperature, humidity);
float heatIndex = envCalc.heatIndex(temperature, humidity);
// Print the readings and calculations to the serial monitor
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment