mirror of
https://github.com/openshwprojects/OpenBK7231T_App.git
synced 2026-02-09 17:45:39 +00:00
Merge branch 'main' of https://github.com/openshwprojects/OpenBK7231T_App
# Conflicts: # src/cmnds/cmd_public.h
This commit is contained in:
@ -141,7 +141,7 @@ HassDeviceInfo* hass_init_device_info(ENTITY_TYPE type, int index, char* payload
|
||||
#ifndef OBK_DISABLE_ALL_DRIVERS
|
||||
if ((index >= OBK_VOLTAGE) && (index <= OBK_POWER))
|
||||
sprintf(g_hassBuffer, "%s %s", CFG_GetShortDeviceName(), sensor_mqttNames[index]);
|
||||
if ((index >= OBK_CONSUMPTION_TOTAL) && (index <= OBK_CONSUMPTION_STATS))
|
||||
else if ((index >= OBK_CONSUMPTION_TOTAL) && (index <= OBK_CONSUMPTION_STATS))
|
||||
sprintf(g_hassBuffer, "%s %s", CFG_GetShortDeviceName(), counter_mqttNames[index - OBK_CONSUMPTION_TOTAL]);
|
||||
#endif
|
||||
break;
|
||||
@ -250,22 +250,24 @@ HassDeviceInfo* hass_init_sensor_device_info(int index) {
|
||||
|
||||
sprintf(g_hassBuffer, "~/%s/get", sensor_mqttNames[index]);
|
||||
cJSON_AddStringToObject(info->root, STATE_TOPIC_KEY, g_hassBuffer);
|
||||
|
||||
cJSON_AddStringToObject(info->root, "stat_cla", "measurement");
|
||||
}
|
||||
if ((index >= OBK_CONSUMPTION_TOTAL) && (index <= OBK_CONSUMPTION_STATS))
|
||||
else if ((index >= OBK_CONSUMPTION_TOTAL) && (index <= OBK_CONSUMPTION_STATS))
|
||||
{
|
||||
const char* device_class_value = counter_devClasses[index - OBK_CONSUMPTION_TOTAL];
|
||||
if (strlen(device_class_value) > 0) {
|
||||
cJSON_AddStringToObject(info->root, "dev_cla", device_class_value); //device_class=energy
|
||||
cJSON_AddStringToObject(info->root, "unit_of_meas", "Wh"); //unit_of_measurement
|
||||
|
||||
//state_class can be measurement, total or total_increasing. Energy values should be total_increasing.
|
||||
cJSON_AddStringToObject(info->root, "stat_cla", "total_increasing");
|
||||
}
|
||||
|
||||
sprintf(g_hassBuffer, "~/%s/get", counter_mqttNames[index - OBK_CONSUMPTION_TOTAL]);
|
||||
cJSON_AddStringToObject(info->root, STATE_TOPIC_KEY, g_hassBuffer);
|
||||
}
|
||||
|
||||
//state_class can be measurement, total or total_increasing. Something like daily power consumption could be total_increasing.
|
||||
cJSON_AddStringToObject(info->root, "stat_cla", "measurement");
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
@ -142,6 +142,22 @@ void postFormAction(http_request_t* request, char* action, char* value) {
|
||||
hprintf255(request, "<form action=\"%s\"><input type=\"submit\" value=\"%s\"/></form>", action, value);
|
||||
}
|
||||
|
||||
/// @brief Generate a pair of label and field elements for Name type entry. The field is limited to entry of a-zA-Z0-9_- characters.
|
||||
/// @param request
|
||||
/// @param label
|
||||
/// @param fieldId This also gets used as the field name
|
||||
/// @param value
|
||||
/// @param preContent
|
||||
void add_label_name_field(http_request_t* request, char* label, char* fieldId, const char* value, char* preContent) {
|
||||
if (strlen(preContent) > 0) {
|
||||
poststr(request, preContent);
|
||||
}
|
||||
|
||||
hprintf255(request, "<label for=\"%s\">%s:</label><br>", fieldId, label);
|
||||
hprintf255(request, "<input type=\"text\" id=\"%s\" name=\"%s\" value=\"%s\" ", fieldId, fieldId, value);
|
||||
poststr(request, "pattern=\"^[a-zA-Z0-9_-]+$\" title=\"Only alphanumerics, underscore and hyphen characters allowed.\">");
|
||||
}
|
||||
|
||||
/// @brief Generate a pair of label and field elements.
|
||||
/// @param request
|
||||
/// @param label
|
||||
@ -153,7 +169,6 @@ void add_label_input(http_request_t* request, char* inputType, char* label, char
|
||||
poststr(request, preContent);
|
||||
}
|
||||
|
||||
//These individual strings should be less than 256 .. yes hprintf255 uses 256 char buffer
|
||||
hprintf255(request, "<label for=\"%s\">%s:</label><br>", fieldId, label);
|
||||
hprintf255(request, "<input type=\"%s\" id=\"%s\" name=\"%s\" value=\"%s\">", inputType, fieldId, fieldId, value);
|
||||
}
|
||||
@ -556,15 +571,20 @@ int http_fn_index(http_request_t* request) {
|
||||
inputName = "pwm";
|
||||
|
||||
pwmValue = LED_GetTemperature();
|
||||
long pwmKelvin = 1000000 / pwmValue;
|
||||
|
||||
poststr(request, "<tr><td>");
|
||||
hprintf255(request, "<h5>LED Temperature Slider %s (cur=%i, min=%i, max=%i) Mired (Cool <--- ---> Warm)</h5>", activeStr, pwmValue, HASS_TEMPERATURE_MIN, HASS_TEMPERATURE_MAX);
|
||||
hprintf255(request, "<form class='r' style='background: linear-gradient(to right, rgb(166, 209, 255), rgb(255, 160, 0));' action=\"index\" id=\"form%i\">", SPECIAL_CHANNEL_TEMPERATURE);
|
||||
hprintf255(request, "<input type=\"range\" min=\"%i\" max=\"%i\"", HASS_TEMPERATURE_MIN, HASS_TEMPERATURE_MAX);
|
||||
hprintf255(request, "name=\"%s\" id=\"slider%i\" value=\"%i\" onchange=\"this.form.submit()\">", inputName, SPECIAL_CHANNEL_TEMPERATURE, pwmValue);
|
||||
hprintf255(request, "<input type=\"hidden\" name=\"%sIndex\" value=\"%i\">", inputName, SPECIAL_CHANNEL_TEMPERATURE);
|
||||
hprintf255(request, "<input type=\"submit\" style=\"display:none;\" value=\"Toggle %i\"/></form>", SPECIAL_CHANNEL_TEMPERATURE);
|
||||
poststr(request, "</td></tr>");
|
||||
hprintf255(request, "<h5>LED Temperature Slider %s (%ld K) (Warm <--- ---> Cool)</h5>", activeStr, pwmKelvin);
|
||||
hprintf255(request, "<form class='r' style='background: linear-gradient(to right, rgb(255, 160, 0), rgb(166, 209, 255));' action=\"index\" id=\"form%i\">", SPECIAL_CHANNEL_TEMPERATURE);
|
||||
|
||||
//(KELVIN_TEMPERATURE_MAX - KELVIN_TEMPERATURE_MIN) / (HASS_TEMPERATURE_MAX - HASS_TEMPERATURE_MIN) = 13
|
||||
hprintf255(request, "<input type=\"range\" step='13' min=\"%ld\" max=\"%ld\" ", KELVIN_TEMPERATURE_MIN, KELVIN_TEMPERATURE_MAX);
|
||||
hprintf255(request, "value=\"%ld\" onchange=\"submitTemperature(this);\"/>", pwmKelvin);
|
||||
|
||||
hprintf255(request, "<input type=\"hidden\" name=\"%sIndex\" value=\"%i\"/>", inputName, SPECIAL_CHANNEL_TEMPERATURE);
|
||||
hprintf255(request, "<input id=\"kelvin%i\" type=\"hidden\" name=\"%s\" />", SPECIAL_CHANNEL_TEMPERATURE, inputName);
|
||||
|
||||
poststr(request, "</form></td></tr>");
|
||||
}
|
||||
|
||||
}
|
||||
@ -926,8 +946,9 @@ int http_fn_cfg_name(http_request_t* request) {
|
||||
CFG_Save_IfThereArePendingChanges();
|
||||
|
||||
poststr(request, "<h2> Use this to change device names</h2>");
|
||||
add_label_text_field(request, "ShortName", "shortName", CFG_GetShortDeviceName(), "<form action=\"/cfg_name\">");
|
||||
add_label_text_field(request, "Full Name", "name", CFG_GetDeviceName(), "<br>");
|
||||
add_label_name_field(request, "ShortName", "shortName", CFG_GetShortDeviceName(), "<form action=\"/cfg_name\">");
|
||||
add_label_name_field(request, "Full Name", "name", CFG_GetDeviceName(), "<br>");
|
||||
|
||||
poststr(request, "<br><br>");
|
||||
poststr(request, "<input type=\"submit\" value=\"Submit\" "
|
||||
"onclick=\"return confirm('Are you sure? "
|
||||
|
||||
@ -19,9 +19,12 @@ const char httpMimeTypeHTML[] = "text/html"; // HTML MIME type
|
||||
const char httpMimeTypeText[] = "text/plain"; // TEXT MIME type
|
||||
const char httpMimeTypeJson[] = "application/json"; // TEXT MIME type
|
||||
const char httpMimeTypeBinary[] = "application/octet-stream"; // binary/file MIME type
|
||||
|
||||
const char htmlShortcutIcon[] = "<link rel='shortcut icon' href='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsIAAA7CARUoSoAAAAHESURBVDhPpZPLS1VhFMV/pyuFb1HIHhDcixGU/glpNKg7ihLCMnOUQQ/6K5LmIg0ciQMRFMeZIMmlbFxEFIaYUCGIUQoRer7Wut/B8BVFC9Y5++y9Nuxvffsk7I9asVcM4oi4Jv4TStdaCF2i4tmY+jNaxZfiotjfXEWa3iWYzZWkzmU1a6zdhbmhc6Tvu0lPNRCqKwibdyKrFDvnmjXSvogtcCB7G0faj8HJBpLxi7ChwRe+RW4qnlDONWuEo+WnkMvexuHpJdo7JGhrgjONhOdf4O0q3D4NHcdJXq9A5xOSlR88ln4mtkW3Sz6nxz6UI0wWSfP1hGJfpGPnXLMm86TkXl/jPbk9OHpB9+Wxv8PkB8JMK8mDIVWFgT44/4bQWSDJ10Giru6nMDbPfXvgvt/Y9rE/Mln5VSPOeiy7vXUEuV68tfsI1mRH8G7U2MSf4vD6BgcLdZydvhQNO1FNqF+C/DJcb4ErGv9yAaY+ahnWeKSem1nvFhZ9z0GL86orTjLfI96IsXOuWWNtbNm+B5+ffYJ3XwlXp6BCRuV1PzYtp9g516yxtvzcAa+nN2xB3GuVH2a1OXHPVd6Jv/qZ/vN3hl/Pmb41kmFXMgAAAABJRU5ErkJggg==' />";
|
||||
|
||||
const char htmlDoctype[] =
|
||||
"<!DOCTYPE html><html>";
|
||||
const char htmlHeadMain[] =
|
||||
const char htmlHeadMeta[] =
|
||||
"<meta charset=\"utf-8\">"
|
||||
"<meta name=\"viewport\" content=\"width=device-width,initial-scale=1,user-scalable=no\">"
|
||||
"<meta name=\"robots\" content=\"none\">";
|
||||
@ -116,6 +119,64 @@ int my_strnicmp(const char* a, const char* b, int len) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/// @brief Write escaped data to the response.
|
||||
/// @param request
|
||||
/// @param str
|
||||
void poststr_escaped(http_request_t* request, char* str) {
|
||||
if (str == NULL) {
|
||||
postany(request, NULL, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
int i;
|
||||
bool foundChar = false;
|
||||
int len = strlen(str);
|
||||
|
||||
//Do a quick check if escaping is necessary
|
||||
for (i = 0; (foundChar == false) && (i < len); i++) {
|
||||
switch (str[i]) {
|
||||
case '<':
|
||||
foundChar = true;
|
||||
break;
|
||||
case '>':
|
||||
foundChar = true;
|
||||
break;
|
||||
case '&':
|
||||
foundChar = true;
|
||||
break;
|
||||
case '"':
|
||||
foundChar = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (foundChar) {
|
||||
for (i = 0; i < len; i++) {
|
||||
switch (str[i]) {
|
||||
case '<':
|
||||
postany(request, "<", 4);
|
||||
break;
|
||||
case '>':
|
||||
postany(request, ">", 4);
|
||||
break;
|
||||
case '&':
|
||||
postany(request, "&", 5);
|
||||
break;
|
||||
case '"':
|
||||
postany(request, """, 6);
|
||||
break;
|
||||
default:
|
||||
postany(request, str + i, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
postany(request, str, strlen(str));
|
||||
}
|
||||
}
|
||||
|
||||
bool http_startsWith(const char* base, const char* substr) {
|
||||
while (*substr != 0) {
|
||||
if (*base != *substr)
|
||||
@ -167,17 +228,18 @@ void http_setup(http_request_t* request, const char* type) {
|
||||
|
||||
void http_html_start(http_request_t* request, const char* pagename) {
|
||||
poststr(request, htmlDoctype);
|
||||
poststr(request, "<title>");
|
||||
poststr(request, CFG_GetDeviceName()); // todo: check escaping
|
||||
poststr(request, "<head><title>");
|
||||
poststr(request, CFG_GetDeviceName());
|
||||
if (pagename) {
|
||||
poststr(request, " - ");
|
||||
poststr(request, pagename);
|
||||
hprintf255(request, " - %s", pagename);
|
||||
}
|
||||
poststr(request, "</title>");
|
||||
poststr(request, htmlHeadMain);
|
||||
poststr(request, htmlShortcutIcon);
|
||||
poststr(request, htmlHeadMeta);
|
||||
poststr(request, htmlHeadStyle);
|
||||
poststr(request, "</head>");
|
||||
poststr(request, htmlBodyStart);
|
||||
poststr(request, CFG_GetDeviceName()); // todo: check escaping
|
||||
poststr(request, CFG_GetDeviceName());
|
||||
poststr(request, htmlBodyStart2);
|
||||
}
|
||||
|
||||
@ -424,7 +486,7 @@ int hprintf255(http_request_t* request, const char* fmt, ...) {
|
||||
va_list argList;
|
||||
//BaseType_t taken;
|
||||
char tmp[256];
|
||||
memset(tmp, 0, 256);
|
||||
memset(tmp, 0, sizeof(tmp));
|
||||
va_start(argList, fmt);
|
||||
vsnprintf(tmp, 255, fmt, argList);
|
||||
va_end(argList);
|
||||
@ -624,7 +686,7 @@ 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=()=>{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>";
|
||||
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()}function submitTemperature(e){var t=getElement(\"form132\");getElement(\"kelvin132\").value=Math.round(1e6/parseInt(e.value)),t.submit()}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
|
||||
|
||||
@ -8,6 +8,10 @@ extern const char httpMimeTypeText[]; // TEXT MIME type
|
||||
extern const char httpMimeTypeJson[];
|
||||
extern const char httpMimeTypeBinary[];
|
||||
|
||||
extern const char htmlShortcutIcon[];
|
||||
extern const char htmlDoctype[];
|
||||
extern const char htmlHeadMeta[];
|
||||
|
||||
extern const char htmlFooterReturnToMenu[];
|
||||
extern const char htmlFooterRefreshLink[];
|
||||
extern const char htmlFooterReturnToCfgLink[];
|
||||
@ -57,6 +61,7 @@ void http_setup(http_request_t* request, const char* type);
|
||||
void http_html_start(http_request_t* request, const char* pagename);
|
||||
void http_html_end(http_request_t* request);
|
||||
int poststr(http_request_t* request, const char* str);
|
||||
void poststr_escaped(http_request_t* request, char* str);
|
||||
int postany(http_request_t* request, const char* str, int len);
|
||||
void misc_formatUpTimeString(int totalSeconds, char* o);
|
||||
// void HTTP_AddBuildFooter(http_request_t *request);
|
||||
@ -82,3 +87,4 @@ typedef int (*http_callback_fn)(http_request_t* request);
|
||||
int HTTP_RegisterCallback(const char* url, int method, http_callback_fn callback);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@ -53,7 +53,6 @@ static int http_rest_get_lfs_delete(http_request_t* request);
|
||||
static int http_rest_get_lfs_file(http_request_t* request);
|
||||
static int http_rest_post_lfs_file(http_request_t* request);
|
||||
#endif
|
||||
static int http_favicon(http_request_t* request);
|
||||
|
||||
static int http_rest_post_reboot(http_request_t* request);
|
||||
static int http_rest_post_flash(http_request_t* request, int startaddr, int maxaddr);
|
||||
@ -78,57 +77,8 @@ void init_rest() {
|
||||
HTTP_RegisterCallback("/api/", HTTP_GET, http_rest_get);
|
||||
HTTP_RegisterCallback("/api/", HTTP_POST, http_rest_post);
|
||||
HTTP_RegisterCallback("/app", HTTP_GET, http_rest_app);
|
||||
HTTP_RegisterCallback("/favicon.ico", HTTP_GET, http_favicon);
|
||||
}
|
||||
|
||||
const char* apppage1 =
|
||||
"<!DOCTYPE html>"
|
||||
"<html>"
|
||||
" <head>"
|
||||
" <script>"
|
||||
" var root = '";
|
||||
#if WINDOWS
|
||||
const char* obktype = "windows";
|
||||
const char* apppage2 = "';"
|
||||
" var obktype = 'windows';"
|
||||
" var device = 'http://";
|
||||
#elif PLATFORM_XR809
|
||||
const char* obktype = "XR809";
|
||||
const char* apppage2 = "';"
|
||||
" var obktype = 'XR809';"
|
||||
" var device = 'http://";
|
||||
#elif PLATFORM_BL602
|
||||
const char* obktype = "BL602";
|
||||
const char* apppage2 = "';"
|
||||
" var obktype = 'BL602';"
|
||||
" var device = 'http://";
|
||||
#elif PLATFORM_W600
|
||||
const char* obktype = "W600";
|
||||
const char* apppage2 = "';"
|
||||
" var obktype = 'W600';"
|
||||
" var device = 'http://";
|
||||
#elif PLATFORM_W800
|
||||
const char* obktype = "W800";
|
||||
const char* apppage2 = "';"
|
||||
" var obktype = 'W800';"
|
||||
" var device = 'http://";
|
||||
#else
|
||||
const char* obktype = "beken";
|
||||
const char* apppage2 = "';"
|
||||
" var obktype = 'beken';"
|
||||
" var device = 'http://";
|
||||
#endif
|
||||
|
||||
const char* apppage3 = "';"
|
||||
" </script>"
|
||||
" <script src=\"";
|
||||
const char* apppage4 = "startup.js\"></script>"
|
||||
" </head>"
|
||||
"<body>"
|
||||
"</body>"
|
||||
"</html>";
|
||||
|
||||
|
||||
/* Extracts string token value into outBuffer (128 char). Returns true if the operation was successful. */
|
||||
bool tryGetTokenString(const char* json, jsmntok_t* tok, char* outBuffer) {
|
||||
int length;
|
||||
@ -168,20 +118,20 @@ static int http_rest_get(http_request_t* request) {
|
||||
|
||||
#ifdef BK_LITTLEFS
|
||||
if (!strcmp(request->url, "api/fsblock")) {
|
||||
uint32_t newsize = CFG_GetLFS_Size();
|
||||
uint32_t newstart = (LFS_BLOCKS_END - newsize);
|
||||
uint32_t newsize = CFG_GetLFS_Size();
|
||||
uint32_t newstart = (LFS_BLOCKS_END - newsize);
|
||||
|
||||
newsize = (newsize/LFS_BLOCK_SIZE)*LFS_BLOCK_SIZE;
|
||||
newsize = (newsize / LFS_BLOCK_SIZE) * LFS_BLOCK_SIZE;
|
||||
|
||||
// double check again that we're within bounds - don't want
|
||||
// boot overwrite or anything nasty....
|
||||
if (newstart < LFS_BLOCKS_START_MIN){
|
||||
return http_rest_error(request, -20, "LFS Size mismatch");
|
||||
}
|
||||
if ((newstart + newsize > LFS_BLOCKS_END) ||
|
||||
(newstart + newsize < LFS_BLOCKS_START_MIN)){
|
||||
return http_rest_error(request, -20, "LFS Size mismatch");
|
||||
}
|
||||
// double check again that we're within bounds - don't want
|
||||
// boot overwrite or anything nasty....
|
||||
if (newstart < LFS_BLOCKS_START_MIN) {
|
||||
return http_rest_error(request, -20, "LFS Size mismatch");
|
||||
}
|
||||
if ((newstart + newsize > LFS_BLOCKS_END) ||
|
||||
(newstart + newsize < LFS_BLOCKS_START_MIN)) {
|
||||
return http_rest_error(request, -20, "LFS Size mismatch");
|
||||
}
|
||||
|
||||
return http_rest_get_flash(request, newstart, newsize);
|
||||
}
|
||||
@ -266,20 +216,20 @@ static int http_rest_post(http_request_t* request) {
|
||||
if (lfs_present()) {
|
||||
release_lfs();
|
||||
}
|
||||
uint32_t newsize = CFG_GetLFS_Size();
|
||||
uint32_t newstart = (LFS_BLOCKS_END - newsize);
|
||||
uint32_t newsize = CFG_GetLFS_Size();
|
||||
uint32_t newstart = (LFS_BLOCKS_END - newsize);
|
||||
|
||||
newsize = (newsize/LFS_BLOCK_SIZE)*LFS_BLOCK_SIZE;
|
||||
newsize = (newsize / LFS_BLOCK_SIZE) * LFS_BLOCK_SIZE;
|
||||
|
||||
// double check again that we're within bounds - don't want
|
||||
// boot overwrite or anything nasty....
|
||||
if (newstart < LFS_BLOCKS_START_MIN){
|
||||
return http_rest_error(request, -20, "LFS Size mismatch");
|
||||
}
|
||||
if ((newstart + newsize > LFS_BLOCKS_END) ||
|
||||
(newstart + newsize < LFS_BLOCKS_START_MIN)){
|
||||
return http_rest_error(request, -20, "LFS Size mismatch");
|
||||
}
|
||||
// double check again that we're within bounds - don't want
|
||||
// boot overwrite or anything nasty....
|
||||
if (newstart < LFS_BLOCKS_START_MIN) {
|
||||
return http_rest_error(request, -20, "LFS Size mismatch");
|
||||
}
|
||||
if ((newstart + newsize > LFS_BLOCKS_END) ||
|
||||
(newstart + newsize < LFS_BLOCKS_START_MIN)) {
|
||||
return http_rest_error(request, -20, "LFS Size mismatch");
|
||||
}
|
||||
|
||||
// we are writing the lfs block
|
||||
int res = http_rest_post_flash(request, newstart, LFS_BLOCKS_END);
|
||||
@ -313,13 +263,17 @@ static int http_rest_app(http_request_t* request) {
|
||||
const char* ourip = HAL_GetMyIPString(); //CFG_GetOurIP();
|
||||
http_setup(request, httpMimeTypeHTML);
|
||||
if (webhost && ourip) {
|
||||
poststr(request, apppage1);
|
||||
poststr(request, webhost);
|
||||
poststr(request, apppage2);
|
||||
poststr(request, ourip);
|
||||
poststr(request, apppage3);
|
||||
poststr(request, webhost);
|
||||
poststr(request, apppage4);
|
||||
poststr(request, htmlDoctype);
|
||||
|
||||
poststr(request, "<head><title>");
|
||||
poststr(request, CFG_GetDeviceName());
|
||||
poststr(request, "</title>");
|
||||
|
||||
poststr(request, htmlShortcutIcon);
|
||||
poststr(request, htmlHeadMeta);
|
||||
hprintf255(request, "<script>var root='%s',device='http://%s';</script>", webhost, ourip);
|
||||
hprintf255(request, "<script src='%s/startup.js'></script>", webhost);
|
||||
poststr(request, "</head><body></body></html>");
|
||||
}
|
||||
else {
|
||||
http_html_start(request, "Not available");
|
||||
@ -607,18 +561,18 @@ exit:
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int http_favicon(http_request_t* request) {
|
||||
request->url = "api/lfs/favicon.ico";
|
||||
return http_rest_get_lfs_file(request);
|
||||
}
|
||||
// static int http_favicon(http_request_t* request) {
|
||||
// request->url = "api/lfs/favicon.ico";
|
||||
// return http_rest_get_lfs_file(request);
|
||||
// }
|
||||
|
||||
#else
|
||||
static int http_favicon(http_request_t* request) {
|
||||
request->responseCode = HTTP_RESPONSE_NOT_FOUND;
|
||||
http_setup(request, httpMimeTypeHTML);
|
||||
poststr(request, NULL);
|
||||
return 0;
|
||||
}
|
||||
// static int http_favicon(http_request_t* request) {
|
||||
// request->responseCode = HTTP_RESPONSE_NOT_FOUND;
|
||||
// http_setup(request, httpMimeTypeHTML);
|
||||
// poststr(request, NULL);
|
||||
// return 0;
|
||||
// }
|
||||
#endif
|
||||
|
||||
|
||||
@ -788,7 +742,6 @@ static int http_rest_get_info(http_request_t* request) {
|
||||
http_setup(request, httpMimeTypeJson);
|
||||
hprintf255(request, "{\"uptime_s\":%d,", Time_getUpTimeSeconds());
|
||||
hprintf255(request, "\"build\":\"%s\",", g_build_str);
|
||||
hprintf255(request, "\"sys\":\"%s\",", obktype);
|
||||
hprintf255(request, "\"ip\":\"%s\",", HAL_GetMyIPString());
|
||||
hprintf255(request, "\"mac\":\"%s\",", HAL_GetMACStr(macstr));
|
||||
hprintf255(request, "\"mqtthost\":\"%s:%d\",", CFG_GetMQTTHost(), CFG_GetMQTTPort());
|
||||
|
||||
@ -77,6 +77,13 @@ function onLoad() {
|
||||
showState();
|
||||
}
|
||||
|
||||
function submitTemperature(slider) {
|
||||
var form = getElement("form132");
|
||||
var kelvinField = getElement("kelvin132");
|
||||
kelvinField.value = Math.round(1000000 / parseInt(slider.value));
|
||||
form.submit();
|
||||
}
|
||||
|
||||
window.addEventListener("load", onLoad);
|
||||
history.pushState(null, "", "index"); // drop actions like 'toggle' from URL
|
||||
|
||||
|
||||
Reference in New Issue
Block a user