Beispiel #1
0
static boolean getconfig_handler(TinyWebServer& web_server)
{
	web_server.send_error_code(200);
	web_server.send_content_type("text/xml");
	web_server.end_headers();
	web_server << IP_Config.toXML();
	return true;
}
Beispiel #2
0
static boolean file_handler(TinyWebServer& web_server)
{
	const char *path = web_server.get_path();
	Serial << "GET " << path << '\n';

	if (strcmp(path, "/") == 0) path = "/index.html";

	const struct httpd_fsdata_segment *segment;
	int len;
	bool use_gzip;

	if (find_file(path, &segment, &len, &use_gzip)) {
		web_server.send_error_code(200);
		web_server.send_last_modified("Wed, 21 Oct 2015 07:28:00 GMT");
		web_server.send_content_type(web_server.get_mime_type_from_filename(path));
		if (use_gzip) web_server.write("Content-Encoding: gzip\n");
		web_server.end_headers(); 
	
		while (segment && len > 0) {
			char *data = (char *)pgm_read_word(&(segment->data));
			int i;
			int segment_len = min(len, httpd_fsdata_segment_len);
			
			while (segment_len > 0) {
				uint8_t buf[256];
				int i;
				for (i = 0; i < segment_len && i < sizeof(buf); i++) {
					buf[i] = pgm_read_byte(data++);
				}
				segment_len -= i;
				len -= i;
				web_server.write(buf, i);
			}
			segment = (const struct httpd_fsdata_segment *)pgm_read_word(&(segment->next));
		}
	}
	else {
		web_server.send_error_code(404);
		web_server.send_content_type("text/plain");
		web_server.end_headers();
		web_server.print("not found");
	}

	return true;
}
Beispiel #3
0
static boolean reboot_handler(TinyWebServer& web_server)
{
	web_server.send_error_code(200);
	web_server.send_content_type("text/plain");
	web_server.end_headers();
	web_server.write("rebooting");
	doReset = true;
	return true;
}
Beispiel #4
0
static boolean reboot_handler(TinyWebServer& web_server)
{
	web_server.send_error_code(200);
	web_server.send_content_type("text/html");
	web_server.end_headers();
	Client& client = web_server.get_client();
	client << F("<html><body><pre><a href='/reboot_confirm'>Please confirm reboot</a>\n<a href='/'>Cancel</a></pre></body></html>");
	return true;
}
Beispiel #5
0
static boolean index_handler(TinyWebServer& web_server)
{
	D(Serial.println("GET index.html"));
	web_server.send_error_code(200);
	web_server.send_content_type("text/html");
	web_server.end_headers();
	Client& client = web_server.get_client();
	main_page(client);
	return true;
}
Beispiel #6
0
static boolean getstate_handler(TinyWebServer& web_server)
{
	web_server.send_error_code(200);
	web_server.send_content_type("text/xml");
	web_server.send_content_type("Connection: keep-alive");
	web_server.end_headers();

	manage_toggle(web_server.get_path());
	manage_setvalue(web_server.get_path());
	Client& stream = web_server.get_client();
	lduino.XML_State(stream);
	return true;
}
Beispiel #7
0
static boolean reboot_confirm_handler(TinyWebServer& web_server)
{
	web_server.send_error_code(200);
	web_server.send_content_type("text/html");
	web_server.end_headers();

	Client& client = web_server.get_client();
	String str((__FlashStringHelper *)reboot_confirm_html_flash);
	str.replace("%ip", IP2Ascii(Ethernet.localIP()));
	client << str;

	doReset = true;
	return true;
}
Beispiel #8
0
boolean put_handler(TinyWebServer& web_server) {
  web_server.send_error_code(200);
  web_server.end_headers();

  const char* length_str = web_server.get_header_value("Content-Length");
  long length = atol(length_str);
  uint32_t start_time = 0;
  boolean watchdog_start = false;

  EthernetClient client = web_server.get_client();

  if (put_handler_fn) {
    (*put_handler_fn)(web_server, START, NULL, length);
  }

  uint32_t i;
  for (i = 0; i < length && client.connected();) {
    int16_t size = read_chars(web_server, client, (uint8_t*)buffer, 64);
    if (!size) {
      if (watchdog_start) {
        if (millis() - start_time > 30000) {
          // Exit if there has been zero data from connected client
          // for more than 30 seconds.
#if DEBUG
          Serial << F("TWS:There has been no data for >30 Sec.\n");
#endif
          break;
        }
      } else {
        // We have hit an empty buffer, start the watchdog.
        start_time = millis();
        watchdog_start = true;
      }
      continue;
    }
    i += size;
    // Ensure we re-start the watchdog if we get ANY data input.
    watchdog_start = false;

    if (put_handler_fn) {
      (*put_handler_fn)(web_server, WRITE, buffer, size);
    }
  }
  if (put_handler_fn) {
    (*put_handler_fn)(web_server, END, NULL, 0);
  }

  return true;
}
Beispiel #9
0
static boolean config_handler(TinyWebServer& web_server) 
{
	web_server.send_error_code(200);
	web_server.end_headers();

	const char* length_str = web_server.get_header_value("Content-Length");
	int length = atoi(length_str);
	uint32_t start_time = millis();
	StringParse buf;

	EthernetClient client = web_server.get_client();

	while (buf.length() < length && client.connected() && (millis() - start_time < 30000)) {
		if (!client.available()) continue;
		buf += client.readString();
	}

	ParseConfig(buf);
	IP_Config.SaveConfig();

	main_page(client, F("<font color='green'>IP Config saved</font>"));

	return true;
}