Should Habpanel refresh?

Hi Simon,

Thanks for sharing your solution! I’m having the same issue as you’ve described. I’m running on OH 2.5 and the front-end is running on an older android tablet. The issue is as described, running well for a couple of minutes then the auto-refresh is gone. I’ve also dev skills (not java :)), but having less free time (2 small kids) :). What version of OH are you using? If 2.5, then would it be possible to share you patched DLL, so I don’t have to struggle by building OH sources?

Thanks,
Attila

hi attila,

I would do so in a heartbeat, but I ultimately just got a better tablet and threw this “fix” away. I kept neither the patched package nor the source code - sorry…

HI Simon,

No problem, yesterday night, I was able to build the sources, so will try the change. One little question, if I uninstall the “original” habpanel, will it uninstall my dashboards as well or the setting will be kept?

Thanks,
Attila

Hi,

Just and update for the others. The original code from Simon was working for me as well on the old wall tablet, but was breaking the HabPanel after few minutes on newer devices. The final solution for me was, to do a small modification on Simon’s code and control the re-connect behavior by a query parameter. On the old tablet, this parameter is set, on newer ones not. Now, habpanel is working correctly everywhere.

Here is my URL: http://192.168.1.110:8080/habpanel/index.html?autoreload=1#/view/Test

Here is the modified code (please note I’m also not an angular geek :)):

$http.get('/rest/items')
    .then(function (data) {
        if (angular.isArray(data.data)) {
            console.log("Loaded " + data.data.length + " openHAB items");
            $rootScope.reconnecting = false;
            $rootScope.items = data.data;
            if (!liveUpdatesEnabled) registerEventSource();
            
            var getUrlParam = function(name) {
                name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
                var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
                var results = regex.exec(window.location.search);
                return results === null ? null : decodeURIComponent(results[1].replace(/\+/g, ' '));
            }
            
            var autoReload = getUrlParam('autoreload');
            console.log("Auto-reconnect >> url: " + window.location.href);
            console.log("Auto-reconnect >> autoReload: " + autoReload);
            var doAutorReload = (autoReload && autoReload == '1' ? true : false)
            console.log("Auto-reconnect >> doAutorReload: " + doAutorReload);
            if (doAutorReload && !autoRefreshEnabled) {
                autoRefreshEnabled = true;
                console.log("Auto-reconnect >> Setting up 2 minute reconnect watch-dog.");
                
                refresher = $interval(function () {
                    console.log("Auto-reconnect >> Renewing SSE connection...");
                    if(eventSource != null) {
                        eventSource.close();
                        console.log("Auto-reconnect >> Closing old stream");
                        eventSource = null;
                    }
                    liveUpdatesEnabled = false;
                    $timeout(loadItems, 100);
                }, 120000); //re-establish connection to SSE API every two minutes
            }
        } else {
            console.warn("Items not found? Retrying in 5 seconds");
            $rootScope.reconnecting = true;
            $rootScope.items = [];
            $timeout(loadItems, 5000);
        }
        $rootScope.$emit('openhab-update');
    },
    function (err) {
        console.warn("Error loading openHAB items... retrying in 5 seconds");
        $rootScope.reconnecting = true;
        $timeout(loadItems, 5000);
    });
}

The build process was quite easy (after finding the correct source codes :slight_smile:), but here are my notes, how to build OH UI sources. Maybe that will spare some time for the others …

  1. Install mpn
  2. npm install -g bower (https://bower.io/#install-bower)
  3. npm install gulp -g (https://gulpjs.com/)
  4. Install python 2 (https://www.python.org/downloads/release) -> make sure to check in setup: add to PATH variable
  5. Setup dev environment, by following the instructions here: https://www.openhab.org/docs/developer/#setup-the-development-environment
    a. Download marven and add the bin folder into PATH environment variable: https://maven.apache.org/download.cgi
    b. Download and install JAVA JDK 8: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
  6. Clone OH UI sources: git clone https://github.com/openhab/openhab-webui.git
  7. Switch the branch: git checkout 2.5.x
  8. Modify the source code
  9. Build the JS code, by following the notes from bundles\org.openhab.ui.habpanel\CONTRIBUTING.md
    a. To build the Javascript part of HABPanel, navigate to the web/ subfolder, then:
    i. Run npm install
    ii. Run bower install
    iii. Run gulp
    b. Navigate to the root folder and build the java code: mvn clean package
    c. After a successful build (cca 1hour), the package files will be located in the target folder (bundles\org.openhab.ui.habpanel\target)

congrats!

I am happy you got it working, and that my original patch is useful to somebody else too.