Merge branch 'main' into iot-ay2023

This commit is contained in:
Siwat Sirichai 2023-11-07 19:38:18 +07:00
commit c4c9d8d6ed
28 changed files with 948 additions and 211 deletions

View File

@ -13,6 +13,8 @@
"type_traits": "cpp", "type_traits": "cpp",
"utility": "cpp", "utility": "cpp",
"*.d": "cpp", "*.d": "cpp",
"*.html": "cpp" "*.html": "cpp",
"*.tcc": "cpp",
"regex": "cpp"
} }
} }

View File

@ -18,11 +18,9 @@ bool standalone = true;
char MQTT_BASE_TOPIC[20]; char MQTT_BASE_TOPIC[20];
uint8_t base_topic_length = 0; uint8_t base_topic_length = 0;
char STATE_REQUEST_TOPIC[40]; char STATE_REQUEST_TOPIC[40];
// #define MQTT_USE_AUTH bool MQTT_USE_AUTH = false;
#ifdef MQTT_USE_AUTH char MQTT_USERNAME[32];
const char MQTT_USERNAME[] = "username"; char MQTT_PASSWORD[32];
const char MQTT_PASSWORD[] = "password";
#endif
uint8_t utc_offset = 7; uint8_t utc_offset = 7;
float current_room_temp = 0; float current_room_temp = 0;
float current_room_humid = 0; float current_room_humid = 0;
@ -73,19 +71,22 @@ char AC_ROOM_TEMPERATURE_TOPIC[75];
char AC_HUMIDITY_TOPIC[75]; char AC_HUMIDITY_TOPIC[75];
// EEPROM ADDRESS // EEPROM ADDRESS
#define EEPROM_ADDRESS_AC_MODE 0 // 01bytes #define EEPROM_ADDRESS_AC_MODE 0 // 01bytes
#define EEPROM_ADDRESS_AC_TEMPERATURE 1 // 01bytes #define EEPROM_ADDRESS_AC_TEMPERATURE 1 // 01bytes
#define EEPROM_ADDRESS_AC_FAN_SPEED 2 // 01bytes #define EEPROM_ADDRESS_AC_FAN_SPEED 2 // 01bytes
#define EEPROM_ADDRESS_PWM_STATE 3 // 16bytes, thru 18 #define EEPROM_ADDRESS_PWM_STATE 3 // 16bytes, thru 18
#define EEPROM_ADDRESS_PWM_VALUE 19 // 32bytes, thru 50 #define EEPROM_ADDRESS_PWM_VALUE 19 // 32bytes, thru 50
#define EEPROM_ADDRESS_HOSTNAME 65 // 15bytes, thru 79 #define EEPROM_ADDRESS_HOSTNAME 65 // 15bytes, thru 79
#define EEPROM_ADDRESS_TOPIC 80 // 20bytes, thru 99 #define EEPROM_ADDRESS_TOPIC 80 // 20bytes, thru 99
#define EEPROM_ADDRESS_IP 100 // 04bytes, thru 103 #define EEPROM_ADDRESS_IP 100 // 04bytes, thru 103
#define EEPROM_ADDRESS_SUBNET 104 // 04bytes, thru 107 #define EEPROM_ADDRESS_SUBNET 104 // 04bytes, thru 107
#define EEPROM_ADDRESS_GATEWAY 108 // 04bytes, thru 111 #define EEPROM_ADDRESS_GATEWAY 108 // 04bytes, thru 111
#define EEPROM_ADDRESS_DNS 112 // 04bytes, thru 115 #define EEPROM_ADDRESS_DNS 112 // 04bytes, thru 115
#define EEPROM_ADDRESS_MQTT_SERVER 116 // 04bytes, thru 119 #define EEPROM_ADDRESS_MQTT_SERVER 116 // 04bytes, thru 119
#define EEPROM_ADDRESS_MQTT_PORT 120 // 02bytes, thru 121 #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_STATE_TOPIC[75];
char PWM_VALUE_TOPIC[75]; char PWM_VALUE_TOPIC[75];
@ -122,6 +123,7 @@ void setup()
lcd_send_stop_bit(); lcd_send_stop_bit();
lcd_init(); lcd_init();
lcd_begin(); lcd_begin();
check_boot_reset();
#ifdef ENABLE_EXTERNAL_LCD #ifdef ENABLE_EXTERNAL_LCD
Serial2.print("rest"); Serial2.print("rest");
Serial2.write(0xFF); Serial2.write(0xFF);
@ -136,6 +138,8 @@ void setup()
lcd_send_command("boot_state.txt=\"Network Initializing . . .\""); lcd_send_command("boot_state.txt=\"Network Initializing . . .\"");
network_begin(); network_begin();
lcd_send_command("boot_state.txt=\"IoT Core Initializing . . .\""); lcd_send_command("boot_state.txt=\"IoT Core Initializing . . .\"");
mqtt_client.setSocketTimeout(1000);
eth.setTimeout(1);
mqtt_connect(); mqtt_connect();
lcd_send_command("boot_state.txt=\"Threads Initializing . . .\""); lcd_send_command("boot_state.txt=\"Threads Initializing . . .\"");
thread_initialization(); thread_initialization();
@ -203,6 +207,9 @@ void eeprom_retrieve_init()
MQTT_SERVER = eeprom_ip_retrieve(EEPROM_ADDRESS_MQTT_SERVER); MQTT_SERVER = eeprom_ip_retrieve(EEPROM_ADDRESS_MQTT_SERVER);
eeprom_hostname_retrieve(); eeprom_hostname_retrieve();
eeprom_mqtt_port_retrieve(); eeprom_mqtt_port_retrieve();
eeprom_mqtt_useauth_retrieve();
eeprom_mqtt_username_retrieve();
eeprom_mqtt_password_retrieve();
mqtt_client.setServer(MQTT_SERVER, MQTT_PORT); mqtt_client.setServer(MQTT_SERVER, MQTT_PORT);
eeprom_basetopic_retrieve(); eeprom_basetopic_retrieve();
base_topic_length = strlen(MQTT_BASE_TOPIC) + 1; base_topic_length = strlen(MQTT_BASE_TOPIC) + 1;
@ -241,13 +248,81 @@ void ota_begin()
otaserver.on("/", HTTP_GET, []() otaserver.on("/", HTTP_GET, []()
{ {
otaserver.sendHeader("Connection", "close"); otaserver.sendHeader("Connection", "close");
String otabuffer = ota_part1+HOSTNAME+ota_part2+IP.toString()+ota_part3+ETH.macAddress()+ota_part4+ESPMEGA_REV+ota_part5+MQTT_SERVER.toString()+ota_part6+String(MQTT_BASE_TOPIC)+ota_part7; String otabuffer = ota_part1;
otabuffer+=ota_part2_1+"Hostname"+ota_part2_2+String(HOSTNAME)+ota_part2_3;
otabuffer+=ota_part2_1+"IP Address"+ota_part2_2+IP.toString()+ota_part2_3;
otabuffer+=ota_part2_1+"MAC Address"+ota_part2_2+ETH.macAddress()+ota_part2_3;
otabuffer+=ota_part2_1+"Device"+ota_part2_2+ESPMEGA_REV+ota_part2_3;
otabuffer+=ota_part2_1+"BMS Server"+ota_part2_2+MQTT_SERVER.toString()+ota_part2_3;
otabuffer+=ota_part2_1+"BMS Endpoint"+ota_part2_2+String(MQTT_BASE_TOPIC)+ota_part2_3;
otabuffer+=ota_part2_1+"Centrally Managed"+ota_part2_2;
if(standalone) if(standalone)
otabuffer+=String("No"); otabuffer+=String("No");
else else
otabuffer+=String("Yes"); otabuffer+=String("Yes");
otabuffer+=ota_part8; otabuffer+=ota_part2_3+ota_part3;
otaserver.send(200, "text/html", otabuffer); }); otaserver.send(200, "text/html", otabuffer); });
otaserver.on("/config", HTTP_GET, []()
{
otaserver.sendHeader("Connection", "close");
String configbuffer = config_part1;
configbuffer+=config_txt_part1+"IP Address"+config_txt_part2+"text"+config_txt_part3+"dev_ip"+config_txt_part4+"dev_ip"+config_txt_part5+IP.toString()+config_txt_part6;
configbuffer+=config_txt_part1+"Network Mask"+config_txt_part2+"text"+config_txt_part3+"netmask"+config_txt_part4+"netmask"+config_txt_part5+SUBNET.toString()+config_txt_part6;
configbuffer+=config_txt_part1+"Gateway"+config_txt_part2+"text"+config_txt_part3+"gateway"+config_txt_part4+"gateway"+config_txt_part5+GATEWAY.toString()+config_txt_part6;
configbuffer+=config_txt_part1+"DNS Server"+config_txt_part2+"text"+config_txt_part3+"dns"+config_txt_part4+"dns"+config_txt_part5+DNS.toString()+config_txt_part6;
configbuffer+=config_txt_part1+"Hostname"+config_txt_part2+"text"+config_txt_part3+"hostname"+config_txt_part4+"hostname"+config_txt_part5+String(HOSTNAME)+config_txt_part6;
configbuffer+=config_txt_part1+"BMS Server - IP Address"+config_txt_part2+"text"+config_txt_part3+"bms_ip"+config_txt_part4+"bms_ip"+config_txt_part5+MQTT_SERVER.toString()+config_txt_part6;
configbuffer+=config_txt_part1+"BMS Server - Port"+config_txt_part2+"text"+config_txt_part3+"bms_port"+config_txt_part4+"bms_port"+config_txt_part5+String(MQTT_PORT)+config_txt_part6;
configbuffer+=config_auth_part1+(MQTT_USE_AUTH?"checked=\"checked\"":"")+config_auth_part2;
configbuffer+=config_txt_part1+"BMS Server - Username"+config_txt_part2+"text"+config_txt_part3+"bms_username"+config_txt_part4+"bms_username"+config_txt_part5+String(MQTT_USERNAME)+config_txt_part6;
configbuffer+=config_txt_part1+"BMS Server - Password"+config_txt_part2+"password"+config_txt_part3+"bms_password"+config_txt_part4+"bms_password"+config_txt_part5+String(MQTT_PASSWORD)+config_txt_part6;
configbuffer+=config_txt_part1+"BMS Server - Endpoint"+config_txt_part2+"text"+config_txt_part3+"bms_endpoint"+config_txt_part4+"bms_endpoint"+config_txt_part5+String(MQTT_BASE_TOPIC)+config_txt_part6;
configbuffer+=config_part2;
otaserver.send(200, "text/html", configbuffer); });
otaserver.on("/save_config", HTTP_GET, []()
{
otaserver.sendHeader("Connection", "close");
String configbuffer = "Configuration Saved. Rebooting . . .";
otaserver.send(200, "text/html", configbuffer);
bool use_auth = false;
for(int i=0;i<otaserver.args();i++) {
String arg = otaserver.argName(i);
String value = otaserver.arg(i);
if(!arg.compareTo("dev_ip")) {
set_ip(value);
} else if(!arg.compareTo("netmask")) {
set_netmask(value);
} else if(!arg.compareTo("gateway")) {
set_gw(value);
} else if(!arg.compareTo("dns")) {
set_dns(value);
} else if(!arg.compareTo("hostname")) {
set_hostname(value);
} else if(!arg.compareTo("bms_ip")) {
set_mqtt_server(value);
} else if(!arg.compareTo("bms_username")) {
set_mqtt_username(value);
}else if(!arg.compareTo("bms_port")) {
uint16_t port = value.toInt();
mqtt_port_set(port);
}else if(!arg.compareTo("bms_endpoint")) {
set_basetopic(value);
}
else if(!arg.compareTo("bms_password")) {
set_mqtt_password(value);
} else if(!arg.compareTo("bms_useauth")) {
if(!value.compareTo("yes"))
use_auth = true;
}
}
set_mqtt_useauth(use_auth);
otaserver.send(200, "text/html", configbuffer);
delay(500);
ESP.restart();
});
otaserver.on( otaserver.on(
"/update", HTTP_POST, []() "/update", HTTP_POST, []()
{ {
@ -345,11 +420,10 @@ void mqtt_connect()
{ {
Serial.print("MQTT not connected, connecting . . .\n"); Serial.print("MQTT not connected, connecting . . .\n");
lcd_send_stop_bit(); lcd_send_stop_bit();
#ifdef MQTT_USE_AUTH if (MQTT_USE_AUTH)
mqtt_client.connect(HOSTNAME, MQTT_USERNAME, MQTT_PASSWORD); mqtt_client.connect(HOSTNAME, MQTT_USERNAME, MQTT_PASSWORD);
#else else
mqtt_client.connect(HOSTNAME); mqtt_client.connect(HOSTNAME);
#endif
if (mqtt_client.connected()) if (mqtt_client.connected())
{ {
mqtt_subscribe(); mqtt_subscribe();
@ -360,6 +434,7 @@ void mqtt_connect()
publish_ac_state(); publish_ac_state();
mqtt_connected_user_callback(); mqtt_connected_user_callback();
standalone = false; standalone = false;
ESPMega_updateTimeFromNTP();
} }
else else
{ {
@ -831,10 +906,15 @@ void lcd_refresh()
panel.writeStr("netmask_set.txt", SUBNET.toString()); panel.writeStr("netmask_set.txt", SUBNET.toString());
panel.writeStr("gateway_set.txt", GATEWAY.toString()); panel.writeStr("gateway_set.txt", GATEWAY.toString());
panel.writeStr("dns_set.txt", DNS.toString()); panel.writeStr("dns_set.txt", DNS.toString());
panel.writeStr("mqttsv_set.txt", MQTT_SERVER.toString());
panel.writeStr("host_set.txt", HOSTNAME); panel.writeStr("host_set.txt", HOSTNAME);
break;
case 11:
panel.writeStr("mqttsv_set.txt", MQTT_SERVER.toString());
panel.writeNum("port_set.val", MQTT_PORT); panel.writeNum("port_set.val", MQTT_PORT);
panel.writeStr("topic_set.txt", MQTT_BASE_TOPIC); panel.writeStr("topic_set.txt", MQTT_BASE_TOPIC);
panel.writeStr("user_set.txt", MQTT_USERNAME);
panel.writeStr("password_set.txt", MQTT_PASSWORD);
panel.writeNum("use_auth.val", MQTT_USE_AUTH);
break; break;
default: default:
break; break;
@ -949,20 +1029,30 @@ void trigger13()
set_netmask(panel.readStr("netmask_set.txt")); set_netmask(panel.readStr("netmask_set.txt"));
set_gw(panel.readStr("gateway_set.txt")); set_gw(panel.readStr("gateway_set.txt"));
set_dns(panel.readStr("dns_set.txt")); set_dns(panel.readStr("dns_set.txt"));
set_mqtt_server(panel.readStr("mqttsv_set.txt"));
set_hostname(panel.readStr("host_set.txt")); set_hostname(panel.readStr("host_set.txt"));
set_basetopic(panel.readStr("topic_set.txt"));
uint16_t port = panel.readNumber("port_set.val");
mqtt_port_set(port);
delay(100); delay(100);
ESP.restart(); ESP.restart();
} }
void trigger14() { void trigger14()
{
Serial.print("page dashboard"); Serial.print("page dashboard");
lcd_send_stop_bit(); lcd_send_stop_bit();
} }
void trigger15()
{
set_mqtt_server(panel.readStr("mqttsv_set.txt"));
set_basetopic(panel.readStr("topic_set.txt"));
uint16_t port = panel.readNumber("port_set.val");
mqtt_port_set(port);
set_mqtt_useauth(panel.readNumber("use_auth.val"));
set_mqtt_username(panel.readStr("user_set.txt"));
set_mqtt_password(panel.readStr("password_set.txt"));
delay(100);
ESP.restart();
}
void eeprom_pwm_update() void eeprom_pwm_update()
{ {
if (memcmp(pwm_states, pwm_states_eeprom, 16)) if (memcmp(pwm_states, pwm_states_eeprom, 16))
@ -1078,3 +1168,63 @@ uint8_t ac_get_fan_speed()
{ {
return ac_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);
}
void factory_reset() {
for(int i=5;i>0;i--) {
if(digitalRead(2)==HIGH) {
lcd_send_command("boot_state.txt=\"Factory Reset Canceled, Restarting\"");
delay(5000);
ESP.restart();
}
Serial.printf("boot_state.txt=\"Factory Reset in %d\"",i);
lcd_send_stop_bit();
delay(1000);
}
lcd_send_command("boot_state.txt=\"Factory Reseting . . .\"");
// Format FRAM
for(int i=0;i<32768;i++) {
ESPMega_FRAM.write8(i,0);
}
// Load Default Values
set_ip("192.168.0.10");
set_gw("192.168.0.1");
// Reboot
lcd_send_stop_bit();
lcd_send_command("boot_state.txt=\"Factory Reset OK. Release Button.\"");
delay(3000);
ESP.restart();
}
void check_boot_reset() {
pinMode(2, INPUT_PULLUP);
if(digitalRead(2)==LOW) {
factory_reset();
}
}

View File

@ -78,6 +78,7 @@ void trigger11();
void trigger12(); void trigger12();
void trigger13(); void trigger13();
void trigger14(); void trigger14();
void trigger15();
void eeprom_retrieve_init(); void eeprom_retrieve_init();
void eeprom_pwm_update(); void eeprom_pwm_update();
@ -98,3 +99,12 @@ void set_basetopic(String topic);
void eeprom_basetopic_retrieve(); void eeprom_basetopic_retrieve();
void mqtt_port_set(uint16_t port); void mqtt_port_set(uint16_t port);
void eeprom_mqtt_port_retrieve(); 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);
void factory_reset();
void check_boot_reset();

View File

@ -3,24 +3,46 @@
const String ota_part1 = { const String ota_part1 = {
#include "ota_html/ota-part1.html" #include "ota_html/ota-part1.html"
}; };
const String ota_part2 = { const String ota_part2_1 = {
#include "ota_html/ota-part2.html" #include "ota_html/ota-part2-1_itr.html"
};
const String ota_part2_2 = {
#include "ota_html/ota-part2-2_itr.html"
};
const String ota_part2_3 = {
#include "ota_html/ota-part2-3_itr.html"
}; };
const String ota_part3 = { const String ota_part3 = {
#include "ota_html/ota-part3.html" #include "ota_html/ota-part3.html"
}; };
const String ota_part4 = {
#include "ota_html/ota-part4.html" const String config_part1 = {
#include "ota_html/config-part1.html"
}; };
const String ota_part5 = { const String config_part2 = {
#include "ota_html/ota-part5.html" #include "ota_html/config-part2.html"
}; };
const String ota_part6 = { const String config_txt_part1 = {
#include "ota_html/ota-part6.html" #include "ota_html/config-textfield-part1.html"
}; };
const String ota_part7 = { const String config_txt_part2 = {
#include "ota_html/ota-part7.html" #include "ota_html/config-textfield-part2.html"
}; };
const String ota_part8 = { const String config_txt_part3 = {
#include "ota_html/ota-part8.html" #include "ota_html/config-textfield-part3.html"
};
const String config_txt_part4 = {
#include "ota_html/config-textfield-part4.html"
};
const String config_txt_part5 = {
#include "ota_html/config-textfield-part5.html"
};
const String config_txt_part6 = {
#include "ota_html/config-textfield-part6.html"
};
const String config_auth_part1 = {
#include "ota_html/config-auth-part1.html"
};
const String config_auth_part2 = {
#include "ota_html/config-auth-part2.html"
}; };

View File

@ -1,10 +1,17 @@
#pragma once #pragma once
#include <ESPMegaPRO.h> #include <ESPMegaPRO.h>
extern const String ota_part1; extern const String ota_part1;
extern const String ota_part2; extern const String ota_part2_1;
extern const String ota_part2_2;
extern const String ota_part2_3;
extern const String ota_part3; extern const String ota_part3;
extern const String ota_part4; extern const String config_part1;
extern const String ota_part5; extern const String config_part2;
extern const String ota_part6; extern const String config_txt_part1;
extern const String ota_part7; extern const String config_txt_part2;
extern const String ota_part8; extern const String config_txt_part3;
extern const String config_txt_part4;
extern const String config_txt_part5;
extern const String config_txt_part6;
extern const String config_auth_part1;
extern const String config_auth_part2;

View File

@ -0,0 +1,2 @@
R"=====(<label class="container">Authentication
<input type="checkbox" name="bms_useauth" id="bms_useauth" )====="

View File

@ -0,0 +1,3 @@
R"=====( value="yes">
<span class="checkmark"></span>
</label>)====="

View File

@ -0,0 +1,4 @@
R"=====(<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<form enctype="multipart/form-data" id="config_form" onsubmit="send_config()" action="/save_config">
<h1>ESPMega PRO</h1>
<h3>Device Configurations</h3>)====="

View File

@ -0,0 +1,167 @@
R"=====( <input type="submit" class="btn" value="Save">
<button type="button" class="conf" onclick="window.location.href='/'">Back</button><br /><br />
<b>SIWAT SYSTEM 2023</b>
</form>
<style>
p.config_title {
font-size: 12;
font-weight: bold;
text-align: left;
align-self: left;
margin-bottom: 0;
margin-top: 0;
}
hr {
display: block;
color: #aaaaaa;
background-color: #aaaaaa;
margin-top: 0.5em;
margin-bottom: 0.5em;
margin-left: auto;
margin-right: auto;
border-style: inset;
border-width: 0px;
height: 3px;
}
#file-input,
input {
width: 100%;
height: 44px;
border-radius: 4px;
margin: 10px auto;
font-size: 15px;
}
input {
background: #f1f1f1;
border: 0;
padding: 0 15px;
}
body {
background-image: url("https://fs.siwatsystem.com/arona_bg.png");
background-size: cover;
font-family: sans-serif;
font-size: 14px;
color: #777;
}
#file-input {
background-color: #CCCCCC;
color: #5E5E5E;
padding: 0;
border: 1px solid #ddd;
line-height: 44px;
text-align: center;
display: block;
cursor: pointer;
}
#bar,
#prgbar {
background-color: #D9D9D9;
border-radius: 10px;
}
#bar {
background-color: #29CD1F;
width: 0%;
height: 10px;
}
form {
background: rgba(255, 255, 255, 0.95);
max-width: 258px;
margin: 75px auto;
padding: 30px;
border-radius: 15px;
text-align: center;
}
.btn {
background: #CA3D3D;
color: #fff;
cursor: pointer;
}
.conf {
background: #417df3;
color: #fff;
cursor: pointer;
width: 100%;
height: 44px;
border-radius: 4px;
margin: 10px auto;
font-size: 15px;
border: 0;
}
.conf_txt {
background-color: #e2e2e2;
}
.checkbox {
size: 4;
display: inline-block;
}
.container {
display: block;
position: relative;
padding-left: 0px;
margin-bottom: 12px;
cursor: pointer;
font-size: 20px;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.container input {
position: absolute;
opacity: 0;
cursor: pointer;
height: 0;
width: 0;
}
.checkmark {
position: absolute;
top: 0;
left: 0;
height: 25px;
width: 25px;
background-color: #eee;
}
.container:hover input ~ .checkmark {
background-color: #ccc;
}
.container input:checked ~ .checkmark {
background-color: #2196F3;
}
.checkmark:after {
content: "";
position: absolute;
display: none;
}
.container input:checked ~ .checkmark:after {
display: block;
}
.container .checkmark:after {
left: 9px;
top: 5px;
width: 5px;
height: 10px;
border: solid white;
border-width: 0 3px 3px 0;
-webkit-transform: rotate(45deg);
-ms-transform: rotate(45deg);
transform: rotate(45deg);
}
</style>)====="

