mirror of
https://github.com/openshwprojects/OpenBK7231T_App.git
synced 2026-02-12 12:25:53 +00:00
Merge branch 'main' of https://github.com/openshwprojects/OpenBK7231T_App
This commit is contained in:
@ -36,8 +36,8 @@
|
||||
#endif
|
||||
|
||||
#if defined(PLATFORM_BK7231T) || defined(PLATFORM_BK7231N)
|
||||
int tuya_os_adapt_wifi_all_ap_scan(AP_IF_S **ap_ary, unsigned int *num);
|
||||
int tuya_os_adapt_wifi_release_ap(AP_IF_S *ap);
|
||||
int tuya_os_adapt_wifi_all_ap_scan(AP_IF_S** ap_ary, unsigned int* num);
|
||||
int tuya_os_adapt_wifi_release_ap(AP_IF_S* ap);
|
||||
#endif
|
||||
|
||||
static char* UNIQUE_ID_FORMAT = " - unique_id: \"%s\"\n";
|
||||
@ -548,10 +548,10 @@ int http_fn_index(http_request_t* request) {
|
||||
|
||||
hprintf255(request, "<h5>Ping watchdog - %i lost, %i ok!</h5>",
|
||||
PingWatchDog_GetTotalLost(), PingWatchDog_GetTotalReceived());
|
||||
if (Main_HasWiFiConnected())
|
||||
{
|
||||
hprintf255(request, "<h5>Wifi RSSI: %s (%idBm)</h5>", str_rssi[wifi_rssi_scale(HAL_GetWifiStrength())], HAL_GetWifiStrength());
|
||||
}
|
||||
if (Main_HasWiFiConnected())
|
||||
{
|
||||
hprintf255(request, "<h5>Wifi RSSI: %s (%idBm)</h5>", str_rssi[wifi_rssi_scale(HAL_GetWifiStrength())], HAL_GetWifiStrength());
|
||||
}
|
||||
hprintf255(request, "<h5>MQTT State: %s RES: %d(%s)<br>", (Main_HasMQTTConnected() == 1) ? "connected" : "disconnected",
|
||||
MQTT_GetConnectResult(), get_error_name(MQTT_GetConnectResult()));
|
||||
hprintf255(request, "MQTT ErrMsg: %s <br>", (MQTT_GetStatusMessage() != NULL) ? MQTT_GetStatusMessage() : "");
|
||||
@ -576,8 +576,8 @@ int http_fn_index(http_request_t* request) {
|
||||
{
|
||||
hprintf255(request, "P%02i: NA ", i);
|
||||
}
|
||||
else
|
||||
{
|
||||
else
|
||||
{
|
||||
hprintf255(request, "P%02i: %i ", i, (int)HAL_PIN_ReadDigitalInput(i));
|
||||
}
|
||||
if (i % 10 == 9)
|
||||
@ -589,10 +589,10 @@ int http_fn_index(http_request_t* request) {
|
||||
}
|
||||
|
||||
#if defined(PLATFORM_BK7231T) || defined(PLATFORM_BK7231N)
|
||||
if (ota_progress()>=0)
|
||||
{
|
||||
hprintf255(request, "<h5>OTA In Progress. Status: %06lXh</h5>", ota_progress());
|
||||
}
|
||||
if (ota_progress() >= 0)
|
||||
{
|
||||
hprintf255(request, "<h5>OTA In Progress. Status: %06lXh</h5>", ota_progress());
|
||||
}
|
||||
#endif
|
||||
|
||||
// for normal page loads, show the rest of the HTML
|
||||
@ -1670,7 +1670,7 @@ int http_fn_cfg(http_request_t* request) {
|
||||
postFormAction(request, "cfg_mac", "Change MAC");
|
||||
postFormAction(request, "cfg_ping", "Ping Watchdog (Network lost restarter)");
|
||||
postFormAction(request, "cfg_webapp", "Configure Webapp");
|
||||
postFormAction(request, "ha_cfg", "Generate Home Assistant cfg");
|
||||
postFormAction(request, "ha_cfg", "Home Assistant Configuration");
|
||||
postFormAction(request, "ota", "OTA (update software by WiFi)");
|
||||
postFormAction(request, "cmd_tool", "Execute custom command");
|
||||
postFormAction(request, "flash_read_tool", "Flash Read Tool");
|
||||
|
||||
@ -617,9 +617,9 @@ const char htmlHeadStyle[] = "<style>div,fieldset,input,select{padding:5px;font-
|
||||
//region_end htmlHeadStyle
|
||||
|
||||
//region_start pageScript
|
||||
const char pageScript[] = "<script type='text/javascript'>var firstTime,lastTime,onlineFor,req=null,onlineForEl=null,getElement=e=>document.getElementById(e);function showState(){clearTimeout(firstTime),clearTimeout(lastTime),null!=req&&req.abort(),(req=new XMLHttpRequest).onreadystatechange=()=>{4==req.readyState&&200==req.status&&((\"INPUT\"!=document.activeElement.tagName||\"number\"!=document.activeElement.type&&\"color\"!=document.activeElement.type)&&(getElement(\"state\").innerHTML=req.responseText),clearTimeout(firstTime),clearTimeout(lastTime),lastTime=setTimeout(showState,3e3))},req.open(\"GET\",\"index?state=1\",!0),req.send(),firstTime=setTimeout(showState,3e3)}function fmtUpTime(e){var t,n,o=Math.floor(e/86400);return e%=86400,t=Math.floor(e/3600),e%=3600,n=Math.floor(e/60),e=e%60,0<o?o+` days, ${t} hours, ${n} minutes and ${e} seconds`:0<t?t+` hours, ${n} minutes and ${e} seconds`:0<n?n+` minutes and ${e} seconds`:`just ${e} seconds`}function updateOnlineFor(){onlineForEl.textContent=fmtUpTime(++onlineFor)}function onLoad(){(onlineForEl=getElement(\"onlineFor\"))&&(onlineFor=parseInt(onlineForEl.dataset.initial,10))&&setInterval(updateOnlineFor,1e3),showState()}window.addEventListener(\"load\",onLoad),history.pushState(null,\"\",\"index\"),setTimeout(()=>{getElement(\"changed\").innerHTML=\"\"},5e3);</script>";
|
||||
const char pageScript[] = "<script type='text/javascript'>var firstTime,lastTime,onlineFor,req=null,onlineForEl=null,getElement=e=>document.getElementById(e);function showState(){clearTimeout(firstTime),clearTimeout(lastTime),null!=req&&req.abort(),(req=new XMLHttpRequest).onreadystatechange=()=>{var e;4==req.readyState&&200==req.status&&((\"INPUT\"!=document.activeElement.tagName||\"number\"!=document.activeElement.type&&\"color\"!=document.activeElement.type)&&(e=getElement(\"state\"))&&(e.innerHTML=req.responseText),clearTimeout(firstTime),clearTimeout(lastTime),lastTime=setTimeout(showState,3e3))},req.open(\"GET\",\"index?state=1\",!0),req.send(),firstTime=setTimeout(showState,3e3)}function fmtUpTime(e){var t,n,o=Math.floor(e/86400);return e%=86400,t=Math.floor(e/3600),e%=3600,n=Math.floor(e/60),e=e%60,0<o?o+` days, ${t} hours, ${n} minutes and ${e} seconds`:0<t?t+` hours, ${n} minutes and ${e} seconds`:0<n?n+` minutes and ${e} seconds`:`just ${e} seconds`}function updateOnlineFor(){onlineForEl.textContent=fmtUpTime(++onlineFor)}function onLoad(){(onlineForEl=getElement(\"onlineFor\"))&&(onlineFor=parseInt(onlineForEl.dataset.initial,10))&&setInterval(updateOnlineFor,1e3),showState()}window.addEventListener(\"load\",onLoad),history.pushState(null,\"\",\"index\"),setTimeout(()=>{var e=getElement(\"changed\");e&&(e.innerHTML=\"\")},5e3);</script>";
|
||||
//region_end pageScript
|
||||
|
||||
//region_start ha_discovery_script
|
||||
const char ha_discovery_script[] = "<script type='text/javascript'>function send_ha_disc(){var e=new XMLHttpRequest;e.open(\"GET\",\"/ha_discovery?prefix=\"+document.getElementById(\"ha_disc_topic\").value,!1),e.onload=function(){200===e.status?alert(e.responseText):404===e.status&&alert(\"Error invoking ha_discovery\")},e.onerror=function(){alert(\"Error invoking ha_discovery\")},e.send()}</script>";
|
||||
//region_end ha_discovery_script
|
||||
//region_end ha_discovery_script
|
||||
@ -1,8 +1,8 @@
|
||||
//The content of this file get set into htmlHeadStyle (new_http.cs)
|
||||
|
||||
var firstTime,
|
||||
lastTime,
|
||||
req = null;
|
||||
lastTime,
|
||||
req = null;
|
||||
var onlineFor;
|
||||
var onlineForEl = null;
|
||||
|
||||
@ -10,73 +10,79 @@ var getElement = (id) => document.getElementById(id);
|
||||
|
||||
// refresh status section every 3 seconds
|
||||
function showState() {
|
||||
clearTimeout(firstTime);
|
||||
clearTimeout(lastTime);
|
||||
if (req != null) {
|
||||
req.abort();
|
||||
}
|
||||
req = new XMLHttpRequest();
|
||||
req.onreadystatechange = () => {
|
||||
if (req.readyState == 4 && req.status == 200) {
|
||||
if (
|
||||
!(
|
||||
document.activeElement.tagName == "INPUT" &&
|
||||
(document.activeElement.type == "number" || document.activeElement.type == "color")
|
||||
)
|
||||
) {
|
||||
getElement("state").innerHTML = req.responseText;
|
||||
}
|
||||
clearTimeout(firstTime);
|
||||
clearTimeout(lastTime);
|
||||
lastTime = setTimeout(showState, 3e3);
|
||||
}
|
||||
};
|
||||
req.open("GET", "index?state=1", true);
|
||||
req.send();
|
||||
firstTime = setTimeout(showState, 3e3);
|
||||
clearTimeout(firstTime);
|
||||
clearTimeout(lastTime);
|
||||
if (req != null) {
|
||||
req.abort();
|
||||
}
|
||||
req = new XMLHttpRequest();
|
||||
req.onreadystatechange = () => {
|
||||
if (req.readyState == 4 && req.status == 200) {
|
||||
if (
|
||||
!(
|
||||
document.activeElement.tagName == "INPUT" &&
|
||||
(document.activeElement.type == "number" || document.activeElement.type == "color")
|
||||
)
|
||||
) {
|
||||
var stateEl = getElement("state");
|
||||
if (stateEl) {
|
||||
stateEl.innerHTML = req.responseText;
|
||||
}
|
||||
}
|
||||
clearTimeout(firstTime);
|
||||
clearTimeout(lastTime);
|
||||
lastTime = setTimeout(showState, 3e3);
|
||||
}
|
||||
};
|
||||
req.open("GET", "index?state=1", true);
|
||||
req.send();
|
||||
firstTime = setTimeout(showState, 3e3);
|
||||
}
|
||||
|
||||
function fmtUpTime(totalSeconds) {
|
||||
var days, hours, minutes, seconds;
|
||||
var days, hours, minutes, seconds;
|
||||
|
||||
days = Math.floor(totalSeconds / (24 * 60 * 60));
|
||||
totalSeconds = totalSeconds % (24 * 60 * 60);
|
||||
hours = Math.floor(totalSeconds / (60 * 60));
|
||||
totalSeconds = totalSeconds % (60 * 60);
|
||||
minutes = Math.floor(totalSeconds / 60);
|
||||
seconds = totalSeconds % 60;
|
||||
days = Math.floor(totalSeconds / (24 * 60 * 60));
|
||||
totalSeconds = totalSeconds % (24 * 60 * 60);
|
||||
hours = Math.floor(totalSeconds / (60 * 60));
|
||||
totalSeconds = totalSeconds % (60 * 60);
|
||||
minutes = Math.floor(totalSeconds / 60);
|
||||
seconds = totalSeconds % 60;
|
||||
|
||||
if (days > 0) {
|
||||
return `${days} days, ${hours} hours, ${minutes} minutes and ${seconds} seconds`;
|
||||
}
|
||||
if (hours > 0) {
|
||||
return `${hours} hours, ${minutes} minutes and ${seconds} seconds`;
|
||||
}
|
||||
if (minutes > 0) {
|
||||
return `${minutes} minutes and ${seconds} seconds`;
|
||||
}
|
||||
return `just ${seconds} seconds`;
|
||||
if (days > 0) {
|
||||
return `${days} days, ${hours} hours, ${minutes} minutes and ${seconds} seconds`;
|
||||
}
|
||||
if (hours > 0) {
|
||||
return `${hours} hours, ${minutes} minutes and ${seconds} seconds`;
|
||||
}
|
||||
if (minutes > 0) {
|
||||
return `${minutes} minutes and ${seconds} seconds`;
|
||||
}
|
||||
return `just ${seconds} seconds`;
|
||||
}
|
||||
|
||||
function updateOnlineFor() {
|
||||
onlineForEl.textContent = fmtUpTime(++onlineFor);
|
||||
onlineForEl.textContent = fmtUpTime(++onlineFor);
|
||||
}
|
||||
|
||||
function onLoad() {
|
||||
onlineForEl = getElement("onlineFor");
|
||||
if (onlineForEl) {
|
||||
onlineFor = parseInt(onlineForEl.dataset.initial, 10); //We have some valid value
|
||||
if (onlineFor) {
|
||||
setInterval(updateOnlineFor, 1000);
|
||||
}
|
||||
}
|
||||
onlineForEl = getElement("onlineFor");
|
||||
if (onlineForEl) {
|
||||
onlineFor = parseInt(onlineForEl.dataset.initial, 10); //We have some valid value
|
||||
if (onlineFor) {
|
||||
setInterval(updateOnlineFor, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
showState();
|
||||
showState();
|
||||
}
|
||||
|
||||
window.addEventListener("load", onLoad);
|
||||
history.pushState(null, "", "index"); // drop actions like 'toggle' from URL
|
||||
|
||||
setTimeout(() => {
|
||||
getElement("changed").innerHTML = "";
|
||||
var changedEl = getElement("changed");
|
||||
if (changedEl) {
|
||||
changedEl.innerHTML = "";
|
||||
}
|
||||
}, 5e3); // hide change info
|
||||
|
||||
Reference in New Issue
Block a user