RaspberryConnect / AutoHotspot-Installer

For the RaspberryPi computers. Allows switching between a Raspberry Pi Access Point and Wifi Network connection without a reboot.
GNU General Public License v3.0
67 stars 24 forks source link

Add bridge to ethernet from WiFi Internet connection #4

Closed ThomasFreedman closed 2 years ago

ThomasFreedman commented 2 years ago

It would be great if an option existed to bridge wlan0 <> eth0 regardless of which has Internet.

Half of that works, that is if Internet origin is on eth0 then wlan clients connected to the Pi's hotspot will have an Internet connection (if correct autospot options are used).

However, when the Pi gets Internet through a WiFi connection packets are not routed to eth0. Ideally dhcpcd should also be setup to provide dhcp IP addresses to computers connected to eth0.

There are several use cases for this functionality, for example to provide an Internet connection to a wired home network from a smartphone's hotspot.

ThomasFreedman commented 2 years ago

I also noticed an unusual code structure in the "forceswitch" function of the autohotspot-setup.sh script.

There are 3 functions defined within the braces of forceswitch (createAdHocNetwork_N, createAdHocNetwork_D and get_HS_IP) before the closing body of code and function termination brace.

Those "child" functions are not indented, and it isn't clear if this structure is intended or a mistake in editing. The syntax appears to be acceptable to bash regardless. Just not a typical style of bash script, tho not unusual in object oriented languages such as python or javascript.

RaspberryConnect commented 2 years ago

Hi Thomas Allowing wlan1 internet connection for the Autohotspots is not possible as it will break the switching setup. Though any device connected to wlan0 access point can send and receive data through eth0. If I remember the device at the other end of eth0, in my case a PC, need it's route setup modified to ping the access point devices but that's out of my control. All access point devices can ping each other and the network at eth0.

The Static Access point can have wlan1 or eth0 supplying internet it just needs a mod to the ip tables from eth0 to wlan1 to work. Though again that is one or the other. Setting it up so Internet can be from either is on the to do list when I get round to doing further updates.

Setting the static access point up to supply IP address to eth0 is possible but I would need to research that further. It's not on my to do list but I may consider it.

Thanks for pointing out the forceswitch issue. The child functions are intended. I don't write bash scripts much, other than little command scripts, the scripts here are the most complex ones I have written. It made sense at the time and works. I have indented the child function for now and updated Git. I will revisit that and clean it up . Thanks

ThomasFreedman commented 2 years ago

Glad to contribute, even if in a small way to your project which has helped me in mine.

I'm not a very proficient git user. Although I've used "pull requests" and repo "clones" in the past, it's been years so I'm not familiar with them now. With that said, here is the code for a new GUI front end menu I created for my Pirate-Box project on the Raspberry Pi. You can find all of the code on my repo after I update it later today"

`#!/bin/bash

This is a new front end to the RaspberryConnect.com "Autohotspot" script,

the bulk of which can be found in the "dispatch" script file. All of the
user functionality is preserved, and a new help menu entry is provided
to describe each menu item in detail via a zenity popup dialog.

Additional changes for Pirate Box

The default hotspot SSID name is now PirateBox with a different random
number appended the first time the Pirate Box is booted.
dispatch version PB-0.72.1 (23 Jul 2021), based on autohotspot-setup,
version 0.72 (17 Oct 2020) by RaspberryConnect.com.

go() { cpath="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" if [ "$1" == "HLP" ]; then TITLE='Pirate Box Hotspot Help' zenity --filename="$cpath/ReadMe.txt" --text-info --title="$TITLE" \ --width=600 --height=400 else TITLE='Hotspot Control' xterm -geometry 80x20+150+100 -fa 'Monospace' -fs 11 -title "$TITLE" \ -e "sudo $cpath/dispatch $1" fi }

menu() {

selection menu

title="Pirate Box Autohotspot" error="Invalid option, click 'OK' to choose again" prompt="Pick an option then click OK or Cancel to exit:" options=("Automatic hotspot with Internet for connected devices" "Hotspot for Pirate Box only, no Internet for devices" "Permanent Hotspot with Internet for devices" "Use normal Raspberry Pi wired & wireless networking" "Add/Change WiFi SSID to access the Internet" "Force to a Hotspot or Force to Network if SSID in Range" "Change the Hotspots SSID and Password" "Help for each of these options")

while opt=$(zenity --list --title="$title" --width 450 --height 350 \ --text="$prompt" --column="Available Options:" "${options[@]}"); do selected="" case "$opt" in "${options[0]}" ) selected="AHN";; "${options[1]}" ) selected="AHD";; "${options[2]}" ) selected="SHS";; "${options[3]}" ) selected="REM";; "${options[4]}" ) selected="SSI";; "${options[5]}" ) selected="FOR";; "${options[6]}" ) selected="HSS";; "${options[7]}" ) selected="HLP";; *) continue esac go $selected done }

menu # <--- primary program loop `

RaspberryConnect commented 2 years ago

That look good. It's good to see how my scripts get used in other projects, thanks

ThomasFreedman commented 2 years ago

Glad you liked it. Here's an actual bug for you to fix, and it will be easy.

On line 229 of autohotspot-setup.sh is a mv statement to move config/dhcpcd-default.conf to /etc However there is no such file in the config folder.

Would the standard one shipped with Raspberry Pi OS be appropriate for the default there?

RaspberryConnect commented 2 years ago

