Displaying log texts in openhab

HI Niklas

In your Post there might be an interesting topic when thinking about it but I don’t know about the implications for Openhab…

Is it possible to call an PHP script on the apache that generates the sitemap (e.g. depending from where you call it, internal or external) and then forward to this address? With this there might be some other nice effects :smile:

But how does Openhab react in that case? Maybe @steve1 could give us a clue as developer?

Regards
Dieter

I’m probably misunderstanding something you are saying, but this part doesn’t sound correct to me. In my experience most home routers/gateways do not do name resolution for the LAN (although it may be possible depending on the router firmware). For example, the only local names that are resolved on my LAN are through mDNS, NetBIOS, local hostname configurations, etc., none of which are router-based.

However, the router may cache WAN addresses as a performance optimization after querying the WAN DNS servers. As @Frasier said, a TCP connection to the WAN (DDNS) address will go through the ISP’s gateway and back to the WAN->LAN router/gateway. The router then may forward the messages to the LAN if port forwarding is enabled. If the port is forwarded, the WAN address is converted to a LAN address using NAT inside the router. At that point the connection proceeds on the LAN side of the router.

Unless one has a very slow or intermittent connection to the ISP, the extra hop from the ISP gateway back to the LAN will not have a significant impact on performance when the information is accessed from the LAN.

The results of nslookup, traceroute or dig should give a definitive indication whether the hostname is being resolved to a LAN or WAN address and at least a hint about why it’s being resolved that way.

I’m not sure, but I think that openhab loads the sitemap file from the file system when a web request is made. I think you may need to modify the openhab web application to dynamically choose a sitemap for LAN vs WAN access. There might be some way to configure the openhab Jetty server to rewrite the request URL depending on the requester’s IP address (LAN or WAN), but this is just a guess.

Hi @steve1

Thank you for your quick answer.

First my thoughts to what @Frasier wrote: I couldn’t agree with you completly that there is no name resolution as I have one here. Reason why I know that if that I had to change all bookmarks on my PC after I’ve moved OH related items to a different subnet in my LAN to use FQDN after getting message “could not resolve name”. But this is just my observation and maybe only in my network and as I’ve said I’m not the protocol expert in this case. As you’ve written we will see the results of the tests but I can’t think of being completly wrong…

For the second part: I’m impressed that you came to a more complicate solution of a non existing problem than I did, only a few people are able to do this ;-). But let me explain: Having thought it over again my idea now is the following. One can create a “template” (call it this way) sitemap as file somewhere. This file is read by a script and that script creates the different versions of the real sitemaps, for example local or remote, also as files in OH sitemap directory. (here was my problem first for that I’ve asked for your help) The script is either called by some trigger (are there file-changed-trigger in Linux?) or online when calling a url on the apache (@Frasier mentioned that). When online generating is done, the client will be forwarded to the normal OH url as you have it on thousands of websites (like: “…you will be forwarded in x seconds, if not click here…”). In any subsequent call or when offline generation is active (“real” sitemap is newer than “template” sitemap) you will be directly forwarded by the apache script by sending http 303/307 return code (temporary redirect, temporary because the browser should not cache the forwarding). So OH will never notice that it is not called directly but using a different server with redirection first.

The benefits of the solution are that you manually still have to deal with only one sitemap (the template), your system is still available on one address (the routing script on the apache) and the routing can be done based on any information available when the script is called, which are a lot. For me it could be interesting to change the sitemap when calling from my computer (24" display) or phone (4" display)…

Regards
Dieter

@steve1, both ping and nslookup were successful in resolving my true IP in 1 ms. I really cant understand this. The behaviour is the same independantly if I try with my DNS hostname or WAN IP address.

From time to time I’ve actually been able to reach my Openhab site from within the LAN pointing at my DNS hostname with my Windows Phone. Although the connection is extremely slow and my PiCam interface updates one frame per like 20s.

I guess this might be router dependant and there are a lot of options in there that might complicate things. Like virtual server, port forwarding (which I use), application rules, Network Filter, Access Control, Routing, Firewall etc. Perhaps my ISP could be effecting things as well.

Perhaps I should try with a different router as a next step.

Not really surprising for me (or, to quote Sheldon Cooper: I told you so ;-)). When you do a tracert you will see that you don’t leave your network.

If I were you, before buying a new router, I would try to configure the raspberry to react on your ddns name. But I don’t know how to do it myself, you might ask google (“linux hostname external” or something similar). Even if that doesn’t work, at least you haven’t spent money. If you really would buy a new router you might look for one that offers a DMZ (or exposed host) port as this is what you are doing here. But I’ve also no idea whether or not they are available for an acceptable price…

Or you implement the solution I’ve described in my last post and when it’s done and working, provide it to me so I don’t have to do it myself :wink:

Regards
Dieter

I solved it finally. As I thought one way of fixing it was to target the router. I was one google search away from a good description of the issue. Serverfault.com : Loopback to forwarded Public IP address from local network - Hairpin NAT

Luckily my dlink router could be fed with a new firmware from dd-wrt.com and after defining my port forward rules everything just works (so far). Apparently the so called NAT loopback functionality is enabled by default. And as a bonus the router firmware seems quite capable!

Thanks @steve1 and @DieterL for your thoughts and suggestions. Hopefully this thread can be of use for someone else as well.

The WAN vs LAN address issue is a router problem, and nothing to do with openhab as such.

I was having a similar problem, as I use my DDNS name everywhere, and port forwarding on my router to map the external ports to my internal ports.

I found a bug in my router firmware (Netgear 7500) where it would fail to resolve the external DNS name when used on the internal LAN - this is supposed to be a feature of this router (some routers don’t do this at all). A later version of firmware fixed this bug, and now my DDNS name resolves correctly whether I’m at home (LAN), or away (WAN). My other router (Netgear 7000) did not have this bug, so it would resolve correctly.

So a router issue/feature -something to look for when shopping for a new router.

I have used DD-WRT firmware before, and it has lots of features, so it’s a good choice for adding features to a router that doesn’t have them built in. It’s not for the faint of heart though! Still if you’re running openhab, you’re probably up for a challenge…

As to displaying log files in openhab -which was how I found this thread - I am trying to do the same thing. I already have a web page that will display any log file (like tail -f), but it’s complicated, and uses web sockets, so I’m not sure if it will work with the webview widget on all platforms.

I was looking at the sitemap list widget (display text broken at delimiter), which may work, I’ll experiment and let you know what works.

Just an update, the List widget doesn’t seem to work at all, but the Webview widget works just fine.

A couple if gotchas, for JavaScript and css file names you have to use the full name (or http address) -doesn’t work with relative names for some reason.

The height variable is important, too large and the page continually refreshes, too small and you can’t see anything. It also isn’t device specific, so you can’t easily switch from browser to iPad to phone. You can manually change the height value (using visibility). I don’t think this parameter is well thought out. Value of 22 is full height on my iPad mini.

I moved my index, css and js files to my Apache2 server sub directory (because of the relative file names issue), and used this URLs for the Webview URL -and it works!

I can now view any of my logs in openhab using my tail web-app.