diff --git a/platforms/LN882H/CMakeLists.txt b/platforms/LN882H/CMakeLists.txt index a58c5d23d..e4f5dc8a6 100644 --- a/platforms/LN882H/CMakeLists.txt +++ b/platforms/LN882H/CMakeLists.txt @@ -59,6 +59,7 @@ set(PROJ_ALL_SRC app/src/driver/drv_mcp9808.c # app/src/driver/drv_ntp_events.c app/src/driver/drv_ntp.c + app/src/driver/drv_openWeatherMap.c app/src/driver/drv_pt6523.c app/src/driver/drv_pwm_groups.c app/src/driver/drv_pwmToggler.c diff --git a/platforms/W600/Makefile b/platforms/W600/Makefile index 8f49d7529..c201feda1 100644 --- a/platforms/W600/Makefile +++ b/platforms/W600/Makefile @@ -34,14 +34,22 @@ CSRCS += $(_SHARED_APP)/cmnds/cmd_test.c CSRCS += $(_SHARED_APP)/cmnds/cmd_tcp.c CSRCS += $(_SHARED_APP)/cmnds/cmd_tokenizer.c CSRCS += $(_SHARED_APP)/cmnds/cmd_if.c +CSRCS += $(_SHARED_APP)/cmnds/cmd_script.c CSRCS += $(_SHARED_APP)/cJSON/cJSON.c CSRCS += $(_SHARED_APP)/base64/base64.c CSRCS += $(_SHARED_APP)/devicegroups/deviceGroups_read.c CSRCS += $(_SHARED_APP)/devicegroups/deviceGroups_write.c CSRCS += $(_SHARED_APP)/devicegroups/deviceGroups_util.c +CSRCS += $(_SHARED_APP)/driver/drv_aht2x.c +CSRCS += $(_SHARED_APP)/driver/drv_sht3x.c CSRCS += $(_SHARED_APP)/driver/drv_bl0937.c CSRCS += $(_SHARED_APP)/driver/drv_bl_shared.c +CSRCS += $(_SHARED_APP)/driver/drv_ssdp.c +CSRCS += $(_SHARED_APP)/driver/drv_openWeatherMap.c CSRCS += $(_SHARED_APP)/driver/drv_pwrCal.c +CSRCS += $(_SHARED_APP)/driver/drv_bmp280.c +CSRCS += $(_SHARED_APP)/driver/drv_bmpi2c.c +CSRCS += $(_SHARED_APP)/driver/drv_soft_i2c.c CSRCS += $(_SHARED_APP)/driver/drv_dht.c CSRCS += $(_SHARED_APP)/driver/drv_dht_internal.c CSRCS += $(_SHARED_APP)/driver/drv_httpButtons.c diff --git a/platforms/W800/Makefile b/platforms/W800/Makefile index af56539e3..124b2806e 100644 --- a/platforms/W800/Makefile +++ b/platforms/W800/Makefile @@ -61,6 +61,8 @@ CSRCS += $(_SHARED_APP)/new_ping.c CSRCS += $(_SHARED_APP)/new_pins.c CSRCS += $(_SHARED_APP)/rgb2hsv.c CSRCS += $(_SHARED_APP)/tiny_crc8.c +CSRCS += $(_SHARED_APP)/driver/drv_aht2x.c +CSRCS += $(_SHARED_APP)/driver/drv_sht3x.c CSRCS += $(_SHARED_APP)/driver/drv_adcButton.c CSRCS += $(_SHARED_APP)/driver/drv_adcSmoother.c CSRCS += $(_SHARED_APP)/driver/drv_battery.c diff --git a/sdk/OpenW800 b/sdk/OpenW800 index d345661b0..590585c25 160000 --- a/sdk/OpenW800 +++ b/sdk/OpenW800 @@ -1 +1 @@ -Subproject commit d345661b0a0639cde8a18a2ceec147f6ad1a1e5c +Subproject commit 590585c25a0d83af546a55df6f396a8dea369e65 diff --git a/src/cmnds/cmd_eventHandlers.c b/src/cmnds/cmd_eventHandlers.c index d349ad301..815ed115f 100644 --- a/src/cmnds/cmd_eventHandlers.c +++ b/src/cmnds/cmd_eventHandlers.c @@ -304,7 +304,7 @@ void EventHandlers_ProcessVariableChange_Integer(byte eventCode, int oldValue, i ev = ev->next; } -#if defined(PLATFORM_BEKEN) || defined(WINDOWS) || defined(PLATFORM_BL602) || defined(PLATFORM_LN882H) +#if ENABLE_OBK_SCRIPTING CMD_Script_ProcessWaitersForEvent(eventCode, newValue); #endif } @@ -388,7 +388,7 @@ void EventHandlers_FireEvent(byte eventCode, int argument) { ev = ev->next; } -#if defined(PLATFORM_BEKEN) || defined(WINDOWS) || defined(PLATFORM_BL602) || defined(PLATFORM_LN882H) +#if ENABLE_OBK_SCRIPTING CMD_Script_ProcessWaitersForEvent(eventCode, argument); #endif } diff --git a/src/cmnds/cmd_public.h b/src/cmnds/cmd_public.h index 7b5509365..ce37b32b7 100644 --- a/src/cmnds/cmd_public.h +++ b/src/cmnds/cmd_public.h @@ -169,7 +169,8 @@ int Tokenizer_GetArgsCount(); bool Tokenizer_CheckArgsCountAndPrintWarning(const char* cmdStr, int reqCount); const char* Tokenizer_GetArg(int i); const char* Tokenizer_GetArgFrom(int i); -int Tokenizer_GetArgInteger(int i); +int Tokenizer_GetArgInteger(int i); +int Tokenizer_GetPin(int i, int def); int Tokenizer_GetArgIntegerDefault(int i, int def); float Tokenizer_GetArgFloatDefault(int i, float def); bool Tokenizer_IsArgInteger(int i); @@ -271,6 +272,7 @@ const char* CMD_GetResultString(commandResult_t r); void SVM_RunThreads(int deltaMS); void CMD_InitScripting(); +void SVM_RunStartupCommandAsScript(); byte* LFS_ReadFile(const char* fname); int LFS_WriteFile(const char *fname, const byte *data, int len, bool bAppend); diff --git a/src/cmnds/cmd_script.c b/src/cmnds/cmd_script.c index ad43310e9..f7aab7c46 100644 --- a/src/cmnds/cmd_script.c +++ b/src/cmnds/cmd_script.c @@ -299,7 +299,12 @@ scriptFile_t *SVM_RegisterFile(const char *fname) { memset(r,0,sizeof(scriptFile_t)); r->fname = strdup(fname); // cast from byte* to char* - r->data = (char*)LFS_ReadFile(fname); + if (!strcmp(fname, "@startup")) { + r->data = strdup(CFG_GetShortStartupCommand()); + } + else { + r->data = (char*)LFS_ReadFile(fname); + } r->next = g_scriptFiles; g_scriptFiles = r; if(r->data == 0) @@ -356,8 +361,7 @@ const char *SVM_FindLabel(const char *text, const char *label, const char *fname ADDLOG_INFO(LOG_FEATURE_CMD, "Label %s not found in %s - will go to the start of file",label,fname); return text; } -void SVM_RunThread(scriptInstance_t *t) { - int maxLoops = 10; +void SVM_RunThread(scriptInstance_t *t, int maxLoops) { int loop = 0; const char *start, *end; int len, p; @@ -449,7 +453,7 @@ void SVM_RunThreads(int deltaMS) { c_sleep++; } else { - SVM_RunThread(g_activeThread); + SVM_RunThread(g_activeThread, 20); c_run++; } } @@ -585,7 +589,7 @@ void SVM_GoToLocal(scriptInstance_t *th, const char *label) { return; } -void SVM_StartScript(const char *fname, const char *label, int uniqueID) { +scriptInstance_t *SVM_StartScript(const char *fname, const char *label, int uniqueID) { scriptFile_t *f; scriptInstance_t *th; @@ -593,18 +597,18 @@ void SVM_StartScript(const char *fname, const char *label, int uniqueID) { if(f == 0) { ADDLOG_INFO(LOG_FEATURE_CMD, "CMD_StartScript: failed to get file %s",fname); - return; + return NULL; } if(f->data == 0) { ADDLOG_INFO(LOG_FEATURE_CMD, "CMD_StartScript: failed to get file %s dataa",fname); - return; + return NULL; } th = SVM_RegisterThread(); if(th == 0) { ADDLOG_INFO(LOG_FEATURE_CMD, "CMD_StartScript: failed to alloc thread"); - return; + return NULL; } th->uniqueID = uniqueID; th->curFile = f; @@ -616,7 +620,21 @@ void SVM_StartScript(const char *fname, const char *label, int uniqueID) { ADDLOG_INFO(LOG_FEATURE_CMD, "CMD_StartScript: started %s at label %s",fname,label); } - return; + return th; +} +void SVM_RunStartupCommandAsScript() { + scriptInstance_t *th = SVM_StartScript("@startup", 0, 0); + if (th) { + //ADDLOG_INFO(LOG_FEATURE_CMD, "SVM_RunStartupCommandAsScript: started command run"); + // Hacky as hell? + g_activeThread = th; + SVM_RunThread(g_activeThread, 200); + g_activeThread = 0; + } + else { + //ADDLOG_INFO(LOG_FEATURE_CMD, "SVM_RunStartupCommandAsScript: failed command run"); + } + } static commandResult_t CMD_GoTo(const void *context, const char *cmd, const char *args, int cmdFlags){ diff --git a/src/cmnds/cmd_tokenizer.c b/src/cmnds/cmd_tokenizer.c index 1859c63ce..cc45b55a0 100644 --- a/src/cmnds/cmd_tokenizer.c +++ b/src/cmnds/cmd_tokenizer.c @@ -6,6 +6,7 @@ #include "../new_pins.h" #include "../new_cfg.h" #include "../logging/logging.h" +#include "../hal/hal_pins.h" #define MAX_CMD_LEN 512 #define MAX_ARGS 32 @@ -209,6 +210,14 @@ int Tokenizer_GetArgIntegerRange(int i, int rangeMin, int rangeMax) { } return ret; } +int Tokenizer_GetPin(int i, int def) { + int r; + + if (g_numArgs <= i) { + return def; + } + return HAL_PIN_Find(g_args[i]); +} int Tokenizer_GetArgIntegerDefault(int i, int def) { int r; diff --git a/src/driver/drv_aht2x.c b/src/driver/drv_aht2x.c index f4553fe1b..6cbf762c4 100644 --- a/src/driver/drv_aht2x.c +++ b/src/driver/drv_aht2x.c @@ -185,8 +185,8 @@ commandResult_t AHT2X_Reinit(const void* context, const char* cmd, const char* a void AHT2X_Init() { - g_softI2C.pin_clk = Tokenizer_GetArgIntegerDefault(1, 9); - g_softI2C.pin_data = Tokenizer_GetArgIntegerDefault(2, 14); + g_softI2C.pin_clk = Tokenizer_GetPin(1, 9); + g_softI2C.pin_data = Tokenizer_GetPin(2, 14); channel_temp = Tokenizer_GetArgIntegerDefault(3, -1); channel_humid = Tokenizer_GetArgIntegerDefault(4, -1); @@ -232,7 +232,7 @@ void AHT2X_OnEverySecond() void AHT2X_AppendInformationToHTTPIndexPage(http_request_t* request) { - hprintf255(request, "

AHT2X Temperature=%f, Humidity=%f

", g_temp, g_humid); + hprintf255(request, "

AHT2X Temperature=%.1fC, Humidity=%.0f%%

", g_temp, g_humid); if(!isWorking) { hprintf255(request, "WARNING: AHT sensor appears to have failed initialization, check if configured pins are correct!"); diff --git a/src/driver/drv_bmp280.c b/src/driver/drv_bmp280.c index 9891442b6..0901f8f87 100644 --- a/src/driver/drv_bmp280.c +++ b/src/driver/drv_bmp280.c @@ -43,8 +43,8 @@ void BMP280_Stop(void) { //manufacturer ID // Adr8bit 236 for 0x76, 238 for 0x77 void BMP280_Init() { - g_softI2C.pin_clk = Tokenizer_GetArgIntegerDefault(1, 8); - g_softI2C.pin_data = Tokenizer_GetArgIntegerDefault(2, 14); + g_softI2C.pin_clk = Tokenizer_GetPin(1, 8); + g_softI2C.pin_data = Tokenizer_GetPin(2, 14); g_targetChannelTemperature = Tokenizer_GetArgIntegerDefault(3, -1); g_targetChannelPressure = Tokenizer_GetArgIntegerDefault(4, -1); g_targetChannelHumidity = Tokenizer_GetArgIntegerDefault(5, -1); diff --git a/src/driver/drv_openWeatherMap.c b/src/driver/drv_openWeatherMap.c index 4b4097a43..0d0e2ed88 100644 --- a/src/driver/drv_openWeatherMap.c +++ b/src/driver/drv_openWeatherMap.c @@ -254,7 +254,7 @@ void OWM_AppendInformationToHTTPIndexPage(http_request_t *request) { struct tm *tm = gmtime(&g_weather.sunrise); strftime(buff, sizeof(buff), "%H:%M:%S", tm); hprintf255(request, "
Timezone: %d, Sunrise: %s, ", g_weather.timezone, buff); - tm = gmtime(&g_weather.sunrise); + tm = gmtime(&g_weather.sunset); strftime(buff, sizeof(buff), "%H:%M:%S", tm); hprintf255(request, "Sunset: %s
", buff); } diff --git a/src/driver/drv_sht3x.c b/src/driver/drv_sht3x.c index e8c830082..c7718ed8f 100644 --- a/src/driver/drv_sht3x.c +++ b/src/driver/drv_sht3x.c @@ -519,7 +519,7 @@ void SHT3X_OnEverySecond() void SHT3X_AppendInformationToHTTPIndexPage(http_request_t* request) { - hprintf255(request, "

SHT3X Temperature=%.1f°c, Humidity=%.0f%

", g_temp, g_humid); + hprintf255(request, "

SHT3X Temperature=%.1fC, Humidity=%.0f%%

", g_temp, g_humid); if (channel_humid == channel_temp) { hprintf255(request, "WARNING: You don't have configured target channels for temp and humid results, set the first and second channel index in Pins!"); } diff --git a/src/hal/hal_pins.h b/src/hal/hal_pins.h index c8c9f1e1f..689791188 100644 --- a/src/hal/hal_pins.h +++ b/src/hal/hal_pins.h @@ -11,6 +11,8 @@ void HAL_PIN_PWM_Start(int index); void HAL_PIN_PWM_Update(int index, float value); int HAL_PIN_CanThisPinBePWM(int index); const char* HAL_PIN_GetPinNameAlias(int index); +// Translate name like RB5 for OBK pin index +int HAL_PIN_Find(const char *name); /// @brief Get the actual GPIO pin for the pin index. /// @param index diff --git a/src/hal/ln882h/hal_pins_ln882h.c b/src/hal/ln882h/hal_pins_ln882h.c index 91651c3c9..565496d90 100644 --- a/src/hal/ln882h/hal_pins_ln882h.c +++ b/src/hal/ln882h/hal_pins_ln882h.c @@ -51,6 +51,19 @@ lnPinMapping_t g_pins[] = { static int g_numPins = sizeof(g_pins) / sizeof(g_pins[0]); +int HAL_PIN_Find(const char *name) { + if (isdigit(name[0])) { + return atoi(name); + } + for (int i = 0; i < g_numPins; i++) { + if (!stricmp(g_pins[i].name, name)) { + return i; + } + } + return -1; +} + + int PIN_GetPWMIndexForPinIndex(int pin) { return -1; } diff --git a/src/hal/w800/hal_pins_w800.c b/src/hal/w800/hal_pins_w800.c index cc885429b..b11f05b6c 100644 --- a/src/hal/w800/hal_pins_w800.c +++ b/src/hal/w800/hal_pins_w800.c @@ -94,6 +94,18 @@ static wmPin_t g_pins[] = { static int g_numPins = sizeof(g_pins) / sizeof(g_pins[0]); +int HAL_PIN_Find(const char *name) { + if (isdigit(name[0])) { + return atoi(name); + } + for (int i = 0; i < g_numPins; i++) { + if (!stricmp(g_pins[i].name, name)) { + return i; + } + } + return -1; +} + static int IsPinIndexOk(int index) { if (index < 0) return 0; diff --git a/src/hal/win32/hal_pins_win32.c b/src/hal/win32/hal_pins_win32.c index 84f96606b..0c6e01a7c 100644 --- a/src/hal/win32/hal_pins_win32.c +++ b/src/hal/win32/hal_pins_win32.c @@ -38,6 +38,9 @@ static int adcToGpio[] = { }; static int c_adcToGpio = sizeof(adcToGpio)/sizeof(adcToGpio[0]); +int HAL_PIN_Find(const char *name) { + return atoi(name); +} static int gpioToAdc(int gpio) { int i; diff --git a/src/httpserver/http_fns.c b/src/httpserver/http_fns.c index 31fcea2e6..2e2616ac2 100644 --- a/src/httpserver/http_fns.c +++ b/src/httpserver/http_fns.c @@ -1628,7 +1628,7 @@ int http_fn_cmd_tool(http_request_t* request) { #if ENABLE_HTTP_STARTUP int http_fn_startup_command(http_request_t* request) { - char tmpA[512]; + char tmpA[8]; http_setup(request, httpMimeTypeHTML); http_html_start(request, "Set startup command"); poststr_h4(request, "Set/Change/Clear startup command line"); @@ -1638,15 +1638,27 @@ int http_fn_startup_command(http_request_t* request) { "Use backlog cmd1; cmd2; cmd3; etc to enter multiple commands

"); if (http_getArg(request->url, "startup_cmd", tmpA, sizeof(tmpA))) { - http_getArg(request->url, "data", tmpA, sizeof(tmpA)); - // hprintf255(request,"

Set command to %s!

",tmpA); - // tmpA can be longer than 128 bytes and this would crash - hprintf255(request, "

Command changed!

"); - CFG_SetShortStartupCommand(tmpA); + // direct config access to remove buffer on stack + int realSize = http_getArg(request->url, "data", g_cfg.initCommandLine, sizeof(g_cfg.initCommandLine)); + // mark as dirty (value has changed) + g_cfg_pendingChanges++; + if (realSize >= sizeof(g_cfg.initCommandLine)) { + hprintf255(request, "

Command trimmed from %i to %i!

",realSize, sizeof(g_cfg.initCommandLine)); + } else { + hprintf255(request, "

Command changed!

"); + } CFG_Save_IfThereArePendingChanges(); } +#if ENABLE_OBK_SCRIPTING + poststr(request, "
"); + poststr(request, "
"); + poststr(request, "
"); +#else add_label_text_field(request, "Startup command", "data", CFG_GetShortStartupCommand(), ""); +#endif poststr(request, ""); poststr(request, SUBMIT_AND_END_FORM); diff --git a/src/httpserver/http_tcp_server_nonblocking.c b/src/httpserver/http_tcp_server_nonblocking.c index 278e3f841..5d8d474eb 100644 --- a/src/httpserver/http_tcp_server_nonblocking.c +++ b/src/httpserver/http_tcp_server_nonblocking.c @@ -113,7 +113,7 @@ void HTTPServer_RunQuickTick() { // Receive until the peer shuts down the connection do { - iResult = recv(ClientSocket, recvbuf, recvbuflen, 0); + iResult = recv(ClientSocket, recvbuf, recvbuflen-1, 0); if (iResult > 0) { http_request_t request; memset(&request, 0, sizeof(request)); diff --git a/src/httpserver/new_http.c b/src/httpserver/new_http.c index c0552c257..ec294c04a 100644 --- a/src/httpserver/new_http.c +++ b/src/httpserver/new_http.c @@ -156,7 +156,7 @@ void poststr_escaped(http_request_t* request, char* str) { bool foundChar = false; int len = strlen(str); - //Do a quick check if escaping is necessary + // Do a quick check if escaping is necessary for (i = 0; (foundChar == false) && (i < len); i++) { switch (str[i]) { case '<': @@ -200,6 +200,53 @@ void poststr_escaped(http_request_t* request, char* str) { } } +void poststr_escapedForJSON(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 '\n': + foundChar = true; + break; + case '\r': + foundChar = true; + break; + case '\"': + foundChar = true; + break; + } + } + + if (foundChar) { + for (i = 0; i < len; i++) { + switch (str[i]) { + case '\n': + postany(request, "\\n", 2); + break; + case '\r': + postany(request, "\\r", 2); + break; + case '\"': + postany(request, "\\\"", 2); + 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) @@ -666,6 +713,11 @@ int HTTP_ProcessPacket(http_request_t* request) { return 0; } } + else { + // if p is 0, then strchr below would crash + ADDLOGF_ERROR("invalid request\n"); + return 0; + } request->url = urlStr; diff --git a/src/httpserver/new_http.h b/src/httpserver/new_http.h index e4ea86499..6c1d992f3 100644 --- a/src/httpserver/new_http.h +++ b/src/httpserver/new_http.h @@ -68,6 +68,7 @@ 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); +void poststr_escapedForJSON(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); diff --git a/src/httpserver/rest_interface.c b/src/httpserver/rest_interface.c index ec892368f..94d21e821 100644 --- a/src/httpserver/rest_interface.c +++ b/src/httpserver/rest_interface.c @@ -910,7 +910,7 @@ static int http_rest_get_info(http_request_t* request) { hprintf255(request, "\"shortName\":\"%s\",", CFG_GetShortDeviceName()); poststr(request, "\"startcmd\":\""); // This can be longer than 255 - poststr(request, CFG_GetShortStartupCommand()); + poststr_escapedForJSON(request, CFG_GetShortStartupCommand()); poststr(request, "\","); #ifndef OBK_DISABLE_ALL_DRIVERS hprintf255(request, "\"supportsSSDP\":%d,", DRV_IsRunning("SSDP") ? 1 : 0); diff --git a/src/obk_config.h b/src/obk_config.h index 324922641..13f3414bc 100644 --- a/src/obk_config.h +++ b/src/obk_config.h @@ -30,8 +30,13 @@ #elif PLATFORM_W600 -// Some limited drivers are supported on W600, OBK_DISABLE_ALL_DRIVERS is not defined +// parse things like $CH1 or $hour etc +#define ENABLE_EXPAND_CONSTANT 1 +#define ENABLE_DRIVER_BMP280 1 #define ENABLE_HA_DISCOVERY 1 +#define ENABLE_DRIVER_AHT2X 1 +#define ENABLE_DRIVER_OPENWEATHERMAP 1 +#define ENABLE_DRIVER_SSDP 1 #define ENABLE_MQTT 1 #define ENABLE_TASMOTADEVICEGROUPS 1 #define ENABLE_NTP 1 @@ -41,14 +46,19 @@ #define ENABLE_TASMOTA_JSON 1 #define ENABLE_DRIVER_DS1820 1 #define OBK_OTA_EXTENSION ".img" +#define ENABLE_OBK_SCRIPTING 1 #elif PLATFORM_W800 +// parse things like $CH1 or $hour etc +#define ENABLE_EXPAND_CONSTANT 1 #define ENABLE_HA_DISCOVERY 1 #define ENABLE_DRIVER_OPENWEATHERMAP 1 #define ENABLE_DRIVER_SSDP 1 #define ENABLE_DRIVER_CHARTS 1 #define ENABLE_MQTT 1 +#define ENABLE_DRIVER_SHT3X 1 +#define ENABLE_DRIVER_AHT2X 1 #define ENABLE_TASMOTA_JSON 1 #define ENABLE_DRIVER_DS1820 1 #define ENABLE_DRIVER_DHT 1 @@ -189,7 +199,7 @@ // parse things like $CH1 or $hour etc #define ENABLE_EXPAND_CONSTANT 1 #define ENABLE_DRIVER_DHT 1 -//#define ENABLE_DRIVER_AHT2X 1 +#define ENABLE_DRIVER_AHT2X 1 #define ENABLE_DRIVER_TMGN 0 #define ENABLE_DRIVER_DRAWERS 0 #define ENABLE_TASMOTA_JSON 1 @@ -229,6 +239,7 @@ #define ENABLE_LITTLEFS 1 #define ENABLE_TEST_COMMANDS 0 #define ENABLE_EXPAND_CONSTANT 1 +#define ENABLE_DRIVER_OPENWEATHERMAP 1 //#define ENABLE_DRIVER_TMGN 1 #define ENABLE_TASMOTA_JSON 1 #define ENABLE_DRIVER_DS1820 1 diff --git a/src/selftest/selftest_cmd_startup.c b/src/selftest/selftest_cmd_startup.c index d6164aceb..f44e8ded5 100644 --- a/src/selftest/selftest_cmd_startup.c +++ b/src/selftest/selftest_cmd_startup.c @@ -29,6 +29,18 @@ void Test_Commands_Startup() { SELFTEST_ASSERT_STRING(CFG_GetShortStartupCommand(), "setChannel 0 234"); SELFTEST_ASSERT_CHANNEL(0, 234); + const char *loremIpsum = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Phasellus pretium felis vel metus dictum, non lacinia elit interdum. Proin vehicula sem vel orci convallis pharetra. Vivamus scelerisque, erat id tincidunt fringilla, felis enim vehicula ipsum, in condimentum risus enim eget mi. Curabitur nec felis libero. Cras mattis justo a nulla malesuada, sit amet gravida urna dictum. Integer et nisi sed tortor dictum tincidunt. Donec a lectus sit amet sapien suscipit fringilla. Nulla facilisi. Morbi ac facilisis eros. Suspendisse facilisis convallis eros, in sagittis nisi eleifend vitae."; + CFG_SetShortStartupCommand(loremIpsum); + CMD_ExecuteCommand(CFG_GetShortStartupCommand(), 0); + + + const char *loremIpsum2 = "startDriver Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Phasellus pretium felis vel metus dictum, non lacinia elit interdum. Proin vehicula sem vel orci convallis pharetra. Vivamus scelerisque, erat id tincidunt fringilla, felis enim vehicula ipsum, in condimentum risus enim eget mi. Curabitur nec felis libero. Cras mattis justo a nulla malesuada, sit amet gravida urna dictum. Integer et nisi sed tortor dictum tincidunt. Donec a lectus sit amet sapien suscipit fringilla. Nulla facilisi. Morbi ac facilisis eros. Suspendisse facilisis convallis eros, in sagittis nisi eleifend vitae."; + CFG_SetShortStartupCommand(loremIpsum2); + CMD_ExecuteCommand(CFG_GetShortStartupCommand(), 0); + + const char *loremIpsum3 = "startDriver DS1820startDriver BMP280 25 24 9 10 11 236// wifi waitwaitFor WiFiState 4startDriver OpenWeatherMap// owm_setup lat long APIkeyowm_setup 40.7128 -74.0060 d6fae53c4278ffb3fe4c17c23fc6a7c6 setChannelType 6 Temperature_div10setChannelType 7 HumiditysetChannelType 8 Pressure_div100// owm_channels temperature humidity pressureowm_channels 6 7 8// this will send a HTTP GET onceowm_requestsetChannel 30 0again:addChannel 30 1echo Hello $CH30delay_s 1goto again"; + CFG_SetShortStartupCommand(loremIpsum3); + CMD_ExecuteCommand(CFG_GetShortStartupCommand(), 0); } diff --git a/src/user_main.c b/src/user_main.c index 8b046fd95..18921a59e 100644 --- a/src/user_main.c +++ b/src/user_main.c @@ -1120,7 +1120,11 @@ void Main_Init_AfterDelay_Unsafe(bool bStartAutoRunScripts) { // NOTE: this will try to read autoexec.bat, // so ALL commands expected in autoexec.bat should have been registered by now... +#if ENABLE_OBK_SCRIPTING + SVM_RunStartupCommandAsScript(); +#else CMD_ExecuteCommand(CFG_GetShortStartupCommand(), COMMAND_FLAG_SOURCE_SCRIPT); +#endif CMD_ExecuteCommand("startScript autoexec.bat", COMMAND_FLAG_SOURCE_SCRIPT); } HAL_Configure_WDT(); @@ -1406,6 +1410,16 @@ void Main_Init_After_Delay() ADDLOGF_INFO("Main_Init_After_Delay done"); } +// to be overriden +// Translate name like RB5 for OBK pin index +#ifdef _MSC_VER +///#pragma comment(linker, "/alternatename:HAL_PIN_Find=Default_HAL_PIN_Find") +#else +int HAL_PIN_Find(const char *name) __attribute__((weak)); +int HAL_PIN_Find(const char *name) { + return atoi(name); +} +#endif void Main_Init()