saved
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
#include <HTTPClient.h> // Include the HTTPClient library for sending logs
|
||||
|
||||
// Version of the code
|
||||
//ver 0.0.11
|
||||
//ver 0.0.10
|
||||
|
||||
// Constants for Access Point mode
|
||||
const char* ap_ssid = "ESP32-AP"; // SSID for the Access Point mode
|
||||
@@ -37,7 +37,7 @@ void sendLog(String message) {
|
||||
String url = "http://" + logServerIP + ":" + logServerPort + "/log";
|
||||
http.begin(url);
|
||||
http.addHeader("Content-Type", "application/json");
|
||||
String payload = "{\"hostname\": \"" + hostname + "\", \"message\": \"" + message + "\"}";
|
||||
String payload = "{\"hostname\": \"" + hostname + "\", \"status\": \"online\", \"message\": \"" + message + "\"}";
|
||||
int httpResponseCode = http.POST(payload);
|
||||
http.end();
|
||||
if (httpResponseCode > 0) {
|
||||
@@ -48,6 +48,16 @@ void sendLog(String message) {
|
||||
}
|
||||
}
|
||||
|
||||
// Log the status of the board and the status of each input and relay
|
||||
void logBoardStatus() {
|
||||
String message = "Board started. Status of inputs and relays:\n";
|
||||
for (int i = 0; i < 4; i++) {
|
||||
message += "Relay " + String(i + 1) + ": " + (digitalRead(relayPins[i]) == HIGH ? "ON" : "OFF") + "\n";
|
||||
message += "Input " + String(i + 1) + ": " + (digitalRead(inputPins[i]) == LOW ? "Pressed" : "Not Pressed") + "\n";
|
||||
}
|
||||
sendLog(message);
|
||||
}
|
||||
|
||||
// Handle the root URL ("/") and serve the configuration page
|
||||
void handleRoot() {
|
||||
// Get the default MAC address of the ESP32
|
||||
@@ -275,6 +285,7 @@ void setup() {
|
||||
}
|
||||
}
|
||||
Serial.println("Setup completed");
|
||||
logBoardStatus(); // Log the status of the board at startup
|
||||
}
|
||||
|
||||
void loop() {
|
||||
@@ -371,16 +382,3 @@ String getDefaultMacAddress() {
|
||||
return mac;
|
||||
}
|
||||
|
||||
// Get the MAC address of a specific interface
|
||||
String getInterfaceMacAddress(esp_mac_type_t interface) {
|
||||
String mac = "";
|
||||
unsigned char mac_base[6] = {0};
|
||||
|
||||
if (esp_read_mac(mac_base, interface) == ESP_OK) {
|
||||
char buffer[18]; // 6*2 characters for hex + 5 characters for colons + 1 character for null terminator
|
||||
sprintf(buffer, "%02X:%02X:%02X:%02X:%02X:%02X", mac_base[0], mac_base[1], mac_base[2], mac_base[3], mac_base[4], mac_base[5]);
|
||||
mac = buffer;
|
||||
}
|
||||
|
||||
return mac;
|
||||
}
|
||||
Reference in New Issue
Block a user