pihome-shc / pihome

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

Button for wifi reset #417

Open sandreialexandru opened 3 years ago

sandreialexandru commented 3 years ago

I was thinking about adding a button to the RPi GPIO wich would put it into access point mode for the configuration of the home newtwork(reset button). Steps:

  1. Python script to put Raspberry Pi into access point mode when button is pushed so PiHOME settings cand be changed.
  2. Web UI to update SSID and password in wpa_supplicant.conf (maybe rewrite it completely) and restart the RPi. This is useful when router network settings are changed.

I have an idea about the python script but the web UI is php and not my area of expertise. We would need hostapd and the ISC DHCPD server. What do you think?

pihome-shc commented 3 years ago

brilliant idea, i was thinking something like if rpi not connected to wifi or network then make it access pint automatically but button would be better option so gives user control over this.

sandreialexandru commented 3 years ago

I was thinking of using hostapd and the ISC DHCPD server. Preconfigured etc/hostapd/hostapd.conf

subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.50 192.168.1.60;
option broadcast-address 192.168.1.255;
option routers 192.168.1.100;
default-lease-time 600;
max-lease-time 7200;
option domain-name “pihome.local”;
option domain-name-servers 8.8.8.8, 8.8.4.4;
}

The script reads like this: Button attached to physical pin 5 on the RaspberryPi is pressed for 10 seconds. The network configuration is changed and the Pi gets into access point mode. Connecting to the access point and going to the preconfigured domain name (pihome.local) we can access the web interface and set the SSID and password. A reboot is needed and the Pi should connect to wifi. This method needs some testing.

WiFi_script.zip

pihome-shc commented 3 years ago

@sandreialexandru once again great work, when i press the button for 10 seconds rpi becomes as access point, thinking out loud, anyway to we can setup simple web portal or simple webpage and ask user to enter wifi details and save and reboot rpi

sandreialexandru commented 3 years ago

I'm still working on finding a solution to this. Current kernel has issues with wifi driver for acces point and hostapd does not start. If we succeed to turn Pi into access point there would not be the need for a web portal because we could access apache web server wich runs PiHOME. A settings section could rewrite the /etc/wpa_supplicant.conf and reboot the Pi.

pihome-shc commented 3 years ago

@sandreialexandru have look at raspap-webgui maybe you can find solution how they are doing this.

sandreialexandru commented 3 years ago

After many searches and almost giving up, I have found a solution to our problem here

Steps:

  1. I never got it working without doing rpi-update in the console, so do that
  2. curl "https://www.raspberryconnect.com/images/hsinstaller/AutoHotspot-Setup.tar.gz" -o AutoHotspot-Setup.tar.gz
  3. tar -xzvf AutoHotspot-Setup.tar.gz
  4. cd Autohotspot
  5. sudo ./autohotspot-setup.sh

Stopping here works fine, but I have gone a little further. I thought it would be nice to have the name of the hotspot "PiHOME" with "pihome" as the password so I changed those. The script verifies an md5 for the files so I have eliminated that. The rest remains the same.

After the hotspot is up and we are connected we can navigate to 10.0.0.5 and login into PiHOME

The script runs at every boot and creates a hotspot when no credentials are found for a wifi network in range. If we delete the file /etc/systemd/system/autohotspot.service the script won't start at every boot and we can call it with a button and python.(script bellow)

WiFi_button_script.zip

To install the modified version, copy the archive bellow to the root directory follow steps 3, 4, 5. When asked I have chosen option 2 Install Autohotspot with No Internet for connected devices Autohotspot.tar.gz

pihome-shc commented 3 years ago

Is this compatible with other sbc? i.e orange pi etc?

On 21 Oct 2020, at 12:25, sandreialexandru notifications@github.com wrote:

After many searches and almost giving up, I have found a solution to our problem here

Steps:

I never got it working without doing rpi-update in the console, so do that curl "https://www.raspberryconnect.com/images/hsinstaller/AutoHotspot-Setup.tar.gz" -o AutoHotspot-Setup.tar.gz tar -xzvf AutoHotspot-Setup.tar.gz cd Autohotspot sudo ./autohotspot-setup.sh Stopping here works fine, but I have gone a little further. I thought it would be nice to have the name of the hotspot "PiHOME" with "pihome" as the password so I changed those. The script verifies an md5 for the files so I have eliminated that. The rest remains the same.

After the hotspot is up and we are connected we can navigate to 10.0.0.5 and login into PiHOME

The script runs at every boot and creates a hotspot when no credentials are found for a wifi network in range. If we delete the file /etc/systemd/system/autohotspot.service the script won't start at every boot and we can call it with a button and python.(script bellow)

WiFi_button_script.zip

To install the modified version, copy the archive bellow to the root directory follow steps 3, 4, 5. When asked I have chosen option 2 Install Autohotspot with No Internet for connected devices Autohotspot.tar.gz

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

sandreialexandru commented 3 years ago

I have tested it only on RPi 3B+ and RPi Zero W. I can't say for sure, because I have no any other sbc to test on, but I believe it should work as long as the wifi chip is capable of "listening" mode.

pihome-shc commented 3 years ago

I m waiting for orange pi delivery any day, once i have it i”ll give it a try, thank you for working on this.

On 21 Oct 2020, at 15:52, sandreialexandru notifications@github.com wrote:

I have tested it only on RPi 3B+ and RPi Zero W. I can't say for sure, because I have no any other sbc to test on, but I believe it should work as long as the wifi chip is capable of "listening" mode.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

sandreialexandru commented 3 years ago

Response from the creator of the script: This installer is set to only work on Raspberry PI OS (Raspbian) specifically. As Linux uses different network managers I can't guarantee it will work on other setup as it required dhcpcd.

I see Orange Pi has Debian as a listed OS. If that version is using dhcpcd as the network manger instead of dhcp or other network manager then the script will most likely work. The file /etc/network/interfaces must not be used with this as it will conflict. Lots of older guides online will use this file for network config.

you can check with sudo systemctl status dhcpcd

if it returns with Active: active (running) then it probably work if you follow the manual guides. I would be interested to know if you do try it.

I will look at other OS at a future point and see what needs be modified.

sandreialexandru commented 3 years ago

Speaking of wifi reset, has anyone managed lately to get a fallback access point for the gateway?

pihome-shc commented 3 years ago

no i haven't, still waiting for orange pi delivery,

sandreialexandru commented 3 years ago

Sorry! I meant the WiFi gateway, not serial gateway.

pihome-shc commented 3 years ago

Yes i have WiFi gateway at home and works great, why you asking?

sandreialexandru commented 3 years ago

I have recently tried the Double Reset Detector library and the WiFiManager library, but none of them seem to work. I want to get an access point fallback for the gateway and not have to re-flash the NodeMCU for every SSID

pihome-shc commented 3 years ago

I have different sketch that i m using with with custom wifimanager library, if you want i can share with you, including library, it has its web interface with some stats and fall back to access point when wifi not available.

On 25 Oct 2020, at 19:58, sandreialexandru notifications@github.com wrote:

I have recently tried the Double Reset Detector library and the WiFiManager library, but none of them seem to work. I want to get an access point fallback for the gateway and not have to re-flash the NodeMCU for every SSID

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

sandreialexandru commented 3 years ago

That would be great! Thank you in advance!

pihome-shc commented 3 years ago

@sandreialexandru committed update to ESP8266 gateway sketch

sandreialexandru commented 3 years ago

Thank you! Will download and try.

sandreialexandru commented 3 years ago

I can't get this to work because wifi_ssid and wifi_password are not defined

pihome-shc commented 3 years ago

did you move wifimanager library to your library folder (i placed it in same folder)

sandreialexandru commented 3 years ago

Yes, I've replaced it with the one that you gave me

twa127 commented 3 years ago

Hi,

I've tried the autohotspot script on a Banana Pi M2 Zero and after a few tweeks got it to work, the main problem was that Armbian uses NetworkManager rather than wpasupplicant, but this was no problem to re-configure, also had to install dhcpcd, and modify the installer script.

I see this being useful when setting-up from an img file where a wired connection is not available, if building from scratch then you would have already sorted out the network connections.

In the img file case wifi will not be configured and the system will default to a hot-spot and the user can connect to the GUI to configure the wifi and reboot.

pihome-shc commented 3 years ago

Can we make single install script for all boards ?

twa127 commented 3 years ago

I guess so, will have a look.

By the way there is a bug in the code - in file /config/hostapd the line DAEMON_CONF="/etc/hostapd/hostapd.config" should read DAEMON_CONF="/etc/hostapd/hostapd.conf"

twa127 commented 3 years ago

Hi,

Patched version which will install on Raspbian or Armbian, fixed /config/hostapd and recalculated md5 checksums

Will run as AP if no wifi credentials have been set

Autohotspot.zip

twa127 commented 3 years ago

An update to fix a couple of Armbian issues, the SSID is PiHomeHotspot and the password is 1234567890

autohotspot-setup.zip

twa127 commented 3 years ago

Hi,

I think this is now working, if not connected to your local wifi network it will startup as a hotspot called PiHome, the IP address will be either 192.168.50.5 or 10.0.0.5, depending if you chose option 1 or 2 in the setup, the password is 1234567890

You can connect with a browser and if in hotspot mode it will enable you to select a SSID and enter the password and then Set and Reboot into connected mode, with the usual login page

Attached the latest setup package and new index.php, please re-run autohotspot-setup.sh as it now adds sudo access for the wifi configuration

