Makes MDNS optional by user setting

Makes WIFI AP optional by user setting
Tweaks ifdefs for double battery and charger settings
Updates platformio platform packages
This commit is contained in:
Paul Brand 2024-08-24 23:14:01 +02:00
parent ca07bb3b9d
commit 00e44ccf9a
6 changed files with 47 additions and 23 deletions

View file

@ -26,9 +26,15 @@
#include "src/datalayer/datalayer.h" #include "src/datalayer/datalayer.h"
#ifdef WEBSERVER #ifdef WEBSERVER
#include <ESPmDNS.h>
#include "src/devboard/webserver/webserver.h" #include "src/devboard/webserver/webserver.h"
#endif #ifdef MDNSRESPONDER
#include <ESPmDNS.h>
#endif // MDNSRESONDER
#else // WEBSERVER
#ifdef MDNSRESPONDER
#error WEBSERVER needs to be enabled for MDNSRESPONDER!
#endif // MDNSRSPONDER
#endif // WEBSERVER
Preferences settings; // Store user settings Preferences settings; // Store user settings
// The current software version, shown on webserver // The current software version, shown on webserver
@ -167,7 +173,9 @@ void loop() {
void connectivity_loop(void* task_time_us) { void connectivity_loop(void* task_time_us) {
// Init // Init
init_webserver(); init_webserver();
#ifdef MDNSRESPONDER
init_mDNS(); init_mDNS();
#endif
#ifdef MQTT #ifdef MQTT
init_mqtt(); init_mqtt();
#endif #endif
@ -286,7 +294,7 @@ void core_loop(void* task_time_us) {
} }
} }
#ifdef WEBSERVER #ifdef MDNSRESPONDER
// Initialise mDNS // Initialise mDNS
void init_mDNS() { void init_mDNS() {
@ -305,7 +313,7 @@ void init_mDNS() {
MDNS.addService("battery_emulator", "tcp", 80); MDNS.addService("battery_emulator", "tcp", 80);
} }
} }
#endif #endif // MDNSRESPONDER
// Initialization functions // Initialization functions
void init_serial() { void init_serial() {
@ -928,19 +936,19 @@ void receive_can(CAN_frame* rx_frame, int interface) {
if (interface == can_config.battery) { if (interface == can_config.battery) {
receive_can_battery(*rx_frame); receive_can_battery(*rx_frame);
} }
if (interface == can_config.inverter) {
#ifdef CAN_INVERTER_SELECTED #ifdef CAN_INVERTER_SELECTED
if (interface == can_config.inverter) {
receive_can_inverter(*rx_frame); receive_can_inverter(*rx_frame);
#endif
} }
if (interface == can_config.battery_double) { #endif
#ifdef DOUBLE_BATTERY #ifdef DOUBLE_BATTERY
if (interface == can_config.battery_double) {
receive_can_battery2(*rx_frame); receive_can_battery2(*rx_frame);
#endif
} }
if (interface == can_config.charger) { #endif
#ifdef CHARGER_SELECTED #ifdef CHARGER_SELECTED
if (interface == can_config.charger) {
receive_can_charger(*rx_frame); receive_can_charger(*rx_frame);
#endif
} }
#endif
} }

View file

@ -14,17 +14,22 @@ CAN_ADDON_FD_MCP2518 = Add-on CAN-FD MCP2518 connected to GPIO pins
volatile CAN_Configuration can_config = { volatile CAN_Configuration can_config = {
.battery = CAN_NATIVE, // Which CAN is your battery connected to? .battery = CAN_NATIVE, // Which CAN is your battery connected to?
.inverter = CAN_NATIVE, // Which CAN is your inverter connected to? (No need to configure incase you use RS485) .inverter = CAN_NATIVE, // Which CAN is your inverter connected to? (No need to configure incase you use RS485)
#ifdef DOUBLE_BATTERY
.battery_double = CAN_ADDON_MCP2515, // (OPTIONAL) Which CAN is your second battery connected to? .battery_double = CAN_ADDON_MCP2515, // (OPTIONAL) Which CAN is your second battery connected to?
.charger = CAN_NATIVE // (OPTIONAL) Which CAN is your charger connected to? #endif
#ifdef CHARGER_SELECTED
.charger = CAN_NATIVE // (OPTIONAL) Which CAN is your charger connected to?
#endif
}; };
#ifdef WEBSERVER #ifdef WEBSERVER
volatile uint8_t AccessPointEnabled = true; //Set to either true/false to enable direct wifi access point
std::string ssid = "REPLACE_WITH_YOUR_SSID"; // Maximum of 63 characters; std::string ssid = "REPLACE_WITH_YOUR_SSID"; // Maximum of 63 characters;
std::string password = "REPLACE_WITH_YOUR_PASSWORD"; // Minimum of 8 characters; std::string password = "REPLACE_WITH_YOUR_PASSWORD"; // Minimum of 8 characters;
const char* ssidAP = "Battery Emulator"; // Maximum of 63 characters; const char* ssidAP = "Battery Emulator"; // Maximum of 63 characters, also used for device name on web interface
#ifdef WIFIAP
const char* passwordAP = "123456789"; // Minimum of 8 characters; set to NULL if you want the access point to be open const char* passwordAP = "123456789"; // Minimum of 8 characters; set to NULL if you want the access point to be open
const uint8_t wifi_channel = 0; // Set to 0 for automatic channel selection #endif
const uint8_t wifi_channel = 0; // Set to 0 for automatic channel selection
// MQTT // MQTT
#ifdef MQTT #ifdef MQTT
const char* mqtt_user = "REDACTED"; const char* mqtt_user = "REDACTED";

View file

@ -54,6 +54,8 @@
//#define SERIAL_LINK_RECEIVER //Enable this line to receive battery data over RS485 pins from another Lilygo (This LilyGo interfaces with inverter) //#define SERIAL_LINK_RECEIVER //Enable this line to receive battery data over RS485 pins from another Lilygo (This LilyGo interfaces with inverter)
//#define SERIAL_LINK_TRANSMITTER //Enable this line to send battery data over RS485 pins to another Lilygo (This LilyGo interfaces with battery) //#define SERIAL_LINK_TRANSMITTER //Enable this line to send battery data over RS485 pins to another Lilygo (This LilyGo interfaces with battery)
#define WEBSERVER //Enable this line to enable WiFi, and to run the webserver. See USER_SETTINGS.cpp for the Wifi settings. #define WEBSERVER //Enable this line to enable WiFi, and to run the webserver. See USER_SETTINGS.cpp for the Wifi settings.
#define MDNSRESPONDER //Enable this line to enable MDNS, allows battery monitor te be found by .local address. Requires WEBSERVER to be enabled.
#define WIFIAP //Enable this line to make battery monitor create an wifi access point. When disabled make sure to hardcode wifi settings to make battery emulator connect to you home wifi.
#define LOAD_SAVED_SETTINGS_ON_BOOT //Enable this line to read settings stored via the webserver on boot (overrides Wifi/battery settings set below) #define LOAD_SAVED_SETTINGS_ON_BOOT //Enable this line to read settings stored via the webserver on boot (overrides Wifi/battery settings set below)
//#define FUNCTION_TIME_MEASUREMENT // Enable this to record execution times and present them in the web UI (WARNING, raises CPU load, do not use for production) //#define FUNCTION_TIME_MEASUREMENT // Enable this to record execution times and present them in the web UI (WARNING, raises CPU load, do not use for production)
@ -89,11 +91,14 @@ typedef enum { CAN_NATIVE = 0, CANFD_NATIVE = 1, CAN_ADDON_MCP2515 = 2, CAN_ADDO
typedef struct { typedef struct {
CAN_Interface battery; CAN_Interface battery;
CAN_Interface inverter; CAN_Interface inverter;
#ifdef DOUBLE_BATTERY
CAN_Interface battery_double; CAN_Interface battery_double;
#endif
#ifdef CHARGER_SELECTED
CAN_Interface charger; CAN_Interface charger;
#endif
} CAN_Configuration; } CAN_Configuration;
extern volatile CAN_Configuration can_config; extern volatile CAN_Configuration can_config;
extern volatile uint8_t AccessPointEnabled;
extern const uint8_t wifi_channel; extern const uint8_t wifi_channel;
extern volatile float charger_setpoint_HV_VDC; extern volatile float charger_setpoint_HV_VDC;
extern volatile float charger_setpoint_HV_IDC; extern volatile float charger_setpoint_HV_IDC;

View file

@ -37,12 +37,12 @@ unsigned long last_wifi_attempt_time = millis(); //init millis so wifi monitor
void init_webserver() { void init_webserver() {
// Configure WiFi // Configure WiFi
if (AccessPointEnabled) { #ifdef WIFIAP
WiFi.mode(WIFI_AP_STA); // Simultaneous WiFi AP and Router connection WiFi.mode(WIFI_AP_STA); // Simultaneous WiFi AP and Router connection
init_WiFi_AP(); init_WiFi_AP();
} else { #else
WiFi.mode(WIFI_STA); // Only Router connection WiFi.mode(WIFI_STA); // Only Router connection
} #endif
init_WiFi_STA(ssid.c_str(), password.c_str(), wifi_channel); init_WiFi_STA(ssid.c_str(), password.c_str(), wifi_channel);
String content = index_html; String content = index_html;
@ -286,6 +286,7 @@ void init_webserver() {
#endif #endif
} }
#ifdef WIFIAP
void init_WiFi_AP() { void init_WiFi_AP() {
#ifdef DEBUG_VIA_USB #ifdef DEBUG_VIA_USB
Serial.println("Creating Access Point: " + String(ssidAP)); Serial.println("Creating Access Point: " + String(ssidAP));
@ -299,6 +300,7 @@ void init_WiFi_AP() {
Serial.println(IP); Serial.println(IP);
#endif #endif
} }
#endif
String getConnectResultString(wl_status_t status) { String getConnectResultString(wl_status_t status) {
switch (status) { switch (status) {

View file

@ -23,7 +23,9 @@ extern std::string ssid;
extern std::string password; extern std::string password;
extern const uint8_t wifi_channel; extern const uint8_t wifi_channel;
extern const char* ssidAP; extern const char* ssidAP;
#ifdef WIFI_AP
extern const char* passwordAP; extern const char* passwordAP;
#endif
// Common charger parameters // Common charger parameters
extern float charger_stat_HVcur; extern float charger_stat_HVcur;
@ -54,6 +56,7 @@ void init_webserver();
*/ */
void wifi_monitor(); void wifi_monitor();
#ifdef WIFI_AP
/** /**
* @brief Initialization function that creates a WiFi Access Point. * @brief Initialization function that creates a WiFi Access Point.
* *
@ -62,6 +65,7 @@ void wifi_monitor();
* @return void * @return void
*/ */
void init_WiFi_AP(); void init_WiFi_AP();
#endif
/** /**
* @brief Initialization function that connects to an existing network. * @brief Initialization function that connects to an existing network.

View file

@ -14,8 +14,8 @@ src_dir = ./Software
[env:esp32dev] [env:esp32dev]
platform = espressif32 platform = espressif32
platform_packages= platform_packages=
framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#3.0.2 framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#3.0.4
framework-arduinoespressif32-libs @ https://github.com/espressif/arduino-esp32/releases/download/3.0.2/esp32-arduino-libs-3.0.2.zip framework-arduinoespressif32-libs @ https://github.com/espressif/arduino-esp32/releases/download/3.0.4/esp32-arduino-libs-3.0.4.zip
board = esp32dev board = esp32dev
monitor_speed = 115200 monitor_speed = 115200
monitor_filters = default, time, log2file monitor_filters = default, time, log2file