Thanks for spotting that, looks like the file has fell out of the Config folder somewhere along the way. Yes the default dhcpcd.conf file will be fine.
The ones for the Autohotspots get modified rather than replaced as they may have user custom config for when the hotspot is not active. The static Hotspot has a single setup so it is suppose to go with the default dhcpcd.conf file.

ThomasFreedman commented 2 years ago

I have a strange problem with WiFi on the new 64 bit Raspberry Pi OS I hope you can offer some insight on.

It has something to do with additional packages I've installed. It does not occur on the fresh OS image. The symptom is that the Pi will not connect via WiFi until after the screen saver times out and blanks the screen. A very weird behavior!

I've logged out, rebooted, restarted networking with systemd - no effect.

I am using another account, not "pi". I've added that account to the netdev group so it can use the networking tool on the right of the taskbar.  Without that the network widget can't update /etc/wpa_supplicant/wpa_supplicant.conf.

The pi scans & finds my router after I turn on WiFi, I enter the passphrase, click OK and /etc/wpa_supplicant/wpa_supplicant.conf reflects that. After that nothing, I've waited a long time and logged in & out etc nothing. ONLY after the screen saver kicks in & blanks chthe screen and I move the mouse or touch the keyboard does it replace the double Xs and connect.

I have installed dnsmasq and hostapd packages + your scripts. but have not configured, initialized or executed any of them. I have not changed or added anything about the screen saver. The behavior is very repeatable and dependable. It was only a fluke that I discovered it (I found it connected the next morning after leaving the Pi on all night, but it wasn't able to connect the night before. When I left it the night before it was NOT connected, when I moved the mouse the next morning it was).

I can't seem to find any info online about the sequence of software events required to establish a WiFi connection on the Pi.

If you have any ideas on what to check or how to troubleshoot this I'm all ears - all suggestions welcome.

Hope you're doing well so far this year!

1) This private E-mail including but not limited to any / all attachment(s), are lawfully protected in any public jurisdiction subject to 1a. 2) Nunc pro tunc "Now for Then" (retroactive): All Rights Reserved (Without Prejudice(2a)), Non Assumpsit(2b), and Without the United States(2c) 1a) Electronic Communications Privacy Act, 18 U.S.C. § 2510-2521 2a) Without Prejudice UCC 1-308, UCC 1-306.6, in other words: All Rights Reserved 2b) Non Assumpsit "Did not undertake" (compulsory contracts) 2c) United States as defined by 26 USC § 7701 2c § 7701.9) Legalese: “The United States government is a foreign corporation with respect to a state" (20 C.J.S. Corporations §1785) 2c § 7701.10) Legalese: "include" in Latin: "expressio unius est exclusio alterius" or "to express or include one thing implies the exclusion of the other." Black's Law Dictionary (8th, 9th ed. 2009)

3) The color of the text above designates political jurisdiction: red-private non-statutory, flesh and blood, man / woman, blue-administrative, admiralty law, corporate jurisdiction. These are also pen ink colors and are significant on legal documents. Underlined text are links to further information.

Sent with ProtonMail Secure Email.

‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐

On Wednesday, July 28th, 2021 at 3:25 PM, RaspberryConnect @.***> wrote:

Thanks for spotting that, looks like the file has fell out of the Config folder somewhere along the way.

Yes the default dhcpcd.conf file will be fine.

The ones for the Autohotspots get modified rather than replaced as they may have user custom config for when the hotspot is not active.

The static Hotspot has a single setup so it is suppose to go with the default dhcpcd.conf file.

You are receiving this because you authored the thread.

Reply to this email directly, view it on GitHub, or unsubscribe.

ThomasFreedman commented 2 years ago

Doh! It occurred  to me after I emailed you to login to a different account to see if the behavior is the same - it's not, normal behavior returns under the pi account.

It has nothing to do with group membership. Whatever it is it rules out the network stack or op sys. So I'll figure it out, no need to respond. Sorry to trouble you.


1) This private E-mail including but not limited to any / all attachment(s), are lawfully protected in any public jurisdiction subject to 1a. 2) Nunc pro tunc "Now for Then" (retroactive): All Rights Reserved (Without Prejudice(2a)), Non Assumpsit(2b), and Without the United States(2c) 1a) Electronic Communications Privacy Act, 18 U.S.C. § 2510-2521 2a) Without Prejudice UCC 1-308, UCC 1-306.6, in other words: All Rights Reserved 2b) Non Assumpsit "Did not undertake" (compulsory contracts) 2c) United States as defined by 26 USC § 7701 2c § 7701.9) Legalese: “The United States government is a foreign corporation with respect to a state" (20 C.J.S. Corporations §1785) 2c § 7701.10) Legalese: "include" in Latin: "expressio unius est exclusio alterius" or "to express or include one thing implies the exclusion of the other." Black's Law Dictionary (8th, 9th ed. 2009)

3) The color of the text above designates political jurisdiction: red-private non-statutory, flesh and blood, man / woman, blue-administrative, admiralty law, corporate jurisdiction. These are also pen ink colors and are significant on legal documents. Underlined text are links to further information.

Sent with ProtonMail Secure Email.

‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐

On Wednesday, July 28th, 2021 at 3:25 PM, RaspberryConnect @.***> wrote:

Thanks for spotting that, looks like the file has fell out of the Config folder somewhere along the way.

Yes the default dhcpcd.conf file will be fine.

The ones for the Autohotspots get modified rather than replaced as they may have user custom config for when the hotspot is not active.

The static Hotspot has a single setup so it is suppose to go with the default dhcpcd.conf file.

You are receiving this because you authored the thread.

Reply to this email directly, view it on GitHub, or unsubscribe.