autohotspot-setup.zip index.zip IMG_0140

sandreialexandru commented 3 years ago

@twa127 amazing work! Thank you!

dvdcut commented 3 years ago

that is really amazing work, one question though, what if my raspberry pi connected to wired connection?

twa127 commented 3 years ago

could be an issue if wifi is not available, wired connection gets you to the wifi connect index page and if you can set wifi then all is okay, but if you don't have access to a wifi connection, then you can't get to the login index page. I'll add a checkbox to enable wired only access

aszumski commented 3 years ago

Hi Guys this will be working on button only or automatically. Cause for example my setup is wired ethernet to home network/internet and wifi access point on pi for wireless mysensors gateway and sonoff switches in the future. I like to keep sensors independent from my home network.

pihome-shc commented 3 years ago

First of all great work @twa127, I think adding option for button to trigger ap mode would be very good addition, but we have to make it to check wird connection or give user option in screen to check box which will ignore wifi setup which might not be a good option, perhaps login screen option to setup wireless settings?

twa127 commented 3 years ago

I see this as a initial set-up mechanism, so don't see the need for a button. I've now added a check for an ethernet connection and if found the normal login page is displayed, if wifi is not configured then the wifi operates as an AP (added another line to /etc/sudoers.d/pihome). If you want to configure the wifi, then just boot without the ethernet cable or refresh the login page with the cable unplugged.

index.zip autohotspot-setup.zip

sandreialexandru commented 3 years ago

The wifi button posted earlier worked for me. The only thing to take into consideration is the fact that one of the GPIOs would be occupied for the button, which means that the script for board detection would have to be modified.

twa127 commented 3 years ago

Forgot to include the amended language file

en.zip

dvdcut commented 3 years ago

my 2cent: once wifi is connected then you dont need button to trigger ap mode, simply disconnect wire or power off your wifi router to make it to ap mode (i haven't tested this scenario) but i think it should work.

twa127 commented 3 years ago

yes definitely does work and that's my preferred option.

The only thing this does not allow is the situation where you want to permanently access PiHome as an AP ie connect to it as an AP and login to PiHome GUI, but personally I don't see why you would want to use it like this.

aszumski commented 3 years ago

My pihome is currently in manually setup AP mode used for wifi gateway independent from my home wifi network with wired connection to home network. I don't want to mix my home network and control network. So there are people with permanent AP setups :)

pihome-shc commented 3 years ago

I know one user who has setup like this, but majority users would be happy to have setup in ap mode to setup WiFi,

twa127 commented 3 years ago

Added an option to the AP mode login screen to enable AP mode working. Can be de-selected from the Network Settings GUI. Note - a new field has been added to the network_settings table. If AP Mode tickbox is ticked then you do not need to enter a SSID or Password.

pihome-shc commented 3 years ago

@twa127 is there any conflict between #432 and /cron/check_wifi.sh

twa127 commented 3 years ago

Sorry can't test this on my bpi m2 zero, but I would have thought it makes no sense to be running check_wifi.sh if you were operating in AP mode and so not connected to a router

pihome-shc commented 3 years ago

i have rpi b+ and usb WiFi, once every while it decide to disconnect WiFi network and stay disconnected. so option was to power off and on rpi or have this script checking WiFi connection. i think it time for me to upgrade my rpi

twa127 commented 3 years ago

Thinking a bit more, the answer is no, check_wifi.sh is not compatible with #432 as it uses ifup and ifdown which require the use of entries in /etc/network/interfaces and these entries were removed by the autohotspot installer. I suggest a re-think of the code for check_wifi.sh and/or reboot_wifi.sh so that they do not use ifup and ifdown

twa127 commented 3 years ago

I think swapping ifup wlan0 to be ifconfig wlan0 up and ifdown to be ifconfig wlan0 down will fix the issue

twa127 commented 3 years ago

Looking at the current configuration, crontab is not using check_wifi.sh but is using reboot_wifi.sh. reboot_wifi.sh should be compatible with #432 as it uses 'ip link set wlan0 down' and 'ip link set wlan0 up' to toggle the wireless interface.

pihome-shc commented 3 years ago

yes you are right, reboot_wifi.sh is in use

*/2 * * * * sh /var/www/cron/reboot_wifi.sh >/dev/null 2>&1

pihome-shc commented 3 years ago

i did one test on rpi 4 4gb, i can connect to PiHomeHotspot but in safari i tried 192.168.50.5 (option 1 during installation) but can not open page PiHome page is there anything else i have to do?

twa127 commented 3 years ago

Not tried it on a RPi but both BPi and OPi worked fine with option 1, opened in both Edge and Safari. If you do ifconfig/ipconfig on the client are you getting a valid ip address with a gateway of 192.168.50.5 ?