[SOLVED] Hostnames inplace of IP Address is Rules, Services, & Things

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("", "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

2018-11-19 15:22:26.042 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Set Fan': Invalid URI host: null (authority: RA_CT50_Dn)

Any way to get rid of the hardcoded IP addresses?

Edit your /etc/hosts file
Google it before your do anything stupid with it

This is mine:       localhost       home2    openhab    pitv    camera01    pizero     router     milights    printer    largebedroom_radiatorvalve     masterbedroom_hotblanket   sonoff4ch   btrouter

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

@vzorglub thanks for the idea but I don’t think that is addressing the issue I’m referring to.

I have IP addresses assigned dynamically by my router and it acts as a DNS server. I am able to successfully ping RA_CT50_Dn from the server

user@server:~$ ping RA_CT50_Dn
PING RA_CT50_Dn.blahblah.lan ( 56(84) bytes of data.
64 bytes from RA_CT50_Dn.blahblah.lan ( icmp_seq=1 ttl=255 time=1.40 ms

And successfully curl RA_CT50_Dn from the server

user@server:~$ curl http://RA_CT50_Dn/tstat

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.

you may have found a bug

try the following:

val output = sendHttpPostRequest("http://RA_CT50_Dn.blahblah.lan/tstat/fmode", "application/json", '{"fmode":' + receivedCommand + '}')

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.

@Dim & @mhilbush: the fully qualified name didn’t help. Same error (but with the fully qualified name)

2018-11-19 22:13:56.135 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Set Fan': Invalid URI host: null (authority: RA_CT50_Dn.blahblah.lan)

@mhilbush & @vzorglub: I tried adding references to my /etc/hosts file. This didn’t work for RA_CT50_dn

or 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).

Really strange.

The only other difference I see is that your hostname has underscores. Really, this is a stretch, but I’m stumped why it’s not working for you.

Maybe put HttpUtil into debug mode to shed some additional light on what’s happening.

I think it’s in org.eclipse.smarthome.io.net

So in the console

log:set DEBUG org.eclipse.smarthome.io.net

Wikipedia says

While a hostname may not contain other characters, such as the underscore character ( _ ), other DNS names may contain the underscore.


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 + '}')

It worked.

Thanks for your help @mhilbush

Sure thing. I was not aware of the underscore issue either. Especially since it can be used in a domain name, but not a hostname!

Could you please mark the post above as the solution? That way it will be clear when someone else runs into the same issue.