Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Button for wifi reset #417

Open
sandreialexandru opened this issue Oct 17, 2020 · 56 comments
Open

Button for wifi reset #417

sandreialexandru opened this issue Oct 17, 2020 · 56 comments

Comments

@sandreialexandru
Copy link
Contributor

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
Copy link
Owner

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
Copy link
Contributor Author

sandreialexandru commented Oct 18, 2020

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
Copy link
Owner

@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
Copy link
Contributor Author

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
Copy link
Owner

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

@sandreialexandru
Copy link
Contributor Author

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
Copy link
Owner

pihome-shc commented Oct 21, 2020 via email

@sandreialexandru
Copy link
Contributor Author

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
Copy link
Owner

pihome-shc commented Oct 21, 2020 via email

@sandreialexandru
Copy link
Contributor Author

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
Copy link
Contributor Author

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

@pihome-shc
Copy link
Owner

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

@sandreialexandru
Copy link
Contributor Author

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

@pihome-shc
Copy link
Owner

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

@sandreialexandru
Copy link
Contributor Author

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
Copy link
Owner

pihome-shc commented Oct 25, 2020 via email

@sandreialexandru
Copy link
Contributor Author

That would be great! Thank you in advance!

@pihome-shc
Copy link
Owner

@sandreialexandru committed update to ESP8266 gateway sketch

@sandreialexandru
Copy link
Contributor Author

Thank you! Will download and try.

@sandreialexandru
Copy link
Contributor Author

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

@pihome-shc
Copy link
Owner

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

@sandreialexandru
Copy link
Contributor Author

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

@twa127
Copy link
Contributor

twa127 commented Nov 7, 2020

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
Copy link
Owner

Can we make single install script for all boards ?

@twa127
Copy link
Contributor

twa127 commented Nov 7, 2020

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
Copy link
Contributor

twa127 commented Nov 7, 2020

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
Copy link
Contributor

twa127 commented Nov 8, 2020

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

autohotspot-setup.zip

@twa127
Copy link
Contributor

twa127 commented Nov 10, 2020

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
Copy link
Contributor Author

@twa127 amazing work! Thank you!

@aszumski
Copy link
Contributor

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
Copy link
Owner

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
Copy link
Contributor

twa127 commented Nov 10, 2020

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
Copy link
Contributor Author

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
Copy link
Contributor

twa127 commented Nov 10, 2020

Forgot to include the amended language file

en.zip

@dvdcut
Copy link
Contributor

dvdcut commented Nov 11, 2020

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
Copy link
Contributor

twa127 commented Nov 11, 2020

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
Copy link
Contributor

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
Copy link
Owner

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
Copy link
Contributor

twa127 commented Nov 14, 2020

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
Copy link
Owner

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

@twa127
Copy link
Contributor

twa127 commented Nov 14, 2020

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
Copy link
Owner

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
Copy link
Contributor

twa127 commented Nov 14, 2020

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
Copy link
Contributor

twa127 commented Nov 14, 2020

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

@twa127
Copy link
Contributor

twa127 commented Nov 14, 2020

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
Copy link
Owner

yes you are right, reboot_wifi.sh is in use

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

@pihome-shc
Copy link
Owner

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
Copy link
Contributor

twa127 commented Nov 15, 2020

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 ?

@pihome-shc
Copy link
Owner

yes my mobile had correct range of ip address with gateway 192.168.50.5

@twa127
Copy link
Contributor

twa127 commented Nov 15, 2020

is the hostapd service running eg

ps -aux | grep hostapd
root 1481 0.0 0.3 4644 1628 ? Ss 19:12 0:00 /usr/sbin/hostapd -B -P /run/hostapd.pid /etc/hostapd/hostapd.conf
root 5567 0.0 0.1 6728 536 pts/1 S+ 21:09 0:00 grep hostapd

@twa127
Copy link
Contributor

twa127 commented Nov 15, 2020

also found opening with safari on my phone was slow but if I waited it did open after about 60 seconds

@pihome-shc
Copy link
Owner

on iphone it took little longer to connect to ap as well and i dont know how long i waited before giving up, let me try again later and i'll update here.

@pihome-shc
Copy link
Owner

@twa127 today i installed PiHome on CentOS 7 on HP T620 Thin Client, i couldnt get pass the WiFi AP setup, so i had to make small change in index.php and set $eth_connected = 1; after line 62 to get passed this,
i m thinking should we put something there to ignore ap mode all time?

@twa127
Copy link
Contributor

twa127 commented Nov 20, 2020

That's pushing the envelope :-) I've added a check for if the autohotspot service has been installed

pihome-shc added a commit that referenced this issue Nov 20, 2020
Ignore AP mode in index.php if autohotspot.service has not been installed, #417
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants