How to display the openhab wifi signal as item in sitemap?

  • Platform information:
    • Hardware: Raspberry Pi 3 b+
    • OS: openhab 2.4
      I want to display wifi signal as an item in the sitemap
      thanks

Could you specify this a little bit more? Wifi Signal of which device? Is the device already connected to openHAB? …

Thanks , I mean the openhab itself . The wifi on the same device’s signal

So you connected the openHAB machine using Wifi. From my point of view not a good solution, but anyway.

If you are using linux there are some commands to get signal levels. The output could be processed with a script.

And I believe I have seen them mentioned on this forum but I am too lazy to search to find the thread for somebody else.

So you connected the openHAB machine using Wifi. From my point of view not a good solution, but anyway.

but very interesting :slight_smile:
i did not dare doing this and i have something like 3 running at my house
i have a RPI that i just dont want to run a cable to ,

can you say do you have any issues because its wifi ?

If they use 5 GHz Wi-Fi (not the non-existent wifi) there should be no issues, assuming adequate signal

I’ll give you a starting point, try to issue this command on your raspberry:

If you are connected this should give you a line with the signal strength

sudo iwconfig wlan0 | grep -i --color signal

If you want to scan for what it’s around :

sudo iwlist wlan0 scan | egrep "Cell|ESSID|Signal|Rates"

You need to manipulate the output to match your goal.

1 Like

here what I did but still get nothing

my.things

Thing exec:command:chekWifiSignal [ command="iwconfig wlan0 | grep -i --color 'signal level='", autorun=true ]

my.items

String WifiSignal "Wifi Signal [%s] dBm" <network>  {channel="exec:command:chekWifiSignal:output"}

sitemap

Text item=WifiSignal

Sorry I don’t use files for things and items so I can’t help…surely for this purpose you can remove the --color parameter, but surely it’s not the problem.

With the exec binding usually the main problem is permission by openhab user to run the command.

Another thing to try to avoid some path related issue is to put the full path of the command, in this case: /sbin/iwconfig

I would first check that the user openhab can run that command

2 Likes

Thanks
I getting an error now says:

iwconfig: unknown command "|"

rules

var String results = executeCommandLine("/sbin/iwconfig wlan0 | grep -i 'signal level='", 5000)
    logInfo("executeCommandLine", results)

I’ve never used the executeCommandLine
Usually I create a script file and use the exec binding.
Anyway from the docs it says:

Note: The commandLine variable often has to use a special format where @@ needs to be used in place of spaces. For example the bash command touch somefile will have to be written as touch@@somefile

Try to put @@ instead of every space.

1 Like

still getting : unknown command “|” error

things

Thing exec:command:chekWifiSignal [ command="/sbin/iwconfig wlan0@@|@@grep@@-i@@'signal level='", autorun=true ]

thanks for help and being patient
now i’m getting

iwconfig: unknown command "-i"

Before you were using a rule with executeCommandLine, now a thing definition, please do not change the way you are issueing the command, otherwise we cannot find the right string for the right way.

As it seems we are a bit stuck…I would suggest to create a script file…this way you can call it without having spaces or anything that could cause problem.

Create a file with .sh extension let’s say wifi_signal.sh and place it in a folder accessible by openhab let’s say /etc/openhab2/scripts

Inside the file copy this text:

#!/bin/sh

/sbin/iwconfig wlan0 | grep -i signal

Then run theese commands ( add the execute permission to everyone and change the owner of the file to openhab user) :

chmod a+x wifi_signal.sh
chown openhab wifi_signal.sh

Now you can use the full path as the command:

command="/etc/openhab2/scripts/wifi_signal.sh"

And like John Lennon said : “Let’s hope it’s a good one” :grimacing:

1 Like