Connection lost

Hi there,

I set up openhab2 on my main homeserver a few weeks ago and am slowly expanding it. Now I ran into a little problem. When I go to HABPanel, it stays empty and shows “Connection lost! Trying to reconnect…”
The browser console shows a few messages which might indicate what the problem is:

Content Security Policy: The page’s settings blocked the loading of a resource at self (“script-src http://nostromo:8080 ‘sha256-5hvlzGKhlKhafFjW6G/cRVpM/e+JewYxe/pLpQ5Kj9M=’”). Source: call to eval() or related function blocked by CSP.
[…]
window.controllers is deprecated. Do not use it for UA detection.
[…]
Service worker not registered (not using HTTPS?): SecurityError: The operation is insecure. index.html:27:21
openHAB 2 service configuration loaded openhab.service.js:252:17
Error loading openHAB items… retrying in 5 seconds openhab.service.js:48:17
Error loading openHAB items… retrying in 5 seconds openhab.service.js:48:17
[…]

When I restart openhab, I get back in for a couple of hours and then it’s gone again. Any idea where to look for the problem?

Interesting… Just noticed that when I go to PaperUI / Items I get an empty screen and an Error 500 notification popup…

First thing to try:

If that does not resolve the problem, please tell us more about your system:

Which operating system?
Which openHAB build?
Regular or openHABian install?
Manual or apt-get install?

Ubuntu server 16.04.3

nostromo:~ # apt list --installed | grep openhab
openhab2/stable,stable,now 2.1.0-1 all [installed]
openhab2-addons/stable,stable,now 2.1.0-1 all [installed]

I’ll test deleting the cache

Nope, didn’t help. Again, after having habpanel open for an hour or so, the error comes up.

What about this one?:

As far as I understand this post, their habpanels aren’t working at all. Mine is working for some time after restarting the server instance and then suddenly stops working. I also checked already (read that post before writing mine :wink: ) and I’m not using any map transformations with %d - or any other for that matter.

The JS error I’m getting points to some other problem entirely but I’m not deep enough inside the code to understand where it might come from.

At least I would try:

octoprint.items:

Number  OPprogress      {mqtt="<[broker:octoprint/progress/printing:state:JSONPATH($.progress)"}
Number  OPtempBed       {mqtt="<[broker:octoprint/temperature/bed:state:JSONPATH($.actual)"}
Number  OPtempBedT      {mqtt="<[broker:octoprint/temperature/bed:state:JSONPATH($.target)"}
Number  OPtempExtr      {mqtt="<[broker:octoprint/temperature/tool0:state:JSONPATH($.actual)"}
Number  OPtempExtrT     {mqtt="<[broker:octoprint/temperature/tool0:state:JSONPATH($.target)"}

switches.items

Group:Switch:OR(ON,OFF) gALL
Group:Switch:OR(ON,OFF) gLIGHTS                                                                                                                                
Group:Switch:OR(ON,OFF) gSOUND
Group:Switch:OR(ON,OFF) gPHONES

Number sceneSwitch "Scene"
Switch sceneSet "Scene set"

Switch Network_WOL_ENT  "Wakeup Enterprise"     (Status, Network)       { channel="network:device:192_168_10_1:online", wol="192.168.10.255#78:e7:d1:f7:ac:0c" }

Switch Bedroom1         "Bedroom Ch1"           (gALL, gLIGHTS)         { mqtt="<[broker:bedroom/stat/POWER1:state:default], >[broker:bedroom/cmnd/POWER1:command:*:${command}]" }
Switch Bedroom2         "Bedroom Ch2"           (gALL, gSOUND)          { mqtt="<[broker:bedroom/stat/POWER2:state:default], >[broker:bedroom/cmnd/POWER2:command:*:${command}]" }

Switch Livroom1         "Livroom Ch1"           (gALL, gLIGHTS)         { mqtt="<[broker:livroom/stat/POWER1:state:default], >[broker:livroom/cmnd/POWER1:command:*:${command}]" }
Switch Livroom2         "Livroom Ch2"           (gALL, gLIGHTS)         { mqtt="<[broker:livroom/stat/POWER2:state:default], >[broker:livroom/cmnd/POWER2:command:*:${command}]" }

Switch B1_1_Sw          "B1-1-Switch"           (gALL, gLIGHTS)         { mqtt="<[broker:b1-1/stat/RESULT:state:JSONPATH($.POWER)],  >[broker:b1-1/cmnd/POWER:command:*:${command}]" }
Number B1_1_Dim         "B1-1-Dimmer"                                   { mqtt="<[broker:b1-1/stat/RESULT:state:JSONPATH($.Dimmer)], >[broker:b1-1/cmnd/Dimmer:command:*:default]" }
Number B1_1_CT          "B1-1-ColorTemp"                                { mqtt="<[broker:b1-1/stat/RESULT:state:JSONPATH($.CT)],     >[broker:b1-1/cmnd/CT:command:*:default], >[broker:b1-1/cmnd/CT:command:*: ]" }
String B1_1_Col         "B1-1-Color"                                    { mqtt="<[broker:b1-1/stat/RESULT:state:JSONPATH($.Color)],  >[broker:b1-1/cmnd/Color:command:*:default]" }

weather.items

Number  weatherTemp     "Outside temperature"   { mqtt="<[broker:weather/temperature:state:default]" }
Number  weatherPress    "Pressure"              { mqtt="<[broker:weather/pressure:state:default]" }
Number  weatherHum      "Outside humidity"      { mqtt="<[broker:weather/humidity:state:default]" }
Number  weatherDew      "Outside dew point"     { mqtt="<[broker:weather/dewpoint:state:default]" }
Switch  weatherStat     "Weather sensor status" { mqtt="<[broker:weather/stat:state:default]" }

DateTime        weatherUpdated  "[%1$tm/%1$td %1$tH:%1$tM]"

(assuming you use Chrome)
When the connection drops, open the developers tools (F12) and go to the Network tab - you should see a bunch of failed calls (red) to “events”. Click one and post what you see in the “Response” tab.

… and also make sure you are meeting the prerequisites:

http://docs.openhab.org/installation/linux.html

In particular:

Meeting the Requirements: As a first step, please verify, that your system meets the prerequisites. You may want to install Zulu, a fully certified Java build as a package or manually.

Try to avoid OpenJDK, use Zulu or Oracle java …

I use firefox but I will check next time it fails. I just restarted the server again. I put a few messages in my opening post, in case you didn’t see that :).

