onbeforeunload = function(){
            eventSource.close();
        };

        eventSource.onopen = function (e) {
            addMessage('Connection opened');
        };
        eventSource.onmessage = function (e) {
            var event = JSON.parse(e.data);
            addMessage('Temperature: ' + Number(event.value).toFixed(2) + "C");
        };
        eventSource.onerror = function (e) {
            if (e.readyState === EventSource.CONNECTING) {
                addMessage('Connecting to server');
