Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
E
esp32-http-server
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
esp
esp32-http-server
Commits
7b736437
Commit
7b736437
authored
Feb 12, 2018
by
Tiago Medicci
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
GET method example added
parent
ec07ec13
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
0 deletions
+54
-0
http_server.c
http_server.c
+44
-0
http_server.h
http_server.h
+10
-0
No files found.
http_server.c
View file @
7b736437
...
@@ -111,6 +111,22 @@ static esp_err_t add_keyval_pair(http_header_list_t *list, const char* name, con
...
@@ -111,6 +111,22 @@ static esp_err_t add_keyval_pair(http_header_list_t *list, const char* name, con
static
const
char
*
TAG
=
"http_server"
;
static
const
char
*
TAG
=
"http_server"
;
const
static
char
index_html
[]
=
"<!DOCTYPE html>"
"<html>
\n
"
"<head>
\n
"
" <meta name=
\"
viewport
\"
content=
\"
width=device-width, initial-scale=1
\"
>
\n
"
" <style type=
\"
text/css
\"
>
\n
"
" html, body, iframe { margin: 0; padding: 0; height: 100%; }
\n
"
" iframe { display: block; width: 100%; border: none; }
\n
"
" </style>
\n
"
"<title>HELLO ESP32</title>
\n
"
"</head>
\n
"
"<body>
\n
"
"<h1>Hello World, from ESP32!</h1>
\n
"
"</body>
\n
"
"</html>
\n
"
;
esp_err_t
http_register_handler
(
http_server_t
server
,
esp_err_t
http_register_handler
(
http_server_t
server
,
const
char
*
uri_pattern
,
int
method
,
const
char
*
uri_pattern
,
int
method
,
int
events
,
http_handler_fn_t
callback
,
void
*
callback_arg
)
int
events
,
http_handler_fn_t
callback
,
void
*
callback_arg
)
...
@@ -818,3 +834,31 @@ esp_err_t http_server_stop(http_server_t server)
...
@@ -818,3 +834,31 @@ esp_err_t http_server_stop(http_server_t server)
free
(
server
);
free
(
server
);
return
ESP_OK
;
return
ESP_OK
;
}
}
static
void
cb_GET_method
(
http_context_t
http_ctx
,
void
*
ctx
)
{
size_t
response_size
=
strlen
(
index_html
);
http_response_begin
(
http_ctx
,
200
,
"text/html"
,
response_size
);
http_buffer_t
http_index_html
=
{
.
data
=
index_html
};
http_response_write
(
http_ctx
,
&
http_index_html
);
http_response_end
(
http_ctx
);
}
esp_err_t
simple_GET_method_example
(
void
)
{
http_server_t
server
;
http_server_options_t
http_options
=
HTTP_SERVER_OPTIONS_DEFAULT
();
esp_err_t
res
;
res
=
http_server_start
(
&
http_options
,
&
server
);
if
(
res
!=
ESP_OK
)
{
return
res
;
}
res
=
http_register_handler
(
server
,
"/"
,
HTTP_GET
,
HTTP_HANDLE_RESPONSE
,
&
cb_GET_method
,
NULL
);
if
(
res
!=
ESP_OK
)
{
return
res
;
}
return
res
;
}
http_server.h
View file @
7b736437
...
@@ -285,6 +285,16 @@ esp_err_t http_response_write(http_context_t http_ctx, const http_buffer_t* buff
...
@@ -285,6 +285,16 @@ esp_err_t http_response_write(http_context_t http_ctx, const http_buffer_t* buff
*/
*/
esp_err_t
http_response_end
(
http_context_t
http_ctx
);
esp_err_t
http_response_end
(
http_context_t
http_ctx
);
/**
* @brief Example of GET method. Responding a simple "Hello World" html. All initializations included.
* @param none
* @return
* - ESP_OK on success
* - other errors in the future?
*/
esp_err_t
simple_GET_method_example
(
void
);
#ifdef __cplusplus
#ifdef __cplusplus
}
}
#endif
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment