void parseHttp() { String line = Serial.readStringUntil('\n'); if (line.startsWith("Content-Length: ")) { sscanf(line.c_str() + 16, "%d", &contentLength); } else if (line.startsWith("GET")) { method = GET; path = parsePath(line); } else if (line.startsWith("PUT")) { method = PUT; path = parsePath(line); } else if (line == "\r") { if (path.startsWith("/reset")) { sendResponse(200); setup(); } else if (path.startsWith("/sensors") && method == GET) { getSensors(); } else if (path.startsWith("/leds") && (method == GET)) { getLeds(); } else if (path.startsWith("/leds") && (method == PUT)) { putLeds(); } else if (path.startsWith("/settings") && (method == GET)) { getSettings(); } else if (path.startsWith("/settings") && (method == PUT)) { putSettings(); } else { sendResponse(404); } contentLength = 0; } }
int main(void) { unsigned int b; unsigned char c; init_all(); lcd_puts("Ready.", FIRST); for(;;) { /* * Get received character from ringbuffer * uart_getc() returns in the lower byte the received character and * in the higher byte (bitmask) the last receive error * UART_NO_DATA is returned when no data is available. * */ b = uart_getc(); if ( b & UART_NO_DATA ) { /* * no data available from UART */ } else { /* * new data available from UART * check for Frame or Overrun error */ if ( b & UART_FRAME_ERROR ) { /* Framing Error detected, i.e no stop bit detected */ lcd_puts("UART Frame Error", FIRST); } if ( b & UART_OVERRUN_ERROR ) { /* * Overrun, a character already present in the UART UDR register was * not read by the interrupt handler before the next character arrived, * one or more received characters have been dropped */ lcd_puts("UART Overrun Error", FIRST); } if ( b & UART_BUFFER_OVERFLOW ) { /* * We are not reading the receive buffer fast enough, * one or more received character have been dropped */ lcd_puts("Buffer overflow error", FIRST); } /* * send received character back */ c = (unsigned char) b; switch(c) { case 0x16: uart_putc(button); button = 0; break; case 0x00: break; case 0x07: //BELL beep(); //BEEP!!! break; case 0x11: //DEVICE CONTROL 1 setLeds(getLeds() ^ RED); //rote LED togglen break; case 0x12: //DEVICE CONTROL 2 setLeds(getLeds() ^ GREEN); //gruene LED togglen break; case 0x13: //DEVICE CONTROL 3 lcd_clearLine(FIRST); //Erste Zeile leeren und ab da schreiben break; case 0x14: //DEVICE CONTROL 4 lcd_clearLine(SECOND); //Zweite Zeile leeren und ab da schreiben break; default: // Normales Zeichen lcd_putc(c); //Zeichen schreiben break; } } } return 0; }