GEAR - Geauga Engineering and Robotics
header graphic

GEAR Internet of Things Projects

Internet of Things (IoT) projects employ the Internet to connect electronic devices. In preparing for your project, it is a good idea to develop some basic knowledge of the inner workings of the Internet.

The Internet was developed to provide a means for computers to share data. How does that work? Let's take an example of using the World Wide Web to read web pages. When you are nearly finished with high school, you may be thinking of going to college. You want to learn more about some colleges. You have heard that the University of Chicago is great place to study and you want to know more. You Google the name and determine that the address is https://www.uchicago.edu/ . Putting that address into your web browser results in the appearance of the University of Chicago home page on your computer screen. Did you ever stop and wonder how all that works?

Let's first review the basic architecture of a digital computing device. Computers utilize a large number of transistors, packaged into integrated circuits, to do computations and handle other operations related to data processing. In this case, an individual transistor can have two states: 1) turned on or 2) turned off. Thus, computers operate at their base level using a binary number system. The digits of the binary system are 1 and 0 (on and off). A transistor can store one bit of binary information (a one or a zero).

Data is also transmitted across the Internet as a series of ones and zeros. You can learn more about this from the video link below.

Here is a video that provides a great introduction to the Internet from Khan Academy.

Client and Server Computers

There is a great deal of detail in how the Internet works. You don't need to understand all the details. However, it is helpful to have a basic outline. Computers can be categorized into two kinds: clients and servers. Your computer is the client. When you put the address into your web browser, your computer sends a message to the University of Chicago web server. In English that message would be: "please send a copy of your home page." In response, the University of Chicago server sends back to your computer a copy of the home page. That is a very simplified explanation of what happens. The key point here is that you understand that client and server computers are connected together using the Internet. Client computers ask for information and server computers supply it.

