Getting Started with Python for the Internet of Things
上QQ阅读APP看书,第一时间看更新

How to do it...

Many networks connect and configure themselves automatically using the Dynamic Host Configuration Protocol (DHCP), which is controlled by the router or switch. If this is the case, simply plug the network cable into a spare network port on your router or network switch (or wall network socket if applicable).

Alternatively, if a DHCP server is not available, you shall have to configure the settings manually (refer to the There's more... section for details).

You can confirm this is functioning successfully with the following steps:

  1. Ensure that the two LEDs on either side of Raspberry Pi light up (the left orange LED indicates a connection and the green LED on the right shows activity by flashing). This will indicate that there is a physical connection to the router and that the equipment is powered and functioning.
  2. Test the link to your local network using the ping command. First, find out the IP address of another computer on the network (or the address of your router, perhaps, often 192.168.0.1 or 192.168.1.254). Now, on the Raspberry Pi Terminal, use the ping command (the -c 4 parameter is used to send just four messages; otherwise, press Ctrl + C to stop) to ping the IP address, as follows:
sudo ping 192.168.1.254 -c 4
  1. Test the link to the internet (this will fail if you usually connect to the internet through a proxy server) as follows:
sudo ping www.raspberrypi.org -c 4
  
  1. Finally, you can test the link back to Raspberry Pi by discovering the
    IP address using hostname -I on Raspberry Pi. You can then use the ping command on another computer on the network to ensure it is accessible (using Raspberry Pi's IP address in place of www.raspberrypi.org). The Windows version of the ping command will perform five pings and stop automatically, and will not need the -c 4 option.

If the aforementioned tests fail, you will need to check your connections and then confirm the correct configuration for your network.