SSE over REST-API

From Chrome it is also working as far as I can see.

What maybe is hampering is the authorization ( check if you see in the developers tab a “No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘http://zzz’ is therefore not allowed access.” errors)

Putting very basic example in the html folder of openhab2 will give you results in a filtered way (replace with your item)

<!DOCTYPE html>
<html>
<body>
<h1>Getting server updates</h1>
<div id="result"></div>
<script>
if(typeof(EventSource) !== "undefined") {
    var source = new EventSource("http://192.168.3.50:8080/rest/events?topics=smarthome/items/ReigerPowerAbsWd/state");
    source.onmessage = function(event) {
        document.getElementById("result").innerHTML += event.data + "<br>";
    };
} else {
    document.getElementById("result").innerHTML = "Sorry, your browser does not support server-sent events...";
}
</script>
</body>
</html>
1 Like