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
156 template <typename _In, typename _Out>
157 bool from_chars(const _In& input, _Out& out)
158 {
159 const auto& result{std::from_chars(input.data(), input.data() + input.size(), out)};
160 return result.ec == std::errc();
161 }
162
171 extern EOTAType::Type getOtaBootType();
172
180 extern void saveOtaBootIndicator(EOTAType::Type type = EOTAType::OTA_GENERIC);
181
193 template<class _Type1, class _Type2>
194 inline bool starts_with(const _Type1& input, const _Type2& match)
195 {
196 return input.size() >= match.size() && std::equal(match.begin(), match.end(), input.begin());
197 }
198
202 extern const std::string getResetReason();
203
209 extern const std::string getUptimeFromSeconds(uint32_t seconds);
210
215 extern const std::string getUptimeString();
216
222 extern void loadCredentials(std::string& ssid, std::string& password);
223
229 extern void saveCredentials(std::string ssid, std::string password);
230}