Two Arduino Messaging System

Messaging System 

By the end of these sections you'll be able to create a system that can send and receive messages between multiple Arduinos! In the picture below, one Arduino uses a keyboard and the serial monitor for its input and output. While the other uses a potentiometer, button, and the LCD display. This simple network is possible due to the extra Arduino and WiFi module included in the kit.

Networking 101 

When you type in a web address and press enter a lot of things happen before you see the page. Your request is converted into 1's and 0's and is sent down a wire to the server that has the web page you're looking for. The web page is then sent back to you as 1's and 0's, and then your browser converts those 1's and 0's into a webpage that you can see.

The abstraction commonly used to explain this process is called the Open Systems Interconneciton Model. Or OSI model for short. This is not the end all be all for how information is transferred in the Internet but it's pretty spot on for most things.

OSI Model 

The OSI Model is split into 7 layers. The layer above needs the layer below and the layer below only serves the layer above. Each layer has one objective in the process of transferring data. Once it fulfills that, whatever else needs to be done is part of another layer.

OSI ModelOSI Model

Layer 1 - Physical Layer

The Physical Layer is responsible for taking 1's and 0's and converting them into a signal and vice versa. This could mean sending electricity down a wire, generating waves for radio, or sending light down a fiber for fiber optics. This layer takes a digital signal and coverts it into some physical means of transmitting. What's the data it's sending? Doesn't care. Where is it going? Doesn't care. Those questions are for a higher layers.

Physical LayerPhysical Layer

Layer 2 - Data Link Layer

The Data Link Layer is responsible for getting the data to the next step in a network. This layer adds the address of the physical hardware that Layer 1 will send to. It is concerned about one step in a relay race. The place where the Data Link Layer decides to send data might not be the final destination. The Data Link layer concerns itself with hop to hop delivery. So how does data get from a certain source to it's final destination? That's a questions for a higher layer.

Data Link LayerData Link Layer

Layer 3 - Network Layer

The Network Layer is responsible for figuring out the path data will take to get from its source to its destination. The network layer will figure out what devices are connected to what and figure out the best path from getting to point A to point B. It does this with Internet Protocol, or IP, address. There might not be a direct path but by using a destination IP the data will eventually find its way. Similar to ordering a package. The person shipping a package is often not the one delivering it. There are many stops and transfer but by knowing where the package is going it will get closer and closer until it arrives. Does the package have the correct contents? If so then who do you give it to? Those questions are for a higher layers.

Network LayerNetwork Layer

Layer 4 - Transport Layer

The Transport Layer is responsible for making sure data has no errors and for sending good data to the person who requested it. There are two main protocols for dealing with this. They are TCP and UDP. TCP makes sure that each packet of data arrives to it's destination and in the right order. When you request information from a web page you want all of the information you asked for. UDP is used when speed is required over accuracy. A video call or live stream might use UDP since you want the most current information as fast as possible, but it doesn't really matter if a small piece of data gets lost, it's old data now and we can just skip over it.

Once a packet is determined to be good. The Transport Layer also sends it to the right place. A package might be delivered to the right building but until it gets to the specific person who ordered it, its journey isn't complete.

Transport LayerTransport Layer

A Breather

There are 3 more layers to the OSI model. We won't be implementing them in this project but we will come back to them later.

Summary 

Let's say you have some data to send. The Transport Layer adds information that is used to check things like whether the data arrived in the right order and whether it was damaged along the way. It is then passed to the Network Layer. The Network Layer adds the source and destination before the data, and then passes it to the Data Link Layer. The Data Link Layer finds the best point to send the data next. If it can it will send it directly to the destination but usually the trip takes a few hops. The data is sent from one device to another until it finally reaches its destination. With each hop the Physical Layer converts the data from a signal and then back into a signal to be transmitted. This keeps happening until the packet arrives at the correct location.