# Understanding Edge Devices & Gateways

## metadata
- title: Understanding Edge Devices & Gateways
- description: In the last blog , we went through the basics of edge computing, in this blog we will delve a little deeper to understand devices and how they connect with gateways. Code on Devices The code on the devices performs one or many of these It makes a secure connection to the cloud endpoint.
- author: David Pasternak
- topic: Industrial AI
- industry: 
- technology: 
- published_at: 2024-02-02T14:58:59
- route: /resources/blog/edge-devices-gateways
- canonical: https://klyff.com/resources/blog/edge-devices-gateways

## Summary and Use
In the last blog , we went through the basics of edge computing, in this blog we will delve a little deeper to understand devices and how they connect with gateways. Code on Devices The code on the devices performs one or many of these It makes a secure connection to the cloud endpoint.

## Article Content
In the [last blog](https://staging4blogs.klyff.com/understanding-edge-computing/), we went through the basics of edge computing, in this blog we will delve a little deeper to understand devices and how they connect with gateways.

 

### Code on Devices

The code on the devices performs one or many of these

 

- It **makes a secure connection** to the cloud endpoint. Secure means that it can connect and authenticate as well.

- **Sends data** from sensors to the cloud. These are device-to-cloud messages or could be file uploads like video, audio, or images sent to the cloud. The device could send them synchronously or batch them.

- Manages **device state** and keeps it in sync with the cloud. It can act as a device twin for the device it is managing or act as a digital twin to represent the device’s location, capabilities, and relationship to other devices

- Receives and responds to **commands from the cloud**. For example, asking a motor to start in 30 seconds.

- Enables **firmware installation and upgrades** from the cloud. For example, notifying the device that there is a new firmware ready for download and then transferring that over the network

- Enables the device to function even when **not connected to the cloud**
 

The device code is usually containerized. For Example, docker. These containers have the runtime environment of the code along with all packages and libraries.

 

### Types of devices

MCUs and MPUs

**MCUs** (microcontrollers) are less expensive than MPUs (microprocessors). They do not have processing power but have memory, interfaces, and I/O on the chip. Often they use real-time OS (RTOS) or bare metal (no OS). They are highly deterministic to external events.

**MPUs** connect with the MCUs to get data. They have general-purpose OS like Linux, macOS, or Windows. They provide non-deterministic real-time responses.

### Connectivity

Either the devices connect to the IoT hub using a connection string that needs to have the hostname. In this case, all the devices would be hard-wired to the host. Another option is to go through a provisioning service that allows the devices to connect to a well-known endpoint and protocol. This provisioning service then connects to the hub or cloud end-points and the devices need not know about that.

Given loose abstraction the provisioning service should be a better approach.

Devices use TLS (Transport Level Security) to authenticate the IoT Hub or the provisioning service. TLS  is a widely adopted security protocol designed to facilitate privacy and data security for communications over the Internet. A primary use case of TLS is encrypting the communication between web applications and servers, such as web browsers loading a website.

#### Protocols

Devices can use several protocols to connect to the Hub. Some of them are

 

- [MQTT / MQTT over WebSockets](https://docs.oasis-open.org/mqtt/mqtt/v3.1.1/mqtt-v3.1.1.pdf) 

- [ AMQP / AMQP over WebSockets ](https://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-complete-v1.0-os.pdf)

- HTTPS

- [OPC UA](https://opcfoundation.org/about/opc-technologies/opc-ua/) (Open Platforms Communications Unified Architecture). In this case, the edge would be running the OPC Publisher
 

 

### Connections

Are of two kinds, persistent and ephemeral

Persistent – When the solution needs command and control capabilities. The edge would maintain a connection to the cloud and reconnect if disconnected. MQTT and AMQP are most used for persistent connections

Ephemeral – Brief connections to send telemetry to the cloud. Once the payload is sent, the connection is dropped. Usually, device clients use HTTP API connection

### Field Gateways & Bridges

Deployed close to gateways and help the devices connect to the cloud. They help with

 

Bridges help connect to 3rd party clouds like[ The Things Network ](https://www.thethingsnetwork.org/)
