Smart Cities - Setup IoT WiFi Router: Difference between revisions
(Created page with "= Set up the Raspberry Pi server static IP Address = To set up a static IP address on your Raspberry Pi so it connects to a WiFi router (e.g., setting it to 192.168.2.2), you will need to modify the Raspberry Pi's network configuration. Below are the steps to achieve this: == Step 1: Find Your Current Network Information == Before configuring the static IP, find out your current network details, such as the gateway and DNS servers, by running the following command: <s...") |
No edit summary |
||
| (3 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
= Set up the Raspberry Pi | = Set up the IoT WiFi router SSID = | ||
= Test that your Raspberry Pi can connect to the Experimental Router = | |||
To verify that your Raspberry Pi is connected to the experimental router with the 192.168.2.x subnet, you can perform a few simple checks. These checks will confirm whether the Raspberry Pi is using the expected network configuration. Here's how you can do it: | |||
==1. Check IP Address== | |||
The first step is to verify that your Raspberry Pi has an IP address in the 192.168.2.x range, which indicates it is connected to the experimental router. | |||
Run the following command to display the IP address of the wlan0 (WiFi) or eth0 (Ethernet) interface: | |||
<syntaxhighlight lang="bash"> | |||
ip a | |||
</syntaxhighlight> | |||
Look for the inet line under the wlan0 or eth0 section. If you see something like this: | |||
<syntaxhighlight lang="bash"> | |||
inet 192.168.2.x/24 | |||
</syntaxhighlight> | |||
This confirms that your Raspberry Pi is connected to a router in the 192.168.2.x subnet. If you see an IP address in a different range (like 192.168.1.x), the Pi is connected to the wrong network. | |||
==2. Check Default Gateway== | |||
The default gateway is the router through which your Raspberry Pi sends traffic to other networks, such as the internet. To check if the gateway is your experimental router: | |||
<syntaxhighlight lang="bash"> | |||
ip route | |||
</syntaxhighlight> | |||
You should see an output similar to this: | |||
<syntaxhighlight lang="bash"> | |||
default via 192.168.2.1 dev wlan0 | |||
</syntaxhighlight> | |||
* default via 192.168.2.1: This confirms that your Raspberry Pi is using the experimental router (which likely has the IP address 192.168.2.1) as the default gateway. | |||
* dev wlan0: This shows that the connection is via the WiFi interface (use eth0 for Ethernet). | |||
If the gateway IP is different (e.g., 192.168.1.1), then your Pi is connected to Router #1 instead. | |||
==3. Check Router Response with ping== | |||
You can ping the experimental router (192.168.2.1) to ensure that the Raspberry Pi is communicating with it correctly: | |||
<syntaxhighlight lang="bash"> | |||
ping 192.168.2.1 | |||
</syntaxhighlight> | |||
You should get a response like: | |||
<syntaxhighlight lang="bash"> | |||
64 bytes from 192.168.2.1: icmp_seq=1 ttl=64 time=1.23 ms | |||
</syntaxhighlight> | |||
If you receive responses, the Raspberry Pi is successfully connected to the experimental router. If not, the connection might be to a different network. | |||
== | ==4. Check Connected SSID (if using WiFi)== | ||
If your Raspberry Pi is connected to the experimental router via WiFi, you can check the SSID of the network to ensure it matches the experimental router’s SSID. | |||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
iwgetid | |||
</syntaxhighlight> | </syntaxhighlight> | ||
The output will show something like: | |||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
wlan0 ESSID:"YourExperimentRouterSSID" | |||
</syntaxhighlight> | </syntaxhighlight> | ||
This confirms the Raspberry Pi is connected to the correct WiFi network. | |||
= Set up the Raspberry Pi server static IP Address = | |||
If you have two routers at home, one for internet access (Router #1) and the other for experimentation (Router #2), and you want to set a static IP address for your Raspberry Pi only when it's connected to Router #2, here's how to handle it: | |||
Open the configuration file | == Scenario Overview:== | ||
* Router #1: Used for internet access (e.g., 192.168.1.1) | |||
* Router #2: Used for experimentation (e.g., 192.168.2.1) | |||
* You want the Raspberry Pi to use a static IP (e.g., 192.168.2.2) when connected to Router #2. | |||
==Plan:== | |||
* Configure the Raspberry Pi to have a static IP only when connected to Router #2's network. | |||
* Ensure that when connected to Router #1, the Raspberry Pi continues to use dynamic IP (DHCP) for regular internet access. | |||
==Steps to Set a Static IP for the Experimental Router Only== | |||
==1. Find Your Network Information for Router #2== | |||
You need the following network details from Router #2: | |||
* Router (gateway) IP address: Likely 192.168.2.1 | |||
* DNS server: Can be Router #2's IP or a public DNS like 8.8.8.8. | |||
* Subnet mask: /24 usually corresponds to 255.255.255.0. | |||
==2. Configure Static IP for Specific WiFi Network (Router #2)== | |||
The Raspberry Pi can be set to use different network configurations based on the WiFi network it connects to. This is done in the /etc/dhcpcd.conf file by associating static IP settings with a specific SSID (network name). | |||
Open the DHCP configuration file for editing: | |||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
| Line 31: | Line 100: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
At the end of the file, add the following section, which will apply only when connected to the WiFi network of Router #2: | |||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
interface wlan0 | interface wlan0 | ||
ssid "YourExperimentRouterSSID" | |||
static ip_address=192.168.2.2/24 | static ip_address=192.168.2.2/24 | ||
static routers=192.168.2.1 | static routers=192.168.2.1 | ||
| Line 41: | Line 110: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
* | * ssid "YourExperimentRouterSSID": Replace this with the actual SSID (network name) of Router #2. | ||
* static ip_address: | * static ip_address: This sets the static IP for the Raspberry Pi when connected to Router #2. | ||
* static routers: | * static routers: The IP of Router #2 (likely 192.168.2.1). | ||
* static domain_name_servers: | * static domain_name_servers: The DNS server; it can be the router’s IP or an external DNS (like Google’s 8.8.8.8). | ||
== | ==3. Save and Exit== | ||
Press CTRL + X to exit. | * Press CTRL + X to exit. | ||
Press Y to | * Press Y to save changes. | ||
Press Enter to confirm | * Press Enter to confirm. | ||
== | ==4. Keep DHCP for Other Networks (e.g., Router #1)== | ||
Reboot your Raspberry Pi | |||
When the Pi connects to other networks (such as Router #1 for internet access), it will continue to use DHCP (dynamic IP), because we have not specified static settings for other SSIDs. | |||
==5. Reboot the Raspberry Pi== | |||
Reboot your Raspberry Pi for the changes to take effect: | |||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
| Line 60: | Line 133: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
6. Testing the Setup | |||
Connect to Router #2 (experimental network): Verify the Pi gets the static IP (192.168.2.2) by running: | |||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
| Line 67: | Line 141: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Look for the wlan0 interface, and | * Look for the wlan0 interface, and check that the IP is 192.168.2.2. | ||
* Connect to Router #1 (internet network): Verify that the Raspberry Pi receives an IP dynamically via DHCP from Router #1’s IP range (192.168.1.x or similar). | |||
== | ==Important Notes:== | ||
* | * Different Subnets: Routers #1 and #2 should be on different subnets (e.g., 192.168.1.x for Router #1 and 192.168.2.x for Router #2). This ensures no IP conflicts between the two routers. | ||
* Make sure the | * SSID: Make sure the SSID of Router #2 is correctly specified in /etc/dhcpcd.conf, as the static IP configuration will only apply when connected to that specific SSID. | ||
* This | * This setup ensures that the Raspberry Pi will use a static IP only when connected to the experimental router (Router #2), while using dynamic IP (DHCP) when connected to other networks like Router #1. | ||
Latest revision as of 05:57, 5 October 2024
Set up the IoT WiFi router SSID
Test that your Raspberry Pi can connect to the Experimental Router
To verify that your Raspberry Pi is connected to the experimental router with the 192.168.2.x subnet, you can perform a few simple checks. These checks will confirm whether the Raspberry Pi is using the expected network configuration. Here's how you can do it:
1. Check IP Address
The first step is to verify that your Raspberry Pi has an IP address in the 192.168.2.x range, which indicates it is connected to the experimental router.
Run the following command to display the IP address of the wlan0 (WiFi) or eth0 (Ethernet) interface:
ip a
Look for the inet line under the wlan0 or eth0 section. If you see something like this:
inet 192.168.2.x/24
This confirms that your Raspberry Pi is connected to a router in the 192.168.2.x subnet. If you see an IP address in a different range (like 192.168.1.x), the Pi is connected to the wrong network.
2. Check Default Gateway
The default gateway is the router through which your Raspberry Pi sends traffic to other networks, such as the internet. To check if the gateway is your experimental router:
ip route
You should see an output similar to this:
default via 192.168.2.1 dev wlan0
- default via 192.168.2.1: This confirms that your Raspberry Pi is using the experimental router (which likely has the IP address 192.168.2.1) as the default gateway.
- dev wlan0: This shows that the connection is via the WiFi interface (use eth0 for Ethernet).
If the gateway IP is different (e.g., 192.168.1.1), then your Pi is connected to Router #1 instead.
3. Check Router Response with ping
You can ping the experimental router (192.168.2.1) to ensure that the Raspberry Pi is communicating with it correctly:
ping 192.168.2.1
You should get a response like:
64 bytes from 192.168.2.1: icmp_seq=1 ttl=64 time=1.23 ms
If you receive responses, the Raspberry Pi is successfully connected to the experimental router. If not, the connection might be to a different network.
4. Check Connected SSID (if using WiFi)
If your Raspberry Pi is connected to the experimental router via WiFi, you can check the SSID of the network to ensure it matches the experimental router’s SSID.
iwgetid
The output will show something like:
wlan0 ESSID:"YourExperimentRouterSSID"
This confirms the Raspberry Pi is connected to the correct WiFi network.
Set up the Raspberry Pi server static IP Address
If you have two routers at home, one for internet access (Router #1) and the other for experimentation (Router #2), and you want to set a static IP address for your Raspberry Pi only when it's connected to Router #2, here's how to handle it:
Scenario Overview:
- Router #1: Used for internet access (e.g., 192.168.1.1)
- Router #2: Used for experimentation (e.g., 192.168.2.1)
- You want the Raspberry Pi to use a static IP (e.g., 192.168.2.2) when connected to Router #2.
Plan:
- Configure the Raspberry Pi to have a static IP only when connected to Router #2's network.
- Ensure that when connected to Router #1, the Raspberry Pi continues to use dynamic IP (DHCP) for regular internet access.
Steps to Set a Static IP for the Experimental Router Only
1. Find Your Network Information for Router #2
You need the following network details from Router #2:
- Router (gateway) IP address: Likely 192.168.2.1
- DNS server: Can be Router #2's IP or a public DNS like 8.8.8.8.
- Subnet mask: /24 usually corresponds to 255.255.255.0.
2. Configure Static IP for Specific WiFi Network (Router #2)
The Raspberry Pi can be set to use different network configurations based on the WiFi network it connects to. This is done in the /etc/dhcpcd.conf file by associating static IP settings with a specific SSID (network name).
Open the DHCP configuration file for editing:
sudo nano /etc/dhcpcd.conf
At the end of the file, add the following section, which will apply only when connected to the WiFi network of Router #2:
interface wlan0
ssid "YourExperimentRouterSSID"
static ip_address=192.168.2.2/24
static routers=192.168.2.1
static domain_name_servers=192.168.2.1 8.8.8.8
- ssid "YourExperimentRouterSSID": Replace this with the actual SSID (network name) of Router #2.
- static ip_address: This sets the static IP for the Raspberry Pi when connected to Router #2.
- static routers: The IP of Router #2 (likely 192.168.2.1).
- static domain_name_servers: The DNS server; it can be the router’s IP or an external DNS (like Google’s 8.8.8.8).
3. Save and Exit
- Press CTRL + X to exit.
- Press Y to save changes.
- Press Enter to confirm.
4. Keep DHCP for Other Networks (e.g., Router #1)
When the Pi connects to other networks (such as Router #1 for internet access), it will continue to use DHCP (dynamic IP), because we have not specified static settings for other SSIDs.
5. Reboot the Raspberry Pi
Reboot your Raspberry Pi for the changes to take effect:
sudo reboot
6. Testing the Setup
Connect to Router #2 (experimental network): Verify the Pi gets the static IP (192.168.2.2) by running:
ip a
- Look for the wlan0 interface, and check that the IP is 192.168.2.2.
- Connect to Router #1 (internet network): Verify that the Raspberry Pi receives an IP dynamically via DHCP from Router #1’s IP range (192.168.1.x or similar).
Important Notes:
- Different Subnets: Routers #1 and #2 should be on different subnets (e.g., 192.168.1.x for Router #1 and 192.168.2.x for Router #2). This ensures no IP conflicts between the two routers.
- SSID: Make sure the SSID of Router #2 is correctly specified in /etc/dhcpcd.conf, as the static IP configuration will only apply when connected to that specific SSID.
- This setup ensures that the Raspberry Pi will use a static IP only when connected to the experimental router (Router #2), while using dynamic IP (DHCP) when connected to other networks like Router #1.