Smart Cities - Setup IoT WiFi Router
Set up the IoT WiFi router SSID
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:
ip r
This command will output something like this:
default via 192.168.2.1 dev wlan0
192.168.2.0/24 dev wlan0 proto dhcp src 192.168.2.45 metric 303
In this example:
Gateway (router): 192.168.2.1 Network range: 192.168.2.0/24
Step 2: Modify the DHCP Client Configuration
Edit the dhcpcd.conf file to configure the static IP. This file tells your Raspberry Pi to always request the same IP address when connecting to the router.
Open the configuration file using a text editor like nano:
sudo nano /etc/dhcpcd.conf
Step 3: Add Static IP Configuration
Scroll to the bottom of the file and add the following lines:
interface wlan0
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
- interface wlan0: This specifies the wireless network interface.
- static ip_address: Set the static IP you want (e.g., 192.168.2.2).
- static routers: Set this to your router’s IP (e.g., 192.168.2.1).
- static domain_name_servers: Specify the DNS servers (usually your router's IP and an external DNS like Google's 8.8.8.8).
Step 4: Save and Exit
After editing the file, save the changes:
Press CTRL + X to exit. Press Y to confirm saving the changes. Press Enter to confirm the file name.
Step 5: Reboot the Raspberry Pi
Reboot your Raspberry Pi to apply the changes:
sudo reboot
Step 6: Verify the Static IP Address
After rebooting, verify that your Raspberry Pi is using the static IP address you set (192.168.2.2) by running:
ip a
Look for the wlan0 interface, and you should see 192.168.2.2 as the IP address.
Troubleshooting
- If the static IP isn't applied, check if the WiFi connection is working and the router's DHCP isn't conflicting with the static IP.
- Make sure the static IP (192.168.2.2) is outside your router’s DHCP range or reserved for static assignment.
- This should successfully configure your Raspberry Pi with a static IP address connected to your WiFi router.