I’m fairly new to OpenHAB and have copied most of my Radio Thermostat CT50 code from others. That being said I’ve noticed some hardcoded IP addresses in a number of places, particularly in Rules, Services, and Things.
I’ve been unsuccessful in my attempts to replace these IP addresses with Hostnames. For instance, in my Rules file I have a link that looks like this
val output = sendHttpPostRequest("http://172.27.4.2/tstat/fmode", "application/json", '{"fmode":' + receivedCommand + '}')
I’d rather it look something like this
val output = sendHttpPostRequest("http://RA_CT50_Dn/tstat/fmode", "application/json", '{"fmode":' + receivedCommand + '}')
However, doing that throws an error in /var/log/openhab2/openhab.log
However the Sitemap doesn’t work and the log shows the error I listed earlier when I replace the IP address with the hostname in my Rules file. So I think the issue lies within OpenHAB (or the way I’m coding things within OpenHAB) and not on the greater Linux Server.
I’m using local hosts in my sendHttpPostRequest calls, and they work fine. For example:
val String response = sendHttpGetRequest("http://webswitch.my.domain.com/state.xml?relay1State=2")
The only difference I see is that I’m using fully qualified names (host.my.domain.com), not simple host names. I don’t know if your setup allows you the ability to use a fully qualified name or not, but that might be worth a try.
I also would suggest trying @vzorglub’s suggestion as a way to demonstrate that it will work using a locally defined host.
@mhilbush & @vzorglub: I tried adding references to my /etc/hosts file. This didn’t work for
172.27.4.2 RA_CT50_dn
or
172.27.4.2 RA_CT50_dn.blahblah.lan
Same errors (with our without the .blahblah.lan) as before.
I wonder why your systems can operate off of hostnames and mine can’t (even though the underlying Linux understands the hostnames and other services like ping and curl can).
You win the prize! That was it. I never knew of the restriction to a-z, A-Z, 0-9, and - (minus sign). After updating the hostnames on the router and changing the rule to
val output = sendHttpPostRequest("http://RA-CT50-Dn/tstat/fmode", "application/json", '{"fmode":' + receivedCommand + '}')