int x2i(char *s) { int x = 0; for(;;) { char c = *s; if (c >= '0' && c <= '9') { x *= 16; x += c - '0'; } else if (c >= 'A' && c <= 'F') { x *= 16; x += (c - 'A') + 10; } else if (c >= 'a' && c <= 'f') { x *= 16; x += (c - 'a') + 10; } else break; s++; } return x; } void explode(String s, String delimiter, String arr[], int ARR_LEN) { // by timemage on #arduino/freenode unsigned part_begin = 0; for (size_t i = 0; i < ARR_LEN; ++i) { const auto delim_index = s.indexOf(delimiter, part_begin); const auto part_end = (delim_index >= 0) ? delim_index : s.length(); arr[i] = s.substring(part_begin, part_end); if (delim_index >= 0) { part_begin = delim_index + delimiter.length(); } } } int pin2gpio(String in) { in.toUpperCase(); if (in == "A0") return int(A0); if (in == "D0") return int(D0); if (in == "D1") return int(D1); if (in == "D2") return int(D2); if (in == "D3") return int(D3); if (in == "D4") return int(D4); if (in == "D5") return int(D5); if (in == "D6") return int(D6); if (in == "D7") return int(D7); if (in == "D8") return int(D8); return in.toInt();// fallback to gpio } String getContentType(String filename) { // convert the file extension to the MIME type if (filename.endsWith(".html")) return "text/html"; else if (filename.endsWith(".css")) return "text/css"; else if (filename.endsWith(".js")) return "application/javascript"; else if (filename.endsWith(".ico")) return "image/x-icon"; else if (filename.endsWith(".jpg")) return "image/jpeg"; else if (filename.endsWith(".jpeg")) return "image/jpeg"; else if (filename.endsWith(".txt")) return "text/plain"; else if (filename.endsWith(".pdf")) return "application/pdf"; else if (filename.endsWith(".png")) return "image/png"; else if (filename.endsWith(".zip")) return "application/zip"; else if (filename.endsWith(".ttf")) return "font/ttf"; else if (filename.endsWith(".gif")) return "image/gif"; else if (filename.endsWith(".mp3")) return "application/ogg"; else if (filename.endsWith(".ogg")) return "application/ogg"; else if (filename.endsWith(".mp4")) return "application/ogg"; else if (filename.endsWith(".gz")) return "application/x-gzip"; else if (filename.endsWith(".xml")) return "text/xml"; else if (filename.endsWith(".svg")) return "text/svg+xml"; return "application/octet-stream"; } bool writefile(String filepath, String contents) { File file = SPIFFS.open(filepath, "w"); if (!file) { return false; } int bytesWritten = file.print(String(contents)); if (bytesWritten == 0) { return false; } file.close(); return true; } String readfile(String filepath) { File file = SPIFFS.open(filepath, "r"); if (!file) { return ""; } String filecontents; while (file.available()) { filecontents += char(file.read()); } file.close(); return filecontents; } String fihr(int code, String text) { // format inline html response return "