diff --git a/chata/index.html b/chata/index.html
index d6e0488..197321f 100644
--- a/chata/index.html
+++ b/chata/index.html
@@ -1,116 +1,231 @@
-
-
-
-
- MQTT
-
-
-
-
- Dálkové ovládání chaty.
-
-
- |
- |
- |
-
-
- |
-
-
-
-
+ function sendMessage (n) {
+ var nval = 0;
+ switch (n) {
+ case 0: nval = document.getElementById("led1Range").value; break;
+ case 1: nval = document.getElementById("led2Range").value; break;
+ default: return;
+ }
+ if ( websocket != null ) {
+ var strToSend = n + '/' + nval;
+ websocket.send (strToSend);
+ }
+ }
+ function setPotValue (val) {
+ potenciometer = document.getElementById ('potBar');
+ const percent = val + '%';
+ potenciometer.style.width = percent;
+ potenciometer.innerHTML = percent;
+ }
+ function setButValue (id, val) {
+ const mbut = document.getElementById(id);
+ if (val) mbut.style.backgroundColor = '#00FF00';
+ else mbut.style.backgroundColor = '#F0F0F0';
+ }
+ function setSldValue (id, val) {
+ const msld = document.getElementById(id);
+ msld.value = val;
+ }
+ var websocket = null;
+
+ function initWebSocket() {
+ try {
+ if (typeof MozWebSocket == 'function')
+ WebSocket = MozWebSocket;
+ if ( websocket && websocket.readyState == 1 )
+ websocket.close();
+ var wsUri = server_id.value;
+ websocket = new WebSocket( wsUri );
+ websocket.onopen = function (evt) {
+ debug("CONNECTED");
+ document.getElementById("connectButton").disabled = true;
+ document.getElementById("disconnectButton").disabled = false;
+ document.getElementById("led1Range").disabled = false;
+ document.getElementById("led2Range").disabled = false;
+ };
+ websocket.onclose = function (evt) {
+ debug("DISCONNECTED");
+ document.getElementById("connectButton").disabled = false;
+ document.getElementById("disconnectButton").disabled = true;
+ document.getElementById("led1Range").disabled = true;
+ document.getElementById("led2Range").disabled = true;
+ };
+ websocket.onmessage = function (evt) {
+ // console.log (evt.data);
+ var list = evt.data.split ('/');
+ if (list.length != 2) return;
+ var cmd = parseInt (list[0], 10);
+ var val = parseInt (list[1], 10);
+ switch (cmd) {
+ case 0: setPotValue (val); break;
+ case 1: setButValue ('in0', val); break;
+ case 3: setButValue ('in1', val); break;
+ case 4: setSldValue ('led1Range', val); break;
+ case 5: setSldValue ('led2Range', val); break;
+ default: break;
+ }
+ };
+ websocket.onerror = function (evt) {
+ debug('ERROR: ' + evt.data);
+ };
+ } catch (exception) {
+ debug('ERROR: ' + exception);
+ }
+ }
+
+ function stopWebSocket() {
+ if (websocket)
+ websocket.close();
+ }
+
+ function checkSocket() {
+ if (websocket != null) {
+ var stateStr;
+ switch (websocket.readyState) {
+ case 0: {
+ stateStr = "CONNECTING";
+ break;
+ }
+ case 1: {
+ stateStr = "OPEN";
+ break;
+ }
+ case 2: {
+ stateStr = "CLOSING";
+ break;
+ }
+ case 3: {
+ stateStr = "CLOSED";
+ break;
+ }
+ default: {
+ stateStr = "UNKNOW";
+ break;
+ }
+ }
+ debug("WebSocket state = " + websocket.readyState + " ( " + stateStr + " )");
+ } else {
+ debug("WebSocket is null");
+ }
+ }
+
+
+