Doxygen with github
Loading...
Searching...
No Matches
ksConstants.h
1/*
2 * Copyright (c) 2020-2026, Krzysztof Strehlau
3 *
4 * This file is a part of the ksIotFrameworkLib IoT library.
5 * All licensing information can be found inside LICENSE.md file.
6 *
7 * https://github.com/cziter15/ksIotFrameworkLib/blob/master/LICENSE
8 */
9
10#pragma once
11
12#include <Arduino.h>
13#include <cstdint>
14#include <limits>
15#include <string>
16#include <charconv>
17#include <stdlib_noniso.h>
18
20#define KSF_ONE_SEC_MS 1000UL
21
27#define KSF_SEC_TO_MS(seconds) (seconds*1000UL)
28
29#ifndef KSF_MQTT_RECONNECT_DELAY_MS
31#define KSF_MQTT_RECONNECT_DELAY_MS 10000UL
32#endif
33
34#ifndef KSF_DOMAIN_QUERY_INTERVAL_MS
36#define KSF_DOMAIN_QUERY_INTERVAL_MS 3000UL
37#endif
38
39#ifndef KSF_DOMAIN_QUERY_DNS_SERVER
41#define KSF_DOMAIN_QUERY_DNS_SERVER IPAddress(8, 8, 8, 8)
42#endif
43
44#ifndef KSF_MQTT_TIMEOUT_MS
46#define KSF_MQTT_TIMEOUT_MS 4000UL
47#endif
48
49#ifndef KSF_WIFI_TIMEOUT_MS
51#define KSF_WIFI_TIMEOUT_MS 120000UL
52#endif
53
54#ifndef KSF_WIFI_RECONNECT_TIME_MS
56#define KSF_WIFI_RECONNECT_TIME_MS 5000UL
57#endif
58
59#ifndef KSF_WATCHDOG_TIMEOUT_SECS
61#define KSF_WATCHDOG_TIMEOUT_SECS 10UL
62#endif
63
65#define KSF_FRAMEWORK_INIT() ksf::initializeFramework();
66
68#define KSF_LIBRARY_VERSION "1.0.49"
69
70namespace ksf
71{
72 namespace EOTAType
73 {
77 enum Type
78 {
80 NO_OTA,
82 OTA_GENERIC,
84 OTA_PORTAL,
85 };
86 }
87
92 extern const char* getNvsDirectory();
93
97 extern void initializeFramework();
98
104 extern bool removeDirectory(const char* path);
105
110 extern bool eraseConfigData();
111
115 extern void updateDeviceUptime();
116
121 extern uint64_t millis64();
122
131 extern std::string to_string(double value, const int base);
132
142 extern std::string to_string(float value, const int base);
143
152 template <typename _Type>
153 inline std::string to_string(const _Type& input)
154 {
155 return std::to_string(input);
156 }
157
165 inline std::string to_hex(int value)
166 {
167 if (value == 0)
168 return {"0"};
169
170 char buffer[8];
171 unsigned int uvalue{static_cast<unsigned int>(value)}, pos{8};
172
173 while (uvalue != 0)
174 {
175 unsigned int nibble{uvalue & 0xf};
176 buffer[--pos] = (nibble < 10) ? ('0' + nibble) : ('a' + (nibble - 10));
177 uvalue >>= 4;
178 }
179
180 return std::string(buffer + pos, 8 - pos);
181 }
182
193 template <typename _In, typename _Out>
194 bool from_chars(const _In& input, _Out& out)
195 {
196 const auto& result{std::from_chars(input.data(), input.data() + input.size(), out)};
197 return result.ec == std::errc();
198 }
199
208 std::string getDeviceUuidHex();
209
218 extern EOTAType::Type getOtaBootType();
219
227 extern void saveOtaBootIndicator(EOTAType::Type type = EOTAType::OTA_GENERIC);
228
240 template<class _Type1, class _Type2>
241 inline bool starts_with(const _Type1& input, const _Type2& match)
242 {
243 return input.size() >= match.size() && std::equal(match.begin(), match.end(), input.begin());
244 }
245
255 extern std::string json_escape(const std::string& input);
256
261 extern const std::string getResetReason();
262
268 extern const std::string getUptimeFromSeconds(uint32_t seconds);
269
274 extern const std::string getUptimeString();
275
281 extern void loadCredentials(std::string& ssid, std::string& password);
282
288 extern void saveCredentials(std::string ssid, std::string password);
289}