diff --git a/src/espmega_iot_core.cpp b/src/espmega_iot_core.cpp index 5714960..60fe25f 100644 --- a/src/espmega_iot_core.cpp +++ b/src/espmega_iot_core.cpp @@ -18,11 +18,9 @@ bool standalone = true; char MQTT_BASE_TOPIC[20]; uint8_t base_topic_length = 0; char STATE_REQUEST_TOPIC[40]; -// #define MQTT_USE_AUTH -#ifdef MQTT_USE_AUTH -const char MQTT_USERNAME[] = "username"; -const char MQTT_PASSWORD[] = "password"; -#endif +bool MQTT_USE_AUTH = false; +char MQTT_USERNAME[32]; +char MQTT_PASSWORD[32]; uint8_t utc_offset = 7; float current_room_temp = 0; float current_room_humid = 0; @@ -73,19 +71,22 @@ char AC_ROOM_TEMPERATURE_TOPIC[75]; char AC_HUMIDITY_TOPIC[75]; // EEPROM ADDRESS -#define EEPROM_ADDRESS_AC_MODE 0 // 01bytes -#define EEPROM_ADDRESS_AC_TEMPERATURE 1 // 01bytes -#define EEPROM_ADDRESS_AC_FAN_SPEED 2 // 01bytes -#define EEPROM_ADDRESS_PWM_STATE 3 // 16bytes, thru 18 -#define EEPROM_ADDRESS_PWM_VALUE 19 // 32bytes, thru 50 -#define EEPROM_ADDRESS_HOSTNAME 65 // 15bytes, thru 79 -#define EEPROM_ADDRESS_TOPIC 80 // 20bytes, thru 99 -#define EEPROM_ADDRESS_IP 100 // 04bytes, thru 103 -#define EEPROM_ADDRESS_SUBNET 104 // 04bytes, thru 107 -#define EEPROM_ADDRESS_GATEWAY 108 // 04bytes, thru 111 -#define EEPROM_ADDRESS_DNS 112 // 04bytes, thru 115 -#define EEPROM_ADDRESS_MQTT_SERVER 116 // 04bytes, thru 119 -#define EEPROM_ADDRESS_MQTT_PORT 120 // 02bytes, thru 121 +#define EEPROM_ADDRESS_AC_MODE 0 // 01bytes +#define EEPROM_ADDRESS_AC_TEMPERATURE 1 // 01bytes +#define EEPROM_ADDRESS_AC_FAN_SPEED 2 // 01bytes +#define EEPROM_ADDRESS_PWM_STATE 3 // 16bytes, thru 18 +#define EEPROM_ADDRESS_PWM_VALUE 19 // 32bytes, thru 50 +#define EEPROM_ADDRESS_HOSTNAME 65 // 15bytes, thru 79 +#define EEPROM_ADDRESS_TOPIC 80 // 20bytes, thru 99 +#define EEPROM_ADDRESS_IP 100 // 04bytes, thru 103 +#define EEPROM_ADDRESS_SUBNET 104 // 04bytes, thru 107 +#define EEPROM_ADDRESS_GATEWAY 108 // 04bytes, thru 111 +#define EEPROM_ADDRESS_DNS 112 // 04bytes, thru 115 +#define EEPROM_ADDRESS_MQTT_SERVER 116 // 04bytes, thru 119 +#define EEPROM_ADDRESS_MQTT_PORT 120 // 02bytes, thru 121 +#define EEPROM_ADDRESS_MQTT_USERNAME 122 // 32bytes, thru 153 +#define EEPROM_ADDRESS_MQTT_PASSWORD 154 // 32bytes, thru 185 +#define EEPROM_ADDRESS_MQTT_USEAUTH 186 // 1bytes char PWM_STATE_TOPIC[75]; char PWM_VALUE_TOPIC[75]; @@ -203,6 +204,9 @@ void eeprom_retrieve_init() MQTT_SERVER = eeprom_ip_retrieve(EEPROM_ADDRESS_MQTT_SERVER); eeprom_hostname_retrieve(); eeprom_mqtt_port_retrieve(); + eeprom_mqtt_useauth_retrieve(); + eeprom_mqtt_username_retrieve(); + eeprom_mqtt_password_retrieve(); mqtt_client.setServer(MQTT_SERVER, MQTT_PORT); eeprom_basetopic_retrieve(); base_topic_length = strlen(MQTT_BASE_TOPIC) + 1; @@ -1077,4 +1081,26 @@ uint8_t ac_get_mode() uint8_t ac_get_fan_speed() { return ac_fan_speed; +} + +void eeprom_mqtt_username_retrieve() { + ESPMega_FRAM.read(EEPROM_ADDRESS_MQTT_USERNAME, (uint8_t *)MQTT_USERNAME, 32); +} +void eeprom_mqtt_password_retrieve() { + ESPMega_FRAM.read(EEPROM_ADDRESS_MQTT_PASSWORD, (uint8_t *)MQTT_PASSWORD, 32); +} +void set_mqtt_username(String username) { + username.toCharArray(MQTT_USERNAME,32); + ESPMega_FRAM.write(EEPROM_ADDRESS_MQTT_USERNAME, (uint8_t *)MQTT_USERNAME, 20); +} +void set_mqtt_password(String password) { + password.toCharArray(MQTT_PASSWORD,32); + ESPMega_FRAM.write(EEPROM_ADDRESS_MQTT_PASSWORD, (uint8_t *)MQTT_PASSWORD, 20); +} +void eeprom_mqtt_useauth_retrieve() { + MQTT_USE_AUTH = ESPMega_FRAM.read8(EEPROM_ADDRESS_MQTT_USEAUTH); +} +void set_mqtt_useauth(bool use_auth) { + MQTT_USE_AUTH = use_auth; + ESPMega_FRAM.write8(EEPROM_ADDRESS_MQTT_USEAUTH, MQTT_USE_AUTH); } \ No newline at end of file diff --git a/src/espmega_iot_core.hpp b/src/espmega_iot_core.hpp index 6acc508..b19ace1 100644 --- a/src/espmega_iot_core.hpp +++ b/src/espmega_iot_core.hpp @@ -78,6 +78,7 @@ void trigger11(); void trigger12(); void trigger13(); void trigger14(); +void trigger15(); void eeprom_retrieve_init(); void eeprom_pwm_update(); @@ -97,4 +98,10 @@ void eeprom_hostname_retrieve(); void set_basetopic(String topic); void eeprom_basetopic_retrieve(); void mqtt_port_set(uint16_t port); -void eeprom_mqtt_port_retrieve(); \ No newline at end of file +void eeprom_mqtt_port_retrieve(); +void eeprom_mqtt_username_retrieve(); +void eeprom_mqtt_password_retrieve(); +void set_mqtt_username(String username); +void set_mqtt_password(String password); +void eeprom_mqtt_useauth_retrieve(); +void set_mqtt_useauth(bool use_auth); \ No newline at end of file diff --git a/src/ota_html/config.html b/src/ota_html/config.html index d5531ee..38bfdc3 100644 --- a/src/ota_html/config.html +++ b/src/ota_html/config.html @@ -17,7 +17,7 @@
BMS Server - Port
BMS Server - Username