ProtoCore
v1.0.16
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
openadr.h
Go to the documentation of this file.
1
// ProtoCore v1.0.16 - 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 (PROTOCORE_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 PROTOCORE_OPENADR_H
23
#define PROTOCORE_OPENADR_H
24
25
#include "
protocore_config.h
"
// the entry point: protocore_types.h for the widths
26
27
#if PROTOCORE_ENABLE_OPENADR
28
29
EMBED_BEGIN_DECLS
30
31
/** @brief One OpenADR interval payload point (a single value over a time interval). */
32
typedef
struct
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
} OpenAdrInterval;
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
*/
48
size_t
protocore_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
*/
60
size_t
protocore_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
EMBED_END_DECLS
64
65
#endif
// PROTOCORE_ENABLE_OPENADR
66
67
#endif
// PROTOCORE_OPENADR_H
protocore_config.h
src
services
energy
openadr
openadr.h
Generated by
1.15.0