pihome-shc / pihome

PiHome - Smart Heating, Ventilation and Air Conditioning (HVAC)
http://www.pihome.eu
Other
52 stars 25 forks source link

PiHome AP Mode fix #449

Closed dvdcut closed 3 years ago

dvdcut commented 3 years ago

command for Setting up AP location is wrong and img file have IE as country code but config have GB and this is causing issues.

pihome-shc commented 3 years ago

@twa127 & @sandreialexandru has done huge amount of work on this, not sure why /usr/sbin/ location, may be to cover other Linux distro perhaps, i leave this to them to answer this for you before we can commit this.

twa127 commented 3 years ago

Hi,

I would argue that /usr/sbin is correct

sbin

As IE is used in the system table as part of the initial install, then for consistency it makes sense to leave as IE in the AP Mode setup and let the user change as part of there system local configuration or I guess we could pull the value from the system table.

dvdcut commented 3 years ago

@twa127 my knowledge is limited and i can do as much as google can find :( thank you for explanation. if i dont make these changes then i dont see any wifi access point on drop down, all three changes worked so far, i still can not save wifi settings from gui

twa127 commented 3 years ago

Hi,

I don't do any of my development on an RPi but use either a BeagleBone or Orange Pi, maybe this issue is specific to the RPi, I'll setup an RPi and investigate, I guess you are using the current release of Raspbian

twa127 commented 3 years ago

If I run the commands from either /sbin or /usr/sbin I get the same results, which makes sense as /sbin is a symlink for /usr/sbin

sbin1

dvdcut commented 3 years ago

i dont have orange pi, but after reading your comments on discord about orange pi (Orange Pi Zero Plus 2 H5) performance i m thinking to switch my setup on orange pi.

are you using img file from pihome website? or you have your own?

twa127 commented 3 years ago

I've created some img files for the Banana Pi M2 Zero, Orange Pi Zero Plus 2 H5 and Orange Pi Zero 2 with LAMPS installed, so the 'standard' PiHome setup runs. I've let @pihome-shc have copies but don't know if he's made them available yet. If you want a copy of anything just let me know. By the way the Orange Pi Zero Plus 2 H5 appears to be out of stock at the moment, but this is my preferred option as I'd rather run from eMMC rather than a micro SD card

twa127 commented 3 years ago

Hi,

I've setup an RPi with and installed Autohotspot, with no wifi connection enabled I can connect to the hotspot okay and browse to PiHome at 192.168.0.50, index.php loads and enables selection of a SSID and entry of valid password. After rebooting the RPi connects to the wifi as normal. Using /sbin or /usr/sbin makes no difference. You need to make sure that if you have an entry in the network_settings table for wlan0, that ap_mode is set to 0

dvdcut commented 3 years ago

if you are getting 192.168.0.50 ip address for rpi then you select option 1 during instillation. and i dont have any entry in network_settings, let me re-do the all and i will report back to you

twa127 commented 3 years ago

okay, checked it works the same with an empty network_settings table, the log-on screen enables selection of the WiFi SSID sbin2

dvdcut commented 3 years ago

after entering password does it save wifi settings? are you using your own img or did you download from pihome?

twa127 commented 3 years ago

Hi,

It should update /etc/wpa_supplicant/wpa_supplicant.conf with the selected SSID and entered password.

My RPi img was downloaded but modified for HVAC version, I'll do a re-install from the base img and try again

twa127 commented 3 years ago

Hi,

It appears that the /sbin /usr/sbin configuration is different for Armbian as used on the Orange Pi, so the change to /sbin is needed and will also be okay for the Orange Pi.

There is a second issue with wpa_supplicant.conf not being updated, the attached should address both issues, please give it a try.

index.zip

dvdcut commented 3 years ago

ok your index.zip file worked like charm but i wonder do i still need to make other changes i.e hostapd.conf country_code=GB sudo visudo

www-data ALL=(ALL) NOPASSWD:/sbin/iwlist wlan0 scan
www-data ALL=(ALL) NOPASSWD:/sbin/iwconfig wlan0
www-data ALL=(ALL) NOPASSWD:/sbin/reboot
www-data ALL=(ALL) NOPASSWD:/sbin/ifconfig eth0
www-data ALL=(ALL) NOPASSWD:/bin/mv myfile.tmp /etc/wpa_supplicant/wpa_supplicant.conf

www-data ALL=(ALL) NOPASSWD:/usr/sbin/iwlist wlan0 scan
www-data ALL=(ALL) NOPASSWD:/usr/sbin/iwconfig wlan0
www-data ALL=(ALL) NOPASSWD:/usr/sbin/reboot
www-data ALL=(ALL) NOPASSWD:/usr/bin/mv myfile.tmp /etc/wpa_supplicant/wpa_supplicant.conf
www-data ALL=(ALL) NOPASSWD:/usr/sbin/ifconfig eth0

Change country code:

nano /etc/hostapd/hostapd.conf
country_code=IE

Make Autohotspot Executable chmod +x /var/www/Autohotspot/autohotspot-setup.sh

Install autohotspot

cd /var/www/Autohotspot
sudo ./autohotspot-setup.sh

Modify hostapd service and add Environment=DAEMON_CONF=

nano /lib/systemd/system/hostapd.service
Environment=DAEMON_CONF=/etc/hostapd/hostapd.conf

nano /etc/default/hostapd
DAEMON_CONF="/etc/hostapd/hostapd.conf"
twa127 commented 3 years ago

Hi,

Glad it worked, the other changes are debatable, my thoughts:

The user is going to have to set the country code dependent on their location The extra sudo changes are not really needed as the shell runs them as sudo, also only applicable if autohotspot is installed I just run the shell as bash /var/www/Autohotspot/autohotspot-setup.sh Not sure about the environment variable, not found I needed it would need to change as autohotspot configuration is changed

twa127 commented 3 years ago

Further to the wifi country code setting - the install script checks /etc/wpa_supplicant/wpa_supplicant.conf for a country code setting, it aborts if one is not found or continues using the country code found for the rest of the configuration. Hence the setting in /etc/hostapd/hostapd.conf is repentant on /etc/wpa_supplicant/wpa_supplicant.conf being set correctly by the user.

Bottom line is that /etc/hostapd/hostapd.conf does not need to be changed

dvdcut commented 3 years ago

i installed hostspot from public not from /var/www/ may be this could be the reason, i redo from pihome img and report back today

twa127 commented 3 years ago

A bit more info - the sudoers entries are created automatically in the new MaxAir version by setup.php

dvdcut commented 3 years ago

so that mean sudoers entries are required? sorry couldn't get my hands on to any laptop as kids doing home schooling

twa127 commented 3 years ago

Hi,

Ah lack of resources, hopefully all back to school soon. :-)

