   analogWrite(GREEN_PIN, blink_on ? (lost ? 0 : green) : 0);
   analogWrite(BLUE_PIN, blink_on ? (lost ? 0 : blue) : 0);
 
-  digitalWrite(SPEAKER_PIN, ( ms < stop_beep_ms )
-                        && ( (micros() & BEEP_US) < BEEP_US/2) );
+  digitalWrite(SPEAKER_PIN, ( ms < stop_buzz_ms )
+                        && ( (micros() & BUZZ_US) < BUZZ_US/2) );
 }
 
-boolean help_handler(TinyWebServer& web_server)
-{
+static void handler_response_common(TinyWebServer& web_server) {
   web_server.send_error_code(200);
-  web_server.send_content_type("text/html");
   web_server.end_headers();
-  web_server << F("<html><body><h1>Space Probe Has A Web Thingy</h1><ul>")
-             << F("<li>GET /knob -> read knob position</li>")
-             << F("<li>POST /leds -> set LEDs, postdata has keys R,G,B,on_duty,off_duty</li>")
-             << F("<li>POST /gauge -> set Gauge position, postdata is number</li>")
-             << F("<li>POST /beep -> Beep, postdata is length</li>")
-             << F("</ul></body></html>\n");
   last_cmd_ms = millis();
+}
+
+boolean alive_handler(TinyWebServer& web_server){
+  handler_response_common(web_server);
+  web_server << F("OK");
   return true;
 }
 
 boolean knob_handler(TinyWebServer& web_server)
 {
-  web_server.send_error_code(200);
-  web_server.end_headers();
-  web_server << knob_pos << "\n";
-  last_cmd_ms = millis();
+  handler_response_common(web_server);
+  web_server << knob_pos;
   return true;
 }
 
 boolean set_leds_handler(TinyWebServer& web_server)
 {
-  //sscanf(&cmd_buf[1], "%04d,%04d,%04d,%04d,%04d", &red, &green, &blue, &on_duty, &off_duty);
-  //Serial.println("Got new LED settings");
-  web_server.send_error_code(200);
-  web_server.end_headers();
-  web_server << "TBD";
+  char buf[40];
+
+  Client& client = web_server.get_client();
+  client.setTimeout(500);
+  client.readBytesUntil('\n',buf,40);
+
+  int r = sscanf(buf, "%04d,%04d,%04d,%04d,%04d", &red, &green, &blue, &on_duty, &off_duty);
+  if(r != 5) {
+    web_server.send_error_code(500);
+    web_server.end_headers();
+    web_server << F("Invalid LED string");
+  }
+  else {
+    handler_response_common(web_server);
+    web_server << F("OK");
+  }
   return true;
 }
 

/*
 * The Space Probe firmware is a very thin stub program, which speaks a
 * simple serial command/response protocol.
 *
 * All numbers <X> are transmitted as 4-digit decimal integers, regardless of scale.
 *
 * Commands:
 *
 * Cmd: L<R>,<G>,<B>,<O>,<F>\n
 * Rsp: OK\n
 *
 * Set LEDs R,G,B levels (0-255) with blink cylce <O>ms On then <F>ms off.
 *
 * ****
 *
 * Cmd: B<N>
 * Rsp: OK\n
 *
 * Beep for N milliseconds
 *
 * *****
 *
 * Cmd: D<N>\n
 * Rsp: OK\n
 *
 * Set dial gauge PWM output to <N> (0-255)
 *
 * *****
 *
 * Cmd: K\n
 * Rsp: <N>\n
 *
 * Read back knob position <N> (0-1023)
 *
 * *****
 *
 * Cmd: P\n
 * Rsp: OK\n
 *
 * Ping! Check the probe is still there. If the probe doesn't see any command (including ping)
 * for 5 seconds it'll start blinking the red LED quickly until it sees a response.
 */

#include <Ethernet.h>
#include <Flash.h>


long last_ms = 0;

boolean knob_handler(TinyWebServer& web_server);
boolean set_leds_handler(TinyWebServer& web_server);
boolean set_dial_handler(TinyWebServer& web_server);
boolean buzz_handler(TinyWebServer& web_server);
boolean alive_handler(TinyWebServer& web_server);

TinyWebServer::PathHandler handlers[] = {
  // Register the index_handler for GET requests on /
  {"/", TinyWebServer::GET, &help_handler },
  {"/is_alive", TinyWebServer::GET, &alive_handler },
  {"/knob", TinyWebServer::GET, &knob_handler },
  {"/leds", TinyWebServer::POST, &set_leds_handler },
  {"/dial", TinyWebServer::POST, &set_dial_handler },
  {"/buzz", TinyWebServer::POST, &buzz_handler },
  {NULL}, // The array has to be NULL terminated this way
};

