From eec2e50a4652a635e1770bb23a80d0702d54cc14 Mon Sep 17 00:00:00 2001 From: gemu2015 Date: Wed, 15 Dec 2021 15:07:36 +0100 Subject: [PATCH] database extraction update, housekeeping --- tasmota/xdrv_10_scripter.ino | 574 +++++++++++++++++++++++++---------- 1 file changed, 406 insertions(+), 168 deletions(-) diff --git a/tasmota/xdrv_10_scripter.ino b/tasmota/xdrv_10_scripter.ino index f744d850b..b567864c1 100755 --- a/tasmota/xdrv_10_scripter.ino +++ b/tasmota/xdrv_10_scripter.ino @@ -1302,69 +1302,170 @@ float DoMedian5(uint8_t index, float in) { #ifdef USE_FEXTRACT -// convert tasmota time stamp to ul seconds -uint32_t tstamp2l(char *ts) { -uint16_t year; -uint8_t month; -uint8_t day; -uint8_t hour; -uint8_t mins; -uint8_t secs; +struct FE_TM { + uint16_t year; + uint8_t month; + uint8_t day; + uint8_t hour; + uint8_t mins; + uint8_t secs; +}; + +// timestamp math add days +int32_t tso(char *src, int32_t days, int32_t flg) { +struct tm tmx; +struct tm *tmp; +struct FE_TM tm; + uint8_t mode = ts2ts(&tm, src); + + tmx.tm_sec = tm.secs; + tmx.tm_min = tm.mins; + tmx.tm_hour = tm.hour; + tmx.tm_mon = tm.month - 1; + tmx.tm_year = tm.year + 100; + tmx.tm_mday = tm.day; + time_t tmd = mktime(&tmx); + tmd += days * (24 * 3600); + tmp = gmtime(&tmd); + if (!flg) { + tm.secs = tmp->tm_sec; + tm.mins = tmp->tm_min; + tm.hour = tmp->tm_hour; + } else { + tm.secs = 0; + tm.mins = 0; + tm.hour = 0; + } + tm.month = tmp->tm_mon + 1; + tm.year = tmp->tm_year - 100; + tm.day = tmp->tm_mday; + tss2ts(&tm, src, mode); + return 0; +} + +uint32_t ts2ts(struct FE_TM *tm, char *ts) { if (strchr(ts, 'T')) { // 2020-12-16T15:36:41 - year = strtol(ts, &ts, 10); - if (year < 2020 || year > 2040) { - year = 2020; + tm->year = strtol(ts, &ts, 10); + if (tm->year < 2020 || tm->year > 2040) { + tm->year = 2020; } - year -= 2000; + tm->year -= 2000; ts++; - month = strtol(ts, &ts, 10); + tm->month = strtol(ts, &ts, 10); ts++; - day = strtol(ts, &ts, 10); + tm->day = strtol(ts, &ts, 10); ts++; - hour = strtol(ts, &ts, 10); + tm->hour = strtol(ts, &ts, 10); ts++; - mins = strtol(ts, &ts, 10); + tm->mins = strtol(ts, &ts, 10); ts++; - secs = strtol(ts, &ts, 10); + tm->secs = strtol(ts, &ts, 10); + return 0; } else { // german excel fromat 16.12.20 15:36 - day = strtol(ts, &ts, 10); + tm->day = strtol(ts, &ts, 10); ts++; - month = strtol(ts, &ts, 10); + tm->month = strtol(ts, &ts, 10); ts++; - year = strtol(ts, &ts, 10); + tm->year = strtol(ts, &ts, 10); ts++; - hour = strtol(ts, &ts, 10); + tm->hour = strtol(ts, &ts, 10); ts++; - mins = strtol(ts, &ts, 10); - secs = 0; + tm->mins = strtol(ts, &ts, 10); + tm->secs = 0; + return 1; } - return (year*365*86400)+(month*31*86400)+(day*86400)+(hour*3600)+(mins*60)+secs; + return 0; +} + +void tss2ts(struct FE_TM *tm, char *dst, uint8_t mode) { + if (mode == 1) { + // was tsm format go to 16.12.20 15:36 + sprintf(dst, "%01d.%01d.%01d %01d:%02d", tm->day, tm->month, tm->year, tm->hour, tm->mins); + } else { + // 2020-12-16T15:36:41 + sprintf(dst, "%04d-%02d-%02dT%02d:%02d:%02d", tm->year + 2000, tm->month, tm->day, tm->hour, tm->mins, tm->secs); + } +} + +// convert time stamp format +void cnvts(char *dst, char *src, uint8_t flg ) { +struct FE_TM tm; + uint8_t mode = ts2ts(&tm, src); + tss2ts(&tm, dst, flg); +} + +// convert tasmota time stamp to ul seconds +uint32_t tstamp2l(char *ts) { +struct FE_TM tm; + + ts2ts(&tm, ts); + + return (tm.year*365*86400)+(tm.month*31*86400)+(tm.day*86400)+(tm.hour*3600)+(tm.mins*60)+tm.secs; } // assume 1. entry is timestamp, others are tab delimited values until LF // file refernece, from timestamp, to timestampm, column offset, array pointers, array lenght, number of arrays -int32_t extract_from_file(uint8_t fref, char *ts_from, char *ts_to, uint8_t coffs, float **a_ptr, uint16_t *a_len, uint8_t numa, int16_t accum) { +int32_t extract_from_file(uint8_t fref, char *ts_from, char *ts_to, int8_t coffs, float **a_ptr, uint16_t *a_len, uint8_t numa, int16_t accum) { if (!glob_script_mem.file_flags[fref].is_open) return -1; char rstr[32]; uint8_t sindex = 0; uint8_t colpos = 0; uint8_t range = 0; + if (coffs < 0) { + uint32_t cpos = glob_script_mem.files[fref].size(); + if (coffs == -1) { + // seek to last entry + if (cpos > 1) cpos -= 2; + // now seek back to last line + uint8_t lbuff[256]; + uint8_t iob; + uint16_t index = sizeof(lbuff) -1; + glob_script_mem.files[fref].seek(cpos - sizeof(lbuff), SeekSet); + glob_script_mem.files[fref].read(lbuff, sizeof(lbuff)); + while (cpos) { + iob = lbuff[index]; + if (iob == '\n' || iob == '\r') { + break; + } + cpos--; + index--; + } + glob_script_mem.files[fref].seek(cpos, SeekSet); + } else { + // seek to line 2 + for (uint32_t cp = 0; cp < cpos; cp++) { + uint8_t buff[2], iob; + glob_script_mem.files[fref].read(buff, 1); + iob = buff[0]; + if (iob == '\n' || iob == '\r') { + cpos = cp + 1; + break; + } + } + } + return cpos; + } uint32_t tsfrom = tstamp2l(ts_from); uint32_t tsto = tstamp2l(ts_to); uint16_t lines = 0; uint16_t rlines = 0; float summs[numa]; + float lastv[numa]; uint16_t accnt[numa]; + uint8_t mflg[numa]; + uint32_t lastpos = 0; for (uint8_t cnt = 0; cnt < numa; cnt++) { summs[cnt] = 0; accnt[cnt] = 0; + mflg[cnt] = 0; + lastv[cnt] = 0; } - uint8_t dflg = 1; + uint8_t dflg = 0; if (accum < 0) { - dflg = 0; + dflg = 1; accum = -accum; } if (accum == 0) accum = 1; @@ -1373,14 +1474,32 @@ int32_t extract_from_file(uint8_t fref, char *ts_from, char *ts_to, uint8_t cof uint8_t buff[2], iob; glob_script_mem.files[fref].read(buff, 1); iob = buff[0]; - if (iob == '\t' || iob == ',' || iob == '\n') { + if (iob == '\t' || iob == ',' || iob == '\n' || iob == '\r') { rstr[sindex] = 0; sindex = 0; - if (colpos == 0) { + if (lines == 0) { + // header line, analye column names + if (colpos >= 1 && colpos >= coffs) { + uint8_t curpos = colpos - coffs; + if (curpos < numa) { + mflg[curpos] = dflg; + char *tp = strstr(rstr, "_a"); + if (tp) { + // mark average values + mflg[curpos] |= 2; + } + } + } + } else { + if (colpos == 0) { // timestamp 2020-12-16T15:36:41 // decompose timestamps uint32_t cts = tstamp2l(rstr); - if (cts > tsto) break; + if (cts > tsto) { + // end of range must seek back to last LF, for next scan + glob_script_mem.files[fref].seek(lastpos, SeekSet); + break; + } if (cts >= tsfrom && cts <= tsto) { // we want this range range = 1; @@ -1388,22 +1507,25 @@ int32_t extract_from_file(uint8_t fref, char *ts_from, char *ts_to, uint8_t cof } else { range = 0; } - } else { + } else { // data columns if (range) { uint8_t curpos = colpos - coffs; if (colpos >= coffs && curpos < numa) { if (a_len[curpos]) { float fval = CharToFloat(rstr); + if (mflg[curpos] == 3) { + // absolute values, build diffs + float tmp = fval; + fval -= lastv[curpos]; + lastv[curpos] = tmp; + } + // average values //AddLog(LOG_LEVEL_INFO, PSTR("cpos %d colp %d numa %d - %s %d"),curpos, colpos, a_len[curpos], rstr, (uint32_t)fval); summs[curpos] += fval; accnt[curpos] += 1; if (accnt[curpos] == accum) { - if (dflg) { - *a_ptr[curpos]++ = summs[curpos] / accum; - } else { - *a_ptr[curpos]++ = summs[curpos]; - } + *a_ptr[curpos]++ = summs[curpos] / accum; summs[curpos] = 0; accnt[curpos] = 0; a_len[curpos]--; @@ -1413,11 +1535,13 @@ int32_t extract_from_file(uint8_t fref, char *ts_from, char *ts_to, uint8_t cof } } } + } } colpos++; - if (iob == '\n') { - colpos = 0; - lines ++; + if (iob == '\n' || iob == '\r') { + lastpos = glob_script_mem.files[fref].position(); + colpos = 0; + lines ++; } } rstr[sindex] = iob; @@ -1925,25 +2049,25 @@ chknext: switch (vname[0]) { case 'a': #ifdef USE_ANGLE_FUNC - if (!strncmp(vname, "acos(", 5)) { + if (!strncmp(lp, "acos(", 5)) { lp=GetNumericArgument(lp + 5, OPER_EQU, &fvar, gv); fvar = acosf(fvar); goto nfuncexit; } #endif - if (!strncmp(vname, "abs(", 4)) { + if (!strncmp(lp, "abs(", 4)) { lp=GetNumericArgument(lp + 4, OPER_EQU, &fvar, gv); fvar = fabs(fvar); goto nfuncexit; } - if (!strncmp(vname, "asc(", 4)) { + if (!strncmp(lp, "asc(", 4)) { char str[SCRIPT_MAXSSIZE]; lp = GetStringArgument(lp + 4, OPER_EQU, str, gv); fvar = str[0]; goto nfuncexit; } - if (!strncmp(vname, "adc(", 4)) { + if (!strncmp(lp, "adc(", 4)) { lp = GetNumericArgument(lp + 4, OPER_EQU, &fvar, gv); while (*lp==' ') lp++; float fvar1 = 1; @@ -1971,7 +2095,7 @@ chknext: len = 0; goto exit; } - if (!strncmp(vname, "acp(", 4)) { + if (!strncmp(lp, "acp(", 4)) { lp += 4; SCRIPT_SKIP_SPACES uint16_t alend; @@ -2002,9 +2126,9 @@ chknext: goto exit; } #ifdef USE_BUTTON_EVENT - if (!strncmp(vname, "bt[", 3)) { + if (!strncmp(lp, "bt[", 3)) { // tasmota button state - GetNumericArgument(vname+3, OPER_EQU, &fvar, gv); + GetNumericArgument(lp + 3, OPER_EQU, &fvar, gv); uint32_t index = fvar; if (index<1 || index>MAX_KEYS) index = 1; fvar = glob_script_mem.script_button[index - 1]; @@ -2015,11 +2139,11 @@ chknext: #endif //USE_BUTTON_EVENT break; case 'c': - if (!strncmp(vname, "chg[", 4)) { + if (!strncmp(lp, "chg[", 4)) { // var changed struct T_INDEX ind; uint8_t vtype; - isvar(vname + 4, &vtype, &ind, 0, 0, gv); + isvar(lp + 4, &vtype, &ind, 0, 0, gv); if (!ind.bits.constant) { uint8_t index = glob_script_mem.type[ind.index].index; if (glob_script_mem.fvars[index] != glob_script_mem.s_fvars[index]) { @@ -2041,7 +2165,7 @@ chknext: goto exit; } #ifdef USE_M5STACK_CORE2 - if (!strncmp(vname, "c2ps(", 5)) { + if (!strncmp(lp, "c2ps(", 5)) { lp = GetNumericArgument(lp + 5, OPER_EQU, &fvar, gv); while (*lp==' ') lp++; float fvar1; @@ -2052,7 +2176,7 @@ chknext: #endif // USE_M5STACK_CORE2 #ifdef USE_SCRIPT_TASK - if (!strncmp(vname, "ct(", 3)) { + if (!strncmp(lp, "ct(", 3)) { lp = GetNumericArgument(lp + 3, OPER_EQU, &fvar, gv); while (*lp==' ') lp++; float fvar1; @@ -2070,12 +2194,31 @@ chknext: #endif //USE_SCRIPT_TASK #endif //ESP32 #ifdef USE_ANGLE_FUNC - if (!strncmp(vname, "cos(", 4)) { + if (!strncmp(lp, "cos(", 4)) { lp = GetNumericArgument(lp + 4, OPER_EQU, &fvar, gv); fvar = cosf(fvar); goto nfuncexit; } #endif +#ifdef USE_FEXTRACT + if (!strncmp(lp, "cts(", 4)) { + char tsin[SCRIPT_MAXSSIZE]; + lp = GetStringArgument(lp + 4, OPER_EQU, tsin, 0); + SCRIPT_SKIP_SPACES + int8_t flg = -1; + if (*lp != ')') { + lp = GetNumericArgument(lp, OPER_EQU, &fvar, gv); + flg = fvar; + } + char tsout[SCRIPT_MAXSSIZE]; + cnvts(tsout, tsin, flg); + if (sp) strlcpy(sp, tsout, glob_script_mem.max_ssize); + lp++; + len = 0; + goto strexit; + } +#endif // USE_FEXTRACT + break; case 'd': if (!strncmp(vname, "day", 3)) { @@ -2086,6 +2229,16 @@ chknext: if (sp) strlcpy(sp, SettingsText(SET_DEVICENAME), glob_script_mem.max_ssize); goto strexit; } + if (!strncmp(lp, "dp(", 3)) { + lp = GetNumericArgument(lp + 3, OPER_EQU, &fvar, gv); + while (*lp==' ') lp++; + glob_script_mem.script_lzero = fvar; + lp = GetNumericArgument(lp , OPER_EQU, &fvar, gv); + while (*lp==' ') lp++; + glob_script_mem.script_dprec = fvar; + fvar = 0; + goto nfuncexit; + } break; case 'e': if (!strncmp(vname, "epoch", 5)) { @@ -2103,7 +2256,7 @@ chknext: goto exit_settable; } #ifdef USE_ENERGY_SENSOR - if (!strncmp(vname, "enrg[", 5)) { + if (!strncmp(lp, "enrg[", 5)) { lp=GetNumericArgument(lp + 5, OPER_EQU, &fvar, gv); while (*lp==' ') lp++; switch ((uint32_t)fvar) { @@ -2158,7 +2311,7 @@ chknext: case 'f': //#define DEBUG_FS #ifdef USE_SCRIPT_FATFS - if (!strncmp(vname, "fo(", 3)) { + if (!strncmp(lp, "fo(", 3)) { char str[SCRIPT_MAXSSIZE]; lp = GetStringArgument(lp + 3, OPER_EQU, str, 0); while (*lp==' ') lp++; @@ -2219,7 +2372,7 @@ chknext: } goto nfuncexit; } - if (!strncmp(vname, "fc(", 3)) { + if (!strncmp(lp, "fc(", 3)) { lp = GetNumericArgument(lp + 3, OPER_EQU, &fvar, gv); if (fvar>=0) { uint8_t ind = fvar; @@ -2233,7 +2386,7 @@ chknext: fvar = 0; goto nfuncexit; } - if (!strncmp(vname, "ff(", 3)) { + if (!strncmp(lp, "ff(", 3)) { lp = GetNumericArgument(lp + 3, OPER_EQU, &fvar, gv); uint8_t ind = fvar; if (ind>=SFS_MAX) ind = SFS_MAX - 1; @@ -2241,7 +2394,7 @@ chknext: fvar = 0; goto nfuncexit; } - if (!strncmp(vname, "fw(", 3)) { + if (!strncmp(lp, "fw(", 3)) { char str[SCRIPT_MAXSSIZE]; lp = ForceStringVar(lp + 3, str); while (*lp==' ') lp++; @@ -2255,7 +2408,7 @@ chknext: } goto nfuncexit; } - if (!strncmp(vname, "fwb(", 4)) { + if (!strncmp(lp, "fwb(", 4)) { lp = GetNumericArgument(lp + 4, OPER_EQU, &fvar, gv); uint8_t buf[2]; buf[0] = fvar; @@ -2271,7 +2424,7 @@ chknext: goto nfuncexit; } - if (!strncmp(vname, "fr(", 3)) { + if (!strncmp(lp, "fr(", 3)) { struct T_INDEX ind; uint8_t vtype; uint8_t sindex = 0; @@ -2344,7 +2497,7 @@ chknext: len = 0; goto exit; } - if (!strncmp(vname, "frb(", 4)) { + if (!strncmp(lp, "frb(", 4)) { lp = GetNumericArgument(lp, OPER_EQU, &fvar, gv); uint8_t ind = fvar; if (ind>=SFS_MAX) ind = SFS_MAX - 1; @@ -2358,7 +2511,7 @@ chknext: } goto nfuncexit; } - if (!strncmp(vname, "fa(", 3)) { + if (!strncmp(lp, "fa(", 3)) { lp = GetNumericArgument(lp + 3, OPER_EQU, &fvar, gv); uint8_t ind = fvar; if (ind>=SFS_MAX) ind = SFS_MAX - 1; @@ -2369,7 +2522,7 @@ chknext: } goto nfuncexit; } - if (!strncmp(vname, "fs(", 3)) { + if (!strncmp(lp, "fs(", 3)) { lp = GetNumericArgument(lp + 3, OPER_EQU, &fvar, gv); uint8_t ind = fvar; SCRIPT_SKIP_SPACES @@ -2377,13 +2530,13 @@ chknext: SCRIPT_SKIP_SPACES if (ind>=SFS_MAX) ind = SFS_MAX - 1; if (glob_script_mem.file_flags[ind].is_open) { - fvar = glob_script_mem.files[ind].seek(fvar, fs::SeekMode::SeekCur); + fvar = glob_script_mem.files[ind].seek(fvar, SeekSet); } else { fvar = -1; } goto nfuncexit; } - if (!strncmp(vname, "fz(", 3)) { + if (!strncmp(lp, "fz(", 3)) { lp = GetNumericArgument(lp + 3, OPER_EQU, &fvar, gv); SCRIPT_SKIP_SPACES uint8_t ind = fvar; @@ -2395,14 +2548,14 @@ chknext: } goto nfuncexit; } - if (!strncmp(vname, "fd(", 3)) { + if (!strncmp(lp, "fd(", 3)) { char str[glob_script_mem.max_ssize + 1]; lp = GetStringArgument(lp + 3, OPER_EQU, str, 0); ufsp->remove(str); goto nfuncexit; } #ifdef USE_UFILESYS - if (!strncmp(vname, "frw(", 4)) { + if (!strncmp(lp, "frw(", 4)) { // read file from web lp = GetNumericArgument(lp + 4, OPER_EQU, &fvar, gv); SCRIPT_SKIP_SPACES @@ -2414,7 +2567,7 @@ chknext: } #endif #if defined(ESP32) && defined(USE_WEBCAM) - if (!strncmp(vname, "fwp(", 4)) { + if (!strncmp(lp, "fwp(", 4)) { lp = GetNumericArgument(lp + 4, OPER_EQU, &fvar, gv); while (*lp==' ') lp++; float fvar1; @@ -2440,7 +2593,7 @@ chknext: } #endif //ESP32 && USE_WEBCAM #ifdef USE_SCRIPT_FATFS_EXT - if (!strncmp(vname, "fe(", 3)) { + if (!strncmp(lp, "fe(", 3)) { char str[glob_script_mem.max_ssize + 1]; lp = GetStringArgument(lp + 3, OPER_EQU, str, 0); // execute script @@ -2461,13 +2614,13 @@ chknext: } goto nfuncexit; } - if (!strncmp(vname, "fmd(", 4)) { + if (!strncmp(lp, "fmd(", 4)) { char str[glob_script_mem.max_ssize + 1]; lp = GetStringArgument(lp + 4, OPER_EQU, str, 0); fvar = ufsp->mkdir(str); goto nfuncexit; } - if (!strncmp(vname, "fmt(", 4)) { + if (!strncmp(lp, "fmt(", 4)) { lp = GetNumericArgument(lp + 4, OPER_EQU, &fvar, gv); if (!fvar) { LittleFS.format(); @@ -2476,13 +2629,13 @@ chknext: } goto nfuncexit; } - if (!strncmp(vname, "frd(", 4)) { + if (!strncmp(lp, "frd(", 4)) { char str[glob_script_mem.max_ssize + 1]; lp = GetStringArgument(lp + 4, OPER_EQU, str, 0); fvar = ufsp->rmdir(str); goto nfuncexit; } - if (!strncmp(vname, "fx(", 3)) { + if (!strncmp(lp, "fx(", 3)) { char str[glob_script_mem.max_ssize + 1]; lp = GetStringArgument(lp + 3, OPER_EQU, str, 0); if (ufsp->exists(str)) fvar = 1; @@ -2490,14 +2643,14 @@ chknext: goto nfuncexit; } - if (!strncmp(vname, "fsi(", 4)) { + if (!strncmp(lp, "fsi(", 4)) { lp = GetNumericArgument(lp + 4, OPER_EQU, &fvar, gv); fvar = UfsInfo(fvar, 0); goto nfuncexit; } #ifdef USE_FEXTRACT - if (!strncmp(vname, "fxt(", 4)) { + if (!strncmp(lp, "fxt(", 4)) { // extract from file lp = GetNumericArgument(lp + 4, OPER_EQU, &fvar, gv); SCRIPT_SKIP_SPACES @@ -2536,7 +2689,7 @@ chknext: goto nfuncexit; } #endif // USE_FEXTRACT - if (!strncmp(vname, "fwa(", 4)) { + if (!strncmp(lp, "fwa(", 4)) { uint16_t alen; float *fa; lp = get_array_by_name(lp + 4, &fa, &alen); @@ -2576,7 +2729,7 @@ chknext: } goto nfuncexit; } - if (!strncmp(vname, "fra(", 4)) { + if (!strncmp(lp, "fra(", 4)) { uint16_t alen; float *fa; lp = get_array_by_name(lp + 4, &fa, &alen); @@ -2622,7 +2775,7 @@ chknext: } #endif // USE_SCRIPT_FATFS_EXT - if (!strncmp(vname, "fl1(", 4) || !strncmp(vname, "fl2(", 4) ) { + if (!strncmp(lp, "fl1(", 4) || !strncmp(lp, "fl2(", 4) ) { uint8_t lknum = *(lp+2)&3; char str[glob_script_mem.max_ssize + 1]; lp = GetStringArgument(lp + 4, OPER_EQU, str, 0); @@ -2631,13 +2784,13 @@ chknext: fvar = 0; goto nfuncexit; } - if (!strncmp(vname, "fsm", 3)) { + if (!strncmp(lp, "fsm", 3)) { fvar=(uint32_t)ufsp; //card_init(); goto exit; } #endif //USE_SCRIPT_FATFS - if (!strncmp(vname, "freq", 4)) { + if (!strncmp(lp, "freq", 4)) { #ifdef ESP32 fvar = getCpuFrequencyMhz(); #else @@ -2645,7 +2798,7 @@ chknext: #endif goto exit; } - if (!strncmp(vname, "frnm", 4)) { + if (!strncmp(lp, "frnm", 4)) { if (sp) strlcpy(sp, SettingsText(SET_FRIENDLYNAME1), glob_script_mem.max_ssize); goto strexit; } @@ -2669,7 +2822,7 @@ chknext: goto strexit; } #ifdef USE_WEBSEND_RESPONSE - if (!strncmp(vname, "gwr(", 4)) { + if (!strncmp(lp, "gwr(", 4)) { char delim[SCRIPT_MAXSSIZE]; lp = GetStringArgument(lp + 4, OPER_EQU, delim, 0); SCRIPT_SKIP_SPACES @@ -2738,7 +2891,7 @@ chknext: #endif #ifdef SCRIPT_GET_HTTPS_JP - if (!strncmp(vname, "gjp(", 4)) { + if (!strncmp(lp, "gjp(", 4)) { char host[SCRIPT_MAXSSIZE]; lp = GetStringArgument(lp + 4, OPER_EQU, host, 0); SCRIPT_SKIP_SPACES @@ -2758,7 +2911,7 @@ chknext: fvar = ESP_getFreeHeap(); goto exit; } - if (!strncmp(vname, "hn(", 3)) { + if (!strncmp(lp, "hn(", 3)) { lp = GetNumericArgument(lp + 3, OPER_EQU, &fvar, gv); if (fvar<0 || fvar>255) fvar = 0; lp++; @@ -2768,7 +2921,7 @@ chknext: } goto strexit; } - if (!strncmp(vname, "hx(", 3)) { + if (!strncmp(lp, "hx(", 3)) { lp = GetNumericArgument(lp + 3, OPER_EQU, &fvar, gv); lp++; len = 0; @@ -2777,13 +2930,13 @@ chknext: } goto strexit; } - if (!strncmp(vname, "hd(", 3)) { + if (!strncmp(lp, "hd(", 3)) { char str[SCRIPT_MAXSSIZE]; lp = GetStringArgument(lp + 3, OPER_EQU, str, 0); fvar = strtol(str, NULL, 16); goto nfuncexit; } - if (!strncmp(vname, "hf(", 3)) { + if (!strncmp(lp, "hf(", 3)) { char str[SCRIPT_MAXSSIZE]; lp = GetStringArgument(lp + 3, OPER_EQU, str, 0); SCRIPT_SKIP_SPACES @@ -2812,7 +2965,7 @@ chknext: } goto nfuncexit; } - if (!strncmp(vname, "http(", 5)) { + if (!strncmp(lp, "http(", 5)) { char host[SCRIPT_MAXSSIZE]; lp = GetStringArgument(lp + 5, OPER_EQU, host, 0); SCRIPT_SKIP_SPACES @@ -2823,7 +2976,7 @@ chknext: goto nfuncexit; } #ifdef USE_LIGHT - if (!strncmp(vname, "hsvrgb(", 7)) { + if (!strncmp(lp, "hsvrgb(", 7)) { lp = GetNumericArgument(lp + 7, OPER_EQU, &fvar, gv); if (fvar<0 || fvar>360) fvar = 0; SCRIPT_SKIP_SPACES @@ -2843,7 +2996,7 @@ chknext: #endif //USE_LIGHT #ifdef USE_HOMEKIT - if (!strncmp(vname, "hki(", 4)) { + if (!strncmp(lp, "hki(", 4)) { if (!TasmotaGlobal.global_state.wifi_down) { // erase nvs lp = GetNumericArgument(lp + 4, OPER_EQU, &fvar, gv); @@ -2858,7 +3011,7 @@ chknext: #endif break; case 'i': - if (!strncmp(vname, "ins(", 4)) { + if (!strncmp(lp, "ins(", 4)) { char s1[SCRIPT_MAXSSIZE]; lp = GetStringArgument(lp + 4, OPER_EQU, s1, 0); SCRIPT_SKIP_SPACES @@ -2873,46 +3026,46 @@ chknext: } goto nfuncexit; } - if (!strncmp(vname, "int(", 4)) { + if (!strncmp(lp, "int(", 4)) { lp = GetNumericArgument(lp + 4, OPER_EQU, &fvar, gv); fvar = floor(fvar); goto nfuncexit; } - if (!strncmp(vname, "is(", 3)) { + if (!strncmp(lp, "is(", 3)) { lp = isargs(lp + 3, 0); fvar = 0; len = 0; goto exit; } - if (!strncmp(vname, "is1(", 4)) { + if (!strncmp(lp, "is1(", 4)) { lp = isargs(lp + 4, 1); fvar = 0; len = 0; goto exit; } - if (!strncmp(vname, "is2(", 4)) { + if (!strncmp(lp, "is2(", 4)) { lp = isargs(lp + 4, 2); fvar = 0; len = 0; goto exit; } - if (!strncmp(vname, "is[", 3)) { + if (!strncmp(lp, "is[", 3)) { lp = isget(lp + 3, sp, 0, gv); len = 0; goto strexit; } - if (!strncmp(vname, "is1[", 4)) { + if (!strncmp(lp, "is1[", 4)) { lp = isget(lp + 4, sp, 1, gv); len = 0; goto strexit; } - if (!strncmp(vname, "is2[", 4)) { + if (!strncmp(lp, "is2[", 4)) { lp = isget(lp + 4, sp, 2, gv); len = 0; goto strexit; } #ifdef USE_SCRIPT_I2C - if (!strncmp(vname, "ia", 2)) { + if (!strncmp(lp, "ia", 2)) { uint8_t bus = 0; lp += 2; if (*lp == '2') { @@ -2923,7 +3076,7 @@ chknext: fvar = script_i2c(0, fvar, bus); goto nfuncexit; } - if (!strncmp(vname, "iw", 2)) { + if (!strncmp(lp, "iw", 2)) { uint8_t bytes = 1; lp += 2; if (*lp != '(') { @@ -2940,7 +3093,7 @@ chknext: fvar = script_i2c(9 + bytes, fvar, fvar2); goto nfuncexit; } - if (!strncmp(vname, "ir", 2)) { + if (!strncmp(lp, "ir", 2)) { uint8_t bytes = 1; lp += 2; if (*lp != '(') { @@ -2956,7 +3109,7 @@ chknext: #endif // USE_SCRIPT_I2C break; case 'l': - if (!strncmp(vname, "lip", 3)) { + if (!strncmp(lp, "lip", 3)) { if (sp) strlcpy(sp, (const char*)WiFi.localIP().toString().c_str(), glob_script_mem.max_ssize); goto strexit; } @@ -2977,7 +3130,7 @@ chknext: return lp + len; } #ifdef USE_LVGL - if (!strncmp(vname, "lvgl(", 5)) { + if (!strncmp(lp, "lvgl(", 5)) { lp = GetNumericArgument(lp + 5, OPER_EQU, &fvar, gv); SCRIPT_SKIP_SPACES fvar = lvgl_test(&lp, fvar); @@ -2986,7 +3139,7 @@ chknext: #endif // USE_LVGL break; case 'm': - if (!strncmp(vname, "med(", 4)) { + if (!strncmp(lp, "med(", 4)) { float fvar1; lp = GetNumericArgument(lp + 4, OPER_EQU, &fvar1, gv); SCRIPT_SKIP_SPACES @@ -2997,7 +3150,7 @@ chknext: goto nfuncexit; } #ifdef USE_ANGLE_FUNC - if (!strncmp(vname, "mpt(", 4)) { + if (!strncmp(lp, "mpt(", 4)) { lp = GetNumericArgument(lp + 4, OPER_EQU, &fvar, gv); fvar = MeasurePulseTime(fvar); goto nfuncexit; @@ -3037,7 +3190,7 @@ chknext: fvar = !TasmotaGlobal.global_state.mqtt_down; goto exit; } - if (!strncmp(vname, "mp(", 3)) { + if (!strncmp(lp, "mp(", 3)) { float fvar1; lp = GetNumericArgument(lp + 3, OPER_EQU, &fvar1, gv); SCRIPT_SKIP_SPACES @@ -3067,7 +3220,7 @@ chknext: goto exit; } #ifdef USE_MORITZ - if (!strncmp(vname, "mo(", 3)) { + if (!strncmp(lp, "mo(", 3)) { float fvar1; lp = GetNumericArgument(lp + 3, OPER_EQU, &fvar1, gv); SCRIPT_SKIP_SPACES @@ -3084,23 +3237,23 @@ chknext: #endif //USE_MORITZ break; case 'p': - if (!strncmp(vname, "pin[", 4)) { + if (!strncmp(lp, "pin[", 4)) { // raw pin level - GetNumericArgument(vname + 4, OPER_EQU, &fvar, gv); + GetNumericArgument(lp + 4, OPER_EQU, &fvar, gv); fvar = digitalRead((uint8_t)fvar); // skip ] bracket len++; goto exit; } - if (!strncmp(vname, "pn[", 3)) { - GetNumericArgument(vname + 3, OPER_EQU, &fvar, gv); + if (!strncmp(lp, "pn[", 3)) { + GetNumericArgument(lp + 3, OPER_EQU, &fvar, gv); fvar = Pin(fvar); // skip ] bracket len++; goto exit; } #if defined(ESP32) && (defined(USE_I2S_AUDIO) || defined(USE_TTGO_WATCH) || defined(USE_M5STACK_CORE2)) - if (!strncmp(vname, "pl(", 3)) { + if (!strncmp(lp, "pl(", 3)) { char path[SCRIPT_MAXSSIZE]; lp = GetStringArgument(lp + 3, OPER_EQU, path, 0); Play_mp3(path); @@ -3109,8 +3262,8 @@ chknext: goto exit; } #endif // USE_I2S_AUDIO - if (!strncmp(vname, "pd[", 3)) { - GetNumericArgument(vname + 3, OPER_EQU, &fvar, gv); + if (!strncmp(lp, "pd[", 3)) { + GetNumericArgument(lp + 3, OPER_EQU, &fvar, gv); uint8_t gpiopin = fvar; /* for (uint8_t i=0;iMAX_COUNTERS) index = 1; fvar = RtcSettings.pulse_counter[index - 1]; @@ -3188,9 +3341,9 @@ chknext: fvar = glob_script_mem.script_mem_size + (glob_script_mem.script_size) + (PMEM_SIZE); goto exit; } - if (!strncmp(vname, "rnd(", 4)) { + if (!strncmp(lp, "rnd(", 4)) { // tasmota switch state - GetNumericArgument(vname + 4, OPER_EQU, &fvar, gv); + GetNumericArgument(lp + 4, OPER_EQU, &fvar, gv); if (fvar<0) { randomSeed(-fvar); fvar = 0; @@ -3202,7 +3355,7 @@ chknext: goto exit; } #if defined(ESP32) && (defined(USE_M5STACK_CORE2)) - if (!strncmp(vname, "rec(", 4)) { + if (!strncmp(lp, "rec(", 4)) { char str[SCRIPT_MAXSSIZE]; lp = GetStringArgument(lp + 4, OPER_EQU, str, 0); SCRIPT_SKIP_SPACES @@ -3218,9 +3371,9 @@ chknext: fvar = RtcTime.second; goto exit; } - if (!strncmp(vname, "sw[", 3)) { + if (!strncmp(lp, "sw[", 3)) { // tasmota switch state - GetNumericArgument(vname + 3, OPER_EQU, &fvar, gv); + GetNumericArgument(lp + 3, OPER_EQU, &fvar, gv); fvar = SwitchLastState((uint32_t)fvar); // skip ] bracket len++; @@ -3240,13 +3393,13 @@ chknext: fvar = strlen(glob_script_mem.script_ram); goto exit; } - if (!strncmp(vname, "sl(", 3)) { + if (!strncmp(lp, "sl(", 3)) { char str[SCRIPT_MAXSSIZE]; lp = GetStringArgument(lp + 3, OPER_EQU, str, 0); fvar = strlen(str); goto nfuncexit; } - if (!strncmp(vname, "sb(", 3)) { + if (!strncmp(lp, "sb(", 3)) { char str[SCRIPT_MAXSSIZE]; lp = GetStringArgument(lp + 3, OPER_EQU, str, 0); SCRIPT_SKIP_SPACES @@ -3264,7 +3417,7 @@ chknext: sp[(uint8_t)fvar2] = '\0'; goto strexit; } - if (!strncmp(vname, "st(", 3)) { + if (!strncmp(lp, "st(", 3)) { char str[SCRIPT_MAXSSIZE]; lp = GetStringArgument(lp + 3, OPER_EQU, str, 0); while (*lp==' ') lp++; @@ -3297,7 +3450,7 @@ chknext: } goto strexit; } - if (!strncmp(vname, "s(", 2)) { + if (!strncmp(lp, "s(", 2)) { lp = GetNumericArgument(lp + 2, OPER_EQU, &fvar, gv); char str[glob_script_mem.max_ssize + 1]; f2char(fvar, glob_script_mem.script_dprec, glob_script_mem.script_lzero, str); @@ -3307,7 +3460,7 @@ chknext: goto strexit; } #if defined(ESP32) && (defined(USE_I2S_AUDIO) || defined(USE_TTGO_WATCH) || defined(USE_M5STACK_CORE2)) - if (!strncmp(vname, "say(", 4)) { + if (!strncmp(lp, "say(", 4)) { char text[SCRIPT_MAXSSIZE]; lp = GetStringArgument(lp + 4, OPER_EQU, text, 0); Say(text); @@ -3318,7 +3471,7 @@ chknext: #endif // USE_I2S_AUDIO #ifdef ESP32 - if (!strncmp(vname, "sf(", 3)) { + if (!strncmp(lp, "sf(", 3)) { lp = GetNumericArgument(lp + 3, OPER_EQU, &fvar, gv); if (fvar<80) fvar = 80; if (fvar>240) fvar = 240; @@ -3328,7 +3481,7 @@ chknext: } #endif //ESP32 #ifdef USE_TTGO_WATCH - if (!strncmp(vname, "slp(", 4)) { + if (!strncmp(lp, "slp(", 4)) { lp = GetNumericArgument(lp + 4, OPER_EQU, &fvar, gv); SCRIPT_SKIP_SPACES TTGO_Sleep(fvar); @@ -3347,8 +3500,8 @@ chknext: #endif //USE_TIMERS #ifdef USE_SHUTTER - if (!strncmp(vname, "sht[", 4)) { - GetNumericArgument(vname + 4, OPER_EQU, &fvar, gv); + if (!strncmp(lp, "sht[", 4)) { + GetNumericArgument(lp + 4, OPER_EQU, &fvar, gv); uint8_t index = fvar; if (index<=TasmotaGlobal.shutters_present) { fvar = Settings->shutter_position[index - 1]; @@ -3360,12 +3513,12 @@ chknext: } #endif //USE_SHUTTER #ifdef USE_ANGLE_FUNC - if (!strncmp(vname, "sin(", 4)) { + if (!strncmp(lp, "sin(", 4)) { lp = GetNumericArgument(lp + 4, OPER_EQU, &fvar, gv); fvar = sinf(fvar); goto nfuncexit; } - if (!strncmp(vname, "sqrt(", 5)) { + if (!strncmp(lp, "sqrt(", 5)) { lp = GetNumericArgument(lp + 5, OPER_EQU, &fvar, gv); fvar = sqrtf(fvar); goto nfuncexit; @@ -3373,13 +3526,13 @@ chknext: #endif //USE_ANGLE_FUNC #if defined(USE_SML_M) && defined (USE_SML_SCRIPT_CMD) - if (!strncmp(vname, "sml[", 4)) { + if (!strncmp(lp, "sml[", 4)) { lp = GetNumericArgument(lp + 4, OPER_EQU, &fvar, gv); SCRIPT_SKIP_SPACES fvar = SML_GetVal(fvar); goto nfuncexit; } - if (!strncmp(vname, "sml(", 4)) { + if (!strncmp(lp, "sml(", 4)) { float fvar1; lp = GetNumericArgument(lp + 4, OPER_EQU, &fvar1, gv); SCRIPT_SKIP_SPACES @@ -3417,13 +3570,13 @@ chknext: tind->index = SML_JSON_ENABLE; goto exit_settable; } - if (!strncmp(vname, "smld(", 5)) { + if (!strncmp(lp, "smld(", 5)) { lp = GetNumericArgument(lp + 5, OPER_EQU, &fvar, gv); if (fvar < 1) fvar = 1; SML_Decode(fvar - 1); goto nfuncexit; } - if (!strncmp(vname, "smlv[", 5)) { + if (!strncmp(lp, "smlv[", 5)) { lp = GetNumericArgument(lp + 5, OPER_EQU, &fvar, gv); fvar = sml_getv(fvar); goto nfuncexit; @@ -3431,7 +3584,7 @@ chknext: #endif //USE_SML_M #ifdef USE_SCRIPT_SERIAL - if (!strncmp(vname, "so(", 3)) { + if (!strncmp(lp, "so(", 3)) { float rxpin, txpin, br; lp = GetNumericArgument(lp + 3, OPER_EQU, &rxpin, gv); SCRIPT_SKIP_SPACES @@ -3490,7 +3643,7 @@ chknext: } goto nfuncexit; } - if (!strncmp(vname, "sw(", 3)) { + if (!strncmp(lp, "sw(", 3)) { char str[SCRIPT_MAXSSIZE]; lp = GetStringArgument(lp + 3, OPER_EQU, str, 0); fvar = -1; @@ -3500,7 +3653,7 @@ chknext: } goto nfuncexit; } - if (!strncmp(vname, "swb(", 4)) { + if (!strncmp(lp, "swb(", 4)) { lp = GetNumericArgument(lp + 4, OPER_EQU, &fvar, 0); fvar = -1; if (glob_script_mem.sp) { @@ -3509,14 +3662,14 @@ chknext: } goto nfuncexit; } - if (!strncmp(vname, "sa(", 3)) { + if (!strncmp(lp, "sa(", 3)) { fvar = -1; if (glob_script_mem.sp) { fvar = glob_script_mem.sp->available(); } goto nfuncexit; } - if (!strncmp(vname, "srb(", 3)) { + if (!strncmp(lp, "srb(", 3)) { fvar = -1; if (glob_script_mem.sp) { fvar = glob_script_mem.sp->available(); @@ -3526,7 +3679,7 @@ chknext: } goto nfuncexit; } - if (!strncmp(vname, "sp(", 3)) { + if (!strncmp(lp, "sp(", 3)) { fvar = -1; if (glob_script_mem.sp) { fvar = glob_script_mem.sp->available(); @@ -3536,7 +3689,7 @@ chknext: } goto nfuncexit; } - if (!strncmp(vname, "sr(", 3)) { + if (!strncmp(lp, "sr(", 3)) { uint16_t size = glob_script_mem.max_ssize; char str[size]; memset(str, 0, size); @@ -3569,7 +3722,7 @@ chknext: if (sp) strlcpy(sp, str, size); goto strexit;; } - if (!strncmp(vname, "sc(", 3)) { + if (!strncmp(lp, "sc(", 3)) { fvar = -1; if (Script_Close_Serial()) { fvar = 0; @@ -3607,25 +3760,25 @@ chknext: goto strexit; } #ifdef USE_SCRIPT_TIMER - if (!strncmp(vname, "ts1(", 4)) { + if (!strncmp(lp, "ts1(", 4)) { lp = GetNumericArgument(lp + 4, OPER_EQU, &fvar, gv); if (fvar<10) fvar = 10; Script_ticker1.attach_ms(fvar, Script_ticker1_end); goto nfuncexit; } - if (!strncmp(vname, "ts2(", 4)) { + if (!strncmp(lp, "ts2(", 4)) { lp = GetNumericArgument(lp + 4, OPER_EQU, &fvar, gv); if (fvar<10) fvar = 10; Script_ticker2.attach_ms(fvar, Script_ticker2_end); goto nfuncexit; } - if (!strncmp(vname, "ts3(", 4)) { + if (!strncmp(lp, "ts3(", 4)) { lp = GetNumericArgument(lp + 4, OPER_EQU, &fvar, gv); if (fvar<10) fvar = 10; Script_ticker3.attach_ms(fvar, Script_ticker3_end); goto nfuncexit; } - if (!strncmp(vname, "ts4(", 4)) { + if (!strncmp(lp, "ts4(", 4)) { lp = GetNumericArgument(lp + 4, OPER_EQU, &fvar, gv); if (fvar<10) fvar = 10; Script_ticker4.attach_ms(fvar, Script_ticker4_end); @@ -3635,8 +3788,8 @@ chknext: #ifdef USE_DISPLAY #ifdef USE_TOUCH_BUTTONS - if (!strncmp(vname, "tbut[", 5)) { - GetNumericArgument(vname + 5, OPER_EQU, &fvar, gv); + if (!strncmp(lp, "tbut[", 5)) { + GetNumericArgument(lp + 5, OPER_EQU, &fvar, gv); uint8_t index = fvar; if (index<1 || index>MAX_TOUCH_BUTTONS) index = 1; index--; @@ -3652,7 +3805,7 @@ chknext: #endif //USE_TOUCH_BUTTONS #endif //USE_DISPLAY #if 0 - if (!strncmp(vname, "test(", 5)) { + if (!strncmp(lp, "test(", 5)) { lp = GetNumericArgument(lp + 5, OPER_EQU, &fvar, gv); uint32_t cycles; uint64_t accu=0; @@ -3675,7 +3828,7 @@ chknext: #endif #ifdef USE_TIMERS - if (!strncmp(vname, "ttget(", 6)) { + if (!strncmp(lp, "ttget(", 6)) { lp = GetNumericArgument(lp + 6, OPER_EQU, &fvar, gv); SCRIPT_SKIP_SPACES uint8_t index = fvar; @@ -3686,6 +3839,27 @@ chknext: goto nfuncexit; } #endif + +#ifdef USE_FEXTRACT + if (!strncmp(lp, "tso(", 4)) { + char str[SCRIPT_MAXSSIZE]; + lp = GetStringArgument(lp + 4, OPER_EQU, str, 0); + fvar = -1; + SCRIPT_SKIP_SPACES + lp = GetNumericArgument(lp, OPER_EQU, &fvar, gv); + SCRIPT_SKIP_SPACES + uint8_t flg = 0; + if (*lp =='0') { + lp++; + flg = 1; + } + tso(str, fvar, flg); + if (sp) strlcpy(sp, str, glob_script_mem.max_ssize); + lp++; + len = 0; + goto strexit; + } +#endif break; case 'u': if (!strncmp(vname, "uptime", 6)) { @@ -3696,11 +3870,11 @@ chknext: fvar = TasmotaGlobal.uptime; goto exit; } - if (!strncmp(vname, "upd[", 4)) { + if (!strncmp(lp, "upd[", 4)) { // var was updated struct T_INDEX ind; uint8_t vtype; - isvar(vname + 4, &vtype, &ind, 0, 0, gv); + isvar(lp + 4, &vtype, &ind, 0, 0, gv); if (!ind.bits.constant) { if (!ind.bits.changed) { fvar = 0; @@ -3719,7 +3893,7 @@ chknext: case 'w': #if defined(ESP32) && defined(USE_WEBCAM) - if (!strncmp(vname, "wc(", 3)) { + if (!strncmp(lp, "wc(", 3)) { float fvar1; lp = GetNumericArgument(lp + 3, OPER_EQU, &fvar1, gv); SCRIPT_SKIP_SPACES @@ -3787,7 +3961,7 @@ chknext: } #endif // USE_TTGO_WATCH #if defined(USE_FT5206) || defined(USE_XPT2046) || defined(USE_LILYGO47) || defined(USE_M5EPD47) - if (!strncmp(vname, "wtch(", 5)) { + if (!strncmp(lp, "wtch(", 5)) { lp = GetNumericArgument(lp + 5, OPER_EQU, &fvar, gv); fvar = Touch_Status(fvar); goto nfuncexit; @@ -4012,9 +4186,10 @@ char *GetStringArgument(char *lp, uint8_t lastop, char *cp, struct GVARS *gv) { char *slp; struct T_INDEX ind; char str[SCRIPT_MAXSSIZE],str1[SCRIPT_MAXSSIZE]; + while (*lp == ' ') { lp++; } // skip leading spaces while (1) { - lp=isvar(lp, &vtype, &ind, 0, str1, gv); - if (vtype!=STR_RES && !(vtype & STYPE)) { + lp = isvar(lp, &vtype, &ind, 0, str1, gv); + if (vtype != STR_RES && !(vtype & STYPE)) { // numeric type glob_script_mem.glob_error = 1; return lp; @@ -4057,6 +4232,7 @@ uint8_t operand = 0; float fvar1,fvar; char *slp; uint8_t vtype; +while (*lp == ' ') { lp++; } // skip leading spaces struct T_INDEX ind; while (1) { // get 1. value @@ -7246,7 +7422,7 @@ const char SCRIPT_MSG_CHKBOX[] PROGMEM = "
"; const char SCRIPT_MSG_PULLDOWNa[] PROGMEM = - "
"; const char SCRIPT_MSG_PULLDOWNb[] PROGMEM = ""; const char SCRIPT_MSG_PULLDOWNc[] PROGMEM = @@ -7255,6 +7431,10 @@ const char SCRIPT_MSG_PULLDOWNc[] PROGMEM = const char SCRIPT_MSG_TEXTINP[] PROGMEM = "
"; +const char SCRIPT_MSG_TEXTINP_U[] PROGMEM = + "
"; + + const char SCRIPT_MSG_NUMINP[] PROGMEM = "
"; @@ -7502,6 +7682,21 @@ void ScriptWebShow(char mc) { optflg = 0; } // check for input elements + // prescan for html tags + /* + restart: + //if (*lp == 0 || *lp == SCRIPT_EOL) + if (*lin == '<') { + char *cp = strchr(lin, '>'); + if (cp) { + char svd = *(cp + 1); + *(cp + 1) = 0; + WSContentSend_PD("%s", lin); + *(cp + 1) = svd; + lin = cp + 1; + } + }*/ + if (!strncmp(lin, "sl(", 3)) { // insert slider sl(min max var left mid right) char *lp = lin; @@ -7576,6 +7771,28 @@ void ScriptWebShow(char mc) { while (*lp) { SCRIPT_SKIP_SPACES lp = GetStringArgument(lp, OPER_EQU, pulabel, 0); + if (index == 1 && pulabel[0] == '#') { + // number range + char *cp = &pulabel[1]; + uint8_t from = strtol(cp, &cp, 10); + uint8_t to = from; + if (*cp == '-') { + cp++; + to = strtol(cp, &cp, 10); + } + for (uint32_t cnt = from; cnt <= to; cnt++) { + sprintf(pulabel, "%d", cnt); + if (val == index) { + cp = (char*)"selected"; + } else { + cp = (char*)""; + } + WSContentSend_PD(SCRIPT_MSG_PULLDOWNb, cp, index, pulabel); + index++; + } + break; + } + char *cp; if (val == index) { cp = (char*)"selected"; @@ -7654,11 +7871,26 @@ void ScriptWebShow(char mc) { SCRIPT_SKIP_SPACES char label[SCRIPT_MAXSSIZE]; lp = GetStringArgument(lp, OPER_EQU, label, 0); - char vname[16]; ScriptGetVarname(vname, slp, sizeof(vname)); - - WSContentSend_PD(SCRIPT_MSG_TEXTINP, label, str, vname); + SCRIPT_SKIP_SPACES + if (*lp != ')') { + char type[SCRIPT_MAXSSIZE]; + lp = GetStringArgument(lp, OPER_EQU, type, 0); + SCRIPT_SKIP_SPACES + // also requires min max values + char min[SCRIPT_MAXSSIZE]; + lp = GetStringArgument(lp, OPER_EQU, min, 0); + SCRIPT_SKIP_SPACES + char max[SCRIPT_MAXSSIZE]; + lp = GetStringArgument(lp, OPER_EQU, max, 0); + SCRIPT_SKIP_SPACES + WSContentSend_PD(SCRIPT_MSG_TEXTINP_U, label, type, str, min, max, vname); + } else { + WSContentSend_PD(SCRIPT_MSG_TEXTINP, label, str, vname); + } + lp++; + //goto restart; } else if (!strncmp(lin, "nm(", 3)) { char *lp = lin; @@ -8210,11 +8442,17 @@ int32_t url2file(uint8_t fref, char *url) { WiFiClient http_client; HTTPClient http; int32_t httpCode = 0; - char hbuff[128]; - strcpy(hbuff, "http://"); - strcat(hbuff, url); - http.begin(http_client, UrlEncode(hbuff)); - httpCode = http.GET(); + String weburl = "http://"+UrlEncode(url); + for (uint32_t retry = 0; retry < 15; retry++) { + http.begin(http_client, weburl); + httpCode = http.GET(); + if (httpCode > 0) { + break; + } + } + if (httpCode < 0) { + AddLog(LOG_LEVEL_INFO,PSTR("HTTP error %d = %s"), httpCode, http.errorToString(httpCode).c_str()); + } if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) { WiFiClient *stream = http.getStreamPtr(); int32_t len = http.getSize();