Example #1
0
void ICACHE_FLASH_ATTR
errorResponse(HttpdConnData *connData, int code, char *message) {
    noCacheHeaders(connData, code);
    httpdEndHeaders(connData);
    httpdSend(connData, message, -1);
#ifdef CGI_DBG
    os_printf("HTTP %d error response: \"%s\"\n", code, message);
#endif
}
Example #2
0
int ICACHE_FLASH_ATTR cgiMenu(HttpdConnData *connData) {
  if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up.
  char buff[1024];
  // don't use jsonHeader so the response does get cached
  noCacheHeaders(connData, 200);
  httpdHeader(connData, "Content-Type", "application/json");
  httpdEndHeaders(connData);
  // limit hostname to 12 chars
  char name[13];
  os_strncpy(name, flashConfig.hostname, 12);
  name[12] = 0;
  // construct json response
  //  limit menu dependend on menu level
  if( flashConfig.menu_level > 0)
	 os_sprintf(buff,
    "{ "
      "\"menu\": [ "
        "\"goDMD\", \"/godmd/index.html\", "
        "\"Home\", \"/home.html\", "
        "\"WiFi Station\", \"/wifi/wifiSta.html\", "
        "\"WiFi Soft-AP\", \"/wifi/wifiAp.html\", "
        "\"µC Console\", \"/console.html\", "
        "\"Services\", \"/services.html\", "
#ifdef MQTT
        "\"REST/MQTT\", \"/mqtt.html\", "
#endif
        "\"Debug log\", \"/log.html\","
        "\"Upgrade Firmware\", \"/flash.html\","
        "\"Web Server\", \"/web-server.html\""
	"%s"
      " ], "
      "\"version\": \"%s\", "
      "\"name\": \"%s\""
    " }",
	WEB_UserPages(), esp_link_version, name);
  else
	 os_sprintf(buff,
	"{ "
	  "\"menu\": [ "
		"\"goDMD\", \"/godmd/index.html\", "
		"\"Home\", \"/home.html\", "
		"\"WiFi Station\", \"/wifi/wifiSta.html\", "
		"\"WiFi Soft-AP\", \"/wifi/wifiAp.html\", "
		"\"Upgrade Firmware\", \"/flash.html\""
	"%s"
	  " ], "
	  "\"version\": \"%s\", "
	  "\"name\": \"%s\""
	" }",
	WEB_UserPages(), esp_link_version, name);


  httpdSend(connData, buff, -1);
  return HTTPD_CGI_DONE;
}
Example #3
0
void ICACHE_FLASH_ATTR jsonHeader(HttpdConnData *connData, int code) {
  noCacheHeaders(connData, code);
  httpdHeader(connData, "Content-Type", "application/json");
  httpdEndHeaders(connData);
}