Reader small image

You're reading from  Arduino Data Communications

Product typeBook
Published inNov 2023
PublisherPackt
ISBN-139781837632619
Edition1st Edition
Right arrow
Author (1)
Robert Thas John
Robert Thas John
author image
Robert Thas John

Robert Thas John is a data engineer with a career that spans two decades. He manages a team of data engineers, analysts, and machine learning engineers – roles that he has held in the past. He leads a number of efforts aimed at increasing the adoption of machine learning on embedded devices through various programs from Google Developers and ARM Ltd, which licenses the chips found in Arduinos and other microcontrollers. He started his career as a software engineer with work that has spanned various industries. His first experience with embedded systems was in programming payment terminals.
Read more about Robert Thas John

Right arrow

Working with Ethernet

In this chapter, you will learn how to deploy Arduino solutions while making use of Ethernet technology. You will write a sketch that communicates with a weather service to get the current weather conditions in a city and then use that information to control the intensity of an onboard LED. You will learn how to work with a RESTful API endpoint and process the JSON response that is returned by that endpoint. This type of activity is useful for controlling devices based on environmental conditions, such as greenhouses and animal housing.

By the end of this chapter, you will have learned how to connect to a web service via Ethernet and process the response.

In this chapter, we are going to cover the following main topics:

  • Introduction to Ethernet
  • Communicating over Ethernet

Technical requirements

The code example in this chapter is available on GitHub at https://github.com/securetorobert/Arduino-Data-Communications/tree/main/chapter-8.

You will need to following to complete the example project in this chapter:

  • Arduino Portenta H7 (or H7 Lite)
  • Arduino Portenta Vision Shield – Ethernet
  • A network switch with internet connectivity
  • An Ethernet cable

Introduction to Ethernet

Ethernet is a wired communication technology. It is frequently used in both residential and commercial applications where a wireless network might be undesirable due to one or more of the following reasons:

  • A need to implement communications without interfering with sensitive equipment, such as medical equipment
  • A need to support much higher speeds than is possible over wireless networks
  • A need to communicate through thick walls
  • A need to provide power to devices while also communicating, using a technology called Power-over-Ethernet (PoE)

Ethernet networks comprise a switch or router and devices.

A network switch creates a dedicated network and enables communication between devices on the network. A switch might have a connection to the internet, in which case the switch will enable the devices to connect to the internet.

A network router enables connectivity between multiple networks. Routers might also serve as firewalls...

Communicating over Ethernet

Let’s build a solution that will control the onboard LED based on the weather conditions in a particular location. We will make use of APIs from AccuWeather. You can sign up for free at https://developer.accuweather.com/.

Creating an AccuWeather app

Once you’ve created your account, you will need to create an app before you can get API keys to work with. Navigate to the MY APPS tab or go to https://developer.accuweather.com/user/me/apps. Follow these steps to create an app:

  1. Click on the + Add a new App button. This is shown here:
Figure 8.2 – AccuWeather developer portal

Figure 8.2 – AccuWeather developer portal

  1. Specify a name for the app.
  2. Under Products, choose Core Weather Limited Trial.
  3. For Where will the app be used?, choose Other.
  4. For What will you be creating with this app?, choose Internal App.
  5. For What is your app written in?, choose C++.
  6. For Is this for Business to Business or Business to Consumer...

Summary

In this chapter, you learned how to set up an account on a public API server, as well as how to fetch weather information from that server. You also learned how to send a HTTP GET request to the API server from an Arduino Portenta using Ethernet, and how to process the response from the server.

In the next chapter, you will learn how to work with cellular communication technologies.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Arduino Data Communications
Published in: Nov 2023Publisher: PacktISBN-13: 9781837632619
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Robert Thas John

Robert Thas John is a data engineer with a career that spans two decades. He manages a team of data engineers, analysts, and machine learning engineers – roles that he has held in the past. He leads a number of efforts aimed at increasing the adoption of machine learning on embedded devices through various programs from Google Developers and ARM Ltd, which licenses the chips found in Arduinos and other microcontrollers. He started his career as a software engineer with work that has spanned various industries. His first experience with embedded systems was in programming payment terminals.
Read more about Robert Thas John