Proxying internal host on widget

Hi,

In my habpanel I have a image widget that points to an internal webserver.

What’s the correct way to have the images avaliable when accessing habpanel from the outside through the cloud service?

Thanks.

Anyone?

It would help if u posted how exactly you are using the image item.
The state of the image should go through fine, but if you are trying to update the image from outside your network that will fail.
Change the state of the image element using a rule inside your network.

As an example, to make Grafana rendered graph images available externally (using my own openhabcloud instance), I use the following (it’s a Jython rule):

# Retrieve the PNG snapshot file.
def getSnapshotImage(url, img):
    tmpFile = "/tmp/"+img+".png"
    Exec.executeCommandLine("wget -O " + tmpFile + " \"" + url + "\"", 12000)
    with open(tmpFile, "rb") as f:
        return "data:image/png;base64,"+base64.b64encode(f.read())

# Refresh the image Item.
def refreshImageItem(itemName):
    panelUrl = GRAFANA_URL + "&panelId="
    imageSnapshot = getSnapshotImage(panelUrl, itemName)
    events.postUpdate(itemName, imageSnapshot)

@rule("Grafana Snapshots Refresh", description="Grafana snapshots rendering refresh", tags=["graphs"])
@when("System started")
@when("Time cron 0 */5 * * * ?")
def grafanaRefreshInit(event):
    for item in ir.getItem(GRAFANA_GROUP).members:
        lastRefresh = get_key_value(item.name, "Grafana_Graphs", "LastRefresh")
        if minutes_between(lastRefresh, DateTime.now()) >= get_key_value(item.name, "Grafana_Graphs", "RefreshRate"):
            refreshImageItem(item.name)
            set_metadata(item.name, "Grafana_Graphs", {"LastRefresh": DateTime.now()})

I left out all non-essential parts (so this is non-working code). What this rule does is:

  1. Loop through group members.
  2. For each item, retrieve a rendered image from Grafana (internally) and convert it to base64.
  3. Update the Image item with the base64-formatted data.
  4. The image item should display just fine from outside your network.

What exactly do you mean by that? Can you show the code?

@noppes123, @matt1 Thanks for the reply. There is no code, just the usage of image widget, like this:

The host doorpi serves a stream of video from a webcam. When I access habpanel on the internal network, where doorpi lives, I get the video feed.

Outside the network, via the openHAB Cloud Connector, there is no video, since the host can’t be reached.

The trivial workaround would be forwarding port 8080 (the video port) on the router, but this would be my last option.

Thanks.

As far as I can see, your setup will not work without an inbound connection, and I would recommend against that! Outbound connections are ok, but will probably not be suitable for your config as it is now.
A ‘next best thing’ could be to generate frequent snapshots and publish them as true images. But that will increase the load depending on the refresh rate…