View File

@ -0,0 +1 @@
R"=====(<p class="config_title">)====="

View File

@ -0,0 +1,2 @@
R"=====(</p>
<input type=")====="

View File

@ -0,0 +1 @@
R"=====(" id=")====="

View File

@ -0,0 +1 @@
R"=====(" name=")====="

View File

@ -0,0 +1 @@
R"=====(" class="conf_txt" value=")====="

View File

@ -0,0 +1 @@
R"=====("><br>)====="

198
src/ota_html/config.html Normal file
View File

@ -0,0 +1,198 @@
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<form enctype="multipart/form-data" id="config_form" onsubmit="send_config()" action="/save_config">
<h1>ESPMega PRO</h1>
<h3>Device Configurations</h3>
<p class="config_title">IP Address</p>
<input type="text" id="dev_ip" name="dev_ip" class="conf_txt" value="0.0.0.0"><br>
<p class="config_title">Network Mask</p>
<input type="text" id="netmask" name="netmask" class="conf_txt" value="0.0.0.0"><br>
<p class="config_title">Gateway</p>
<input type="text" id="gateway" name="gateway" class="conf_txt" value="0.0.0.0"><br>
<p class="config_title">DNS Server</p>
<input type="text" id="dns" name="dns" class="conf_txt" value="0.0.0.0"><br>
<p class="config_title">Hostname</p>
<input type="text" id="hostname" name="hostname" class="conf_txt" value="ESPMegaPRO"><br>
<p class="config_title">BMS Server - IP Address</p>
<input type="text" id="bms_ip" name="bms_ip" class="conf_txt" value="0.0.0.0"><br>
<p class="config_title">BMS Server - Port</p>
<input type="text" id="bms_port" name="bms_port" class="conf_txt" value="1883"><br>
<label class="container">Authentication
<input type="checkbox" name="bms_useauth" id="bms_useauth" checked="checked" value="yes">
<span class="checkmark"></span>
</label>
<p class="config_title">BMS Server - Username</p>
<input type="text" id="bms_username" name="bms_username" class="conf_txt" value="user"><br>
<p class="config_title">BMS Server - Password</p>
<input type="password" id="bms_password" name="bms_password" class="conf_txt" value="password"><br>
<p class="config_title">BMS Server - Endpoint</p>
<input type="text" id="bms_endpoint" name="bms_endpoint" class="conf_txt" value="/espmegapro"><br>
<input type="submit" class="btn" value="Save">
<button type="button" class="conf" onclick="window.location.href='/'">Back</button><br /><br />
<b>SIWAT SYSTEM 2023</b>
</form>
<style>
p.config_title {
font-size: 12;
font-weight: bold;
text-align: left;
align-self: left;
margin-bottom: 0;
margin-top: 0;
}
hr {
display: block;
color: #aaaaaa;
background-color: #aaaaaa;
margin-top: 0.5em;
margin-bottom: 0.5em;
margin-left: auto;
margin-right: auto;
border-style: inset;
border-width: 0px;
height: 3px;
}
#file-input,
input {
width: 100%;
height: 44px;
border-radius: 4px;
margin: 10px auto;
font-size: 15px;
}
input {
background: #f1f1f1;
border: 0;
padding: 0 15px;
}
body {
background-image: url("https://fs.siwatsystem.com/arona_bg.png");
background-size: cover;
font-family: sans-serif;
font-size: 14px;
color: #777;
}
#file-input {
background-color: #CCCCCC;
color: #5E5E5E;
padding: 0;
border: 1px solid #ddd;
line-height: 44px;
text-align: center;
display: block;
cursor: pointer;
}
#bar,
#prgbar {
background-color: #D9D9D9;
border-radius: 10px;
}
#bar {
background-color: #29CD1F;
width: 0%;
height: 10px;
}
form {
background: rgba(255, 255, 255, 0.95);
max-width: 258px;
margin: 75px auto;
padding: 30px;
border-radius: 15px;
text-align: center;
}
.btn {
background: #CA3D3D;
color: #fff;
cursor: pointer;
}
.conf {
background: #417df3;
color: #fff;
cursor: pointer;
width: 100%;
height: 44px;
border-radius: 4px;
margin: 10px auto;
font-size: 15px;
border: 0;
}
.conf_txt {
background-color: #e2e2e2;
}
.checkbox {
size: 4;
display: inline-block;
}
.container {
display: block;
position: relative;
padding-left: 0px;
margin-bottom: 12px;
cursor: pointer;
font-size: 20px;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.container input {
position: absolute;
opacity: 0;
cursor: pointer;
height: 0;
width: 0;
}
.checkmark {
position: absolute;
top: 0;
left: 0;
height: 25px;
width: 25px;
background-color: #eee;
}
.container:hover input ~ .checkmark {
background-color: #ccc;
}
.container input:checked ~ .checkmark {
background-color: #2196F3;
}
.checkmark:after {
content: "";
position: absolute;
display: none;
}
.container input:checked ~ .checkmark:after {
display: block;
}
.container .checkmark:after {
left: 9px;
top: 5px;
width: 5px;
height: 10px;
border: solid white;
border-width: 0 3px 3px 0;
-webkit-transform: rotate(45deg);
-ms-transform: rotate(45deg);
transform: rotate(45deg);
}
</style>

View File

@ -1,8 +1,4 @@
R"=====(<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> R"=====(<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<form method="POST" action="#" enctype="multipart/form-data" id="upload_form"> <form method="POST" action="#" enctype="multipart/form-data" id="upload_form">
<h1>ESPMega PRO</h1> <h1>ESPMega PRO</h1>
<h3>Software Management</h3> <h3>Device Information</h3>)====="
<p style="text-align: left">
Hostname
<span style="float: right">)====="

View File

@ -0,0 +1 @@
R"=====(<p style="text-align: left">)====="

View File

@ -0,0 +1 @@
R"=====(<span style="float: right">)====="

View File

@ -0,0 +1,2 @@
R"=====(</span>
</p>)====="

View File

@ -1,5 +0,0 @@
R"=====(</span>
</p>
<p style="text-align: left">
IP Address
<span style="float: right">)====="

View File

@ -1,5 +1,144 @@
R"=====(</span> R"=====(<button type="button" class="conf" onclick="window.location.href='config'">Settings</button><br /><br />
</p> <hr>
<p style="text-align: left"> <h3>Upload Software Package</h3>
MAC Address <input type="file" name="update" id="file" onchange="sub(this)" style="display: none" />
<span style="float: right">)=====" <label id="file-input" for="file">Choose file...</label>
<input type="submit" class="btn" value="Program" /><br /><br />
<div id="prg"></div>
<br />
<div id="prgbar">
<div id="bar"></div>
</div>
<br />
<b>SIWAT SYSTEM 2023</b>
</form>
<script>
function sub(obj) {
var fileName = obj.value.split("\\");
document.getElementById("file-input").innerHTML =
" " + fileName[fileName.length - 1];
}
$("form").submit(function (e) {
e.preventDefault();
var form = $("#upload_form")[0];
var data = new FormData(form);
$.ajax({
url: "/update",
type: "POST",
data: data,
contentType: false,
processData: false,
xhr: function () {
var xhr = new window.XMLHttpRequest();
xhr.upload.addEventListener(
"progress",
function (evt) {
if (evt.lengthComputable) {
var per = evt.loaded / evt.total;
if (Math.round(per * 100) < 100) {
$("#prg").html("Updating . . . (" + Math.round(per * 100) + "%)");
}
else {
$("#prg").html("Update Completed, Rebooting . . .");
}
$("#bar").css("width", Math.round(per * 100) + "%");
}
},
false
);
return xhr;
},
success: function (d, s) {
console.log("success!");
},
error: function (a, b, c) { },
});
});
</script>
<style>
hr {
display: block;
color: #aaaaaa;
background-color: #aaaaaa;
margin-top: 0.5em;
margin-bottom: 0.5em;
margin-left: auto;
margin-right: auto;
border-style: inset;
border-width: 0px;
height: 3px;
}
#file-input,
input {
width: 100%;
height: 44px;
border-radius: 4px;
margin: 10px auto;
font-size: 15px;
}
input {
background: #f1f1f1;
border: 0;
padding: 0 15px;
}
body {
background-image: url("https://fs.siwatsystem.com/arona_bg.png");
background-size: cover;
font-family: sans-serif;
font-size: 14px;
color: #777;
}
#file-input {
background-color: #CCCCCC;
color: #5E5E5E;
padding: 0;
border: 1px solid #ddd;
line-height: 44px;
text-align: center;
display: block;
cursor: pointer;
}
#bar,
#prgbar {
background-color: #D9D9D9;
border-radius: 10px;
}
#bar {
background-color: #29CD1F;
width: 0%;
height: 10px;
}
form {
background: rgba(255, 255, 255, 0.95);
max-width: 258px;
margin: 75px auto;
padding: 30px;
border-radius: 15px;
text-align: center;
}
.btn {
background: #CA3D3D;
color: #fff;
cursor: pointer;
}
.conf {
background: #417df3;
color: #fff;
cursor: pointer;
width: 100%;
height: 44px;
border-radius: 4px;
margin: 10px auto;
font-size: 15px;
border: 0;
}
</style>)====="

View File

@ -1,5 +0,0 @@
R"=====(</span>
</p>
<p style="text-align: left">
Device
<span style="float: right">)====="

View File

@ -1,5 +0,0 @@
R"=====(</span>
</p>
<p style="text-align: left">
API Server
<span style="float: right">)====="

View File

@ -1,5 +0,0 @@
R"=====(</span>
</p>
<p style="text-align: left">
API Endpoint
<span style="float: right">)====="

View File

@ -1,5 +0,0 @@
R"=====(</span>
</p>
<p style="text-align: left">
Centrally Managed
<span style="float: right">)====="

View File

@ -1,125 +0,0 @@
R"=====(</span>
</p>
<input
type="file"
name="update"
id="file"
onchange="sub(this)"
style="display: none"
/>
<label id="file-input" for="file">Choose file...</label>
<input type="submit" class="btn" value="Program" /><br /><br />
<div id="prg"></div>
<br />
<div id="prgbar">
<div id="bar"></div>
</div>
<br />
<b>SIWAT SYSTEM 2023</b>
</form>
<script>
function sub(obj) {
var fileName = obj.value.split("\\");
document.getElementById("file-input").innerHTML =
" " + fileName[fileName.length - 1];
}
$("form").submit(function (e) {
e.preventDefault();
var form = $("#upload_form")[0];
var data = new FormData(form);
$.ajax({
url: "/update",
type: "POST",
data: data,
contentType: false,
processData: false,
xhr: function () {
var xhr = new window.XMLHttpRequest();
xhr.upload.addEventListener(
"progress",
function (evt) {
if (evt.lengthComputable) {
var per = evt.loaded / evt.total;
if(Math.round(per*100)<100) {
$("#prg").html("Updating . . . (" + Math.round(per * 100) + "%)");
}
else {
$("#prg").html("Update Completed, Rebooting . . .");
}
$("#bar").css("width", Math.round(per * 100) + "%");
}
},
false
);
return xhr;
},
success: function (d, s) {
console.log("success!");
},
error: function (a, b, c) {},
});
});
</script>
<style>
#file-input,
input {
width: 100%;
height: 44px;
border-radius: 4px;
margin: 10px auto;
font-size: 15px;
}
input {
background: #f1f1f1;
border: 0;
padding: 0 15px;
}
body {
background-image: url("https://fs.siwatsystem.com/arona_bg.png");
background-size: cover;
font-family: sans-serif;
font-size: 14px;
color: #777;
}
#file-input {
background-color: #CCCCCC;
color: #5E5E5E;
padding: 0;
border: 1px solid #ddd;
line-height: 44px;
text-align: center;
display: block;
cursor: pointer;
}
#bar,
#prgbar {
background-color: #D9D9D9;
border-radius: 10px;
}
#bar {
background-color: #29CD1F;
width: 0%;
height: 10px;
}
form {
background: rgba(255,255,255,0.95);
max-width: 258px;
margin: 75px auto;
padding: 30px;
border-radius: 15px;
text-align: center;
}
.btn {
background: #CA3D3D;
color: #fff;
cursor: pointer;
}
</style>)====="

