17#include <stdlib_noniso.h>
20#define KSF_ONE_SEC_MS 1000UL
27#define KSF_SEC_TO_MS(seconds) (seconds*1000UL)
29#ifndef KSF_MQTT_RECONNECT_DELAY_MS
31#define KSF_MQTT_RECONNECT_DELAY_MS 10000UL
34#ifndef KSF_DOMAIN_QUERY_INTERVAL_MS
36#define KSF_DOMAIN_QUERY_INTERVAL_MS 3000UL
39#ifndef KSF_DOMAIN_QUERY_DNS_SERVER
41#define KSF_DOMAIN_QUERY_DNS_SERVER IPAddress(8, 8, 8, 8)
44#ifndef KSF_MQTT_TIMEOUT_MS
46#define KSF_MQTT_TIMEOUT_MS 4000UL
49#ifndef KSF_WIFI_TIMEOUT_MS
51#define KSF_WIFI_TIMEOUT_MS 120000UL
54#ifndef KSF_WIFI_RECONNECT_TIME_MS
56#define KSF_WIFI_RECONNECT_TIME_MS 5000UL
59#ifndef KSF_WATCHDOG_TIMEOUT_SECS
61#define KSF_WATCHDOG_TIMEOUT_SECS 10UL
65#define KSF_FRAMEWORK_INIT() ksf::initializeFramework();
89 extern const char* getNvsDirectory();
94 extern void initializeFramework();
101 extern bool removeDirectory(
const char* path);
107 extern bool eraseConfigData();
112 extern void updateDeviceUptime();
118 extern uint64_t millis64();
128 extern std::string to_string(
double value,
const int base);
139 extern std::string to_string(
float value,
const int base);
149 template <
typename _Type>
150 inline std::string to_string(
const _Type& input)
152 return std::to_string(input);
162 inline std::string to_hex(
int value)
168 unsigned int uvalue{
static_cast<unsigned int>(value)}, pos{8};
172 unsigned int nibble{uvalue & 0xf};
173 buffer[--pos] = (nibble < 10) ? (
'0' + nibble) : (
'a' + (nibble - 10));
177 return std::string(buffer + pos, 8 - pos);
190 template <
typename _In,
typename _Out>
191 bool from_chars(
const _In& input, _Out& out)
193 const auto& result{std::from_chars(input.data(), input.data() + input.size(), out)};
194 return result.ec == std::errc();
205 std::string getDeviceUuidHex();
215 extern EOTAType::Type getOtaBootType();
224 extern void saveOtaBootIndicator(EOTAType::Type type = EOTAType::OTA_GENERIC);
237 template<
class _Type1,
class _Type2>
238 inline bool starts_with(
const _Type1& input,
const _Type2& match)
240 return input.size() >= match.size() && std::equal(match.begin(), match.end(), input.begin());
246 extern const std::string getResetReason();
253 extern const std::string getUptimeFromSeconds(uint32_t seconds);
259 extern const std::string getUptimeString();
266 extern void loadCredentials(std::string& ssid, std::string& password);
273 extern void saveCredentials(std::string ssid, std::string password);