I am using Tasmota 14.2.0 and I'm trying to figure out why something in the following changes to my xdrv_01_9_webserver.ino
file bricked my ESP8266 device and made it so I could no longer connect to it over HTTP:
My embedded JavaScript function:
const char HTTP_SCRIPT_EZSALT[] PROGMEM =
"function transitionToEZsaltGo(){"
"var mqttClient = \"%s\".trim();" // Placeholder for mqtt_client
"alert(mqttClient);"
"alert(mqttClient.length);"
"document.getElementById('btnTransitionToEZsaltGo').style.display = 'none';"
"document.getElementById('divFinalStep').style.display = 'block';"
"var countdown = 10;"
"setInterval(function(){"
" countdown--;"
" document.getElementById('divFinalStep').innerHTML = 'Transferring to EZsaltGo<br>in ' + countdown + ' seconds...';"
" if(countdown < 1){"
" location.href = 'https://ezsaltgo.com/AddSensor.php?SensorID=XXXXX';"
" }"
"}, 1000);"
"}";
My attempt to inject the TasmotaGlobal.mqtt_client
runtime value into the JavaScript function (I am suspicious that this might be breaking everything but I don't know why):
char buffer[650];
snprintf_P(buffer, sizeof(buffer), HTTP_SCRIPT_EZSALT, TasmotaGlobal.mqtt_client);
WSContentSend_P(buffer);
And finally the injection of a bit of html, including the button to call my js:
WSContentSend_P(PSTR(D_SUCCESSFUL_WIFI_CONNECTION "<br><br></div><div style='text-align:center;'><button id='btnTransitionToEZsaltGo' onclick='transitionToEZsaltGo()'>Continue Setup</button><div id='divFinalStep' style='display: none'>Transferring to EZsaltGo<br>in 10 seconds...</div><br><br></div>"));
I prototyped the button and JS in a plain HTML page and it all works, so there are no HTML/JS errors. The firmware compiles with no problems. After installation I cannot communicate with the firmware over http like I usually can. Besides the above noted customizations, everything else is standard and works fine in my devices.
The solution was to not use buffers at all, but rather to just do one of these for each line of js:
WSContentSend_P()