According to this source ( https://www.forbes.com/sites/quora/2013/01/07/how-many-things-are-currently-connected-to-the-internet-of-things-iot/#6636f825bd2d ), in 2012 it was estimated that 8.7 billion devices were connected to the Internet. That is a huge number! How are they all connected together? Well, it would be impossible to connect each device directly to each other device. Instead, there is a network (the Internet) that provides a connection for each device. Your computer only needs one connection to the Internet, which in turn provides a potential connection to any other device connected to the Internet.

Internet Protocol and IP addresses

You may be wondering, with billions of devices connected to the Internet, how is it that my computer is able to communicate specifically with one other computer (for example, the University of Chicago web server)? Let's take the analogy of the postal system. There are billions of people living in the world. You want to sent a letter to a friend who lives far away. In order to do that, you put the address of your friend on the envelope of the letter. That address allows the postal system to determine where the letter should be delivered. The same idea works on the Internet. There is a protocol (a set of rules or procedures) used to establish a connection between two computers on the Internet. That protocol is called IP for short or Internet Protocol. The protocol specifies that each device connected to the Internet must have an IP address. That is how computers on the Internet communicate with each other, by using the IP addresses.

There are currently two versions of the IP address scheme used on the Internet, versions 4 and 6. Here we will cover only version 4, but you can read more at this address: ( https://en.wikipedia.org/wiki/Internet_Protocol ). This is the IPv4 address of the Google web server: 172.217.1.46     If you put that number in your browser's address slot, it will load the home page for Google. Notice that the IP address is a set of four numbers, separated by periods. Each number can range from 0 to 255. With this version 4 scheme, there are 4,294,967,296 possible addresses (256 X 256 X 256 X 256). That is approximately 4.3 billion addresses.

Perhaps you have noticed a problem. In 2012 it was estimated that 8.7 billion devices were connected to the Internet. That is more than can be accommodated by the version 4 IP scheme. That is the reason why the version 6 scheme was developed, to accommodate more devices. In any case, we can limit ourselves here in just talking about the version 4 scheme.

How do you get to the Google home page? Well, if you are using the Chrome browser, it may be set to go there automatically. Otherwise, you may know that if you enter google.com into your browser, then it will load the Google home page. But that is not the IP address. Most people don't have the ability and/or desire to memorize a large set of numbers. It is not reasonable for people to memorize the IP numbers for all of the web sites they visit regularly. Instead, a system of domain names was developed, names that people can more easily remember. The Google domain name is google.com and the University of Chicago domain name is uchicago.edu      Those names are a lot easier to remember.

However, behind the scenes, your computer still must use the IP number of the Google or University of Chicago server to make the connection. How does your computer know the IP address? Actually it does not. Your computer must request the IP number from a Domain Name Server (DNS) that is connected to the Internet. Actually, there are many domain name servers connected to the Internet. Together, all of these servers store the domain names and the associated IP addresses of the servers that have domain names. The first thing that happens when you enter a new domain name into your web browser, your computer sends out a request for Domain Name Service. In English the request would look like this: "What is the IP address for the domain name uchicago.edu?" That request is passed along to a series of domain name servers until a server storing the information is found. That server sends back to your computer the IP address to the uchicago.edu server. Then your computer uses that IP address to contact the server.

You might be wondering how I know the IP addresses for the Google and University of Chicago servers. I used a ping command in a terminal window on my computer. Below I have pasted the output resulting from one ping request:

ping uchicago.edu

Pinging uchicago.edu [104.130.110.202] with 32 bytes of data:
Reply from 104.130.110.202: bytes=32 time=23ms TTL=52
Reply from 104.130.110.202: bytes=32 time=23ms TTL=52
Reply from 104.130.110.202: bytes=32 time=23ms TTL=52
Reply from 104.130.110.202: bytes=32 time=23ms TTL=52

Ping statistics for 104.130.110.202:
Packets: Sent = 4, Received = 4, Lost = 0 <0% loss>
Approximate round trip times in milli-seconds:
Minimum = 23 ms, Maximum = 23 ms, Average = 23 ms

 

In the terminal window I entered the following command: ping uchicago.edu

And I get a reply from the uchicago.edu server that includes the IP address! Of course you need to be connected to the Internet for this to work. Notice that the round trip time for the reply to come back from the server is also indicated. In this case, the round trip from my computer to the server and back took only 23 milliseconds (0.023 seconds)!

You can try the ping command yourself. If you are using a Windows computer, open your terminal software, named cmd.exe (put cmd in the search slot that opens when you click Start button or find it listed as Command Prompt in the Accessories folder of the Programs menu). If you are using an Apple computer, you can find the terminal program with Finder: Applications/Utilities/Terminal. With the Apple computer your ping command may result in repeated pinging until you stop it with Ctrl + C on the keyboard.

Here is a nice video covering IP protocol and DNS from Khan Academy.

Transmission Control Protocol

The request and sending of a web page involves much more than just the IP protocol. The IP protocol primarily covers the computer addressing requirements. There are additional protocols necessary in successful transmission of data across the Internet. The protocols used depend in part on the type of data to be transmitted. In the case of web page data, TCP or Transmission Control Protocol is used in combination with the IP protocol.

The unit of data transmission across the Internet is called a packet. The amount of data contained in a packet can vary substantially, but a typical amount might be 1 kilobyte. A web page file is usually larger than 1 kilobyte. Therefore, in order to transmit it, it must be divided into several packets. The Transmission Control Protocol specifies how data should be divided into packets. Each packet contains headers. The IP header contains the IP address of the destination computer (e.g., server receiving a web page request) and the IP address of the sending computer (client asking for a web page). This should make sense because the server must know the IP address of the computer that is requesting data. Following the rules of TCP, the sending computer divides up the file to be sent into packets. In the TCP header, there are 10 required fields of information. One of those fields is the sequence number. The receiving computer must know how to reassemble the packets in proper order and this is done by using the sequence numbers. The TCP header also contains the port numbers used by the sending and receiving (source and destination) computers. A port is a number designation used by a specific software application. For example, the default port number used by web server software is 80. Another important TCP field in the header is the checksum. It is important that all data for a web page be accurately transmitted. The checksum is a number that is used in a mathematical procedure to insure that no data was lost or corrupted (changed) in transmission. If the receiving computer determines from the checksum that there was a problem in transmission of data, then the server will send the needed packets a second time. This procedure insures that data will be received without corruption.

The physical structure of the Internet is such that some data packets never reach their destination. Or during processing or transmission, something happens to corrupt the data in a packet. Depending on the type of data transmitted, it may or may not be acceptable to allow a few lost or corrupted data packets. For example, in a videoconferencing application (like Google Hangouts), it is important to deliver data packets fast. The desire is to have real-time performance. This type of application typically does not use the TCP protocol, which demands a perfect transmission of all data. The cost of that demand is the time required to complete the transmission (if some packets are lost, then they have to be sent again). If you have used Google Hangouts or a similar application to talk to a friend over the Internet, you probably have experienced moments where the sound goes bad or the picture becomes unclear. That is due to the loss or corruption of data packets. But because you don't want to have gaps in time in your conversation, you are willing to accept a few lost or bad packets of data. In the case of a web page, it is not acceptable for some of the words on a page to be missing. Therefore, TCP is used as the protocol.

Here is a nice video covering TCP protocol, packets and routers from Khan Academy.

Access to the Internet and Private Home Networks

Many homes now have access to the Internet through an Internet Service Provider (ISP). The physical access may be through a digital phone line (DSL) or a cable TV line. Other methods are available as well, like cell or satellite service. With wired service (DSL and Cable TV), the end of the cable is connected to a modem, an electronic device that interfaces between your computer and the cable. In many homes, the modem will include or will be connected to a router. Just as there are routers on the Internet to direct the flow of data packets, a home router will establish a private home network, that allows multiple computers and other devices to communicate with each other and share the Internet connection. Computers can connect to the home router by a wired connection using Ethernet or wirelessly if the computer and router have Wi-Fi capability.

If you have a private home network, then your computer will have two IP addresses, one internal and one external. In that case, it is likely that your router serves as a DHCP server, which assigns internal IP addresses to devices connected to the private network. DHCP is short for Dynamic Host Configuration Protocol. IP addresses assigned with DHCP are usually set to last for a certain period of time, for example one day. This is where the word dynamic comes into play, because the internal IP address of the computer can change frequently.

If you have a home network with a router, then it might be a good idea to learn how to manage the router, especially if you intend to use your private network as part of an Internet of Things project. However, you must be fully informed on how to manage the router. Otherwise, you might make a change that stops the functioning of your home network. Access to a router can vary depending on the brand and model. Most are accessible from the web browser of a computer connected to the private network. The router on your network will have its own internal IP address. Common internal IP addresses for a home router are 192.168.1.1, 192.168.0.1 or 192.168.2.1   However, the number may be something else (consult the instruction manual for your router or look for a manual on the Internet). After you determine the IP address for the router, enter the number into your web browser. For example: http://192.168.1.1 You may need a user name and/or password to access the router (check your router manual). After you have accessed the router, a web page containing settings will appear. There may be tabs to look through to see all the settings. Included will be a list of all devices connected to the private network and the internal IP addresses that have been assigned by the router. This can be valuable information when you are trying to set up a communication protocol between two devices on your private network.

Network Address Translation (NAT)

Your home router will operate some type of Network Address Translation (NAT) as a means of managing communications between devices on your private network and devices on the Internet. From outside your private network, devices on the Internet receive data packets that are sent by the router. From the outside, it looks like there is only one device on your private network, the router. A router operating NAT has the job of keeping track of which device on the private network sends a packet to it and then must send the reply packets from the Internet back to the same device on the private network. This system has been helpful in dealing with the IPv4 problem of limited number of IP addresses. As far as the Internet is concerned, all of the devices on your private network have the SAME IP address. Then it is the job of your home router to keep track of where packets come from and go to inside your private network. You can learn more about NAT at this web page

MAC Addresses

In addition to the IP addressing system for networks, each network-connected device has an address called Media Access Control (MAC) address. Your computer will have one or more MAC addresses, one for each Network Interface Card (NIC). If you have a desktop computer, it probably has an Ethernet NIC, which allows you to connect to a network with a wired connection (Ethernet cable). If you have a laptop, you probably have a Wi-Fi NIC, for wireless connection to a network. In the case of the Raspberry Pi, model 3, there is both an Ethernet NIC and Wi-Fi NIC, and it will have two MAC addresses.

The MAC address of a NIC is installed by the manufacturer and is permanent. Unlike an IP address, it cannot change. A common MAC address scheme contains 12 hexadecimal digits. An example of this format would be: c7:35:ce:fd:8e:a1   This provides 1612 or 281,474,976,710,656 unique addresses. In other words, more than 281 trillion addresses. This is a much greater number than the unique addresses possible with the IPv4 address scheme. In the grand scheme of things, Internet and private networks, computer addressing is accomplished using both IP addresses and MAC addresses. Listed below are some web pages if you want to learn more about MAC addresses

How Can I Determine the IP Address of My Computer?

Internal IP address

You can determine the internal IP address of your computer using the terminal program.

For Windows computers, enter this command in your terminal window: ipconfig  This will result in a display of some network information, including your internal IPv4 address.

For Apple computers, enter the following command in your terminal window: ifconfig  This will result in a display of a large amount of network information and it may be difficult to identify the IP address. A more specific command is ifconfig | grep " inet " | grep -v 127.0.0.1  With this command you will easily find the IP address.

For Raspberry Pi, running some flavor of the Linux OS, use the command ifconfig in your terminal window to find the internal IP address.

External IP address

You can test an Internet of Things project within your private network. However, to be a true Internet of Things project, you will need to demonstrate the transport of data across the Internet. Depending on the nature of your project, you may need to know the external IP address, which is used to connect to devices on your private network from a device outside your private network. The external IP address is assigned to your private network by your Internet Service Provider. In most cases that address assignment will be done by the ISP's DHCP server. This means that your external IP address will change over time. To determine the external IP address for your home network, go to this address with your web browser: https://whatismyipaddress.com

How Can I Determine the MAC Address of the NIC card on my computer?

For Windows computers, open your terminal program and enter this command: getmac   For Apple computers, click on the apple icon at upper left corner of screen, select About This Mac, click System Report button, in the left side menu, under Network, click on Locations. For the Raspberry Pi, enter the following command in the terminal window ifconfig eth0 for MAC address of Ethernet NIC or ifconfig wlan0 for the MAC address of Wi-Fi NIC. You can also find the MAC addresses of all devices connected to your home network by logging in to the router.

Operating a server on your home network

Your Internet of Things project will probably involve the use of a server. If you are using a Raspberry Pi as part of your project, you may wish to operate the Raspberry Pi as a server. However, you may have some challenges in making this work. In general, Internet Service Providers don't want their customers to run servers through their system (they only want to support client computers). To prevent the operation of a server, the ISP may block certain ports, like port 80 for a web server. If this is the case, then you won't be able to connect your Raspberry Pi to the Internet as a web server running on port 80. Even if your ISP permits you to operate a server, there are security issues to consider. For example, to operate a web server, you will need to open port 80 on your home router. By doing this, you open yourself to hackers, who may wish to hack into your network and Raspberry Pi. Specific steps must be taken to help secure your home network if you are contemplating operating a server that is connected to the Internet. The security issues are beyond the scope of topics presented on this web page.

A better option for your Internet of Things project would be to use a service offered by a company. For example, this web site is housed on a server provided by Aabaco Small Business. By paying a modest monthly fee, Aabaco provides space on one of their web servers and provides to me the domain name of lafavre.us  

HTML - the markup language of web pages

Your IoT project might include the creation of a web page or web pages. Many web design professionals utilize special software for creating web pages. Nevertheless, it is to your advantage to learn how to create a web page using only HTML markup language.

Let's start by looking at the code for a very simple page. Use the link below (the page will open in a new browser tab):

http://lafavre.us/robotics/simple.htm

This is a very simple web page. Notice that portions of text are enclosed in tags. The first line of text has this:

<!DOCTYPE html>  

When your web browser reads this line, it understands that what follows will be a web page coded in HTML version 5. Then comes the first HTML tag:

<html>

and the html code is closed with this tag:

</html>

at the bottom of the page (just ignore the script tag after the closing html tag, which is added by my web hosting service to track number of visitors to the page).

There are many tutorials you can find on the Internet for learning HTML. I suggest you use the one available at Khan Academy.   You should learn HTML and CSS.

Once you are comfortable creating web pages using the Khan Academy tutorial, you are ready to practice on your own. Notepad++ is a good text editor to use for writing HTML if you use a Windows computer (this web page was created using Notepad++). You can get a free copy here . After you have written your code in notepad++, you can check how the page looks in a browser. To do this, open the Run menu in notepad++ and select a Launch in.. item

You might also want to install the free software named Visual Studio code to assist in developing your web authoring skills. It has more features than Notepad++ and is also available for Apple computers. You can get a copy at this web address: https://code.visualstudio.com/

This page is a work in progress. Please visit later for more information.

 

Last page update: June 22, 2017