Skip to content

Commit 31dfcf1

Browse files
committed
Smartmeter/Stromzähler Script-Auswahl via DropDown Menü
Für Anfänger/neue User: Ihr könnt nun direkt auf dem ESP (Lesekopf) in Tasmota euren Stromzähler auswählen. Das passendes SML Script wird dann im Editor angezeigt wo ihr dann Anpassungen vornehmen könnt (z.B. RX/TX-Pin an euren Lesekopf anpassen).
1 parent f5a7e3e commit 31dfcf1

File tree

4 files changed

+116
-74
lines changed

4 files changed

+116
-74
lines changed

tasmota/scriptlist_ottelo.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#ifndef _SCRIPTLIST_OTTELO_H_
2+
#define _SCRIPTLIST_OTTELO_H_
3+
4+
// Powermeter List for Tasmota SML Script
5+
// adapted from this source
6+
// https://github.com/esplesekopf/Tasmota/blob/development/tasmota/sml_scripts.h
7+
// and https://bitshake.de/skripte/#hersteller
8+
9+
#define SCRIPT_OTTELO_DOWNLOAD_URL "https://raw.githubusercontent.com/ottelo9/tasmota-sml-script/main/smartmeter/"
10+
#define SCRIPT_OTTELO_DOWNLOAD_URL_SMARTMETERS "https://raw.githubusercontent.com/ottelo9/tasmota-sml-script/main/smartmeter/smartmeter.json"
11+
12+
#define SCRIPT_OTTELO_SELECT_OPTIONS "" \
13+
"<option value='sm_0'>--- Select SmartMeter ---</option>"
14+
15+
#define SCRIPT_OTTELO_SELECT_FUNCTION "" \
16+
"if(selSM.value=='sm_0'){ta.innerHTML=''}" \
17+
"else{ta.innerHTML='';fetch('" SCRIPT_OTTELO_DOWNLOAD_URL "'+selSM.value,{cache:'no-store'}).then(response=>response.text()).then(content=>{ta.innerHTML=content;});}"
18+
19+
#define SCRIPT_OTTELO_SELECT "" \
20+
"<p><select id='idSelSM'>" SCRIPT_OTTELO_SELECT_OPTIONS "</select></p>"
21+
22+
#define SCRIPT_OTTELO_SELECT_HANDLER "" \
23+
"var selSM=eb('idSelSM');" \
24+
"selSM.onchange=function(){" SCRIPT_OTTELO_SELECT_FUNCTION "};" \
25+
"fetch('" SCRIPT_OTTELO_DOWNLOAD_URL_SMARTMETERS "',{cache:'no-store'}).then(response=>response.json()).then(data=>{" \
26+
"if(data && data.smartmeter && data.smartmeter.length){" \
27+
"while(selSM.options.length>1){selSM.options.remove(1);}" \
28+
"for(let n=0;n<data.smartmeter.length;n++){" \
29+
"let o=document.createElement('option');o.value=data.smartmeter[n].filename;o.text=data.smartmeter[n].label;selSM.options.add(o);" \
30+
"}}});"
31+
32+
#endif

tasmota/sml_scripts_ottelo.h

Lines changed: 0 additions & 61 deletions
This file was deleted.

tasmota/tasmota_xdrv_driver/xdrv_10_scripter.ino

Lines changed: 77 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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 =
98829890
const 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

98879896
const 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) {
1101711027
TS_FLOAT fvar;
1101811028
char 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);

tasmota/user_config_override.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,13 @@
201201

202202
//-- Software Serial für ESP32 (nur RX), Pin mit dem Zeichen '-' in der SML Sektion definieren (bei mehr als 2/3-Leseköpfen, je nach ESP32 Variante)
203203
//-- Optional: Serielle Schnittstelle (RX/TX RS232) im Script verwenden
204+
//-- Optional: Full Webpage (für Untermenüs/Diagramme)
204205
#if ( !defined(TASMOTA1M_OTTELO) && !defined(TASMOTA4M_OTTELO) && !defined(TASMOTA1M_ENERGY_OTTELO) && !defined(TASMOTA1M_SHELLY_OTTELO) )
205206
#define USE_ESP32_SW_SERIAL
206207
#define USE_SCRIPT_SERIAL //3KB
208+
#define SCRIPT_FULL_WEBPAGE //1KB
209+
#define USE_MQTT_TLS //3KB
210+
#define USE_INFLUXDB //6KB
207211
#endif
208212

209213
//-- Optional: ESP32 WT32_ETH01 (Ethernet LAN Modul)
@@ -232,7 +236,9 @@
232236
//-- Optional: >J Sektion aktivieren https://tasmota.github.io/docs/Scripting-Language/#j
233237
#define USE_SCRIPT_JSON_EXPORT //0KB
234238

239+
#define SCRIPT_OTTELO_USE_SCRIPTLIST
240+
235241
#endif // TASMOTA32 OTTELO
236242

237243

238-
#endif // _USER_CONFIG_OVERRIDE_H_
244+
#endif // _USER_CONFIG_OVERRIDE_H_

0 commit comments

Comments
 (0)