Use Raspberry Pi to solve the problem of insufficient mobile Wi-Fi connection

Overview

By connecting Raspberry Pi as a Wi-Fi repeater to mobile Wi-Fi, which has a limited number of connections, and adding a new Wi-Fi network, the shortage of Wi-Fi connections in the home was solved. During the setting, I encountered a problem that the fixed IP could not be set, so I will show you the solution.

Introduction

Recently, I changed my home internet environment to mobile Wi-Fi. The communication speed is also reasonable, and you can watch Amazon Video comfortably. However, the maximum number of connections is 5 and it is small. There is no problem if you only have a smartphone and a PC, but it is not enough if you connect Google Home etc. It's a waste to buy a new Wi-Fi repeater. It takes some time to select a repeater. Additional Wi-Fi connections are available for Google Home, Nature Remo, and printers. The communication distance may be delivered in one room. As for the communication speed, you can listen to music. Considering the location and communication speed when using Raspberry Pi wirelessly, it seems that there is no problem.

So, I tried to make Raspberry Pi a Wi-Fi repeater. (Here, "repeater" is described as adding a new wireless network, not expanding the communication distance within the same network.)

environment

Raspberry Pi 4 Model B Raspbian Buster

Wi-Fi dongle PLANEX GW-USNano2

Investigation

Earlier, when I tried the same thing, it failed, so I checked multiple sites to understand to some extent.

Raspberry Pi 3 + USB WiFi dongle, Wi-Fi repeater --Qiita [Note] Wi-Fi access point router on Raspberry Pi 3-Qiita Capture packets by relaying wireless LAN with mitmproxy on Raspberry Pi | Maple Rice's Blog How to make a WiFi local server using Raspberry Pi-Qiita Wireless LAN access point with Raspberry Pi – Greenleaf Turn Raspberry Pi into a WiFi access point! [Making WiFi of Raspberry Pi 3 Model B into a wireless LAN access point and making it a WiFi router hostapd + bridge-utils (How to set up the communication environment by using the WiFi built into Raspberry Pi 3 as a wireless LAN access point)](http: / /www.neko.ne.jp/~freewing/raspberry_pi/raspberry_pi_3_wifi_wireless_access_point/) Making WiFi of Raspberry Pi 3 into a wireless LAN access point with ad blocking function hostapd + dnsmasq edition (How to make WiFi built into Raspberry Pi 3 a high-performance router with ad blocking function (with ad + fraud + adult blocking function) ) Access Point | goozenlab

There is a lot of information, but old information is also confused. You also need to search for the Raspbian version (Buster). At first glance, the functions introduced in each article are the following four points.

--hostapd access point --isc-dhcp-server DHCP server --dnsmasq DNS server and DHCP server --bridge-utils Bridge settings

This time, there is a limit to the number of original mobile Wi-Fi connections, so that routing function cannot be used. In order to increase the number of connections, I decided to create a new network with Raspberry Pi and route it. That is, it does not bridge. Also, I feel that Google Home needed DHCP, so DHCP is needed. Also, I don't feel that DNS is particularly necessary.

The required functions were judged to be the following two points.

When I put Buster in and searched again, I found someone who was already doing what they were trying to do. Thanks. I decided to use isc-dhcp-server instead of dnsmasq, referring to the following site.

Build hawksnowlog: RaspberryPi as an extended access point for mobile routers

I also referred to the following site. Thanks. Turn Raspberry Pi into a WiFi access point!

What i did

Check the Wi-Fi dongle

First, make sure your Wi-Fi dongle is enabled. I was able to confirm that I was recognizing it just by pointing it.

pi@raspberrypi:~ $ ifconfig
eth0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
...
lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
...
wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500、
...
wlan1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
...

wlan1 (USB dongle) connection settings

Only wlan1 is set to automatically connect to mobile Wi-Fi. If I didn't set anything, both were connected to mobile Wi-Fi that I had already connected to. I set it referring to here. What I was addicted to when inserting two Wi-Fi adapters on Raspberry Pi-Qiita

Installation and configuration of hostapd

From this section, it was executed with reference to the following site. I wanted to switch wlan0 and wlan1 and set them, so I paid attention to that and executed the same. Build hawksnowlog: RaspberryPi as an extended access point for mobile routers

I did it as instructed. No error was displayed.

