@@ -40,14 +40,22 @@ keywords if then else endif, or, and are better readable for beginners (others m
4040
4141\*********************************************************************************************/
4242
43+ // ottelo.jimdo.de
44+ #ifdef SCRIPT_OTTELO_USE_SCRIPTLIST
45+ #include < scriptlist_ottelo.h>
46+ #else
47+ #define SCRIPT_OTTELO_SELECT_HANDLER
48+ #define SCRIPT_OTTELO_SELECT
49+ #endif
50+
4351#define XDRV_10 10
4452
4553#ifndef TS_FLOAT
4654#define TS_FLOAT float
4755#endif
4856// float = 4, double = 8 bytes
4957
50- const uint8_t SCRIPT_VERS[2 ] = {5 , 5 };
58+ const uint8_t SCRIPT_VERS[2 ] = {5 , 6 };
5159
5260#define SCRIPT_DEBUG 0
5361
@@ -6787,7 +6795,7 @@ void tmod_directModeOutput(uint32_t pin);
67876795 }
67886796 if (sel == 1 && glob_script_mem.Script_PortUdp_1 ) {
67896797 // rec from port
6790- if (TasmotaGlobal.global_state .wifi_down ) {
6798+ if (TasmotaGlobal.global_state .wifi_down && TasmotaGlobal. global_state . eth_down ) {
67916799 if (sp) *sp = 0 ;
67926800 } else {
67936801 int32_t packetSize = glob_script_mem.Script_PortUdp_1 ->parsePacket ();
@@ -9882,11 +9890,13 @@ const char HTTP_FORM_SCRIPT[] PROGMEM =
98829890const char HTTP_FORM_SCRIPT1[] PROGMEM =
98839891 " <div style='text-align:right' id='charNum'> </div>"
98849892 " <label><input style='width:3%%;' id='c%d' name='c%d' type='checkbox'%s><b>" D_SCRIPT_ENABLE " </b></label><br/>"
9893+ SCRIPT_OTTELO_SELECT
98859894 " <br><textarea id='t1' name='t1' rows='8' cols='80' maxlength='%d' style='font-size: 12pt' >" ;
98869895
98879896const char HTTP_FORM_SCRIPT1b[] PROGMEM =
98889897 " </textarea>"
98899898 " <script type='text/javascript'>"
9899+ SCRIPT_OTTELO_SELECT_HANDLER
98909900 " eb('charNum').innerHTML='-';"
98919901 " var ta=eb('t1');"
98929902 " ta.addEventListener('keydown',function(e){"
@@ -11013,39 +11023,66 @@ const char kScriptCommands[] PROGMEM = D_CMND_SCRIPT "|" D_CMND_SUBSCRIBE "|" D_
1101311023#endif
1101411024;
1101511025
11016- void list_var (char *lp) {
11026+ void list_var (char *lp, WiFiClient *client ) {
1101711027TS_FLOAT fvar;
1101811028char str[SCRIPT_MAX_SBSIZE];
11029+ String wbuffer = " " ;
11030+
1101911031 glob_script_mem.glob_error = 0 ;
1102011032 if (check_varname (lp) == NUM_ARRAY_RES && !strchr (lp, ' [' )) {
1102111033 TS_FLOAT *fpd = 0 ;
1102211034 uint16_t alend;
1102311035 char *cp = get_array_by_name (lp, &fpd, &alend, 0 );
11024- ResponseAppend_P (PSTR (" \" %s\" :[" ), lp);
11036+ if (!client) ResponseAppend_P (PSTR (" \" %s\" :[" ), lp);
11037+ else {
11038+ ext_snprintf_P (str, sizeof (str), PSTR (" \" %s\" :[" ), lp);
11039+ wbuffer += str;
11040+ }
11041+
1102511042 for (uint16_t cnt = 0 ; cnt < alend; cnt++) {
1102611043 TS_FLOAT tvar = *fpd++;
1102711044 ext_snprintf_P (str, sizeof (str), PSTR (" %*_f" ), -glob_script_mem.script_dprec , &tvar);
1102811045 if (cnt) {
11029- ResponseAppend_P (PSTR (" ,%s" ), str);
11046+ if (!client) ResponseAppend_P (PSTR (" ,%s" ), str);
11047+ else {
11048+ wbuffer += ' ,' ;
11049+ wbuffer += str;
11050+ }
1103011051 } else {
11031- ResponseAppend_P (PSTR (" %s" ), str);
11052+ if (!client) ResponseAppend_P (PSTR (" %s" ), str);
11053+ else {
11054+ wbuffer += str;
11055+ }
11056+ }
11057+ if (client) {
11058+ if (wbuffer.length () >= 1024 ) {
11059+ client->print (wbuffer);
11060+ wbuffer = " " ;
11061+ }
1103211062 }
1103311063 }
11034- ResponseAppend_P (PSTR (" ]" ));
11064+ if (!client) ResponseAppend_P (PSTR (" ]" ));
11065+ else {
11066+ wbuffer += ' ]' ;
11067+ client->print (wbuffer);
11068+ }
1103511069 } else {
1103611070 glob_script_mem.glob_error = 0 ;
1103711071 glob_script_mem.var_not_found = 0 ;
1103811072 GetNumericArgument (lp, OPER_EQU, &fvar, 0 );
1103911073 if (glob_script_mem.var_not_found ) {
11040- ResponseAppend_P (PSTR (" \" %s\" :\" ???\" " ), lp);
11074+ if (!client) ResponseAppend_P (PSTR (" \" %s\" :\" ???\" " ), lp);
11075+ else client->printf_P (PSTR (" \" %s\" :\" ???\" " ), lp);
1104111076 } else {
1104211077 if (glob_script_mem.glob_error == 1 ) {
1104311078 // was string, not number
1104411079 GetStringArgument (lp, OPER_EQU, str, 0 );
11045- ResponseAppend_P (PSTR (" \" %s\" :\" %s\" " ), lp, str);
11080+ if (!client) ResponseAppend_P (PSTR (" \" %s\" :\" %s\" " ), lp, str);
11081+ else client->printf_P (PSTR (" \" %s\" :\" %s\" " ), lp, str);
1104611082 } else {
1104711083 ext_snprintf_P (str, sizeof (str), PSTR (" %*_f" ), -glob_script_mem.script_dprec , &fvar);
11048- ResponseAppend_P (PSTR (" \" %s\" :%s" ), lp, str);
11084+ if (!client) ResponseAppend_P (PSTR (" \" %s\" :%s" ), lp, str);
11085+ else client->printf_P (PSTR (" \" %s\" :%s" ), lp, str);
1104911086 }
1105011087 }
1105111088 }
@@ -11110,16 +11147,17 @@ bool ScriptCommand(void) {
1111011147 char *cp = strchr (lp, ' ;' );
1111111148 if (cp) {
1111211149 *cp = 0 ;
11113- list_var (lp);
11150+ list_var (lp, 0 );
1111411151 ResponseAppend_P (PSTR (" ," ));
1111511152 lp = cp + 1 ;
1111611153 } else {
11117- list_var (lp);
11154+ list_var (lp, 0 );
1111811155 ResponseAppend_P (PSTR (" }" ));
1111911156 break ;
1112011157 }
1112111158 }
1112211159 ResponseAppend_P (PSTR (" }" ));
11160+ return serviced;
1112311161 }
1112411162 return serviced;
1112511163 }
@@ -11533,6 +11571,33 @@ void ScriptServeFile(void) {
1153311571
1153411572 if (cp) {
1153511573 cp += 4 ;
11574+ char *lp = cp + 1 ;
11575+ if (*lp == ' $' ) {
11576+ lp++;
11577+ WiFiClient wclient;
11578+ wclient = Webserver->client ();
11579+ WiFiClient *client = &wclient;
11580+ client->printf_P (PSTR (" HTTP/1.1 200 OK\r\n " ));
11581+ client->printf_P (PSTR (" Content-type:text/html\r\n\r\n " ));
11582+ client->printf_P (PSTR (" {\" script\" :{" ));
11583+ while (1 ) {
11584+ while (*lp==' ' ) lp++;
11585+ char *cp = strchr (lp, ' ;' );
11586+ if (cp) {
11587+ *cp = 0 ;
11588+ list_var (lp, client);
11589+ client->printf_P (PSTR (" ," ));
11590+ lp = cp + 1 ;
11591+ } else {
11592+ list_var (lp, client);
11593+ client->printf_P (PSTR (" }" ));
11594+ break ;
11595+ }
11596+ }
11597+ client->printf_P (PSTR (" }" ));
11598+ client->flush ();
11599+ return ;
11600+ }
1153611601 if (ufsp) {
1153711602 if (strstr_P (cp, PSTR (" scrdmp.bmp" ))) {
1153811603 SendFile (cp);
0 commit comments