176
src/ota_html/ota.html Normal file
View File

@ -0,0 +1,176 @@
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<form method="POST" action="#" enctype="multipart/form-data" id="upload_form">
<h1>ESPMega PRO</h1>
<h3>Device Information</h3>
<p style="text-align: left">
Hostname
<span style="float: right">ESPMegaDemo0</span>
</p>
<p style="text-align: left">
IP Address
<span style="float: right">192.168.0.243</span>
</p>
<p style="text-align: left">
MAC Address
<span style="float: right">B0:A7:32:07:FC:B3</span>
</p>
<p style="text-align: left">
Device
<span style="float: right">ESPMega PRO R3.3b</span>
</p>
<p style="text-align: left">
API Server
<span style="float: right">192.168.0.26</span>
</p>
<p style="text-align: left">
API Endpoint
<span style="float: right">/facescan</span>
</p>
<p style="text-align: left">
Centrally Managed
<span style="float: right">Yes</span>
</p>
<button type="button" class="conf" onclick="window.location.href='config'">Settings</button><br /><br />
<hr>
<h3>Upload Software Package</h3>
<input type="file" name="update" id="file" onchange="sub(this)" style="display: none" />
<label id="file-input" for="file">Choose file...</label>
<input type="submit" class="btn" value="Program" /><br /><br />
<div id="prg"></div>
<br />
<div id="prgbar">
<div id="bar"></div>
</div>
<br />
<b>SIWAT SYSTEM 2023</b>
</form>
<script>
function sub(obj) {
var fileName = obj.value.split("\\");
document.getElementById("file-input").innerHTML =
" " + fileName[fileName.length - 1];
}
$("form").submit(function (e) {
e.preventDefault();
var form = $("#upload_form")[0];
var data = new FormData(form);
$.ajax({
url: "/update",
type: "POST",
data: data,
contentType: false,
processData: false,
xhr: function () {
var xhr = new window.XMLHttpRequest();
xhr.upload.addEventListener(
"progress",
function (evt) {
if (evt.lengthComputable) {
var per = evt.loaded / evt.total;
if (Math.round(per * 100) < 100) {
$("#prg").html("Updating . . . (" + Math.round(per * 100) + "%)");
}
else {
$("#prg").html("Update Completed, Rebooting . . .");
}
$("#bar").css("width", Math.round(per * 100) + "%");
}
},
false
);
return xhr;
},
success: function (d, s) {
console.log("success!");
},
error: function (a, b, c) { },
});
});
</script>
<style>
hr {
display: block;
color: #aaaaaa;
background-color: #aaaaaa;
margin-top: 0.5em;
margin-bottom: 0.5em;
margin-left: auto;
margin-right: auto;
border-style: inset;
border-width: 0px;
height: 3px;
}
#file-input,
input {
width: 100%;
height: 44px;
border-radius: 4px;
margin: 10px auto;
font-size: 15px;
}
input {
background: #f1f1f1;
border: 0;
padding: 0 15px;
}
body {
background-image: url("https://fs.siwatsystem.com/arona_bg.png");
background-size: cover;
font-family: sans-serif;
font-size: 14px;
color: #777;
}
#file-input {
background-color: #CCCCCC;
color: #5E5E5E;
padding: 0;
border: 1px solid #ddd;
line-height: 44px;
text-align: center;
display: block;
cursor: pointer;
}
#bar,
#prgbar {
background-color: #D9D9D9;
border-radius: 10px;
}
#bar {
background-color: #29CD1F;
width: 0%;
height: 10px;
}
form {
background: rgba(255, 255, 255, 0.95);
max-width: 258px;
margin: 75px auto;
padding: 30px;
border-radius: 15px;
text-align: center;
}
.btn {
background: #CA3D3D;
color: #fff;
cursor: pointer;
}
.conf {
background: #417df3;
color: #fff;
cursor: pointer;
width: 100%;
height: 44px;
border-radius: 4px;
margin: 10px auto;
font-size: 15px;
border: 0;
}
</style>