I have a need to obtain WiFi signal strength on a Pi0W.

I have a PHP script and all works via terminal: php /var/www/html/blah.php (I use exec("iwconfig wlan0", $output_lines);)

The script runs as a cron job.

Basically, cron launches curl every 5 minutes to send a ping to another server (this part works). I POST some JSON data which gets processed on the server. This used to be a static .json file. Now I generate my JSON data on the fly and want/need to include some additional data with it.

The command launched by cron:

curl -d "`php /var/www/html/generate_json.php`" -X POST https://myserver/json_logger.php

The JSON data generates fine, but I am having trouble retrieving the result of iwconfig

The funny thing is when I run the php part in a terminal, it gets the data fine (kind of expected). I also checked whoami and I am "pi" (as expected).

When the command is launched by cron, it is also launched by "pi" user; however, as I stated above, the result of iwconfig is blank.

As I understand, this is most likely a permissions issue, but I am not sure exactly what/where to change.

If there is another way to obtain WiFi information, I am open to options.

  • Have you added the www-data user to the groups to allow it to control the WiFi interface? sudo usermod -a -G netdev www-data
    – Dougie
    Apr 12, 2020 at 8:15
  • No, I haven't, but the funny thing is, this morning I found it to be working. No changes since last night when I made a post and it just refused to work (the output array was blank), but this morning it seems fine. Just now I added cat /proc/net/wireless to the script and they both grab the data just fine. Thanks for the comment, I will keep it in mind if I have a similar issue.
    – nurchi
    Apr 12, 2020 at 15:32
  • This week I finally had the time to get back to this project. Turns out, I was wrong. The successful pings that I saw were from when I manually launched the script a few-times in a row, then unplugged the Pi, and some time later looked at the server. @Dougie, as per your device, I've added www-data to the netdev group, but it doesn't seem to change the behaviour. When I run the script it works, when curl does it, I get no output from iwconfig. While it would be a good experience to get this working, all I really need is a WiFi connection info (network SSID, signal strength, etc.).
    – nurchi
    May 9, 2020 at 6:11


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.