|
| 1 | +--- |
| 2 | +sidebar_position: 5 |
| 3 | +--- |
| 4 | + |
| 5 | +# ESP32 devices |
| 6 | + |
| 7 | +Many IoT devices are or can be based on an ESP32 microcontroller. |
| 8 | +A typical setup for integrating such a device in the OpenRemote ecosystem includes 3 components: |
| 9 | +- a firmware running on the ESP32 MCU in the device |
| 10 | +- a mobile app to configure the device and connect to the backend |
| 11 | +- the OpenRemote backend |
| 12 | + |
| 13 | +```mermaid |
| 14 | +graph LR |
| 15 | + %% Styling Definitions |
| 16 | + classDef greenStyle fill:#d4edda,stroke:#28a745,stroke-width:2px,color:#000; |
| 17 | + classDef innerGreenStyle fill:#e8f5e9,stroke:#28a745,stroke-width:1px,color:#000; |
| 18 | + classDef orangeStyle fill:#ffe0b2,stroke:#f57c00,stroke-width:2px,color:#000; |
| 19 | + classDef redStyle fill:#ffcdd2,stroke:#c62828,stroke-width:2px,color:#000; |
| 20 | + classDef purpleStyle fill:#e1bee7,stroke:#7b1fa2,stroke-width:2px,color:#000; |
| 21 | +
|
| 22 | + App[App]:::orangeStyle |
| 23 | +
|
| 24 | + OR[Backend]:::greenStyle |
| 25 | + |
| 26 | + ESP[Device]:::purpleStyle |
| 27 | +
|
| 28 | + %% Connections |
| 29 | + App <--> OR |
| 30 | + App <--> ESP |
| 31 | + ESP <--> OR |
| 32 | +``` |
| 33 | + |
| 34 | +We offer software elements to support the development of all 3 components. |
| 35 | + |
| 36 | +A device is represented in the OpenRemote backend by an asset of a specific type. |
| 37 | +The device communicates with OpenRemote over MQTTS, authenticated with a dedicated service user. |
| 38 | + |
| 39 | +In this typical use case, the device uses Wi-Fi for its internet connectivity. |
| 40 | + |
| 41 | +To integrate a new device into the system, it needs to be provisioned. |
| 42 | +This can either be done automatically, see [User Guide Auto provisioning](/user-guide/gateways-and-devices/auto-provisioning.md) |
| 43 | +or through a manual process performed by the end-user. |
| 44 | + |
| 45 | +For the latter case, the workflow is as follows |
| 46 | + |
| 47 | +```mermaid |
| 48 | +sequenceDiagram |
| 49 | + autonumber |
| 50 | + |
| 51 | + Note over User,Backend: User login |
| 52 | + |
| 53 | + User->>App: Login |
| 54 | + App->>Backend: Authenticate user |
| 55 | + Backend-->>App: Authenticated |
| 56 | + |
| 57 | + Note over User,Backend: Device Wi-Fi provisioning |
| 58 | + |
| 59 | + User->>Device: Put in discovery mode |
| 60 | + App->>App: Start device scan |
| 61 | + Device-->>App: Device name |
| 62 | + User->>App: select device |
| 63 | + App->>App: Stop device scan |
| 64 | + App->>Device: Connect |
| 65 | + Device->>App: Get PoP |
| 66 | + App-->>Device: PoP |
| 67 | + App->>Device: Start Wi-Fi scan |
| 68 | + Device-->>App: Wi-Fi information |
| 69 | + User->>App: Select Wi-Fi (or join other) |
| 70 | + User->>App: Enter Wi-Fi password |
| 71 | + App->>Device: Wi-Fi configuration |
| 72 | + Device->>App: Wi-Fi connection status |
| 73 | + |
| 74 | + Note over User,Backend: Device provisioning |
| 75 | + |
| 76 | + App->>Device: Get Device Id (DeviceInfo Request) |
| 77 | + Device-->>App: Device Id (DeviceInfo Response) |
| 78 | + |
| 79 | + App->>App: Create password |
| 80 | + App->>Backend: Provision device |
| 81 | + Note right of App: App provides Device Id and password |
| 82 | + |
| 83 | + Backend->>Backend: Create Device Asset |
| 84 | + Note right of Backend: Asset is linked to user account |
| 85 | + |
| 86 | + Backend->>Backend: Create Service Account |
| 87 | + Note right of Backend: Service Account is restricted<br/>and only has rights on the Device Asset.<br/>username is Device Id |
| 88 | + |
| 89 | + Backend-->>App: Confirmed |
| 90 | + Note right of Backend: Returns Asset Id |
| 91 | + |
| 92 | + App->>Device: Send configuration (OpenRemoteConfig Request) |
| 93 | + Device->>Backend: connect |
| 94 | + Note right of Device: Over MQTTS using username/password<br/>(Service Account) |
| 95 | + |
| 96 | + Device-->>App: Status (OpenRemoteConfig Response) |
| 97 | + App->>Device: Get connection status (BackendConnectionStatus Request) |
| 98 | + Device-->>App: connection status (BackendConnectionStatus Response) |
| 99 | + Note right of Device: Repeat to poll for connected status |
| 100 | +``` |
| 101 | + |
| 102 | +Communication between the Mobile Application and the Device is based on Espressif [Unified Provisioning](https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/provisioning/provisioning.html). |
| 103 | +This mechanism is used to discover the device, then establish a secure communication channel over BLE. |
| 104 | +Communication on this channel uses Protocol Buffer payloads, in addition to the messages defined by Espressif, OpenRemote uses messages defined in the following ProtoBuf spec: [ORConfigChannelProtocol](https://github.com/openremote/console-ios-lib/blob/7212bc905c7df34c2f3d62f801f0e4df7529a2f0/ORLib/ORConfigChannelProtocol.proto) |
| 105 | +OpenRemote includes the [ESP Provision provider](apps-and-consoles.md#esp-provision-provider-espprovision) to support the implementation of the mobile application side. |
| 106 | + |
| 107 | +On the backend, the project must implement a single `/rest/device` endpoint, see [Provision Device API](../provisioning-api/provision-device.api.mdx) for more details. |
0 commit comments