DeterministicESPAsyncWebServer
v6.27.1
Zero-allocation, bounded-execution async HTTP server for ESP32
Loading...
Searching...
No Matches
sparkplug.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 sparkplug.h
6
* @brief Sparkplug B payload + topic codec (DETWS_ENABLE_SPARKPLUG) - zero-heap builder for
7
* the Eclipse Sparkplug B industrial-IoT MQTT payload (a Protobuf message) and its
8
* topic namespace. Builds on the Protobuf codec (services/protobuf) and is published
9
* with the MQTT client.
10
*
11
* Topic: `spBv1.0/<group_id>/<message_type>/<edge_node_id>[/<device_id>]`, where message_type
12
* is NBIRTH / NDEATH / NDATA / DBIRTH / DDEATH / DDATA / STATE.
13
*
14
* Payload (Tahu `Payload` protobuf): timestamp(1), metrics(2, repeated), seq(3), uuid(4),
15
* body(5). Each Metric: name(1), alias(2), timestamp(3), datatype(4), and a value in the
16
* oneof - int_value(10) / long_value(11) / float_value(12) / double_value(13) /
17
* boolean_value(14) / string_value(15). Field numbers + datatype codes verified against the
18
* Eclipse Tahu sparkplug_b.proto.
19
*
20
* @author Douglas Quigg (dstroy0)
21
* @date 2026
22
*/
23
24
#ifndef DETERMINISTICESPASYNCWEBSERVER_SPARKPLUG_H
25
#define DETERMINISTICESPASYNCWEBSERVER_SPARKPLUG_H
26
27
#include "
ServerConfig.h
"
28
29
#if DETWS_ENABLE_SPARKPLUG
30
31
#include <stddef.h>
32
#include <stdint.h>
33
34
// Sparkplug B data type codes (a subset; Tahu DataType enum).
35
#define SPB_DT_INT8 1
36
#define SPB_DT_INT16 2
37
#define SPB_DT_INT32 3
38
#define SPB_DT_INT64 4
39
#define SPB_DT_UINT8 5
40
#define SPB_DT_UINT16 6
41
#define SPB_DT_UINT32 7
42
#define SPB_DT_UINT64 8
43
#define SPB_DT_FLOAT 9
44
#define SPB_DT_DOUBLE 10
45
#define SPB_DT_BOOLEAN 11
46
#define SPB_DT_STRING 12
47
48
/** @brief Which value the metric carries (selects the Tahu Metric value-oneof field). */
49
enum class
SpbMetricKind : uint8_t
50
{
51
SPB_M_INT,
///< int_value (field 10, uint32)
52
SPB_M_LONG,
///< long_value (field 11, uint64)
53
SPB_M_FLOAT,
///< float_value (field 12)
54
SPB_M_DOUBLE,
///< double_value (field 13)
55
SPB_M_BOOL,
///< boolean_value (field 14)
56
SPB_M_STRING,
///< string_value (field 15)
57
};
58
59
/** @brief One Sparkplug B metric. nullptr name / has_* false fields are omitted. */
60
struct
SpbMetric
61
{
62
const
char
*name;
///< metric name (omit on DATA when using an alias)
63
bool
has_alias;
64
uint64_t alias;
65
bool
has_timestamp;
66
uint64_t timestamp;
67
uint32_t datatype;
///< SPB_DT_*
68
SpbMetricKind kind;
69
uint32_t int_value;
70
uint64_t long_value;
71
float
float_value;
72
double
double_value;
73
bool
bool_value;
74
const
char
*string_value;
75
};
76
77
/** @brief Build the `spBv1.0/...` topic. @p device may be null for a node-level topic. */
78
size_t
spb_build_topic(
char
*buf,
size_t
cap,
const
char
*group,
const
char
*message_type,
const
char
*edge_node,
79
const
char
*device);
80
81
/** @brief Serialize one Metric (a Tahu Metric protobuf message). Returns length, or 0. */
82
size_t
spb_build_metric(uint8_t *buf,
size_t
cap,
const
SpbMetric *m);
83
84
/** @brief Serialize a Payload: timestamp + the @p n metrics + seq. Returns length, or 0. */
85
size_t
spb_build_payload(uint8_t *buf,
size_t
cap, uint64_t timestamp, uint64_t seq,
const
SpbMetric *metrics,
86
size_t
n);
87
88
#endif
// DETWS_ENABLE_SPARKPLUG
89
90
#endif
// DETERMINISTICESPASYNCWEBSERVER_SPARKPLUG_H
ServerConfig.h
User-facing configuration for DeterministicESPAsyncWebServer.
src
services
sparkplug
sparkplug.h
Generated by
1.9.8