• 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](https://forum.espruino.com/search/?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](https://forum.espruino.com/search/?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>
    
  • Sat 2021.04.24

    From 1st snippet:
    L32 ws.send(oled.value);
    is returning the value of an Html element defined at:
    L19 var oled = document.getElementById('oled');

    I don't believe a WebSocket object returns a temperature in it's payload.

    http://www.espruino.com/ws#line=38

    Would you post the contents of L20 evt please. . . and/or link to datasheet/tutroial that demos that task.

    Is there an additional snippet with a function like getTemp()?

    p.116

    https://www.espruino.com/datasheets/STM32F411xE.pdf
    50C seems to be on the low end of their test cal ranges



    Forgive me on: 'UTF-8 character encoding (hungarian's accented characters)'
    I concur with your observation for the '?' char and will have to defer to others for an answer. Your snippets will provide that detail needed for them to comment on.

    In the mean time: Does this assist at all?

    https://www.espruino.com/Fonts#character-sets
    'Espruino does not support unicode natively'

  • Temperature sending code

    function broadcast(msg) {
      clients.forEach( cl => cl.send( msg ) );
    }
    
    setInterval(function( ) {
      var t = E.getTemperature( ).toFixed( 1 );
      broadcast( '{"param":"temp","value":"'+ t +'"}' );
    }, 500);
    
About

Avatar for Robin @Robin started