Compare commits

...

3 Commits

1 changed files with 10 additions and 9 deletions

View File

@ -2,7 +2,7 @@
//
// server.h
// Call server_init() to start up an http webserver.
// listens on '/' for POST queries with a url query format like
// listens on '/' for GET queries with a url query format like
// ?l=*&r0=*&g0=*&b0=*&a0=*&t0=* ... &rl=*&gl=*&bl=*&al=*&tl=*
// Where l is the number of points on a gradient. And each point of the gradient has a r* g* b* a* and t* where * is the index.
// r g and b are the red green and blue 8-bit colour components of a point on the gradient. A is the 5-bit global component of the led at that point.
@ -40,7 +40,7 @@ void parse_leds_query(char* query_string, size_t query_size) {
return;
}
struct gradient_point_t* points = malloc(gradient_point_count * sizeof(union led_t));
struct gradient_point_t* points = malloc(gradient_point_count * sizeof(struct gradient_point_t));
for(int point = 0; point < gradient_point_count; ++point) {
sprintf(query_key, "r%d", point);
@ -73,12 +73,12 @@ void parse_leds_query(char* query_string, size_t query_size) {
}
leds_set_gradient(points, gradient_point_count, 0);
leds_set_gradient(points, gradient_point_count, 1);
}
// receives HTTP POST requests on root
// receives HTTP GET requests on root
static
esp_err_t on_http_post(httpd_req_t* request) {
esp_err_t on_http_get_root(httpd_req_t* request) {
LOGLN("POST received on '/'.");
char* buffer;
@ -99,10 +99,10 @@ esp_err_t on_http_post(httpd_req_t* request) {
return ESP_OK;
}
httpd_uri_t post = {
httpd_uri_t get_root_uri = {
.uri="/",
.method=HTTP_POST,
.handler=&on_http_post,
.method=HTTP_GET,
.handler=&on_http_get_root,
.user_ctx = NULL
};
@ -113,8 +113,9 @@ httpd_handle_t start_webserver(void) {
httpd_config_t server_config = HTTPD_DEFAULT_CONFIG();
LOGLN("Starting HTTPd server ':%d'.", server_config.server_port);
if(httpd_start(&server, &server_config) == ESP_OK) {
httpd_register_uri_handler(server, &post);
httpd_register_uri_handler(server, &get_root_uri);
return server;
}