Yes they are needed, the current 1.77 img has a file /etc/sudoers.d/pihome, which needs to be changed. If you were building you're own img then you would need to create the file. For the new MaxAir version, where there is currently no pre-built img, I've added the creation of the sudores file to setup.php.

dvdcut commented 3 years ago

during installation which option best to chose 1 or 2,

Permanent Hotspot = permanent hotspot with net access for connected devices

 1 = Install Autohotspot with Internet for Connected Devices
 2 = Install Autohotspot with No Internet for connected devices
 3 = Install a Permanent Hotspot with Internet for connected devices
 4 = Uninstall Autohotspot or Permanent Hotspot
 5 = Add or Change a WiFi network (SSID)
 6 = Autohotspot: Force to a Hotspot or Force to Network if SSID in Range
 7 = Change the Hotspots SSID and Password
 8 = Exit
twa127 commented 3 years ago

Hi

The original idea behind this feature was to provide a way of connecting to the GUI when a fresh install, with no wifi connected, particularly when using the RPi Zero with no Ethernet . The idea was that the user could connect to the HotSpot and configure the wifi connection to the local router, then reboot and connect back using the local wifi connection. If you wanted you can operate with it always in HotSpot mode, this is what the checkbox is for on the initial logon page. Option 1 makes sense if there is also an active ethernet connection, while Option 2 would suit the RPi Zero with only the wifi available.

Hope that makes sense.

dvdcut commented 3 years ago