Routing settings

I did it as instructed. No error was displayed.

dhcp server installation and configuration

Installation and settings are completed without any errors.

An error occurred when starting up the DHCP server. It is shown below.

$ sudo systemctl start isc-dhcp-server
Job for isc-dhcp-server.service failed. See 'systemctl status isc-dhcp-server.service' and 'journalctl -xn' for details

The command was executed according to the message. When I ran systemctl status isc-dhcp-server.service, I didn't notice anything in particular.

Next, when I executed the following command, an error was displayed.

$ journalctl -xn
...
no subnet declaration for wlan0 (no ipv4 addresses)
...

I reviewed the settings, but it didn't improve. I checked some sites here, but couldn't get any useful information. ʻIfconfig, I remembered that the IP was not assigned, and assumed that this was a problem, and confirmed some. I was not confident about how to set the fixed IP and how to write the settings of the two wlans separately, so I reviewed the settings while checking some sites, but I could not solve it. I decided to change the IP specification method and check it, so I wrote the fixed IP setting in / etc / network / interface instead of /etc/dhcpcd.conf and restarted. When I reconfirmed with ʻifconfig, the IP was assigned.

In that state, again

sudo systemctl start isc-dhcp-server

Then, I was able to execute it without any error. I was able to connect to the Internet by connecting to the specified SSID from another terminal. Even after restarting, I was able to confirm that I could connect from another terminal. It was not necessary to execute the above command when restarting.

It seems that it is not recommended to write a fixed IP setting to interface from Raspbian a few years ago, so it is not a very clean solution, but I was able to confirm the operation, so I will operate it for the time being. Also, since the link is attached to interfaces.d, it may be better to write it in that directory, but I did not find the merit of taking time, so I forgot to respond. The fixed IP + α configuration file is shown below for reference.

interfaces


# interfaces(5) file used by ifup(8) and ifdown(8)

# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'

auto wlan0
allow-hotplug wlan0
iface wlan0 inet static
      address 192.168.130.1/24
      netmask 255.255.255.0
      gateway 192.168.130.1
# iface wlan0 inet manual
#       wpa-conf /etc/wpa_supplicant/wpa_supplicant_wlan0.conf

auto wlan1
allow-hotplug wlan1
iface wlan1 inet dhcp
      wpa-conf /etc/wpa_supplicant/wpa_supplicant_wlan1.conf

# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d

Operation check

When I connected to the Internet via Raspberry Pi and did a speed test, it was about 1/5. It seems that it will change depending on the time of day and the situation of other connected terminals, but it is judged that there is no particular problem because the speed is sufficient now. If there is a problem, we will deal with it again.

Channel change and confirmation (addition: 2020/02/29)

I checked the 2.4GHz band channel and decided to change it to a place that seems to be there. If possible, I would like to use the 5GHz band, which has a lot of space, but I remember that Google Nest only supported 2.4GHz, so I did that. There may be a way to use both, but it's on hold. Consider when the performance is insufficient.

