Doxygen with github
Loading...
Searching...
No Matches
ksConstants.h
1/*
2 * Copyright (c) 2021-2023, 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 <stdint.h>
13#include <limits>
14#include <string>
15#include <charconv>
16#include "stdlib_noniso.h"
17
18#include "Arduino.h"
19
21#define KSF_ONE_SEC_MS 1000UL
22
28#define KSF_SEC_TO_MS(seconds) (seconds*1000UL)
29
30#ifndef KSF_MQTT_RECONNECT_DELAY_MS
32#define KSF_MQTT_RECONNECT_DELAY_MS 10000UL
33#endif
34
35#ifndef KSF_MQTT_TIMEOUT_MS
37#define KSF_MQTT_TIMEOUT_MS 4000UL
38#endif
39
40#ifndef KSF_WIFI_TIMEOUT_MS
42#define KSF_WIFI_TIMEOUT_MS 120000UL
43#endif
44
45#ifndef KSF_WIFI_RECONNECT_TIME_MS
47#define KSF_WIFI_RECONNECT_TIME_MS 5000UL
48#endif
49
50#ifndef KSF_WATCHDOG_TIMEOUT_SECS
52#define KSF_WATCHDOG_TIMEOUT_SECS 10UL
53#endif
54
56#define KSF_FRAMEWORK_INIT() ksf::initializeFramework();
57
58namespace ksf
59{
60 namespace EOTAType
61 {
65 enum Type
66 {
68 NO_OTA,
70 OTA_GENERIC,
72 OTA_PORTAL,
73 };
74 }
75
80 extern const char* getNvsDirectory();
81
85 extern void initializeFramework();
86
92 extern bool removeDirectory(const char* path);
93
98 extern bool eraseConfigData();
99
103 extern void updateDeviceUptime();
104
109 extern uint64_t millis64();
110
119 extern std::string to_string(double value, const int base);
120
130 extern std::string to_string(float value, const int base);
131
140 template <typename _Type>
141 inline std::string to_string(const _Type& input)
142 {
143 return std::to_string(input);
144 }
145
153 inline std::string to_hex(int value)
154 {
155 if (value == 0)
156 return {"0"};
157
158 char buffer[8];
159 unsigned int uvalue{static_cast<unsigned int>(value)}, pos{8};
160
161 while (uvalue != 0)
162 {
163 unsigned int nibble{uvalue & 0xf};
164 buffer[--pos] = (nibble < 10) ? ('0' + nibble) : ('a' + (nibble - 10));
165 uvalue >>= 4;
166 }
167
168 return std::string(buffer + pos, 8 - pos);
169 }
170
181 template <typename _In, typename _Out>
182 bool from_chars(const _In& input, _Out& out)
183 {
184 const auto& result{std::from_chars(input.data(), input.data() + input.size(), out)};
185 return result.ec == std::errc();
186 }
187
196 std::string getDeviceUuidHex();
197
206 extern EOTAType::Type getOtaBootType();
207
215 extern void saveOtaBootIndicator(EOTAType::Type type = EOTAType::OTA_GENERIC);
216
228 template<class _Type1, class _Type2>
229 inline bool starts_with(const _Type1& input, const _Type2& match)
230 {
231 return input.size() >= match.size() && std::equal(match.begin(), match.end(), input.begin());
232 }
233
237 extern const std::string getResetReason();
238
244 extern const std::string getUptimeFromSeconds(uint32_t seconds);
245
250 extern const std::string getUptimeString();
251
257 extern void loadCredentials(std::string& ssid, std::string& password);
258
264 extern void saveCredentials(std::string ssid, std::string password);
265}