Doxygen with github
Loading...
Searching...
No Matches
ksConstants.h
1/*
2 * Copyright (c) 2021-2025, Krzysztof Strehlau
3 *
4 * This file is a part of the ksIotFramework 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 <stdint.h>
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
67namespace ksf
68{
69 namespace EOTAType
70 {
74 enum Type
75 {
77 NO_OTA,
79 OTA_GENERIC,
81 OTA_PORTAL,
82 };
83 }
84
89 extern const char* getNvsDirectory();
90
94 extern void initializeFramework();
95
101 extern bool removeDirectory(const char* path);
102
107 extern bool eraseConfigData();
108
112 extern void updateDeviceUptime();
113
118 extern uint64_t millis64();
119
128 extern std::string to_string(double value, const int base);
129
139 extern std::string to_string(float value, const int base);
140
149 template <typename _Type>
150 inline std::string to_string(const _Type& input)
151 {
152 return std::to_string(input);
153 }
154
162 inline std::string to_hex(int value)
163 {
164 if (value == 0)
165 return {"0"};
166
167 char buffer[8];
168 unsigned int uvalue{static_cast<unsigned int>(value)}, pos{8};
169
170 while (uvalue != 0)
171 {
172 unsigned int nibble{uvalue & 0xf};
173 buffer[--pos] = (nibble < 10) ? ('0' + nibble) : ('a' + (nibble - 10));
174 uvalue >>= 4;
175 }
176
177 return std::string(buffer + pos, 8 - pos);
178 }
179
190 template <typename _In, typename _Out>
191 bool from_chars(const _In& input, _Out& out)
192 {
193 const auto& result{std::from_chars(input.data(), input.data() + input.size(), out)};
194 return result.ec == std::errc();
195 }
196
205 std::string getDeviceUuidHex();
206
215 extern EOTAType::Type getOtaBootType();
216
224 extern void saveOtaBootIndicator(EOTAType::Type type = EOTAType::OTA_GENERIC);
225
237 template<class _Type1, class _Type2>
238 inline bool starts_with(const _Type1& input, const _Type2& match)
239 {
240 return input.size() >= match.size() && std::equal(match.begin(), match.end(), input.begin());
241 }
242
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}