AlteriomPainlessMesh v2.1.1
Easy ESP32/ESP8266 mesh networking with Alteriom IoT extensions
Loading...
Searching...
No Matches
configuration.hpp
Go to the documentation of this file.
1#ifndef _PAINLESS_MESH_CONFIGURATION_HPP_
2#define _PAINLESS_MESH_CONFIGURATION_HPP_
3
4// Include Arduino.h in test environment to ensure TSTRING is defined
5#if defined(PAINLESSMESH_BOOST) || defined(ARDUINO_ARCH_ESP8266) || \
6 defined(ARDUINO_ARCH_ESP32)
7#ifndef ARDUINO
8#include "Arduino.h"
9#endif
10#endif
11
12#include <list>
13
14#include "painlessTaskOptions.h"
15
16#include <TaskSchedulerDeclarations.h>
17
18#define ARDUINOJSON_USE_LONG_LONG 1
19#undef ARDUINOJSON_ENABLE_STD_STRING
20#include <ArduinoJson.h>
21#undef ARDUINOJSON_ENABLE_STD_STRING
22
23// Enable (arduino) wifi support
24#define PAINLESSMESH_ENABLE_ARDUINO_WIFI
25
26// Enable OTA support. Define PAINLESSMESH_DISABLE_OTA to compile the OTA
27// plugin out entirely (SECURITY.md, "OTA: integrity checked, not
28// authenticated").
29//
30// It must be a *build flag* -- `-DPAINLESSMESH_DISABLE_OTA`, or platformio.ini
31// `build_flags` -- so that every translation unit sees it. A `#define` above
32// the sketch's `#include <painlessMesh.h>` is not a narrower version of the
33// same thing, it is a bug: src/wifi.cpp and src/painlessMeshSTA.cpp compile
34// separately without it and would reach painlessmesh::Mesh with the OTA
35// members present, while the sketch sees the same class without them. That is
36// an ODR violation, and the standard requires no diagnostic for it.
37//
38// `#undef PAINLESSMESH_ENABLE_OTA` does not work either: it runs before
39// painlessMesh.h includes this header, which then defines the macro straight
40// back.
41#ifdef PAINLESSMESH_DISABLE_OTA
42// Opting out is not the same as declining to define. If the build already
43// supplies PAINLESSMESH_ENABLE_OTA -- redundantly, since it is the default --
44// then merely skipping the definition below leaves that one standing and every
45// #ifdef downstream still compiles OTA in, on a build that looks like it opted
46// out. That is a security control failing open and saying nothing, which is
47// the failure mode this opt-out exists to remove. Refuse the contradiction
48// rather than guessing which flag was meant.
49#ifdef PAINLESSMESH_ENABLE_OTA
50#error \
51 "PAINLESSMESH_DISABLE_OTA and PAINLESSMESH_ENABLE_OTA are both defined. Remove -DPAINLESSMESH_ENABLE_OTA from your build flags: OTA is on by default, so the disable flag alone is what you want."
52#endif
53#else
54#define PAINLESSMESH_ENABLE_OTA
55#endif
56
57// NOTE: there is deliberately no PAINLESSMESH_OTA_REQUIRE_SIGNATURE flag.
58// OTA acceptance (painlessmesh/ota.hpp, OTA_OP_CODES::DATA) authenticates
59// nothing -- it matches the sender-supplied md5/role/hardware tuple -- so a
60// flag that did not gate that path would read as a security control while
61// enforcing nothing. Defining it fails the build rather than passing
62// silently, so no fleet can ship believing its OTA images are verified.
63// Compiling OTA out is the only mitigation the library offers today.
64#ifdef PAINLESSMESH_OTA_REQUIRE_SIGNATURE
65#error \
66 "PAINLESSMESH_OTA_REQUIRE_SIGNATURE is not implemented: painlessMesh does not verify OTA image signatures. Use -DPAINLESSMESH_DISABLE_OTA to compile OTA out, or drop this define."
67#endif
68
69// NOTE: there is likewise no PAINLESSMESH_DISABLE_ACK flag. The one this
70// branch briefly carried gated only the (since-deleted, #386) dead
71// painlessmesh/message_tracker.hpp include, so the flag reclaimed nothing
72// and its advertised RAM saving was not real.
73//
74// That is NOT a claim that acknowledgment is free. The delivery-ack subsystem
75// (painlessmesh/ack.hpp) is a different thing and is genuinely allocated:
76// Mesh holds an ack::AckTracker member whose std::map grows with each
77// in-flight tracked message. Nothing compiles that out today. If a
78// memory-constrained target needs it gone, that is a design question for the
79// ack feature (#379), not a flag to reinstate here.
80
81// NOTE: `MIN_FREE_MEMORY` and `MAX_MESSAGE_QUEUE` are kept as deprecated
82// no-op compatibility macros. The library does not read either macro:
83// the auto-flushing message queue they were meant to tune never landed
84// (see #385, PR #383 review). `MessageQueue`
85// (`painlessmesh/message_queue.hpp`) is a manual priority buffer with
86// its own per-instance `maxSize` argument. Their historical default
87// values are preserved so downstream code that referenced them keeps
88// its prior behavior.
89#ifndef MIN_FREE_MEMORY
90#define MIN_FREE_MEMORY 4000
91#endif
92
93#ifndef MAX_MESSAGE_QUEUE
94#define MAX_MESSAGE_QUEUE 50
95#endif
96
97// The mesh watchdog. Overridable, because the documented remedy for an endpoint
98// that needs longer than the derived gateway budget is to raise this and
99// GATEWAY_HTTP_TIMEOUT_MS together (CHANGELOG, SECURITY.md). Unguarded, a
100// -DNODE_TIMEOUT on the build line was either silently overwritten here or a
101// macro-redefinition error under -Werror, so that remedy could not be followed
102// -- the same shape as the `#undef PAINLESSMESH_ENABLE_OTA` advice this
103// release also had to fix. Pinned by test/catch/catch_node_timeout_override.cpp.
104#ifndef NODE_TIMEOUT
105#define NODE_TIMEOUT 10 * TASK_SECOND
106#endif
107#define SCAN_INTERVAL 30 * TASK_SECOND // AP scan period in ms
108
109// A gateway relays to the Internet with blocking HTTPClient calls, from inside
110// the cooperative scheduler. Those calls must finish well inside NODE_TIMEOUT
111// or the gateway's peers reap connections to a node that is perfectly healthy
112// (issues #318, #332). The socket-timeout budget that enforces this is derived
113// from NODE_TIMEOUT in painlessmesh/gateway.hpp -- see GATEWAY_HTTP_TIMEOUT_MS
114// there. Raising NODE_TIMEOUT raises that budget with it.
115
116#ifdef ESP32
117#include <AsyncTCP.h>
118#include <WiFi.h>
119#if ESP_ARDUINO_VERSION_MAJOR >= 3
120#include "esp_mac.h" // required for core 3.x - exposes esp_mac_type_t values
121#endif
122#elif defined(ESP8266)
123#include <ESP8266WiFi.h>
124#include <ESPAsyncTCP.h>
125#endif // ESP32
126
127// Define TSTRING - use std::string in test environment, Arduino String
128// otherwise
129#if defined(PAINLESSMESH_BOOST)
130// Test environment - TSTRING already defined in test Arduino.h as std::string
131#else
132typedef String TSTRING;
133#endif
134
135// backward compatibility
136template <typename T>
137using SimpleList = std::list<T>;
138
139namespace painlessmesh {
140namespace wifi {
141class Mesh;
142};
143}; // namespace painlessmesh
144
146#ifdef PAINLESSMESH_ENABLE_ARDUINO_WIFI
148#endif
149
150#ifdef ESP32
151#define MAX_CONN 10
152#else
153#define MAX_CONN 4
154#endif // DEBUG
155
156#endif
Definition wifi.hpp:36
std::list< T > SimpleList
Definition configuration.hpp:137
String TSTRING
Definition configuration.hpp:132
Definition wifi.hpp:34