Under the assumption the entire code segment is the 515 'usage' value,
What do you mean with this?
Here is my code from my function that sends the main page.
When I remove the CSS from the function its working fine, but then the page is only ~ 4 KB big, and I want the page to be with the CSS.
I split the string in several pieces, so I can see how much memory is left in between.
function sendMainPage(res) {
print(process.memory());
let hostname = wifi.getHostname();
let ip = wifi.getIP();
res.writeHead(200, {'Content-Type': 'text/html'});
res.write('<html lang="en"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>ESP8266 V0.1</title></head>');
print(process.memory());
res.write(`<body><div class="side-bar"><div><span id="hostname" class="font-20">${hostname}</span><br><span class="font-18"> ESP8266 V0.1 </span></div><div class="verzeichniss"><h3>Einstellungen</h3><ul><li onclick="activateAllgemein()">Allgemein</li><li onclick="activateWlan()">WLAN</li><li onclick="activateSensoren()">Sensoren</li><li onclick="activateNtp()">NTP-Server</li></ul></div><div class="main-buttons"><button type="submit" form="mainContent">Save</button></div><div class="main-buttons"><a href="./reboot"><button name="Reboot">Neustarten</button></a></div></div>`);
print(process.memory());
res.write(`<form action="/" method="post" class="main-content" id="mainContent"><div id="allgemein"><div class="header">Allgemein</div><div class="content"><table><tbody><tr><td>Hostname:</td><td><input type="text" name="hostname" id="hostname" value="${hostname}"></td><td>Currenttime:</td><td>25.03.2021 17:07:54</td></tr><tr><td>Wlan:</td><td>${wifi.getDetails().ssid}</td><td>Uptime:</td><td>25.03.2021 17:07:44</td></tr><tr><td>Mac:</td><td>${ip.mac}</td><td>Ip:</td><td>${ip.ip}</td></tr></tbody></table></div></div>`);
print(process.memory());
res.write(`<div id="wlan" style="display: none;"><div class="header">WLAN</div><div class="content normal"><div><div><div><span>Wlan SSID:</span><input type="text" name="wlanSSID" id="wlanSSID" placeholder="Name des Wlans." value="${config.wifi[0].ssid}"></div><div><span>Wlan Passwort:</span><input type="text" name="wlanPW" id="wlanPW" placeholder="Passwort des Wlans." value="${config.wifi[0].pw}"></div></div><div><div><span>Statische IP:</span><input type="text" name="staticIP" id="staticIP" placeholder="Leer lassen für DHCP."></div><div><span>Gateway-IP:</span><input type="text" name="gatewayIP" id="gatewayIP" placeholder="Nur wenn man eine Statische Ip nimmt."></div></div><div><div><span>Netzwerkmaske:</span><input type="text" name="networkMask" id="networkMask" placeholder="Normalerweise 255.255.255.0."></div><div><span>DNS IP:</span><input type="text" name="dnsIP" id="dnsIP" placeholder="Nur wenn man eine Statische Ip nimmt."></div></div></div></div></div>`);
print(process.memory());
res.write(`<div id="sensoren" style="display: none;"><div class="header">Sensoren</div><div class="content normal"><div><span>Temparatur Sensor DS18B20:</span><div><div><span>Pin:</span><input type="text" name="pin" id="pin" placeholder="Welchen Pin (1, 2, 3, 5...)."></div><div><span>Sensor:</span><select name="sensorTyp" id="sensorTyp"><option value="0">DS18B20</option></select></div></div><div><div><span>Temparatur unterschied:</span><input type="text" name="eichung" id="eichung" placeholder="Um die abweichung anzugleichen."></div><div><span>Sendeintervall:</span><input type="text" name="sendIntervall" id="sendIntervall" placeholder="Der Sende Intervall in Sekunden."></div></div><div><div><span>Node.js Server IP:</span><input type="text" name="serverIP" id="serverIP" placeholder="Ip des Node.js Servers."></div><div><span>Node.js Server Pfad:</span><input type="text" name="serverPfad" id="serverPfad" placeholder="Der Pfad an dem es Senden soll."></div></div><div><div><span>Geräte ID:</span><input type="text" name="clientID" id="clientID" placeholder="Die ID die im Server vermerkt sein muss."></div><div><span>Gerät Passwort:</span><input type="text" name="clientPW" id="clientPW" placeholder="Das Passwort zur ID."></div></div></div></div></div>`);
print(process.memory());
res.write(`<div id="ntp" style="display: none;"><div class="header">NTP-Server</div><div class="content normal"><div><div><div><span>NTP-Server:</span><input type="text" name="ntpServer" id="ntpServer" placeholder="IP des NTP-Servers." value="${config.ntp.server || ""}"></div><div><span>Zeitzone:</span><input type="text" name="timeZone" id="timeZone" placeholder="Zeitzone des NTP-Server." value="${config.ntp.timeZone || ""}"></div><div><span>Winterzeit/Sommerzeit:</span><input class="apple-switch" name="summerTime" id="summerTime" value="true" type="checkbox" ${config.ntp.summerTime ? 'checked=""' : ''}></div></div></div></div></div></form>`);
print(process.memory());
res.write(`<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script><script>function dilsplayNoneForMainContainer(){let allDivs=$('#mainContent > div').toArray(); for (let i=0; i < allDivs.length; i++){allDivs[i].setAttribute("Style", "display: none;");};}; function activateAllgemein(){dilsplayNoneForMainContainer(); allgemein.setAttribute("Style", "display: inline-block;");}; function activateWlan(){dilsplayNoneForMainContainer(); wlan.setAttribute("Style", "display: inline-block;");}; function activateSensoren(){dilsplayNoneForMainContainer(); sensoren.setAttribute("Style", "display: inline-block;");}; function activateNtp(){dilsplayNoneForMainContainer(); ntp.setAttribute("Style", "display: inline-block;");}; </script></body></html>`);
res.end();
print(process.memory());
}
>Uncaught SyntaxError: Got EOF expected '}'
at line 51 col 114
...in.js"></script><script>fu
^
Execution Interrupted
New interpreter error: LOW_MEMORY,MEMORY
I need a way to send the HTML, CSS and JS without using up all the RAM, but I still need to be able to insert data into the HTML.
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Hey @Robin
What do you mean with this?
Here is my code from my function that sends the main page.
When I remove the CSS from the function its working fine, but then the page is only ~ 4 KB big, and I want the page to be with the CSS.
I split the string in several pieces, so I can see how much memory is left in between.
Here is the Console:
Code with CSS:
This happens:
I need a way to send the HTML, CSS and JS without using up all the RAM, but I still need to be able to insert data into the HTML.