+/*
+ * Reply to client the request string.
+ */
+static int cgi_led(struct netconn *client, const char *name, char *revc_buf, size_t revc_len)
+{
+ (void)name;
+
+ http_sendOk(client);
+ netconn_write(client, revc_buf, revc_len, NETCONN_COPY);
+ return 0;
+}
+
+/*
+ * Reply to client the request string.
+ */
+static int cgi_echo(struct netconn *client, const char *name, char *revc_buf, size_t revc_len)
+{
+ (void)name;
+
+ http_sendOk(client);
+ netconn_write(client, revc_buf, revc_len, NETCONN_COPY);
+ return 0;
+}
+
+
+
+/*
+ * Default function that http server call every client request, if it doesn't match a cgi table.
+ * In this implementation all client request are associate to real file stored on FAT file
+ * sistem on SD card. If the file there is not on SD card the server reply to client the
+ * error File not found, and send an harcoded page. In the same way, the server reply
+ * error page if the SD card is not present.
+ *
+ */
+static int http_htmPageLoad(struct netconn *client, const char *name, char *revc_buf, size_t revc_len)
+{
+ (void)revc_buf;
+ (void)revc_len;
+
+ if (SD_CARD_PRESENT())
+ {
+
+ // SD fat filesystem context
+ Sd sd;
+ FATFS fs;
+ FatFile in_file;
+ FRESULT result;
+
+ bool sd_ok = sd_init(&sd, NULL, 0);
+ if (sd_ok)
+ {
+ LOG_INFO("Mount FAT filesystem.\n");
+ result = f_mount(0, &fs);
+ if (result != FR_OK)
+ {
+ LOG_ERR("Mounting FAT volumes error[%d]\n", result);
+ sd_ok = false;
+ f_mount(0, NULL);
+ }
+
+ if (sd_ok)
+ {
+ result = fatfile_open(&in_file, name, FA_OPEN_EXISTING | FA_READ);
+
+ size_t count = 0;
+ if (result == FR_OK)
+ {
+ LOG_INFO("Opened file '%s' size %ld\n", name, in_file.fat_file.fsize);
+
+ http_sendOk(client);
+
+ while (count < in_file.fat_file.fsize)
+ {
+ int len = kfile_read(&in_file.fd, tx_buf, sizeof(tx_buf));
+ netconn_write(client, tx_buf, len, NETCONN_COPY);
+ count += len;
+ }
+
+ kfile_flush(&in_file.fd);
+ kfile_close(&in_file.fd);
+
+ LOG_INFO("Sent: %d\n", count);
+ }
+ else
+ {
+ LOG_ERR("Unable to open file: '%s' error[%d]\n", name, result);
+ http_sendFileNotFound(client);
+ netconn_write(client, http_file_not_found, http_file_not_found_len - 1, NETCONN_NOCOPY);
+ }
+ }
+ }
+ f_mount(0, NULL);
+ LOG_INFO("Umount FAT filesystem.\n");
+ }
+ else
+ {
+ http_sendFileNotFound(client);
+ netconn_write(client, http_sd_not_present, http_sd_not_present_len, NETCONN_NOCOPY);
+ }
+
+ return 0;
+}
+
+/*
+ * Return to client a string that display the CHIP ID information.
+ * See datasheet for more detail.
+ */
+static int cgi_chipInfo(struct netconn *client, const char *name, char *revc_buf, size_t revc_len)