Building Arduino Projects for the Internet of Things

(Steven Felgate) #1

© Adeel Javed 2016 35
A. Javed, Building Arduino Projects for the Internet of Things,
DOI 10.1007/978-1-4842-1940-9_3


CHAPTER 3


Communication Protocols


In Chapter 2 , you connected Arduino to the Internet using Ethernet and WiFi respectively.
This chapter looks at two protocols used for sending and receiving data. A protocol is an
agreed-upon structured format that is used for network communication. It defines what
should be sent and received and what actions should be taken.


Learning Objectives


At the end of this chapter, you will be able to:



  • Understand the basics of the HTTP protocol

  • Send an HTTP request to the server

  • Understand the basics of the MQTT protocol

  • Publish and subscribe to an MQTT broker


HTTP


The web uses Hyper Text Transfer Protocol (HTTP) as its underlying protocol. HTTP
supports multiple methods of data transmission, but in this project you are going to write
code for the two more popular methods, GET and POST. The GET and POST methods do
the same job and their code is very similar, but there is a slight variation in their request
formats. GET has a limit on how much data it can transmit compared to POST , which
has no such limitations. POST is also considered safer compared to GET. Based on your
requirements, you can decide which one works better for you. Figure  3-1 shows a
high-level interaction between a device and an HTTP server.

Free download pdf