diff --git a/.vscode/settings.json b/.vscode/settings.json
index 6fde7f8f5..27dd067b8 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -16,4 +16,4 @@
"prettier.tabWidth": 4,
"prettier.useTabs": true,
"prettier.printWidth": 120
-}
+}
\ No newline at end of file
diff --git a/Makefile b/Makefile
index b51ba0bfd..7d10d2f40 100644
--- a/Makefile
+++ b/Makefile
@@ -1,8 +1,11 @@
# HACK - if COMPILE_PREX defined then we are being called running from original build_app.sh script in standard SDK
# Required to not break old build_app.sh script lines 74-77
+MBEDTLS=output/mbedtls-2.28.5
ifdef COMPILE_PREX
all:
@echo Calling original build_app.sh script
+ mkdir -p output
+ if [ ! -d "$(MBEDTLS)" ]; then wget -q "https://github.com/Mbed-TLS/mbedtls/archive/refs/tags/v2.28.5.tar.gz"; tar -xf v2.28.5.tar.gz -C output; rm -f v2.28.5.tar.gz; mv $(MBEDTLS)/library/base64.c $(MBEDTLS)/library/base64_mbedtls.c; fi
cd $(PWD)/../../platforms/$(TARGET_PLATFORM)/toolchain/$(TUYA_APPS_BUILD_PATH) && sh $(TUYA_APPS_BUILD_CMD) $(APP_NAME) $(APP_VERSION) $(TARGET_PLATFORM) "$(USER_CMD)" $(BUILD_MODE)
else
@@ -204,9 +207,13 @@ prebuild_OpenBK7231N_ALT:
# Build main binaries
OpenBK7231T: prebuild_OpenBK7231T
+ mkdir -p output
+ if [ ! -d "$(MBEDTLS)" ]; then wget -q "https://github.com/Mbed-TLS/mbedtls/archive/refs/tags/v2.28.5.tar.gz"; tar -xf v2.28.5.tar.gz -C output; rm -f v2.28.5.tar.gz; mv $(MBEDTLS)/library/base64.c $(MBEDTLS)/library/base64_mbedtls.c; fi
$(MAKE) APP_NAME=OpenBK7231T TARGET_PLATFORM=bk7231t SDK_PATH=sdk/OpenBK7231T APPS_BUILD_PATH=../bk7231t_os build-BK7231
OpenBK7231N: prebuild_OpenBK7231N
+ mkdir -p output
+ if [ ! -d "$(MBEDTLS)" ]; then wget -q "https://github.com/Mbed-TLS/mbedtls/archive/refs/tags/v2.28.5.tar.gz"; tar -xf v2.28.5.tar.gz -C output; rm -f v2.28.5.tar.gz; mv $(MBEDTLS)/library/base64.c $(MBEDTLS)/library/base64_mbedtls.c; fi
$(MAKE) APP_NAME=OpenBK7231N TARGET_PLATFORM=bk7231n SDK_PATH=sdk/OpenBK7231N APPS_BUILD_PATH=../bk7231n_os build-BK7231
sdk/OpenXR809/tools/gcc-arm-none-eabi-4_9-2015q2:
diff --git a/components.mk b/components.mk
new file mode 100644
index 000000000..552b58a77
--- /dev/null
+++ b/components.mk
@@ -0,0 +1,69 @@
+ifeq ($(TARGET_PLATFORM),bk7231n)
+
+CFG_USE_MQTT_TLS ?= 0
+
+ifeq ($(CFG_USE_MQTT_TLS),1)
+
+MBEDTLS_DIR = $(TOP_DIR)/apps/$(APP_BIN_NAME)/output/mbedtls-2.28.5
+INCLUDES := -I$(MBEDTLS_DIR)/include -I$(TOP_DIR)/apps/$(APP_BIN_NAME)/src $(INCLUDES)
+MQTT_TLS_DEFS += -DMQTT_USE_TLS=1
+MQTT_TLS_DEFS += -DLWIP_ALTCP=1
+MQTT_TLS_DEFS += -DLWIP_ALTCP_TLS=1
+MQTT_TLS_DEFS += -DLWIP_ALTCP_TLS_MBEDTLS=1
+MQTT_TLS_DEFS += -DMEMP_NUM_ALTCP_PCB=4
+MQTT_TLS_DEFS += -DMBEDTLS_CONFIG_FILE='"user_mbedtls_config.h"'
+CPPDEFINES += $(MQTT_TLS_DEFS) -Wno-misleading-indentation
+OSFLAGS += $(MQTT_TLS_DEFS)
+
+SRC_C += ./beken378/func/lwip_intf/lwip-2.1.3/src/apps/altcp_tls/altcp_tls_mbedtls.c
+SRC_C += ./beken378/func/lwip_intf/lwip-2.1.3/src/apps/altcp_tls/altcp_tls_mbedtls_mem.c
+SRC_C += ${MBEDTLS_DIR}/library/ssl_tls.c
+SRC_C += ${MBEDTLS_DIR}/library/x509_crt.c
+SRC_C += ${MBEDTLS_DIR}/library/entropy.c
+SRC_C += ${MBEDTLS_DIR}/library/chachapoly.c
+SRC_C += ${MBEDTLS_DIR}/library/ctr_drbg.c
+SRC_C += ${MBEDTLS_DIR}/library/ssl_msg.c
+SRC_C += ${MBEDTLS_DIR}/library/debug.c
+SRC_C += ${MBEDTLS_DIR}/library/md.c
+SRC_C += ${MBEDTLS_DIR}/library/sha512.c
+SRC_C += ${MBEDTLS_DIR}/library/platform_util.c
+SRC_C += ${MBEDTLS_DIR}/library/sha256.c
+SRC_C += ${MBEDTLS_DIR}/library/sha1.c
+SRC_C += ${MBEDTLS_DIR}/library/ripemd160.c
+SRC_C += ${MBEDTLS_DIR}/library/md5.c
+SRC_C += ${MBEDTLS_DIR}/library/cipher.c
+SRC_C += ${MBEDTLS_DIR}/library/gcm.c
+SRC_C += ${MBEDTLS_DIR}/library/chacha20.c
+SRC_C += ${MBEDTLS_DIR}/library/ccm.c
+SRC_C += ${MBEDTLS_DIR}/library/constant_time.c
+SRC_C += ${MBEDTLS_DIR}/library/aes.c
+SRC_C += ${MBEDTLS_DIR}/library/poly1305.c
+SRC_C += ${MBEDTLS_DIR}/library/pem.c
+SRC_C += ${MBEDTLS_DIR}/library/des.c
+SRC_C += ${MBEDTLS_DIR}/library/asn1parse.c
+SRC_C += ${MBEDTLS_DIR}/library/base64_mbedtls.c
+SRC_C += ${MBEDTLS_DIR}/library/x509.c
+SRC_C += ${MBEDTLS_DIR}/library/oid.c
+SRC_C += ${MBEDTLS_DIR}/library/pkparse.c
+SRC_C += ${MBEDTLS_DIR}/library/ecp.c
+SRC_C += ${MBEDTLS_DIR}/library/bignum.c
+SRC_C += ${MBEDTLS_DIR}/library/pk.c
+SRC_C += ${MBEDTLS_DIR}/library/pk_wrap.c
+SRC_C += ${MBEDTLS_DIR}/library/ecdsa.c
+SRC_C += ${MBEDTLS_DIR}/library/asn1write.c
+SRC_C += ${MBEDTLS_DIR}/library/hmac_drbg.c
+SRC_C += ${MBEDTLS_DIR}/library/rsa.c
+SRC_C += ${MBEDTLS_DIR}/library/rsa_internal.c
+SRC_C += ${MBEDTLS_DIR}/library/ecp_curves.c
+SRC_C += ${MBEDTLS_DIR}/library/ssl_ciphersuites.c
+SRC_C += ${MBEDTLS_DIR}/library/ecdh.c
+SRC_C += ${MBEDTLS_DIR}/library/dhm.c
+SRC_C += ${MBEDTLS_DIR}/library/ssl_srv.c
+SRC_C += ${MBEDTLS_DIR}/library/cipher_wrap.c
+SRC_C += ${MBEDTLS_DIR}/library/arc4.c
+SRC_C += ${MBEDTLS_DIR}/library/blowfish.c
+SRC_C += ${MBEDTLS_DIR}/library/camellia.c
+SRC_C += ${MBEDTLS_DIR}/library/ssl_cli.c
+
+endif #ifeq ($(CFG_USE_MQTT_TLS),1)
+endif #ifeq ($(TARGET_PLATFORM),bk7231n)
\ No newline at end of file
diff --git a/docs/commands.md b/docs/commands.md
index ea148f9b0..886e5f7dc 100644
--- a/docs/commands.md
+++ b/docs/commands.md
@@ -332,6 +332,7 @@ Do not add anything here, as it will overwritten with next rebuild.
| VCPPublishThreshold | [VoltageDeltaVolts][CurrentDeltaAmpers][PowerDeltaWats][EnergyDeltaWh] | Sets the minimal change between previous reported value over MQTT and next reported value over MQTT. Very useful for BL0942, BL0937, etc. So, if you set, VCPPublishThreshold 0.5 0.001 0.5, it will only report voltage again if the delta from previous reported value is largen than 0.5V. Remember, that the device will also ALWAYS force-report values every N seconds (default 60).
See also [VCPPublishThreshold on forum](https://www.elektroda.com/rtvforum/find.php?q=VCPPublishThreshold). |
| VoltageSet | Voltage | Measure the real voltage with an external, reliable power meter and enter this voltage via this command to calibrate. The calibration is automatically saved in the flash memory.
See also [VoltageSet on forum](https://www.elektroda.com/rtvforum/find.php?q=VoltageSet). |
| waitFor | [EventName] [Argument] | Wait forever for event. Can be used within script. For example, you can do: waitFor MQTTState 1 or waitFor NTPState 1. You can also do waitFor NoPingTime 600 to wait for 600 seconds without ping watchdog getting successful reply.
See also [waitFor on forum](https://www.elektroda.com/rtvforum/find.php?q=waitFor). |
+| WebServer | [1or0] | Enable/Disable web interface. 1 to Enable. 0 to Disable. No argument, returns the actual state of the web server interface. No effect on safe mode. In safe mode, the web interface is always enabled. |
| widget_clearAll | | Removes all registered widgets.
See also [widget_clearAll on forum](https://www.elektroda.com/rtvforum/find.php?q=widget_clearAll). |
| widget_create | [LocationIndex][bAllowCache][FileName] | .
See also [widget_create on forum](https://www.elektroda.com/rtvforum/find.php?q=widget_create). |
diff --git a/src/cmnds/cmd_main.c b/src/cmnds/cmd_main.c
index 930b1eb40..d22a17e46 100644
--- a/src/cmnds/cmd_main.c
+++ b/src/cmnds/cmd_main.c
@@ -12,6 +12,8 @@
#include "../driver/drv_public.h"
#include "../hal/hal_adc.h"
#include "../hal/hal_flashVars.h"
+#include "../httpserver/http_tcp_server.h"
+#include "../hal/hal_generic.h"
int cmd_uartInitIndex = 0;
@@ -804,6 +806,37 @@ commandResult_t CMD_DeepSleep_SetEdge(const void* context, const char* cmd, cons
return CMD_RES_OK;
}
+#if MQTT_USE_TLS
+static commandResult_t CMD_WebServer(const void* context, const char* cmd, const char* args, int cmdFlags) {
+ int arg_count;
+ Tokenizer_TokenizeString(args, 0);
+ arg_count = Tokenizer_GetArgsCount();
+ if (arg_count == 0)
+ {
+ ADDLOG_INFO(LOG_FEATURE_CMD, "WebServer:%d", !CFG_GetDisableWebServer());
+ return CMD_RES_OK;
+ }
+ if (arg_count == 1) {
+ if (strcmp(Tokenizer_GetArg(0) , "0") == 0) {
+ ADDLOG_INFO(LOG_FEATURE_CMD, "Stop WebServer");
+ CFG_SetDisableWebServer(true);
+ CFG_Save_IfThereArePendingChanges();
+ HTTPServer_Stop();
+ return CMD_RES_OK;
+ }
+ else if (strcmp(Tokenizer_GetArg(0), "1") == 0) {
+ ADDLOG_INFO(LOG_FEATURE_CMD, "Enable WebServer and restart");
+ CFG_SetDisableWebServer(false);
+ CFG_Save_IfThereArePendingChanges();
+ HAL_RebootModule();
+ return CMD_RES_OK;
+ }
+ }
+ ADDLOG_ERROR(LOG_FEATURE_CMD, "Invalid Argument");
+ return CMD_RES_BAD_ARGUMENT;
+}
+#endif
+
void CMD_Init_Early() {
//cmddetail:{"name":"alias","args":"[Alias][Command with spaces]",
//cmddetail:"descr":"add an aliased command, so a command with spaces can be called with a short, nospaced alias",
@@ -933,6 +966,13 @@ void CMD_Init_Early() {
//cmddetail:"fn":"NULL);","file":"cmnds/cmd_main.c","requires":"",
//cmddetail:"examples":""}
CMD_RegisterCommand("IndexRefreshInterval", CMD_IndexRefreshInterval, NULL);
+#if MQTT_USE_TLS
+ //cmddetail:{"name":"WebServer","args":"[0 - Stop / 1 - Start]",
+ //cmddetail:"descr":"Setting state of WebServer",
+ //cmddetail:"fn":"CMD_WebServer","file":"cmnds/cmd_main.c","requires":"",
+ //cmddetail:"examples":""}
+ CMD_RegisterCommand("WebServer", CMD_WebServer, NULL);
+#endif
#if ENABLE_OBK_SCRIPTING
CMD_InitScripting();
diff --git a/src/driver/drv_cht8305.c b/src/driver/drv_cht8305.c
index 0b3ce8690..3a39b09ed 100644
--- a/src/driver/drv_cht8305.c
+++ b/src/driver/drv_cht8305.c
@@ -282,9 +282,9 @@ void CHT83XX_Init()
//cmddetail:"examples":"CHT_Cycle 60
measurement is taken every 60 seconds"}
CMD_RegisterCommand("CHT_Cycle", CHT83XX_Cycle, NULL);
//cmddetail:{"name":"CHT_Alert","args":"[TempDiff][HumDiff][Freq][FQ]",
- //cmddetail:"descr":"Enable alert pin. TempDif (temperature difference is any float higher than 0.05°C) = set detected difference in temperature required for device to wake. HumDiff (humidity difference is any float higher than 0.1%). Freq (time per measurement in s) = 1, 5, 10, 60, 120 (default if wrong = 1). FQ (fault queue number) = 1, 2, 4, 6 (default if wrong = 1)",
+ //cmddetail:"descr":"Enable alert pin. TempDif (temperature difference is any float higher than 0.05�C) = set detected difference in temperature required for device to wake. HumDiff (humidity difference is any float higher than 0.1%). Freq (time per measurement in s) = 1, 5, 10, 60, 120 (default if wrong = 1). FQ (fault queue number) = 1, 2, 4, 6 (default if wrong = 1)",
//cmddetail:"fn":"CHT_Alert","file":"drv/drv_cht8305.c","requires":"",
- //cmddetail:"examples":"CHT_Alert 0.5 0 5 2
alert pin will trigger when temperature deviates by more than 0.5°C. Humidity will be ignored. Sensor measures every 5s with fault queue number 2."}
+ //cmddetail:"examples":"CHT_Alert 0.5 0 5 2
alert pin will trigger when temperature deviates by more than 0.5�C. Humidity will be ignored. Sensor measures every 5s with fault queue number 2."}
CMD_RegisterCommand("CHT_Alert", CHT83XX_Alert, NULL);
}
diff --git a/src/httpserver/http_fns.c b/src/httpserver/http_fns.c
index 4b0b4f804..3cbca27f9 100644
--- a/src/httpserver/http_fns.c
+++ b/src/httpserver/http_fns.c
@@ -19,6 +19,9 @@
#include
#include "../driver/drv_ntp.h"
#include "../driver/drv_local.h"
+#ifdef PLATFORM_BEKEN
+#include "start_type_pub.h"
+#endif
#ifdef WINDOWS
// nothing
@@ -1073,6 +1076,14 @@ int http_fn_cfg_mqtt_set(http_request_t* request) {
if (http_getArg(request->url, "port", tmpA, sizeof(tmpA))) {
CFG_SetMQTTPort(atoi(tmpA));
}
+
+#if MQTT_USE_TLS
+ CFG_SetMQTTUseTls(http_getArg(request->url, "mqtt_use_tls", tmpA, sizeof(tmpA)));
+ CFG_SetMQTTVerifyTlsCert(http_getArg(request->url, "mqtt_verify_tls_cert", tmpA, sizeof(tmpA)));
+ http_getArg(request->url, "mqtt_cert_file", tmpA, sizeof(tmpA));
+ CFG_SetMQTTCertFile(tmpA);
+#endif
+
if (http_getArg(request->url, "user", tmpA, sizeof(tmpA))) {
CFG_SetMQTTUserName(tmpA);
}
@@ -1109,6 +1120,21 @@ int http_fn_cfg_mqtt(http_request_t* request) {
add_label_text_field(request, "Host", "host", CFG_GetMQTTHost(), "