How to show a local dynamic HTML page over a internet-connection?

Hi,
I’m trying to show a webview from a dynamic html-page (data from weather binding) when not connected to the local network (using myopenhab or HabDroid).
I tried to do it with a “wrapper” html which is reachable via the internet, but that does only work when connected to the local net. When trying to reach that page from the outside it reports that the underlying local adress is not rechable.

My “wrapper”

Is there a better way?

I guess what I did can only be regarded only as a poor workaround.
I am creating picture (jpg) of my html page via an external tool (tool is run via the exec binding) .
Also I am using a different sitemap for remote access.
In this sitemap I am using the image display capabilities of OH to show the picture of the html page.

The downside. All the interactivity of a custom html page is gone.
But atleast I can see my html dash board using myopenhab.

I wouldn’t call the a poor workaround!
Could you give me a hint how you did that?

I have defined an item which triggers a windows batch file.

Switch Renderrefresh   "Refresh Screen Shot"    { exec= "ON:C:/Users/Martin/OH2/conf/winbat/html2img.bat,OFF:C:/Users/Martin/OH2/Conf/winbat/html2img.bat"}

The Batch file looks like this

"C:\Program Files\wkhtmltopdf\bin\wkhtmltoimage.exe" --crop-h 1200 --crop-w 1200 --format jpg "http://localhost:8080/weather?locationId=home&layout=example&iconset=colorful" "C:\Users\Martin\Openhab3\webapps\static\img\head.jpg"

It would probably be possible to call the tool directly without the indirection via a batch file.

you can download the tool under http://wkhtmltopdf.org
It is also running under Linux. So principally this approach should also work with Linux and MacOS.

2 Likes

I did it all on my raspi!
First installed wkhtmltopdf via apt-get.

sudo apt-get install wkhtmltopdf

Using wkhtmltoimage raised an error (“QXcbConnection: Could not connect to display Aborted”), to overcame that the installation of xvfb ws needed.

sudo apt-get install xvfb

Now I can use this tool to make images of my local webpage although this system doesn’t have a display. I guess this error was due to that.

Usage from the commandline as user pi

sudo xvfb-run wkhtmltoimage --crop-h 350 --crop-w 350 http://MyRaspi:8080/static/MyWebFile.html /etc/openhab2/html/MyPicture.jpg

In OpenHAB2 I created anc String Item to hold the path to the picture

String WeatherPicture

and on the sitemap I have

Image refresh=60000 item=WeatherPicture

The picture is made via a rule which is triggered on each change of the ObservationTime.
I’m using the postUpdate for the String Item WeatherPicture to raise a refresh of the sitemap, but I’m not sure if that isworking.

rule “WeatherPicture”

when
Item ObservationTime changed
then
executeCommandLine(“xvfb-run wkhtmltoimage --crop-h 350 --crop-w 350 http://MyRaspi:8080/static/MyWebFile.html /etc/openhab2/html/MyPicture.jpg”)
WeatherPicture.postUpdate(“http://opuspi:8080/static/MyPicture.jpg”)
end

2 Likes

Happy to see it is working::slight_smile: