• Hi,
    First of all I would be like to say a big thank for your products.
    Amazing devices with my favorite programming language :)
    I build a smart barrier controller, controlling barrier and managering proxy cards via socket connection controlled by android phone.
    My problems is UTF-8 character encoding (hungarian's accented characters) and representating. As you can see on attached images the accented characters are well in the Espruino memory but they appear bad on browser. Interestingly, e.x. the "ő" character also appear well in the browser and in the code, but other chars appear as question mark. How can it be?
    HTML code

        html = `
    <!doctype html>
      <head>
        <meta charset="UTF-8">
    .....
      <body>
        <h1>Sorompó vezérlő</h1>
        <p>Alaplap hőmérséklete: <span id="temp">0</span>&nbsp;&#8451;</p>
        <p>Wiegand olvasó 1 csatorna: <span id="wieg1"></span></p>
        <p>Wiegand olvasó 2 csatorna: <span id="wieg2"></span></p>
        <p>
          LED on:
          <select id="oled">
            <option>off</option>
            <option>on</option>
          </select>
        </p>
      </body>
    </html>`;
    

    My other question is, is the operating temperature of the Espruino wifi CPU normal as shown in the attached picture, or does the motherboard require cooling?

    Thank you for your helping hand.

    Laci

  • Sat 2021.04.24

    Hi @Laci So that we may better visualize what is going on, would you mind posting the Javascript code snippet that is performing the actual write back to the browser using the indicated var html.

    and, . . . please post the view source results that the browser is receiving so that we may compare with the image that is posted above.

  • Hi Robin,
    Here is the javascript code with html variable and webserver function.

        html = `
    <!doctype html>
      <head>
        <meta charset="UTF-8">
    	<style>
    		html {font: 20px monospace}
    		body { color: #333; text-align: center; padding: 150px; }
    		h1 { font-size: 50px; }
    		article { display: block; text-align: left; width: 650px; margin: 0 auto; }
    		a { color: [#dc8100](http://forum.espruino.com/sear­ch/?q=%23dc8100); text-decoration: none; }
    		a:hover { color: #333; text-decoration: none; }
            select {font: 20px monospace;padding: 4px;}
    	</style>
        <script>
          window.onload = () => {
            var ws = new WebSocket('ws://' + location.host, 'protocolOne');
            var temp = document.getElementById('temp');
            var wieg1 = document.getElementById('wieg1');
            var oled = document.getElementById('oled');
            ws.onmessage = evt => {
              var d = JSON.parse(evt.data);
              switch(d.param) {
                  case 'temp':
                    temp.innerText = d.value;
                    break;
                  case 'wieg1':
                    wieg1.innerText = d.value;
                    break;
              }
            };
            oled.onchange = evt => {
              ws.send(oled.value);
            };
          };
        </script>
      </head>
      <body>
        <h1>Sorompó vezérlő</h1>
        <p>Alaplap hőmérséklete: <span id="temp">0</span>&nbsp;&#8451;</p>
        <p>Wiegand olvasó 1 csatorna: <span id="wieg1"></span></p>
        <p>Wiegand olvasó 2 csatorna: <span id="wieg2"></span></p>
        <p>
          LED on:
          <select id="oled">
            <option>off</option>
            <option>on</option>
          </select>
        </p>
      </body>
    </html>`;
    function startServer( ) {
      const s = require('ws').createServer(pgHandler);
      s.on('websocket', wsHandler);
      s.listen( 80 );
    }
    function pgHandler(req, res) {
      res.writeHead(200, { 'Content-Type':'text/html' });
      res.end(html);
    }
    

    Chrome received html code

    <!doctype html>
      <head>
        <meta charset="UTF-8">
    	<style>
    		html {font: 20px monospace}
    		body { color: #333; text-align: center; padding: 150px; }
    		h1 { font-size: 50px; }
    		article { display: block; text-align: left; width: 650px; margin: 0 auto; }
    		a { color: [#dc8100](http://forum.espruino.com/sear­ch/?q=%23dc8100); text-decoration: none; }
    		a:hover { color: #333; text-decoration: none; }
            select {font: 20px monospace;padding: 4px;}
    	</style>
        <script>
          window.onload = () => {
            var ws = new WebSocket('ws://' + location.host, 'protocolOne');
            var temp = document.getElementById('temp');
            var wieg1 = document.getElementById('wieg1');
            var oled = document.getElementById('oled');
            ws.onmessage = evt => {
              var d = JSON.parse(evt.data);
              switch(d.param) {
                  case 'temp':
                    temp.innerText = d.value;
                    break;
                  case 'wieg1':
                    wieg1.innerText = d.value;
                    break;
              }
            };
            oled.onchange = evt => {
              ws.send(oled.value);
            };
          };
        </script>
      </head>
      <body>
        <h1>Soromp� vez�rlő</h1>
        <p>Alaplap hőm�rs�klete: <span id="temp">0</span>&nbsp;&#8451;</p>
        <p>Wiegand olvas� 1 csatorna: <span id="wieg1"></span></p>
        <p>Wiegand olvas� 2 csatorna: <span id="wieg2"></span></p>
        <p>
          LED on:
          <select id="oled">
            <option>off</option>
            <option>on</option>
          </select>
        </p>
      </body>
    </html>
    
About

Avatar for Robin @Robin started