bmx280 connected to pins 21 and 22
sd card reader/writer on pins 5,18,19,and 23
-
Sends weather data to a mysql database every minute.
-
updates the clients every 30 seconds.
-
reads the sensors every 30 seconds.
-
connects to wifi
-
retrieves time from ntp servers
-
if index.htm is not present on the SD card, it loads a default webpage to the card.
-
provides real time bi-directional communication between the clients and the ESP-32
-
a new index.htm can be uploaded from the client interface, and once uploaded, all the clients will refresh to the new page.
-
programming can be updated using the arduino OTA interface.
-
it will maintain state between reboots.
Database Table
idweather
= <{idweather: }>,date
= <{date: }>,temp
= <{temp: }>,press
= <{press: }>,p64
= <{p64: }>,humid
= <{humid: }>
- weatherotawebsocketserver03182021.ino
- WiFiCred.h
- bcbaws.h
- bcbsdcard.h
- bcbbmx.h
const char *ntpServer = "pool.ntp.org";
const long gmtOffset_sec = -18000;
const int daylightOffset_sec = 3600;
void TaskRelay(void *pvParameters); // maintains the websocket display
void initWiFi(); initializes wifi
void initTime(); initializes the real-time clock.
String printLocalHour(); retrieves the time
String printLocalTime(); retrieves the date and time
void updateDB(); send data to the mysql database
put your wifi credentials here
//wifi connection credentials
const char* ssid = "*****";
const char* password = "*********";
//set initial state
struct State {
float humidity;
float pressure;
double pressure64;
float temp; String filename;
bool reload;
String json;
bool ota;
float dew () {
return temp - ((100 - humidity) / 5.);
}
};
State state = {0.00, 0.00, 0.00, 0.00,false,"",false};
// web server variables
AsyncWebServer server(80);
AsyncWebSocket ws("/ws");
bool wifiavail = false;
String getJson(bool b); creates the json object for sending to the client
void notifyClients(); sends data to clients
void notifyInitialClients; sends data to clients with a flag
void handleWebSocketMessage(void *arg, uint8_t *data, size_t len); handles websocket messages
void onEvent(AsyncWebSocket *server, AsyncWebSocketClient *client,
AwsEventType type, void *arg, uint8_t *data, size_t len);
void initWebSocket(); initializes websockets
void initWebServer(); initializes webserver
void parseCommand(String command); parses commands from the clients
const char htmlCode[]PROGMEM default webpage
xSemaphoreHandle semFile = xSemaphoreCreateMutex(); // file
operation lock
void initSDCard();
void appendFile(fs::FS &fs, const char * path, const char * message);
void renameFile(fs::FS &fs, const char * path1, const char * path2);
void deleteFile(fs::FS &fs, const char * path);
// write the default index.htm to SPIFFS
// check if index exists and only update if it doesn't
void checkForIndex();
#define BMX_ADDRESS 0x76
//create a BMx280I2C object using the I2C interface with I2C Address 0x76
BMx280I2C bmx280(BMX_ADDRESS);
void initBmx280()
void doSensorMeasurement()
var gateway = `ws://${window.location.hostname}/ws`;
var websocket;
var state = {};
var json = {};
function initWebSocket() opens a connection to the server
function onOpen(event) connection opened
function onClose(event) connection closed
function onMessage(event) message handler
function onLoad(event) page is loaded
function processFile(e) read a text file, break it into 512k chunks and send it to the server
function sendMessage(data, index) send a message to the server.