Content Security Policy: The page’s settings blocked the loading of a resource at self (“script-src http://nostromo:8080 ‘sha256-5hvlzGKhlKhafFjW6G/cRVpM/e+JewYxe/pLpQ5Kj9M=’”). Source: call to eval() or related function blocked by CSP. vendor.js:189
Registered widget type: button widgets.module.js:37:13
Registered widget type: chart widgets.module.js:37:13
Registered widget type: clock widgets.module.js:37:13
Registered widget type: colorpicker widgets.module.js:37:13
Registered widget type: dummy widgets.module.js:37:13
Registered widget type: frame widgets.module.js:37:13
Registered widget type: image widgets.module.js:37:13
Registered widget type: knob widgets.module.js:37:13
Registered widget type: label widgets.module.js:37:13
Registered widget type: slider widgets.module.js:37:13
Registered widget type: switch widgets.module.js:37:13
Registered widget type: timeline widgets.module.js:37:13
Registered widget type: template widgets.module.js:37:13
openHAB 2 service configuration loaded openhab.service.js:252:17
Error loading openHAB items… retrying in 5 seconds openhab.service.js:48:17
window.controllers/Controllers is deprecated. Do not use it for UA detection. index.html
Service worker not registered (not using HTTPS?): SecurityError: The operation is insecure. index.html:27:21
Error loading openHAB items… retrying in 5 seconds openhab.service.js:48:17
GET XHR http://nostromo:8080/rest/items [HTTP/1.1 500 Internal Server Error 3ms]
Error loading openHAB items… retrying in 5 seconds openhab.service.js:48:17
GET XHR http://nostromo:8080/rest/items [HTTP/1.1 500 Internal Server Error 3ms]
Error loading openHAB items… retrying in 5 seconds openhab.service.js:48:17
GET XHR http://nostromo:8080/rest/items [HTTP/1.1 500 Internal Server Error 4ms]
Error loading openHAB items… retrying in 5 seconds openhab.service.js:48:17
GET XHR http://nostromo:8080/rest/items [HTTP/1.1 500 Internal Server Error 3ms]
Error loading openHAB items… retrying in 5 seconds openhab.service.js:48:17
GET XHR http://nostromo:8080/rest/items [HTTP/1.1 500 Internal Server Error 3ms]
Error loading openHAB items… retrying in 5 seconds openhab.service.js:48:17
GET XHR http://nostromo:8080/rest/items [HTTP/1.1 500 Internal Server Error 3ms]
Error loading openHAB items… retrying in 5 seconds openhab.service.js:48:17
GET XHR http://nostromo:8080/rest/items [HTTP/1.1 500 Internal Server Error 4ms]
Error loading openHAB items… retrying in 5 seconds openhab.service.js:48:17
GET XHR http://nostromo:8080/rest/items [HTTP/1.1 500 Internal Server Error 4ms]
Error loading openHAB items… retrying in 5 seconds openhab.service.js:48:17
GET XHR http://nostromo:8080/rest/items [HTTP/1.1 500 Internal Server Error 12ms]
Error loading openHAB items… retrying in 5 seconds openhab.service.js:48:17
GET XHR http://nostromo:8080/rest/items [HTTP/1.1 500 Internal Server Error 3ms]
Error loading openHAB items… retrying in 5 seconds openhab.service.js:48:17

We can’t really help you if you don’t go to the Network tab and give us the actual response of your failed requests like I told you. It’s basically the same in Chrome and Firefox - click on one the requests with a 500 status and look what’s reported in the Response tab.

Sorry, didn’t follow what you meant. I’m more of a console guy, first time debugging some web app.
Do you mean this?

Ah wait, responses tab… it says

exception java.lang.NullPointerException
class java.lang.NullPointerException

I see this in /var/log/openhab.log:

2017-10-03 20:12:50.277 [WARN ] [b.core.events.EventPublisherDelegate] - given new state is NULL, couldn’t post update for ‘B1_1_CT’
2017-10-03 20:12:50.282 [WARN ] [b.core.events.EventPublisherDelegate] - given new state is NULL, couldn’t post update for ‘B1_1_CT’
2017-10-03 20:12:50.325 [WARN ] [b.core.events.EventPublisherDelegate] - given new state is NULL, couldn’t post update for ‘B1_1_Sw’
2017-10-03 20:12:50.325 [WARN ] [b.core.events.EventPublisherDelegate] - given new state is NULL, couldn’t post update for ‘B1_1_Dim’

Could this be the reason for the NullPointerException? IIRC, the issues started, when I added the B1 channels to my items.

Those last messages are likely to be the problem.
Afraid I don’t really know much more. Which binding/devices are these? Maybe you could search “given new state couldn’t post update” on the forum, or repost those messages in one of those categories:

with your configuration and specify which devices those “B1” items are. There are likely knowledgeable people who monitor these categories and could offer more advice.

Good luck!

Jep, I removed the color temperature item for the B1 (Sonoff B1 LED bulb) and the problem is gone. Here’s my theory:

The B1 with tasmota software answers to all commands with

stat/RESULT {“POWER”:“ON”, “Dimmer”:100, “Color”:“FFFFFFFFFF”}

(of course with appropriate values). It also answers with this to the cmnd/CT command which sets the color temperature. If you want the color temperature in a reply, you have to send an empty cmnd/CT and you will get something like this.

b1-1/stat/RESULT {“CT”:500}

Now, JSONPATH returns NULL if it can’t find the path item you are asking for, and as both the standard as well as the CT reply use the RESULT path, there’s always something going to be NULL. If you send a regular command, CT will be NULL and if you ask for CT, POWER, Dimmer and Color will be NULL.

Thanks for the hint with the Network tab…! As I wrote, I have never debugged a web app before and that was very helpfull :).

It’s definitely the JSON issue. When I issue a request for CT by hand, HABpanel goes dark. As soon as I issue a request which makes the B1 return the full RESULT, HABpanel comes back.