DeterministicESPAsyncWebServer v6.28.0
Zero-allocation, bounded-execution async HTTP server for ESP32
Loading...
Searching...
No Matches
openadr.h
Go to the documentation of this file.
1// Copyright (C) 2026 Douglas Quigg (dstroy0) <dquigg123@gmail.com>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4/**
5 * @file openadr.h
6 * @brief OpenADR 3.0 (Open Automated Demand Response) JSON codec (DETWS_ENABLE_OPENADR).
7 *
8 * OpenADR 3.0 is the demand-response protocol as a REST/JSON API (over HTTP + OAuth2, both already
9 * shipped): a VTN (server) posts `event` objects to VENs, and VENs post `report` objects back. This
10 * builds the two core JSON objects into a caller buffer, so a device is an OpenADR 3.0 VEN over the
11 * existing HTTP client/server:
12 *
13 * - **event**: `programID`, `eventName`, and an `intervals` array each carrying a `SIMPLE`/`price`/
14 * `LOAD_CONTROL` payload point (start + duration + a numeric value) - a demand-response signal.
15 * - **report**: `programID`, `eventID`, a `resourceName`, and a reading (a value at a point in time) -
16 * the VEN's telemetry back to the VTN.
17 *
18 * Pure JSON text framing (strings escaped), zero heap, no stdlib, host-testable; the OAuth2 token +
19 * HTTP transport are the existing services.
20 */
21
22#ifndef DETERMINISTICESPASYNCWEBSERVER_OPENADR_H
23#define DETERMINISTICESPASYNCWEBSERVER_OPENADR_H
24
25#include "ServerConfig.h"
26#include <stddef.h>
27#include <stdint.h>
28
29#if DETWS_ENABLE_OPENADR
30
31/** @brief One OpenADR interval payload point (a single value over a time interval). */
32struct OpenAdrInterval
33{
34 uint32_t start; ///< interval start (epoch seconds).
35 uint32_t duration; ///< interval duration (seconds).
36 const char *type; ///< payload type, e.g. "SIMPLE", "PRICE", "LOAD_CONTROL".
37 double value; ///< the payload value (a level, price, or setpoint).
38};
39
40/**
41 * @brief Build an OpenADR 3.0 event JSON object.
42 * @param program_id the program id (string; escaped).
43 * @param event_name the event name (string; escaped).
44 * @param intervals the interval payload points.
45 * @param count number of intervals.
46 * @return length written (excl NUL), or 0 on overflow.
47 */
48size_t detws_openadr_event(const char *program_id, const char *event_name, const OpenAdrInterval *intervals,
49 size_t count, char *out, size_t cap);
50
51/**
52 * @brief Build an OpenADR 3.0 report JSON object (one reading for one resource).
53 * @param program_id the program id.
54 * @param event_id the event id this report answers.
55 * @param resource_name the reporting resource.
56 * @param value the reading value.
57 * @param timestamp the reading time (epoch seconds).
58 * @return length written (excl NUL), or 0 on overflow.
59 */
60size_t detws_openadr_report(const char *program_id, const char *event_id, const char *resource_name, double value,
61 uint32_t timestamp, char *out, size_t cap);
62
63#endif // DETWS_ENABLE_OPENADR
64#endif // DETERMINISTICESPASYNCWEBSERVER_OPENADR_H
User-facing configuration for DeterministicESPAsyncWebServer.