I am looking for a way to be able to access openHAB device over Internet and in case internet isn’t working access it over LAN if connected to same network off course. I would appreciate if someone could shed some light on this as to how it could be done. I am trying to do this while accessing from a mobile phone without having to change address/link.
Have you had a look at my.openHAB?
It sounds like this may be what you are looking for.
Yes! You can say trying achieve the same without using my.openhab.org as that requires me to create an account and would store data on their server. I would like to do that on my own.
It is correct that you will have to create an account (something that comes at no cost), however, it is not correct that you have to store any data in the cloud.
In it’s basic setup, my.openhab is simply giving you a secure channel from outside your LAN to the openhab server on your LAN. With this you can access your sitemaps.
If you want you can install the my.openhab persistence addon and configure persistence of certain items to my.openhab. In this case you will have data stored in the cloud that may be used for e.g. IFTTT recipes, etc.
So, bottom line; by using my.openhab your are still in control of what data (items) you want to expose to the cloud - if any.
I am still a little confused about how the connection will develop with the device. Apologies in advance if it sounds like a real dumb question.
The local ip of openhab is 192.168.1.10. So I can access it by typing this address when connected locally or using internet ip using 188.8.131.52. Now I want to know how will my mobile app know which ip to use to connect. If I try internet ip by default, it will only work when there is internet connectivity. But if I use local ip, I will never access from outside.
I hope I was able to explain the question.
I am not 100% sure but I think the HABdroid application (for Android) is doing something along the following lines:
- Check if the IP address of your client device (Android phone) is on the LAN, i.e. on same network as your openhab server.
- If client is on LAN, try to connect using local IP address of your openhab server.
- If client is not on LAN, try to connect using remote IP address (which in the case of using my.openhab is the URL my.openhab.org).
I thought of the same solution but I was worried this might be too amateur. And secondly there is one small issue
Assuming I assign a static IP to openhab device = 192.168.1.10
Now when I connect to another network (not having openhab device) it also has some random device connected at 192.168.1.10 which isn’t openhab, my logic would consider it as openhab device. How to overcome this? Isn’t there a binding or someother logic which would help me detect if openhab device is connected to this network or not. And if yes what is the local ip assigned to it?
Given that you are using private IP addresses on your LAN (as most people do) you always run the risk of certain problems when you connect to another network that uses the same address range.
It is certainly true that if your logic is very basic, e.g. relying on a simple ping, then you may mistakenly identify an aribtrary host as your openhab device if you connect to a different network.
This only means that your logic must be a bit more complex/intelligent. If you try to open a connection towards port 8080 (that openhab uses) you will be a bit more robust.
If you want to be absolute certain that you are indeed talking to your openhab (and not another persons openhab that is by chance hosted on a machine with the same IP address as yours) then you should probably define security for your openhab and try to access the REST API using your credentials, e.g.
Oh yeh thanks. I kind of like your idea of trying to access REST API as that ensures that indeed the system being talked to is an openhab device. Thanks alot for the assistance. While we are on same topic, I was wondering is there a way to detect on linux (Raspberry) what other devices are connected to network. Because if there was one could use host of each such device and check one by one if it is a openhab device. Then even if the host of openhab isn’t kept static still the things would work out.
Yes, you can use the nmap utility (needs to be installed using apt-get) to do this.
A simple command that should work for “host discovery” is the following:
nmap -sn 192.168.2.0/24
Of course the network range must be tweaked for your setup.
Ok great thanks! You have been very kind sir with all the help. I shall post if I get into trouble trying to implement all this
Glad to help.
Please do! It is always interesting to hear how peoples ideas turn out - regardless of whether it turns out to be a success story or a complete fail.
Ps! I hope you end up in the success story category,
You could also consider openHAB service discovery which uses mDNS and a hostname instead of a static IP address. See…
This interface is currently used by REST bundle to announce available REST interfaces on local network. REST application announces both HTTP and HTTPS connection points depending on their individual availability.
HTTP is announced as
_openhab-server._tcp.local. and it’s name is openHAB
HTTPS is announced as
_openhab-server-ssl._tcp.local. and it’s name is openHAB-ssl
Can any one please explain how to detect eclipse smart home on network