Trouble opening local emoncms website

I’m having trouble accessing my local emoncms website. I type “http://emonpi/emoncms/feed/list” into my browser and I see an emncms login screen. So far so good. But when I enter my username and password I see a pink box appear underneath that says “false” :frowning: Not a very helpful UI but I assume it means there’s some problem. So I looked in /var/log/emoncms/apache2-error.log and I see

PHP Warning: file_get_contents(/etc/wpa_supplicant/wpa_supplicant.conf): Failed to open stream: Permission denied in /var/www/emoncms/Modules/setup/setup_model.php on line 24

So I looked at the file and see it is

-rw------- 1 root root 144 Nov 10 11:47 wpa_supplicant.conf

and when I check that seems to be normal.

I don’t pretend to understand why setup is interested in the file and especially not why it is interested in the state of the wi-fi for a wired ethernet connection?, but so be it. But presumably the code is running as www-data, hence the problem.

I have no idea how the machine got to this state, nor the best way to repair it? Help, please!

This problem seems to be connected somehow with the feature described in emonPi Network Setup Wizard - Blog | OpenEnergyMonitor by @glyn.hudson but quite why it should be trying to set up the wireless network when I try to log in now I have no idea! The system has been running, including its wireless subsystem, quite happily since last Nov.

I don’t remember now exactly how I set up the system when I got the new SD card with the latest emoncms on it. But I don’t remember any of the screens in that blog article, so I expect I did it in the regular pi way, whatever that is. The system has a wired ethernet connection and also a wireless interface.

edit to add: I believe this problem is what is stopping my emoncms talking to my new Home Assistant system, so I’d really appreciate some help in figuring out what is going on so I can fix it.

I’ve been doing some more poking and it appears that the software on the SD card doesn’t match that in the documentation, so I’m stuck. Is anybody else aware of any issues/differences/changes in this area?

Also - is there any way to change the tags I’ve assigned to this thread?

Hello @djh

Which emonSD image version are you running?

This error can usually be fixed with:

sudo chmod 666 /etc/wpa_supplicant/wpa_supplicant.conf

(Provides read and write access to all users - including www-data)

The setup module accesses this file directly to check if a WiFi network has been configured and as a result if it should show the WiFi setup wizard before showing the local emoncms login.

Note that in the latest image emonSD-01Feb24 onwards the networking/wifi implementation has changed to use nmcli rather than accessing wpa_supplicant directly.

How do I know? Admin says “Emoncms Version low-write 11.3.22” if that helps. I got it from the shop back-end of last year.

Yes, but AIUI its permissions are normally rw root-only since it includes the network password in plaintext!

OK, but something in the logic appears to be wrong. I looked at the in the setup directory and it has stuff about adding www-data to sudoers to access the file, but then it blows it all by saying:

Install Emoncms module

ln -s /home/pi/emonpi/emoncms-setup /var/www/emoncms/Modules/setup

but there is no /home/pi/emonpi directory in this image :frowning:

Hence my posting questions about what has gone wrong.

I can’t help thinking there must be a better way to establish (a) whether it is first boot at all and (b) whether there is a wifi network.

Fow example why not just run iw dev or iwconfig to see if there’s a wifi network?

Especially when it’s HA requesting some data and not a user at a screen where they could do anything sensible! :frowning:

Does the above chmod command fix the issue for you?

Like I said latest image implements this differently, it does not use wpa_supplicant at all. Perhaps it would be worth upgrading?

I’m not comfortable with compromising the security of my Pi just to fix this problem in emoncms.

Why is this setup code running at all months after the system was first started?

I’ve been poking about some more and have eventually got the Home Assistant emoncms integration to work (thanks for writing it, Brian :slight_smile: ). I lost the will to live along the way, but hey ho.

So I’m still no closer to understanding why setup code that is supposed to run on first use is still being run months later, but I’ve discovered on the login screen that as well as the login dialog box there’s a little button up on the top right of the screen and if I click that it just logs me in straight away wihout asking for a password, so I’m a happy bunny for human access.

And the error message that was being given to HA changed from the setup failure to an 401 permissions error, for reasons I don’t understand, and after a lot of faffing around I found that the Inputs API help page was lying to me and only showing me part of the APIKEYs (I think it’s something to do with zooming the firefox screen but I’m not sure). Once I discovered what the full APIKEYs were and put them into HA everything started working.

I don’t understand the bizarre CSS formatting of the grey boxes showing the APIKEYs. Putting a box sized in pixels around text seems weird to me, and putting a no entry sign cursor over an area where you explicitly expect people to be trying to copy the text seems weird, and assigning a text string value to a boolean attribute like readonly seems weird, and as I say, I lost the will to live.