@twa127 first of big thank you for helping me on this. after spending hours and trying one change at a time, following steps works for me with index.php offered by @twa127

Update the OS sudo apt-get update && sudo apt-get full-upgrade && sudo apt-get clean

Update PiHome and its Database

cd /var/www/
git pull origin
cd MySQL_Database/
php update_db.php

Set the correct permission for PiHome Web

chown -R www-data /var/www
chgrp -R www-data /var/www

Make Autohotspot Executable and install Autohotspot with option 1

chmod +x /var/www/Autohotspot/autohotspot-setup.sh
cd /var/www/Autohotspot
sudo ./autohotspot-setup.sh

for some reason it set to country code to E so it was missing I,

nano /etc/hostapd/hostapd.conf
country_code=IE

one question: i see script create file in /etc/sudoers.d/pihome with following entries, i left them as it is but as we know location is wrong

www-data ALL=(ALL) NOPASSWD:/usr/sbin/iwlist wlan0 scan
www-data ALL=(ALL) NOPASSWD:/usr/sbin/reboot
www-data ALL=(ALL) NOPASSWD:/usr/bin/mv myfile.tmp /etc/wpa_supplicant/wpa_supplicant.conf
www-data ALL=(ALL) NOPASSWD:/usr/sbin/ifconfig eth0

default image also have following entries if you run sudo visudo command, i dont know where which file hold these entries and if we need them or not and if we do need them can they be moved to /etc/sudoers.d/pihome

www-data ALL=/sbin/reboot
www-data ALL=NOPASSWD: /sbin/reboot
www-data ALL=/sbin/shutdown
www-data ALL=NOPASSWD: /sbin/shutdown
www-data ALL=/usr/bin/crontab
www-data ALL=NOPASSWD: /usr/bin/crontab
www-data ALL=(root)NOPASSWD:/usr/bin/crontab
www-data ALL=(ALL) NOPASSWD: ALL
www-data ALL=/usr/bin/timedatectl
www-data ALL=NOPASSWD: /usr/bin/timedatectl

@pihome-shc can you add these changes to default image please i think this will save lots of time for other uses. also image on pihome site is bit old as well and missing updates.

twa127 commented 3 years ago

Glad to be of help.

I think one of the reasons for not updating the PiHome img is that the aim was to move to Version 2 - MaxAir. Although its still at the Beta testing stage, it is now quite stable, I've been running my central heating system with it for the last month, without any issues. If you want to give it a try, you and download the LAMPS img and then follow the installation instructions, you will need to reconfigure to match the new structure.

dvdcut commented 3 years ago

but i think it would be best if we have default image with all this, can you do pull request with your index.php file please

twa127 commented 3 years ago

@dvdcut probably easier if you update your pull request, adding the change I sent you, I think you should remove the change to hostapd.conf and leave it to the individual user to configure as required

pihome-shc commented 3 years ago

Looks like lot of testing happened for hotspot. I was planning to update img file on PiHome site last week but didn’t enough time to do so, i will do update over weekend and add hotspot option as default so users don’t have to do this work. I will do some basic testing myself as well and add them to instructions. I did receive img files from @twa127 but again kids with remote learning takes lots of parents effort and energy. That is in my mind as well.

pihome-shc commented 3 years ago

@twa127 country code is set to IE for img file but once setup is done user will endup with wrong country code, i m thinking how to fix this or make changeable from gui.

twa127 commented 3 years ago

My thinking is that it should be set to GB as that is probably the main user base and I guess the idea is that the img would be supplied as part of the smart thermostat solution, where the img is initially configured in Mode 2, as there would probably be no ethernet. The user would then connect to the HotSpot and access the GUI, where they would configure their local wifi, or decide to leave it as an Access Point, again with no ethernet. 'Expert' users with wifi and ethernet would configure to suit their needs.

dvdcut commented 3 years ago

@twa127 agree with you, i will add your index.php in my pull request.

dvdcut commented 3 years ago

one last thing, i have moved the hotspot script to add-on, i hope this will not break anything.

pihome-shc commented 3 years ago

@dvdcut i m in middle of updating pihome img file for pihome site, i will add these changes. thank you for your effort.