diff --git a/tasmota/xdrv_10_scripter.ino b/tasmota/xdrv_10_scripter.ino index eb0d00f29..cf148c97b 100755 --- a/tasmota/xdrv_10_scripter.ino +++ b/tasmota/xdrv_10_scripter.ino @@ -71,7 +71,7 @@ uint32_t DecodeLightId(uint32_t hue_id); #ifdef USE_SCRIPT_COMPRESSION #include -Unishox compressor; // singleton +//Unishox compressor; // singleton #define SCRIPT_COMPRESS compressor.unishox_compress #define SCRIPT_DECOMPRESS compressor.unishox_decompress #ifndef UNISHOXRSIZE @@ -1228,6 +1228,52 @@ chknext: fvar=UtcTime()-(uint32_t)EPOCH_OFFSET; goto exit; } +#ifdef USE_ENERGY_SENSOR + if (!strncmp(vname,"enrg[",5)) { + lp+=5; + lp=GetNumericResult(lp,OPER_EQU,&fvar,0); + while (*lp==' ') lp++; + switch ((uint32_t)fvar) { + case 0: + fvar=Energy.total; + break; + case 1: + fvar=Energy.voltage[0]; + break; + case 2: + fvar=Energy.voltage[1]; + break; + case 3: + fvar=Energy.voltage[2]; + break; + case 4: + fvar=Energy.current[0]; + break; + case 5: + fvar=Energy.current[1]; + break; + case 6: + fvar=Energy.current[2]; + break; + case 7: + fvar=Energy.active_power[0]; + break; + case 8: + fvar=Energy.active_power[1]; + break; + case 9: + fvar=Energy.active_power[2]; + break; + + default: + fvar=99999; + break; + } + len=0; + lp++; + goto exit; + } +#endif //USE_ENERGY_SENSOR break; case 'f': #ifdef USE_SCRIPT_FATFS @@ -1948,6 +1994,15 @@ chknext: } #endif #if defined(USE_SML_M) && defined (USE_SML_SCRIPT_CMD) + if (!strncmp(vname,"sml[",4)) { + lp+=4; + lp=GetNumericResult(lp,OPER_EQU,&fvar,0); + SCRIPT_SKIP_SPACES + fvar=SML_GetVal[fvar]; + lp++; + len=0; + goto exit; + } if (!strncmp(vname,"sml(",4)) { lp+=4; float fvar1; @@ -3948,6 +4003,12 @@ void ScriptSaveSettings(void) { strlcpy(glob_script_mem.script_ram,str.c_str(), glob_script_mem.script_size); + if (glob_script_mem.script_ram[0]!='>' && glob_script_mem.script_ram[1]!='D') { + AddLog_P2(LOG_LEVEL_INFO, PSTR("script error: must start with >D")); + bitWrite(Settings.rule_enabled, 0, 0); + } + + #if defined(USE_24C256) && !defined(USE_SCRIPT_FATFS) if (glob_script_mem.flags&1) { EEP_WRITE(0,EEP_SCRIPT_SIZE,glob_script_mem.script_ram); @@ -3983,9 +4044,9 @@ void ScriptSaveSettings(void) { #ifndef ESP32_SCRIPT_SIZE //AddLog_P2(LOG_LEVEL_INFO,PSTR("in string: %s len = %d"),glob_script_mem.script_ram,strlen(glob_script_mem.script_ram)); - uint32_t len_compressed = SCRIPT_COMPRESS(glob_script_mem.script_ram, strlen(glob_script_mem.script_ram)+1, Settings.rules[0], MAX_SCRIPT_SIZE-1); - Settings.rules[0][len_compressed] = 0; + uint32_t len_compressed = SCRIPT_COMPRESS(glob_script_mem.script_ram, strlen(glob_script_mem.script_ram), Settings.rules[0], MAX_SCRIPT_SIZE-1); if (len_compressed > 0) { + Settings.rules[0][len_compressed] = 0; AddLog_P2(LOG_LEVEL_INFO,PSTR("script compressed to %d %%"),len_compressed * 100 / strlen(glob_script_mem.script_ram)); } else { AddLog_P2(LOG_LEVEL_INFO, PSTR("script compress error: %d"), len_compressed); @@ -4899,12 +4960,20 @@ const char SCRIPT_MSG_TEXTINP[] PROGMEM = const char SCRIPT_MSG_NUMINP[] PROGMEM = "
"; + +#ifdef USE_GOOGLE_CHARTS const char SCRIPT_MSG_GTABLE[] PROGMEM = "" "" - "" - "" - ""; + "" + ""; + +const char SCRIPT_MSG_TABLE[] PROGMEM = + ""; +const char SCRIPT_MSG_GAUGE[] PROGMEM = + ""; +const char SCRIPT_MSG_TIMELINE[] PROGMEM = + ""; const char SCRIPT_MSG_GTABLEa[] PROGMEM = @@ -4913,9 +4982,15 @@ const char SCRIPT_MSG_GTABLEa[] PROGMEM = "var data=google.visualization.arrayToDataTable(["; +const char SCRIPT_MSG_GTABLEd[] PROGMEM = +"['Timeline','start','end'],"; + +//#define CHART_EXTRA_OPTIONS ",width:'640px',height:'480px'" +#define CHART_EXTRA_OPTIONS + const char SCRIPT_MSG_GTABLEb[] PROGMEM = "]);" - "var options={%s};" + "var options={%s" CHART_EXTRA_OPTIONS "};" "var chart=new google.visualization.%s(document.getElementById('chart%1d'));" "chart.draw(data,options);}" "google.charts.setOnLoadCallback(drawChart);"; @@ -4923,15 +4998,83 @@ const char SCRIPT_MSG_GTABLEb[] PROGMEM = const char SCRIPT_MSG_GOPT1[] PROGMEM = "title:'%s',isStacked:false"; -const char SCRIPT_MSG_GOPT3[] PROGMEM = -"title:'%s',vAxes:{0:{maxValue:%d},1:{maxValue:%d}},series:{0:{targetAxisIndex:0},1:{targetAxisIndex:1}}"; - - const char SCRIPT_MSG_GOPT2[] PROGMEM = "showRowNumber:true,sort:'disable',allowHtml:true,width:'100%%',height:'100%%',cssClassNames:cssc"; +const char SCRIPT_MSG_GOPT3[] PROGMEM = +"title:'%s',isStacked:false,vAxes:{0:{maxValue:%d},1:{maxValue:%d}},series:{0:{targetAxisIndex:0},1:{targetAxisIndex:1}}%s"; + +const char SCRIPT_MSG_GOPT4[] PROGMEM = +//"hAxis:{minValue:new Date(0,1,1,0,0),maxValue:new Date(0,1,2,0,0),format:'HH:mm'}"; +"hAxis:{minValue:new Date(0,1,1,0,0),maxValue:new Date(0,1,2,0,0),format:'HH:mm'},theme: 'maximized'"; + +const char SCRIPT_MSG_GOPT5[] PROGMEM = +"new Date(0,1,1,%d,%d)"; + const char SCRIPT_MSG_GTE1[] PROGMEM = "'%s'"; +#define GLIBS_MAIN 1<<0 +#define GLIBS_TABLE 1<<1 +#define GLIBS_GAUGE 1<<2 +#define GLIBS_TIMELINE 1<<3 + +#define MAX_GARRAY 4 + +char *gc_get_arrays(char *lp, float **arrays, uint8_t *ranum, uint8_t *rentries) { +struct T_INDEX ind; +uint8_t vtype; +uint8 entries=0; + + uint8_t anum=0; + while (anum> 2 %d\n",(uint32_t)*fa); + if (fa && len>=entries) { + if (!entries) {entries = len;} + // add array to list + arrays[anum]=fa; + anum++; + } + } + } else { + lp=lp1; + break; + } + } + } + *ranum=anum; + *rentries=entries; + return lp; +} + +char *gc_send_labels(char *lp,uint32_t anum) { + WSContentSend_PD("["); + for (uint32_t cnt=0; cnt> 2 %d\n",(uint32_t)*fa); - if (fa && len>=entries) { - if (!entries) {entries = len;} - // add array to list - arrays[anum]=fa; - anum++; - } - } - } else { - lp=lp1; - break; - } - } - } - //Serial.printf("arrays %d\n",anum); - //Serial.printf("entries %d\n",entries); - - if (!google_libs) { - WSContentSend_PD(SCRIPT_MSG_GTABLE); - google_libs=1; - } - - WSContentSend_PD(SCRIPT_MSG_GTABLEa); - - // we know how many arrays and the number of entries - // we need to fetch the labels now - WSContentSend_PD("["); - for (uint32_t cnt=0; cntnanum) { + goto nextwebline; + } + // we know how many arrays and the number of entries + //Serial.printf("arrays %d\n",anum); + //Serial.printf("entries %d\n",entries); + if (ctype=='T') { + if (anum && !(entries&1)) { + WSContentSend_PD(SCRIPT_MSG_GTABLEa); + WSContentSend_PD(SCRIPT_MSG_GTABLEd); + char label[SCRIPT_MAXSSIZE]; + lp=GetStringResult(lp,OPER_EQU,label,0); + SCRIPT_SKIP_SPACES + char *lblp=label; + for (uint32_t ind=0; ind0) glob_script_mem.script_ram[len_decompressed]=0; //AddLog_P2(LOG_LEVEL_INFO, PSTR("decompressed script len %d"),len_decompressed); #endif #endif @@ -5568,6 +5756,14 @@ bool Xdrv10(uint8_t function) glob_script_mem.flags=1; #endif + // a valid script MUST start with >D + if (glob_script_mem.script_ram[0]!='>' && glob_script_mem.script_ram[1]!='D') { + // clr all + memset(glob_script_mem.script_ram,0,glob_script_mem.script_size); + strcpy_P(glob_script_mem.script_ram, PSTR(">D\nscript error must start with >D")); + bitWrite(Settings.rule_enabled, 0, 0); + } + // assure permanent memory is 4 byte aligned { uint32_t ptr=(uint32_t)glob_script_mem.script_pram; ptr&=0xfffffffc; diff --git a/tasmota/xsns_53_sml.ino b/tasmota/xsns_53_sml.ino index c63478b48..3b4357b26 100755 --- a/tasmota/xsns_53_sml.ino +++ b/tasmota/xsns_53_sml.ino @@ -2151,6 +2151,7 @@ init10: #else #ifdef ESP32 meter_ss[meters] = new HardwareSerial(uart_index); + if (uart_index==0) { ClaimSerial(); } uart_index--; if (uart_index<0) uart_index=0; #else @@ -2216,7 +2217,13 @@ uint32_t SML_Write(uint32_t meter,char *hstr) { SML_Send_Seq(meter,hstr); return 1; } -#endif + +float SML_GetVal(uint32_t index) { + if (index<1 && index>SML_MAX_VARS) { index = 1;} + return meter_vars[index-1]; +} + +#endif // USE_SML_SCRIPT_CMD void SetDBGLed(uint8_t srcpin, uint8_t ledpin) {