First, we selected the software used to check the channel. I decided to put an Android app on my Chromebook. After checking some reviews and appearance, I chose WiFi Analyzer (open-source). The reason for selection is because it says ʻopen-source`. Judging that there is a high possibility that there is no advertisement. image.png

When I checked the channel, it looked like this. You can see that the mobile Wi-Fi channel and the Raspberry Pi channel overlap. image.png

I decided to change to channel 1 where the signal power of other Wi-Fi is relatively weak.

Rewrite hostapd.conf according to the procedure described in Referenced site and execute the following command. I ran it.

sudo systemctl restart hostapd
sudo /etc/init.d/isc-dhcp-server restart

I checked again. You can see that the channel has moved. image.png

from now on

Here's what I want to do in the future.

--Review the channel (Completed: 2020/02/29) --Review the fixed IP settings. --Consider whether to connect your home device to mobile Wi-Fi or Raspberry Wi-Fi.

in conclusion

Although there are some parts that seem to be forced to operate, it was confirmed that they work safely. It's not limited to this setting, but it's difficult to debug. You can find out which function works in which configuration file by searching, but you cannot determine the optimum debug flow when an error occurs. This error message was not direct, so it took extra time. One solution seems to have been able to debug a little faster by understanding the behavior of DHCP and APs. In the future, I would like to try to shorten the debugging time and improve the application power by spending more time understanding the functions to be used. However, it may not be the ultimate solution because we think the same thing every time. I would like to discuss how to debug when using a technology that I do not know.

appendix

With the current settings (fcitx-mozc), Ctrl-Space switches between English and Japanese input. Raspberry Pi uses a Japanese keyboard. If you are using Emacs, it will be a problem, so disable it. It could be disabled by setting according to the following site.

How to disable input switching when using Ctrl-Space on Raspberry Pi 63rd Raspbian Stretch and Japanese conversion (fcitx-mozc) | Device Plus --Devapla

I also checked rc.local. The following site was helpful. rc.local - Raspberry Pi Documentation Setting of command (program) to be automatically executed when linux starts-Qiita

Recommended Posts

Use Raspberry Pi to solve the problem of insufficient mobile Wi-Fi connection
How to use the Raspberry Pi relay module Python
I want to be notified of the connection environment when the Raspberry Pi connects to the network
I sent the data of Raspberry Pi to GCP (free)
I tried to automate the watering of the planter with Raspberry Pi
Try to solve the N Queens problem with SA of PyQUBO
Use python on Raspberry Pi 3 to illuminate the LED (Hello World)
How to solve the bin packing problem
Use the Grove sensor on the Raspberry Pi
A memo to simply use the illuminance sensor TSL2561 with Raspberry Pi 2
Use python on Raspberry Pi 3 to light the LED with switch control!
Connect to the console of Raspberry PI and display local IP and SD information
Try to solve the Python class inheritance problem
How to use Raspberry Pi pie camera Python
[At Coder] Solve the problem of binary search
How to make a Raspberry Pi that speaks the tweets of the specified user
Try to use up the Raspberry Pi 2's 4-core CPU with Parallel Python
The 15th offline real-time I tried to solve the problem of how to write with python
Try to solve the problems / problems of "Matrix Programmer" (Chapter 1)
Try to visualize the room with Raspberry Pi, part 1
Try to solve the internship assignment problem with Python
Take the value of SwitchBot thermo-hygrometer with Raspberry Pi
Log the value of SwitchBot thermo-hygrometer with Raspberry Pi
I tried to solve the problem with Python Vol.1
How to write offline real time I tried to solve the problem of F02 with Python
Make a note of what you want to do in the future with Raspberry Pi
I tried to move ROS (Melodic) with the first Raspberry Pi (Stretch) at the beginning of 2021
Use the bin packing problem to reduce cloud usage fees
I want to use only the normalization process of SudachiPy
Try to solve the problems / problems of "Matrix Programmer" (Chapter 0 Functions)
The problem becomes easier to solve depending on the formulation method
Change the message displayed when logging in to Raspberry Pi
Is there a secret to the frequency of pi numbers?
The story of the algorithm drawing a ridiculous conclusion when trying to solve the traveling salesman problem properly
About the error I encountered when trying to use Adafruit_DHT from Python on a Raspberry Pi
Introduced python3-OpenCV3 to Raspberry Pi
Solve the Monty Hall problem
How to use the generator
I talked to Raspberry Pi
Introducing PyMySQL to raspberry pi3
How to use the decorator
Use NeoPixel on Raspberry Pi
Solve the problem of missing libcudart in Ubuntu 16.04 + CUDA 8.0 + Tensorflow environment
Use your Raspberry Pi to read your student ID number from your student ID card
I want to run the Python GUI when starting Raspberry Pi
Use PyCaret to predict the price of pre-owned apartments in Tokyo!
How to use Jupyter on the front end of supercomputer ITO
I wanted to solve the ABC164 A ~ D problem with Python
Solve the initial value problem of ordinary differential equations with JModelica
How to use machine learning for work? 01_ Understand the purpose of machine learning
Raspberry Pi --1 --First time (Connect a temperature sensor to display the temperature)
I tried to solve the shift scheduling problem by various methods
Periodically log the value of Omron environment sensor with Raspberry Pi
Try to solve the function minimization problem using particle swarm optimization
I want to solve the problem of memory leak when outputting a large number of images with Matplotlib
I made an npm package to get the ID of the IC card with Raspberry Pi and PaSoRi
Read the data of the NFC reader connected to Raspberry Pi 3 with Python and send it to openFrameworks with OSC