pihome icon indicating copy to clipboard operation
pihome copied to clipboard

Button for wifi reset

Open sandreialexandru opened this issue 4 years ago • 56 comments

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?

sandreialexandru avatar Oct 17 '20 12:10 sandreialexandru

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.

pihome-shc avatar Oct 17 '20 14:10 pihome-shc

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

sandreialexandru avatar Oct 18 '20 22:10 sandreialexandru

@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

pihome-shc avatar Oct 19 '20 17:10 pihome-shc

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.

sandreialexandru avatar Oct 19 '20 17:10 sandreialexandru

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

pihome-shc avatar Oct 19 '20 23:10 pihome-shc

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

sandreialexandru avatar Oct 21 '20 11:10 sandreialexandru

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

On 21 Oct 2020, at 12:25, sandreialexandru [email protected] 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.

pihome-shc avatar Oct 21 '20 14:10 pihome-shc

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.

sandreialexandru avatar Oct 21 '20 14:10 sandreialexandru

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 [email protected] 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.

pihome-shc avatar Oct 21 '20 15:10 pihome-shc

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 avatar Oct 21 '20 19:10 sandreialexandru

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

sandreialexandru avatar Oct 25 '20 18:10 sandreialexandru

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

pihome-shc avatar Oct 25 '20 19:10 pihome-shc

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

sandreialexandru avatar Oct 25 '20 19:10 sandreialexandru

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

pihome-shc avatar Oct 25 '20 19:10 pihome-shc

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

sandreialexandru avatar Oct 25 '20 19:10 sandreialexandru

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 [email protected] 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.

pihome-shc avatar Oct 25 '20 20:10 pihome-shc

That would be great! Thank you in advance!

sandreialexandru avatar Oct 25 '20 20:10 sandreialexandru

@sandreialexandru committed update to ESP8266 gateway sketch

pihome-shc avatar Oct 25 '20 20:10 pihome-shc

Thank you! Will download and try.

sandreialexandru avatar Oct 25 '20 20:10 sandreialexandru

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

sandreialexandru avatar Oct 31 '20 12:10 sandreialexandru

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

pihome-shc avatar Oct 31 '20 12:10 pihome-shc

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

sandreialexandru avatar Oct 31 '20 12:10 sandreialexandru

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.

twa127 avatar Nov 07 '20 11:11 twa127

Can we make single install script for all boards ?

pihome-shc avatar Nov 07 '20 14:11 pihome-shc

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 avatar Nov 07 '20 15:11 twa127

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 avatar Nov 07 '20 20:11 twa127

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

autohotspot-setup.zip

twa127 avatar Nov 08 '20 13:11 twa127

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

twa127 avatar Nov 10 '20 13:11 twa127

@twa127 amazing work! Thank you!

sandreialexandru avatar Nov 10 '20 14:11 sandreialexandru

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

dvdcut avatar Nov 10 '20 15:11 dvdcut