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 <cstdint>
13#include <string>
14#include <charconv>
15#include <algorithm>
16
18#define KSF_ONE_SEC_MS 1000UL
19
25#define KSF_SEC_TO_MS(seconds) (seconds*1000UL)
26
27#ifndef KSF_MQTT_RECONNECT_DELAY_MS
29#define KSF_MQTT_RECONNECT_DELAY_MS 10000UL
30#endif
31
32#ifndef KSF_DOMAIN_QUERY_INTERVAL_MS
34#define KSF_DOMAIN_QUERY_INTERVAL_MS 3000UL
35#endif
36
37#ifndef KSF_DOMAIN_QUERY_DNS_SERVER
39#define KSF_DOMAIN_QUERY_DNS_SERVER IPAddress(8, 8, 8, 8)
40#endif
41
42#ifndef KSF_MQTT_TIMEOUT_MS
44#define KSF_MQTT_TIMEOUT_MS 4000UL
45#endif
46
47#ifndef KSF_WIFI_TIMEOUT_MS
49#define KSF_WIFI_TIMEOUT_MS 120000UL
50#endif
51
52#ifndef KSF_WIFI_RECONNECT_TIME_MS
54#define KSF_WIFI_RECONNECT_TIME_MS 5000UL
55#endif
56
57#ifndef KSF_WATCHDOG_TIMEOUT_SECS
59#define KSF_WATCHDOG_TIMEOUT_SECS 10UL
60#endif
61
63#define KSF_FRAMEWORK_INIT() ksf::initializeFramework();
64
66#define KSF_LIBRARY_VERSION "1.0.54"
67
68namespace ksf
69{
70 namespace EOTAType
71 {
75 enum Type
76 {
77 NO_OTA,
78 OTA_GENERIC,
79 OTA_PORTAL,
80 };
81 }
82
87 extern const char* getNvsDirectory();
88
92 extern void initializeFramework();
93
99 extern bool removeDirectory(const char* path);
100
105 extern bool eraseConfigData();
106
110 extern void updateDeviceUptime();
111
116 extern uint64_t millis64();
117
126 extern std::string to_string(double value, const int base);
127
137 extern std::string to_string(float value, const int base);
138
147 template <typename _Type>
148 inline std::string to_string(const _Type& input)
149 {
150 return std::to_string(input);
151 }
152
160 inline std::string to_hex(int value)
161 {
162 if (value == 0)
163 return {"0"};
164
165 char buffer[8];
166 unsigned int uvalue{static_cast<unsigned int>(value)}, pos{8};
167
168 while (uvalue != 0)
169 {
170 unsigned int nibble{uvalue & 0xf};
171 buffer[--pos] = (nibble < 10) ? ('0' + nibble) : ('a' + (nibble - 10));
172 uvalue >>= 4;
173 }
174
175 return std::string(buffer + pos, 8 - pos);
176 }
177
188 template <typename _In, typename _Out>
189 bool from_chars(const _In& input, _Out& out)
190 {
191 const auto& result{std::from_chars(input.data(), input.data() + input.size(), out)};
192 return result.ec == std::errc();
193 }
194
203 std::string getDeviceUuidHex();
204
212 extern void saveOtaBootIndicator(EOTAType::Type type = EOTAType::OTA_GENERIC);
213
225 template<class _Type1, class _Type2>
226 inline bool starts_with(const _Type1& input, const _Type2& match)
227 {
228 return input.size() >= match.size() && std::equal(match.begin(), match.end(), input.begin());
229 }
230
240 extern std::string json_escape(const std::string& input);
241
246 extern const std::string getResetReason();
247
253 extern const std::string getUptimeFromSeconds(uint32_t seconds);
254
259 extern const std::string getUptimeString();
260
266 extern void loadCredentials(std::string& ssid, std::string& password);
267
273 extern void saveCredentials(std::string ssid, std::string password);
274}