mirror of
https://github.com/openshwprojects/OpenBK7231T_App.git
synced 2026-02-09 19:05:44 +00:00
Merge branch 'main' of https://github.com/openshwprojects/OpenBK7231T_App
This commit is contained in:
@ -611,6 +611,35 @@ int HTTP_ProcessPacket(http_request_t *request) {
|
||||
|
||||
poststr(request,"<br>");
|
||||
poststr(request,"<a href=\"cfg_mqtt\">Return to MQTT settings</a>");
|
||||
poststr(request,"<br>");
|
||||
poststr(request,htmlReturnToCfg);
|
||||
HTTP_AddBuildFooter(request);
|
||||
poststr(request,htmlEnd);
|
||||
} else if(http_checkUrlBase(urlStr,"cfg_webapp")) {
|
||||
http_setup(request, httpMimeTypeHTML);
|
||||
poststr(request,htmlHeader);
|
||||
poststr(request,g_header);
|
||||
poststr(request,"<h2> Use this to set the URL of the Webapp</h2>");
|
||||
poststr(request,"<form action=\"/cfg_webapp_set\">\
|
||||
<label for=\"url\">Url:</label><br>\
|
||||
<input type=\"text\" id=\"url\" name=\"url\" value=\"");
|
||||
poststr(request,CFG_GetWebappRoot());
|
||||
poststr(request,"\"><br>\
|
||||
<input type=\"submit\" value=\"Submit\">\
|
||||
</form> ");
|
||||
poststr(request,htmlReturnToCfg);
|
||||
HTTP_AddBuildFooter(request);
|
||||
poststr(request,htmlEnd);
|
||||
} else if(http_checkUrlBase(urlStr,"cfg_webapp_set")) {
|
||||
http_setup(request, httpMimeTypeHTML);
|
||||
poststr(request,htmlHeader);
|
||||
poststr(request,g_header);
|
||||
|
||||
if(http_getArg(urlStr,"url",tmpA,sizeof(tmpA))) {
|
||||
CFG_SetWebappRoot(tmpA);
|
||||
}
|
||||
poststr(request,"Webapp url set!");
|
||||
|
||||
poststr(request,"<br>");
|
||||
poststr(request,htmlReturnToCfg);
|
||||
HTTP_AddBuildFooter(request);
|
||||
@ -903,6 +932,7 @@ int HTTP_ProcessPacket(http_request_t *request) {
|
||||
poststr(request,"<form action=\"cfg_quick\"><input type=\"submit\" value=\"Quick Config\"/></form>");
|
||||
poststr(request,"<form action=\"cfg_wifi\"><input type=\"submit\" value=\"Configure WiFi\"/></form>");
|
||||
poststr(request,"<form action=\"cfg_mqtt\"><input type=\"submit\" value=\"Configure MQTT\"/></form>");
|
||||
poststr(request,"<form action=\"cfg_webapp\"><input type=\"submit\" value=\"Configure Webapp\"/></form>");
|
||||
poststr(request,"<form action=\"cfg_ha\"><input type=\"submit\" value=\"Generate Home Assistant cfg\"/></form>");
|
||||
poststr(request,"<form action=\"ota\"><input type=\"submit\" value=\"OTA (update software by WiFi)\"/></form>");
|
||||
poststr(request,"<form action=\"cmd_single\"><input type=\"submit\" value=\"Execute custom command\"/></form>");
|
||||
|
||||
@ -11,6 +11,7 @@ extern const char htmlReturnToMenu[];
|
||||
|
||||
extern const char *htmlPinRoleNames[];
|
||||
|
||||
extern const char *g_build_str;
|
||||
|
||||
#define HTTP_RESPONSE_OK 200
|
||||
#define HTTP_RESPONSE_NOT_FOUND 404
|
||||
|
||||
@ -12,7 +12,8 @@
|
||||
#include "../littlefs/our_lfs.h"
|
||||
#endif
|
||||
#include "lwip/sockets.h"
|
||||
|
||||
#include "../flash_config/flash_config.h"
|
||||
#include "../new_cfg.h"
|
||||
|
||||
|
||||
extern int g_reset;
|
||||
@ -42,7 +43,10 @@ static int http_rest_post_reboot(http_request_t *request);
|
||||
static int http_rest_post_flash(http_request_t *request, int startaddr);
|
||||
static int http_rest_get_flash(http_request_t *request, int startaddr, int len);
|
||||
|
||||
static int http_rest_get_info(http_request_t *request);
|
||||
|
||||
static int http_rest_get_dumpconfig(http_request_t *request);
|
||||
static int http_rest_get_testconfig(http_request_t *request);
|
||||
|
||||
void init_rest(){
|
||||
HTTP_RegisterCallback( "/api/", HTTP_GET, http_rest_get);
|
||||
@ -70,9 +74,8 @@ const char * apppage4 = "startup.js\"></script>"
|
||||
|
||||
|
||||
static int http_rest_app(http_request_t *request){
|
||||
//char *webhost = "http://raspberrypi:1880";//CFG_GetWebRoot();
|
||||
char *webhost = "https://openbekeniot.github.io/webapp/";
|
||||
char *ourip = getMyIp(); //CFG_GetOurIP();
|
||||
const char *webhost = CFG_GetWebappRoot();
|
||||
const char *ourip = getMyIp(); //CFG_GetOurIP();
|
||||
http_setup(request, httpMimeTypeHTML);
|
||||
if (webhost && ourip){
|
||||
poststr(request, apppage1);
|
||||
@ -91,7 +94,6 @@ static int http_rest_app(http_request_t *request){
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#ifdef BK_LITTLEFS
|
||||
|
||||
int EndsWith(const char *str, const char *suffix)
|
||||
@ -301,6 +303,20 @@ static int http_rest_get(http_request_t *request){
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!strcmp(request->url, "api/info")){
|
||||
return http_rest_get_info(request);
|
||||
}
|
||||
|
||||
if (!strcmp(request->url, "api/dumpconfig")){
|
||||
return http_rest_get_dumpconfig(request);
|
||||
}
|
||||
|
||||
if (!strcmp(request->url, "api/testconfig")){
|
||||
return http_rest_get_testconfig(request);
|
||||
}
|
||||
|
||||
|
||||
|
||||
http_setup(request, httpMimeTypeHTML);
|
||||
poststr(request, "GET of ");
|
||||
poststr(request, request->url);
|
||||
@ -466,6 +482,15 @@ static int http_rest_post_logconfig(http_request_t *request){
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
|
||||
static int http_rest_get_info(http_request_t *request){
|
||||
http_setup(request, httpMimeTypeJson);
|
||||
hprintf128(request, "{\"uptimes\":%d,", Time_getUpTimeSeconds());
|
||||
hprintf128(request, "\"build\":\"%s\"}", g_build_str);
|
||||
poststr(request, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int http_rest_post(http_request_t *request){
|
||||
char tmp[20];
|
||||
ADDLOG_DEBUG(LOG_FEATURE_API, "POST to %s", request->url);
|
||||
@ -679,3 +704,89 @@ static int http_rest_get_flash(http_request_t *request, int startaddr, int len){
|
||||
poststr(request, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int http_rest_get_dumpconfig(http_request_t *request){
|
||||
|
||||
config_dump_table();
|
||||
|
||||
http_setup(request, httpMimeTypeText);
|
||||
poststr(request, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// added for OpenBK7231T
|
||||
typedef struct item_new_test_config
|
||||
{
|
||||
INFO_ITEM_ST head;
|
||||
char somename[64];
|
||||
}ITEM_NEW_TEST_CONFIG,*ITEM_NEW_TEST_CONFIG_PTR;
|
||||
|
||||
ITEM_NEW_TEST_CONFIG testconfig;
|
||||
|
||||
static int http_rest_get_testconfig(http_request_t *request){
|
||||
|
||||
INFO_ITEM_ST *ret;
|
||||
int intres;
|
||||
|
||||
testconfig.head.type = (UINT32) *((UINT32*)"TEST");
|
||||
testconfig.head.len = sizeof(testconfig) - sizeof(testconfig.head);
|
||||
strcpy(testconfig.somename, "test it here");
|
||||
|
||||
config_dump_table();
|
||||
|
||||
ret = config_search_item((INFO_ITEM_ST *)&testconfig);
|
||||
ADDLOG_DEBUG(LOG_FEATURE_API, "search found %x", ret);
|
||||
|
||||
config_dump_table();
|
||||
|
||||
intres = config_delete_item(testconfig.head.type);
|
||||
ADDLOG_DEBUG(LOG_FEATURE_API, "delete_item returned %d", intres);
|
||||
|
||||
intres = config_save_item((INFO_ITEM_ST *)&testconfig);
|
||||
|
||||
ADDLOG_DEBUG(LOG_FEATURE_API, "save_item returned %d", intres);
|
||||
|
||||
ret = config_search_item((INFO_ITEM_ST *)&testconfig);
|
||||
ADDLOG_DEBUG(LOG_FEATURE_API, "search2 found %x len %d", ret, (ret?ret->len:0));
|
||||
|
||||
intres = config_save_item((INFO_ITEM_ST *)&testconfig);
|
||||
ADDLOG_DEBUG(LOG_FEATURE_API, "save_item returned %d", intres);
|
||||
|
||||
ret = config_search_item((INFO_ITEM_ST *)&testconfig);
|
||||
ADDLOG_DEBUG(LOG_FEATURE_API, "search3 found %x len %d", ret, (ret?ret->len:0));
|
||||
|
||||
|
||||
if (ret){
|
||||
if (os_memcmp(ret, &testconfig, sizeof(testconfig))){
|
||||
ADDLOG_DEBUG(LOG_FEATURE_API, "content mismatch");
|
||||
} else {
|
||||
ADDLOG_DEBUG(LOG_FEATURE_API, "content match");
|
||||
}
|
||||
}
|
||||
|
||||
testconfig.head.len = sizeof(testconfig) - sizeof(testconfig.head) - 1;
|
||||
intres = config_save_item((INFO_ITEM_ST *)&testconfig);
|
||||
ADDLOG_DEBUG(LOG_FEATURE_API, "save_item returned %d", intres);
|
||||
|
||||
|
||||
ret = config_search_item((INFO_ITEM_ST *)&testconfig);
|
||||
ADDLOG_DEBUG(LOG_FEATURE_API, "search4 found %x len %d", ret, (ret?ret->len:0));
|
||||
|
||||
config_dump_table();
|
||||
|
||||
intres = config_delete_item(testconfig.head.type);
|
||||
ADDLOG_DEBUG(LOG_FEATURE_API, "delete_item returned %d", intres);
|
||||
|
||||
config_dump_table();
|
||||
|
||||
config_release_tbl();
|
||||
|
||||
config_dump_table();
|
||||
|
||||
http_setup(request, httpMimeTypeText);
|
||||
poststr(request, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user