mirror of
https://github.com/cesanta/mongoose.git
synced 2026-10-26 12:14:56 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
62c896a872 | ||
|
|
2db07dfc3b | ||
|
|
34eb3f1e66 | ||
|
|
9d30e892e9 | ||
|
|
0aaba7a461 | ||
|
|
3d6b568c6e | ||
|
|
2b2816cfe4 | ||
|
|
2fa18b47db | ||
|
|
c8af7cdd27 | ||
|
|
f857f6394f | ||
|
|
97d733e129 | ||
|
|
77e44c7c0e | ||
|
|
abf89d32d9 | ||
|
|
177e05deb2 | ||
|
|
eb5645241c | ||
|
|
202300952c | ||
|
|
c7bea65ae7 | ||
|
|
d5a9000d46 | ||
|
|
f62018451f | ||
|
|
0a93e301c9 | ||
|
|
6fe9cae62a | ||
|
|
38e984a008 | ||
|
|
09e4254718 | ||
|
|
d4b55c4ceb | ||
|
|
7d5479985d | ||
|
|
6517af3dea | ||
|
|
7632a5e4af | ||
|
|
7f20c41dd5 | ||
|
|
66b23b11b0 | ||
|
|
448b44094a | ||
|
|
8bbb44f90c | ||
|
|
0fba87c755 | ||
|
|
fea648496c | ||
|
|
944a6b761c | ||
|
|
f1ae183752 | ||
|
|
a0ece4e969 | ||
|
|
0bb14abbdd | ||
|
|
4c37e49274 | ||
|
|
2a2bc33a89 | ||
|
|
41558bbf64 | ||
|
|
4d0cc95ff4 | ||
|
|
cfd28a4f7a | ||
|
|
5a0b6fc35a | ||
|
|
3e59e1c465 | ||
|
|
ae611a6e55 | ||
|
|
a7a2e3deb1 | ||
|
|
cae0a1cbc0 | ||
|
|
244e5f67d3 | ||
|
|
ff078882d5 | ||
|
|
8d76733fad | ||
|
|
fb3a5a7d90 | ||
|
|
f374ac5f9a | ||
|
|
02707364f0 | ||
|
|
104106b9cf | ||
|
|
474e065a30 | ||
|
|
27094896b1 | ||
|
|
cd48bcfd7d | ||
|
|
5baeba53d7 | ||
|
|
3a3b433849 | ||
|
|
a2192ae483 | ||
|
|
023b55f2e5 | ||
|
|
e4309d472b | ||
|
|
c5452fc2ec | ||
|
|
f78ee9d42e | ||
|
|
c8416cc17d | ||
|
|
cf0a969a65 | ||
|
|
06670d3401 | ||
|
|
acfc66cd60 | ||
|
|
6f140202ad | ||
|
|
cfe77a3d58 | ||
|
|
a0527a7f0e | ||
|
|
c90cffa688 | ||
|
|
d7a633bfa3 | ||
|
|
0ea3cdd228 | ||
|
|
ddef065493 | ||
|
|
ac857d18db | ||
|
|
663e928d65 | ||
|
|
189cd8c5f6 | ||
|
|
692f436b3d | ||
|
|
2e65ce8272 | ||
|
|
a35e5bd966 | ||
|
|
83fe5a17f3 | ||
|
|
49bbfaf130 | ||
|
|
cd9c7dcbec | ||
|
|
f868fc861b | ||
|
|
84907d5bc4 | ||
|
|
1cee8a16b9 | ||
|
|
57e32b87c7 | ||
|
|
6926655513 | ||
|
|
8354319e72 | ||
|
|
f9596cc1db | ||
|
|
b2e2ad9a45 | ||
|
|
a07fb2be51 | ||
|
|
7f259f2a79 | ||
|
|
7c0493071f | ||
|
|
c60fe0c6f6 | ||
|
|
8ce34af9f3 | ||
|
|
82761bb875 | ||
|
|
08a10a8af5 | ||
|
|
bd130136bc | ||
|
|
fb04203b72 | ||
|
|
4172c190e5 | ||
|
|
920abd627b | ||
|
|
02b7399f9a | ||
|
|
b8402ed073 | ||
|
|
06c5c4d2a4 | ||
|
|
57a4ec31d1 | ||
|
|
511c9a6d4a | ||
|
|
8ec47111d5 | ||
|
|
8b67274cc0 | ||
|
|
af22fb7a06 | ||
|
|
df5fff5e72 | ||
|
|
d9243d1c0b | ||
|
|
2fb145d39d | ||
|
|
14094aaef7 | ||
|
|
ec752645ee | ||
|
|
ceb2f1da41 | ||
|
|
aab857a66e | ||
|
|
066be0fe30 | ||
|
|
380e87ddfa | ||
|
|
e9a7a2af18 | ||
|
|
a83e7d8c42 | ||
|
|
bf7dd7ac63 | ||
|
|
0fc3370859 | ||
|
|
c416012f97 | ||
|
|
d3a8862bd8 | ||
|
|
08353731ef | ||
|
|
16700244b0 | ||
|
|
49ca223e9c | ||
|
|
38efe632ae | ||
|
|
39a3bb7e44 | ||
|
|
920e8d9145 | ||
|
|
aed6d05d8c | ||
|
|
d85d95a40b | ||
|
|
b5dd54a404 | ||
|
|
f7c0a2ee15 | ||
|
|
874b5bfdbf | ||
|
|
71d09722be | ||
|
|
349d25dccf | ||
|
|
3942914945 | ||
|
|
60c16bbb5d | ||
|
|
70b5f4130e | ||
|
|
17cfecc5c3 | ||
|
|
ebdd18769b | ||
|
|
f974fddd2a | ||
|
|
b1a46da309 | ||
|
|
81879be4be | ||
|
|
0a094d4c1f | ||
|
|
66a96410d4 | ||
|
|
d4b23f08b6 | ||
|
|
d6d956b9d8 | ||
|
|
383b2a48c5 | ||
|
|
ab1c464950 | ||
|
|
f20b5191f2 | ||
|
|
fc113d64f5 | ||
|
|
6f6b12bee7 | ||
|
|
4e6c2867da | ||
|
|
54989e819a | ||
|
|
bf505bb68d | ||
|
|
4072062b72 | ||
|
|
d6ba37dc3c | ||
|
|
a58d21aa28 | ||
|
|
6e8d4129b2 | ||
|
|
2485a8f8d9 | ||
|
|
1ae908f6d5 | ||
|
|
6b923bdff1 | ||
|
|
d39969d1e6 | ||
|
|
eaef5bd133 | ||
|
|
7cc7df8c0e | ||
|
|
551f393da7 | ||
|
|
e81f8373a2 | ||
|
|
dfa83f2c85 | ||
|
|
91bdbc5193 | ||
|
|
707b9ed2d6 | ||
|
|
cd6b846e22 | ||
|
|
807e4ea6ec | ||
|
|
507e8bfac9 | ||
|
|
2ea63a0ea6 | ||
|
|
7988acbff4 | ||
|
|
b8c3740446 | ||
|
|
7bdbd80552 | ||
|
|
577ad2599c |
No files matched your search
@@ -0,0 +1,9 @@
|
|||||||
|
binary/
|
||||||
|
deps/
|
||||||
|
docker/
|
||||||
|
docs/
|
||||||
|
examples/
|
||||||
|
platforms/
|
||||||
|
src/
|
||||||
|
test/
|
||||||
|
multilingual/
|
||||||
@@ -8,18 +8,18 @@ used by vast number of open source and
|
|||||||
commercial products - it even runs on the International Space station!
|
commercial products - it even runs on the International Space station!
|
||||||
Mongoose makes embedded network programming fast, robust, and easy.
|
Mongoose makes embedded network programming fast, robust, and easy.
|
||||||
|
|
||||||
- [Download Mongoose Source Code here](https://www.cesanta.com)
|
- [Download Mongoose Source Code here](https://www.cesanta.com/download.html)
|
||||||
|
|
||||||
Looking for a complete IoT firmware solution?
|
Looking for a complete IoT firmware solution?
|
||||||
|
|
||||||
Check out [Mongoose OS](https://mongoose-iot.com) - open source embedded operating system for low-power connected microcontrollers. Secure, designed for Internet of Things, complete environment for prototyping, development and managing.
|
Check out [Mongoose OS](https://mongoose-os.com) - open source embedded operating system for low-power connected microcontrollers. Secure, designed for Internet of Things, complete environment for prototyping, development and managing.
|
||||||
|
|
||||||
# Support
|
# Support
|
||||||
- [Study mongoose example code](https://github.com/cesanta/mongoose/tree/master/examples)
|
- [Study mongoose example code](https://github.com/cesanta/mongoose/tree/master/examples)
|
||||||
- [Read User Guide and API reference](https://docs.cesanta.com/mongoose)
|
- [Read User Guide and API reference](https://docs.cesanta.com/mongoose)
|
||||||
- [Support Forum - ask your technical questions here] (http://forum.cesanta.com/index.php?p=/categories/mongoose)
|
- [Support Forum - ask your technical questions here](https://forum.mongoose-os.com/categories/mongoose)
|
||||||
- [Commercial licensing and support available] (https://www.cesanta.com/services-support)
|
- [Commercial licensing and support available](https://www.cesanta.com/licensing.html)
|
||||||
- [Check our latest releases] (https://github.com/cesanta/mongoose/releases)
|
- [Check our latest releases](https://github.com/cesanta/mongoose/releases)
|
||||||
|
|
||||||
# Features
|
# Features
|
||||||
|
|
||||||
@@ -47,7 +47,7 @@ Check out [Mongoose OS](https://mongoose-iot.com) - open source embedded operati
|
|||||||
|
|
||||||
Mongoose is released under Commercial and [GNU GPL v.2](http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) open source licenses.
|
Mongoose is released under Commercial and [GNU GPL v.2](http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) open source licenses.
|
||||||
|
|
||||||
Commercial Projects: [Contact us for commercial license.] (https://www.cesanta.com/contact)
|
Commercial Projects: [Contact us for commercial license.](https://www.cesanta.com/contact.html)
|
||||||
|
|
||||||
# Dashboard Example
|
# Dashboard Example
|
||||||
|
|
||||||
@@ -55,18 +55,14 @@ Mongoose is often used to implement device dashboards and real-time
|
|||||||
data exchange over Websocket. Here is a dashboard example that illustrates
|
data exchange over Websocket. Here is a dashboard example that illustrates
|
||||||
the functionality:
|
the functionality:
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
[Developing a new product? Contact us today to discuss how Mongoose can help.
|
[Developing a new product? Contact us today to discuss how Mongoose can help.](https://www.cesanta.com/contact.html)
|
||||||
](https://www.cesanta.com/contact)
|
|
||||||
|
|
||||||
# Contributions
|
# Contributions
|
||||||
|
|
||||||
To submit contributions, sign
|
To submit contributions, sign [Cesanta CLA](https://cesanta.com/cla.html)
|
||||||
[Cesanta CLA](https://docs.cesanta.com/contributors_la.shtml)
|
|
||||||
and send GitHub pull request. You retain the copyright on your contributions.
|
and send GitHub pull request. You retain the copyright on your contributions.
|
||||||
|
|
||||||
# Looking for a pre-compiled Mongoose web server Windows or Mac binary?
|
# Looking for a pre-compiled Mongoose web server Windows or Mac binary?
|
||||||
- [Download pre-compiled Mongoose web server binary.](https://www.cesanta.com/products/binary)
|
- [Download pre-compiled Mongoose web server binary.](https://www.cesanta.com/binary.html)
|
||||||
|
|
||||||
[](https://github.com/cesanta/mongoose)
|
|
||||||
@@ -7,5 +7,5 @@ signature: |
|
|||||||
---
|
---
|
||||||
|
|
||||||
Frees the memory allocated for options.
|
Frees the memory allocated for options.
|
||||||
If the cm paramater doesn't contain any option it does nothing.
|
If the cm parameter doesn't contain any option it does nothing.
|
||||||
|
|
||||||
@@ -21,5 +21,5 @@ This function doesn't update the `name` and `rdata` pointers in the `rr`
|
|||||||
struct because they might be invalidated as soon as the IO buffer grows
|
struct because they might be invalidated as soon as the IO buffer grows
|
||||||
again.
|
again.
|
||||||
|
|
||||||
Returns the number of bytes appened or -1 in case of error.
|
Returns the number of bytes appended or -1 in case of error.
|
||||||
|
|
||||||
@@ -11,6 +11,7 @@ items:
|
|||||||
- { name: mg_send_websocket_handshake.md }
|
- { name: mg_send_websocket_handshake.md }
|
||||||
- { name: mg_send_websocket_handshake2.md }
|
- { name: mg_send_websocket_handshake2.md }
|
||||||
- { name: mg_send_websocket_handshake3.md }
|
- { name: mg_send_websocket_handshake3.md }
|
||||||
|
- { name: mg_send_websocket_handshake3v.md }
|
||||||
- { name: mg_set_protocol_http_websocket.md }
|
- { name: mg_set_protocol_http_websocket.md }
|
||||||
- { name: mg_url_decode.md }
|
- { name: mg_url_decode.md }
|
||||||
- { name: struct_http_message.md }
|
- { name: struct_http_message.md }
|
||||||
|
|||||||
@@ -4,9 +4,8 @@ decl_name: "mg_connect_ws"
|
|||||||
symbol_kind: "func"
|
symbol_kind: "func"
|
||||||
signature: |
|
signature: |
|
||||||
struct mg_connection *mg_connect_ws(struct mg_mgr *mgr,
|
struct mg_connection *mg_connect_ws(struct mg_mgr *mgr,
|
||||||
mg_event_handler_t event_handler,
|
MG_CB(mg_event_handler_t event_handler,
|
||||||
const char *url, const char *protocol,
|
void *user_data);
|
||||||
const char *extra_headers);
|
|
||||||
---
|
---
|
||||||
|
|
||||||
Helper function that creates an outbound WebSocket connection.
|
Helper function that creates an outbound WebSocket connection.
|
||||||
|
|||||||
@@ -3,11 +3,8 @@ title: "mg_connect_ws_opt()"
|
|||||||
decl_name: "mg_connect_ws_opt"
|
decl_name: "mg_connect_ws_opt"
|
||||||
symbol_kind: "func"
|
symbol_kind: "func"
|
||||||
signature: |
|
signature: |
|
||||||
struct mg_connection *mg_connect_ws_opt(struct mg_mgr *mgr,
|
struct mg_connection *mg_connect_ws_opt(
|
||||||
mg_event_handler_t ev_handler,
|
struct mg_mgr *mgr, MG_CB(mg_event_handler_t ev_handler, void *user_data);
|
||||||
struct mg_connect_opts opts,
|
|
||||||
const char *url, const char *protocol,
|
|
||||||
const char *extra_headers);
|
|
||||||
---
|
---
|
||||||
|
|
||||||
Helper function that creates an outbound WebSocket connection
|
Helper function that creates an outbound WebSocket connection
|
||||||
|
|||||||
@@ -9,5 +9,6 @@ signature: |
|
|||||||
|
|
||||||
Sends multiple websocket frames.
|
Sends multiple websocket frames.
|
||||||
|
|
||||||
Like `mg_send_websocket_frame()`, but composes a frame from multiple buffers.
|
Like `mg_send_websocket_frame()`, but composes a frame from multiple
|
||||||
|
*buffers.
|
||||||
|
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
---
|
||||||
|
title: "mg_send_websocket_handshake3v()"
|
||||||
|
decl_name: "mg_send_websocket_handshake3v"
|
||||||
|
symbol_kind: "func"
|
||||||
|
signature: |
|
||||||
|
void mg_send_websocket_handshake3v(struct mg_connection *nc,
|
||||||
|
const struct mg_str path,
|
||||||
|
const struct mg_str host,
|
||||||
|
const struct mg_str protocol,
|
||||||
|
const struct mg_str extra_headers,
|
||||||
|
const struct mg_str user,
|
||||||
|
const struct mg_str pass);
|
||||||
|
---
|
||||||
|
|
||||||
|
Same as mg_send_websocket_handshake3 but with strings not necessarily
|
||||||
|
NUL-temrinated
|
||||||
|
|
||||||
@@ -13,6 +13,7 @@ Source string is specified by (`src`, `src_len`), and destination is
|
|||||||
(`dst`, `dst_len`). If `is_form_url_encoded` is non-zero, then
|
(`dst`, `dst_len`). If `is_form_url_encoded` is non-zero, then
|
||||||
`+` character is decoded as a blank space character. This function
|
`+` character is decoded as a blank space character. This function
|
||||||
guarantees to NUL-terminate the destination. If destination is too small,
|
guarantees to NUL-terminate the destination. If destination is too small,
|
||||||
then the source string is partially decoded and `-1` is returned. Otherwise,
|
then the source string is partially decoded and `-1` is returned.
|
||||||
|
*Otherwise,
|
||||||
a length of the decoded string is returned, not counting final NUL.
|
a length of the decoded string is returned, not counting final NUL.
|
||||||
|
|
||||||
@@ -5,6 +5,7 @@ symbol_kind: "struct"
|
|||||||
signature: |
|
signature: |
|
||||||
struct http_message {
|
struct http_message {
|
||||||
struct mg_str message; /* Whole message: request line + headers + body */
|
struct mg_str message; /* Whole message: request line + headers + body */
|
||||||
|
struct mg_str body; /* Message body. 0-length for requests with no body */
|
||||||
|
|
||||||
/* HTTP Request line (or HTTP response line) */
|
/* HTTP Request line (or HTTP response line) */
|
||||||
struct mg_str method; /* "GET" */
|
struct mg_str method; /* "GET" */
|
||||||
@@ -28,9 +29,6 @@ signature: |
|
|||||||
/* Headers */
|
/* Headers */
|
||||||
struct mg_str header_names[MG_MAX_HTTP_HEADERS];
|
struct mg_str header_names[MG_MAX_HTTP_HEADERS];
|
||||||
struct mg_str header_values[MG_MAX_HTTP_HEADERS];
|
struct mg_str header_values[MG_MAX_HTTP_HEADERS];
|
||||||
|
|
||||||
/* Message body */
|
|
||||||
struct mg_str body; /* Zero-length for requests with no body */
|
|
||||||
};
|
};
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@@ -3,11 +3,9 @@ title: "mg_connect_http()"
|
|||||||
decl_name: "mg_connect_http"
|
decl_name: "mg_connect_http"
|
||||||
symbol_kind: "func"
|
symbol_kind: "func"
|
||||||
signature: |
|
signature: |
|
||||||
struct mg_connection *mg_connect_http(struct mg_mgr *mgr,
|
struct mg_connection *mg_connect_http(
|
||||||
mg_event_handler_t event_handler,
|
struct mg_mgr *mgr,
|
||||||
const char *url,
|
MG_CB(mg_event_handler_t event_handler, void *user_data);
|
||||||
const char *extra_headers,
|
|
||||||
const char *post_data);
|
|
||||||
---
|
---
|
||||||
|
|
||||||
Helper function that creates an outbound HTTP connection.
|
Helper function that creates an outbound HTTP connection.
|
||||||
|
|||||||
@@ -3,12 +3,8 @@ title: "mg_connect_http_opt()"
|
|||||||
decl_name: "mg_connect_http_opt"
|
decl_name: "mg_connect_http_opt"
|
||||||
symbol_kind: "func"
|
symbol_kind: "func"
|
||||||
signature: |
|
signature: |
|
||||||
struct mg_connection *mg_connect_http_opt(struct mg_mgr *mgr,
|
struct mg_connection *mg_connect_http_opt(
|
||||||
mg_event_handler_t ev_handler,
|
struct mg_mgr *mgr, MG_CB(mg_event_handler_t ev_handler, void *user_data);
|
||||||
struct mg_connect_opts opts,
|
|
||||||
const char *url,
|
|
||||||
const char *extra_headers,
|
|
||||||
const char *post_data);
|
|
||||||
---
|
---
|
||||||
|
|
||||||
Helper function that creates an outbound HTTP connection.
|
Helper function that creates an outbound HTTP connection.
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ title: "Server API reference"
|
|||||||
symbol_kind: "intro"
|
symbol_kind: "intro"
|
||||||
decl_name: "http_server.h"
|
decl_name: "http_server.h"
|
||||||
items:
|
items:
|
||||||
|
- { name: mg_check_digest_auth.md }
|
||||||
- { name: mg_file_upload_handler.md }
|
- { name: mg_file_upload_handler.md }
|
||||||
- { name: mg_get_http_basic_auth.md }
|
- { name: mg_get_http_basic_auth.md }
|
||||||
- { name: mg_get_http_header.md }
|
- { name: mg_get_http_header.md }
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
---
|
||||||
|
title: "mg_check_digest_auth()"
|
||||||
|
decl_name: "mg_check_digest_auth"
|
||||||
|
symbol_kind: "func"
|
||||||
|
signature: |
|
||||||
|
int mg_check_digest_auth(struct mg_str method, struct mg_str uri,
|
||||||
|
struct mg_str username, struct mg_str cnonce,
|
||||||
|
struct mg_str response, struct mg_str qop,
|
||||||
|
struct mg_str nc, struct mg_str nonce,
|
||||||
|
struct mg_str auth_domain, FILE *fp);
|
||||||
|
---
|
||||||
|
|
||||||
|
Authenticates given response params against an opened password file.
|
||||||
|
Returns 1 if authenticated, 0 otherwise.
|
||||||
|
|
||||||
|
It's used by mg_http_check_digest_auth().
|
||||||
|
|
||||||
@@ -4,7 +4,8 @@ decl_name: "mg_file_upload_handler"
|
|||||||
symbol_kind: "func"
|
symbol_kind: "func"
|
||||||
signature: |
|
signature: |
|
||||||
void mg_file_upload_handler(struct mg_connection *nc, int ev, void *ev_data,
|
void mg_file_upload_handler(struct mg_connection *nc, int ev, void *ev_data,
|
||||||
mg_fu_fname_fn local_name_fn);
|
mg_fu_fname_fn local_name_fn
|
||||||
|
MG_UD_ARG(void *user_data);
|
||||||
---
|
---
|
||||||
|
|
||||||
File upload handler.
|
File upload handler.
|
||||||
|
|||||||
@@ -12,5 +12,6 @@ Fetches a HTTP form variable.
|
|||||||
Fetches a variable `name` from a `buf` into a buffer specified by `dst`,
|
Fetches a variable `name` from a `buf` into a buffer specified by `dst`,
|
||||||
`dst_len`. The destination is always zero-terminated. Returns the length of
|
`dst_len`. The destination is always zero-terminated. Returns the length of
|
||||||
a fetched variable. If not found, 0 is returned. `buf` must be valid
|
a fetched variable. If not found, 0 is returned. `buf` must be valid
|
||||||
url-encoded buffer. If destination is too small, `-1` is returned.
|
url-encoded buffer. If destination is too small or an error occured,
|
||||||
|
negative number is returned.
|
||||||
|
|
||||||
@@ -12,7 +12,7 @@ Sends a redirect response.
|
|||||||
`status_code` should be either 301 or 302 and `location` point to the
|
`status_code` should be either 301 or 302 and `location` point to the
|
||||||
new location.
|
new location.
|
||||||
If `extra_headers` is not empty, then `extra_headers` are also sent
|
If `extra_headers` is not empty, then `extra_headers` are also sent
|
||||||
after the reponse line. `extra_headers` must NOT end end with new line.
|
after the response line. `extra_headers` must NOT end end with new line.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,8 @@ decl_name: "mg_register_http_endpoint"
|
|||||||
symbol_kind: "func"
|
symbol_kind: "func"
|
||||||
signature: |
|
signature: |
|
||||||
void mg_register_http_endpoint(struct mg_connection *nc, const char *uri_path,
|
void mg_register_http_endpoint(struct mg_connection *nc, const char *uri_path,
|
||||||
mg_event_handler_t handler);
|
MG_CB(mg_event_handler_t handler,
|
||||||
|
void *user_data);
|
||||||
---
|
---
|
||||||
|
|
||||||
Registers a callback for a specified http endpoint
|
Registers a callback for a specified http endpoint
|
||||||
@@ -20,7 +21,7 @@ static void handle_hello1(struct mg_connection *nc, int ev, void *ev_data) {
|
|||||||
nc->flags |= MG_F_SEND_AND_CLOSE;
|
nc->flags |= MG_F_SEND_AND_CLOSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_hello1(struct mg_connection *nc, int ev, void *ev_data) {
|
static void handle_hello2(struct mg_connection *nc, int ev, void *ev_data) {
|
||||||
(void) ev; (void) ev_data;
|
(void) ev; (void) ev_data;
|
||||||
mg_printf(nc, "HTTP/1.0 200 OK\r\n\r\n[I am Hello2]");
|
mg_printf(nc, "HTTP/1.0 200 OK\r\n\r\n[I am Hello2]");
|
||||||
nc->flags |= MG_F_SEND_AND_CLOSE;
|
nc->flags |= MG_F_SEND_AND_CLOSE;
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ signature: |
|
|||||||
Sends buffer `buf` of size `len` to the client using chunked HTTP encoding.
|
Sends buffer `buf` of size `len` to the client using chunked HTTP encoding.
|
||||||
This function sends the buffer size as hex number + newline first, then
|
This function sends the buffer size as hex number + newline first, then
|
||||||
the buffer itself, then the newline. For example,
|
the buffer itself, then the newline. For example,
|
||||||
`mg_send_http_chunk(nc, "foo", 3)` whill append the `3\r\nfoo\r\n` string
|
`mg_send_http_chunk(nc, "foo", 3)` will append the `3\r\nfoo\r\n` string
|
||||||
to the `nc->send_mbuf` output IO buffer.
|
to the `nc->send_mbuf` output IO buffer.
|
||||||
|
|
||||||
NOTE: The HTTP header "Transfer-Encoding: chunked" should be sent prior to
|
NOTE: The HTTP header "Transfer-Encoding: chunked" should be sent prior to
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ signature: |
|
|||||||
|
|
||||||
Sends the response status line.
|
Sends the response status line.
|
||||||
If `extra_headers` is not NULL, then `extra_headers` are also sent
|
If `extra_headers` is not NULL, then `extra_headers` are also sent
|
||||||
after the reponse line. `extra_headers` must NOT end end with new line.
|
after the response line. `extra_headers` must NOT end end with new line.
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
mg_send_response_line(nc, 200, "Access-Control-Allow-Origin: *");
|
mg_send_response_line(nc, 200, "Access-Control-Allow-Origin: *");
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ decl_name: "mqtt.h"
|
|||||||
items:
|
items:
|
||||||
- { name: mg_mqtt_connack.md }
|
- { name: mg_mqtt_connack.md }
|
||||||
- { name: mg_mqtt_disconnect.md }
|
- { name: mg_mqtt_disconnect.md }
|
||||||
|
- { name: mg_mqtt_match_topic_expression.md }
|
||||||
- { name: mg_mqtt_next_subscribe_topic.md }
|
- { name: mg_mqtt_next_subscribe_topic.md }
|
||||||
- { name: mg_mqtt_ping.md }
|
- { name: mg_mqtt_ping.md }
|
||||||
- { name: mg_mqtt_pong.md }
|
- { name: mg_mqtt_pong.md }
|
||||||
@@ -17,6 +18,7 @@ items:
|
|||||||
- { name: mg_mqtt_subscribe.md }
|
- { name: mg_mqtt_subscribe.md }
|
||||||
- { name: mg_mqtt_unsuback.md }
|
- { name: mg_mqtt_unsuback.md }
|
||||||
- { name: mg_mqtt_unsubscribe.md }
|
- { name: mg_mqtt_unsubscribe.md }
|
||||||
|
- { name: mg_mqtt_vmatch_topic_expression.md }
|
||||||
- { name: mg_send_mqtt_handshake.md }
|
- { name: mg_send_mqtt_handshake.md }
|
||||||
- { name: mg_send_mqtt_handshake_opt.md }
|
- { name: mg_send_mqtt_handshake_opt.md }
|
||||||
- { name: mg_set_protocol_mqtt.md }
|
- { name: mg_set_protocol_mqtt.md }
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
---
|
||||||
|
title: "mg_mqtt_match_topic_expression()"
|
||||||
|
decl_name: "mg_mqtt_match_topic_expression"
|
||||||
|
symbol_kind: "func"
|
||||||
|
signature: |
|
||||||
|
int mg_mqtt_match_topic_expression(struct mg_str exp, struct mg_str topic);
|
||||||
|
---
|
||||||
|
|
||||||
|
Matches a topic against a topic expression
|
||||||
|
|
||||||
|
Returns 1 if it matches; 0 otherwise.
|
||||||
|
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
---
|
||||||
|
title: "mg_mqtt_vmatch_topic_expression()"
|
||||||
|
decl_name: "mg_mqtt_vmatch_topic_expression"
|
||||||
|
symbol_kind: "func"
|
||||||
|
signature: |
|
||||||
|
int mg_mqtt_vmatch_topic_expression(const char *exp, struct mg_str topic);
|
||||||
|
---
|
||||||
|
|
||||||
|
Same as `mg_mqtt_match_topic_expression()`, but takes `exp` as a
|
||||||
|
NULL-terminated string.
|
||||||
|
|
||||||
@@ -5,6 +5,7 @@ symbol_kind: "struct"
|
|||||||
signature: |
|
signature: |
|
||||||
struct mg_mqtt_proto_data {
|
struct mg_mqtt_proto_data {
|
||||||
uint16_t keep_alive;
|
uint16_t keep_alive;
|
||||||
|
double last_control_time;
|
||||||
};
|
};
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@@ -11,8 +11,6 @@ items:
|
|||||||
- { name: mg_check_ip_acl.md }
|
- { name: mg_check_ip_acl.md }
|
||||||
- { name: mg_connect.md }
|
- { name: mg_connect.md }
|
||||||
- { name: mg_connect_opt.md }
|
- { name: mg_connect_opt.md }
|
||||||
- { name: mg_enable_javascript.md }
|
|
||||||
- { name: mg_enable_multithreading.md }
|
|
||||||
- { name: mg_mgr_free.md }
|
- { name: mg_mgr_free.md }
|
||||||
- { name: mg_mgr_init.md }
|
- { name: mg_mgr_init.md }
|
||||||
- { name: mg_mgr_init_opt.md }
|
- { name: mg_mgr_init_opt.md }
|
||||||
@@ -33,7 +31,6 @@ items:
|
|||||||
- { name: struct_mg_connection.md }
|
- { name: struct_mg_connection.md }
|
||||||
- { name: struct_mg_mgr.md }
|
- { name: struct_mg_mgr.md }
|
||||||
- { name: struct_mg_mgr_init_opts.md }
|
- { name: struct_mg_mgr_init_opts.md }
|
||||||
- { name: struct_mg_multithreading_opts.md }
|
|
||||||
---
|
---
|
||||||
|
|
||||||
NOTE: Mongoose manager is single threaded. It does not protect
|
NOTE: Mongoose manager is single threaded. It does not protect
|
||||||
|
|||||||
@@ -3,7 +3,9 @@ title: "mg_add_sock()"
|
|||||||
decl_name: "mg_add_sock"
|
decl_name: "mg_add_sock"
|
||||||
symbol_kind: "func"
|
symbol_kind: "func"
|
||||||
signature: |
|
signature: |
|
||||||
struct mg_connection *mg_add_sock(struct mg_mgr *, sock_t, mg_event_handler_t);
|
struct mg_connection *mg_add_sock(struct mg_mgr *mgr, sock_t sock,
|
||||||
|
MG_CB(mg_event_handler_t handler,
|
||||||
|
void *user_data);
|
||||||
---
|
---
|
||||||
|
|
||||||
Creates a connection, associates it with the given socket and event handler
|
Creates a connection, associates it with the given socket and event handler
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ title: "mg_add_sock_opt()"
|
|||||||
decl_name: "mg_add_sock_opt"
|
decl_name: "mg_add_sock_opt"
|
||||||
symbol_kind: "func"
|
symbol_kind: "func"
|
||||||
signature: |
|
signature: |
|
||||||
struct mg_connection *mg_add_sock_opt(struct mg_mgr *, sock_t,
|
struct mg_connection *mg_add_sock_opt(struct mg_mgr *mgr, sock_t sock,
|
||||||
mg_event_handler_t,
|
MG_CB(mg_event_handler_t handler,
|
||||||
struct mg_add_sock_opts);
|
void *user_data);
|
||||||
---
|
---
|
||||||
|
|
||||||
Creates a connection, associates it with the given socket and event handler
|
Creates a connection, associates it with the given socket and event handler
|
||||||
|
|||||||
@@ -3,8 +3,9 @@ title: "mg_bind()"
|
|||||||
decl_name: "mg_bind"
|
decl_name: "mg_bind"
|
||||||
symbol_kind: "func"
|
symbol_kind: "func"
|
||||||
signature: |
|
signature: |
|
||||||
struct mg_connection *mg_bind(struct mg_mgr *, const char *,
|
struct mg_connection *mg_bind(struct mg_mgr *mgr, const char *address,
|
||||||
mg_event_handler_t);
|
MG_CB(mg_event_handler_t handler,
|
||||||
|
void *user_data);
|
||||||
---
|
---
|
||||||
|
|
||||||
Creates a listening connection.
|
Creates a listening connection.
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ decl_name: "mg_bind_opt"
|
|||||||
symbol_kind: "func"
|
symbol_kind: "func"
|
||||||
signature: |
|
signature: |
|
||||||
struct mg_connection *mg_bind_opt(struct mg_mgr *mgr, const char *address,
|
struct mg_connection *mg_bind_opt(struct mg_mgr *mgr, const char *address,
|
||||||
mg_event_handler_t handler,
|
MG_CB(mg_event_handler_t handler,
|
||||||
struct mg_bind_opts opts);
|
void *user_data);
|
||||||
---
|
---
|
||||||
|
|
||||||
Creates a listening connection.
|
Creates a listening connection.
|
||||||
@@ -15,7 +15,7 @@ the same as for the `mg_connect()` call, where `HOST` part is optional.
|
|||||||
`address` can be just a port number, e.g. `:8000`. To bind to a specific
|
`address` can be just a port number, e.g. `:8000`. To bind to a specific
|
||||||
interface, an IP address can be specified, e.g. `1.2.3.4:8000`. By default,
|
interface, an IP address can be specified, e.g. `1.2.3.4:8000`. By default,
|
||||||
a TCP connection is created. To create UDP connection, prepend `udp://`
|
a TCP connection is created. To create UDP connection, prepend `udp://`
|
||||||
prefix, e.g. `udp://:8000`. To summarize, `address` paramer has following
|
prefix, e.g. `udp://:8000`. To summarize, `address` parameter has following
|
||||||
format: `[PROTO://][IP_ADDRESS]:PORT`, where `PROTO` could be `tcp` or
|
format: `[PROTO://][IP_ADDRESS]:PORT`, where `PROTO` could be `tcp` or
|
||||||
`udp`.
|
`udp`.
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,8 @@ title: "mg_broadcast()"
|
|||||||
decl_name: "mg_broadcast"
|
decl_name: "mg_broadcast"
|
||||||
symbol_kind: "func"
|
symbol_kind: "func"
|
||||||
signature: |
|
signature: |
|
||||||
void mg_broadcast(struct mg_mgr *, mg_event_handler_t func, void *, size_t);
|
void mg_broadcast(struct mg_mgr *mgr, mg_event_handler_t cb, void *data,
|
||||||
|
size_t len);
|
||||||
---
|
---
|
||||||
|
|
||||||
Passes a message of a given length to all connections.
|
Passes a message of a given length to all connections.
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ Subnet masks may vary from 0 to 32, inclusive. The default setting
|
|||||||
is to allow all access. On each request the full list is traversed,
|
is to allow all access. On each request the full list is traversed,
|
||||||
and the last match wins. Example:
|
and the last match wins. Example:
|
||||||
|
|
||||||
`-0.0.0.0/0,+192.168/16` - deny all acccesses, only allow 192.168/16 subnet
|
`-0.0.0.0/0,+192.168/16` - deny all accesses, only allow 192.168/16 subnet
|
||||||
|
|
||||||
To learn more about subnet masks, see this
|
To learn more about subnet masks, see this
|
||||||
link:https://en.wikipedia.org/wiki/Subnetwork[Wikipedia page on Subnetwork].
|
link:https://en.wikipedia.org/wiki/Subnetwork[Wikipedia page on Subnetwork].
|
||||||
|
|||||||
@@ -4,7 +4,8 @@ decl_name: "mg_connect"
|
|||||||
symbol_kind: "func"
|
symbol_kind: "func"
|
||||||
signature: |
|
signature: |
|
||||||
struct mg_connection *mg_connect(struct mg_mgr *mgr, const char *address,
|
struct mg_connection *mg_connect(struct mg_mgr *mgr, const char *address,
|
||||||
mg_event_handler_t handler);
|
MG_CB(mg_event_handler_t handler,
|
||||||
|
void *user_data);
|
||||||
---
|
---
|
||||||
|
|
||||||
Connects to a remote host.
|
Connects to a remote host.
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ decl_name: "mg_connect_opt"
|
|||||||
symbol_kind: "func"
|
symbol_kind: "func"
|
||||||
signature: |
|
signature: |
|
||||||
struct mg_connection *mg_connect_opt(struct mg_mgr *mgr, const char *address,
|
struct mg_connection *mg_connect_opt(struct mg_mgr *mgr, const char *address,
|
||||||
mg_event_handler_t handler,
|
MG_CB(mg_event_handler_t handler,
|
||||||
struct mg_connect_opts opts);
|
void *user_data);
|
||||||
---
|
---
|
||||||
|
|
||||||
Connects to a remote host.
|
Connects to a remote host.
|
||||||
|
|||||||
@@ -1,14 +0,0 @@
|
|||||||
---
|
|
||||||
title: "mg_enable_javascript()"
|
|
||||||
decl_name: "mg_enable_javascript"
|
|
||||||
symbol_kind: "func"
|
|
||||||
signature: |
|
|
||||||
enum v7_err mg_enable_javascript(struct mg_mgr *m, struct v7 *v7,
|
|
||||||
const char *init_js_file_name);
|
|
||||||
---
|
|
||||||
|
|
||||||
Enables server-side JavaScript scripting.
|
|
||||||
Requires a `-DMG_ENABLE_JAVASCRIPT` compilation flag and V7 engine sources.
|
|
||||||
V7 instance must not be destroyed during manager's lifetime.
|
|
||||||
Returns a V7 error.
|
|
||||||
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
---
|
|
||||||
title: "mg_enable_multithreading()"
|
|
||||||
decl_name: "mg_enable_multithreading"
|
|
||||||
symbol_kind: "func"
|
|
||||||
signature: |
|
|
||||||
void mg_enable_multithreading(struct mg_connection *nc);
|
|
||||||
---
|
|
||||||
|
|
||||||
Enables multi-threaded handling for the given listening connection `nc`.
|
|
||||||
For each accepted connection, Mongoose will create a separate thread
|
|
||||||
and run an event handler in that thread. Thus, if an event handler is doing
|
|
||||||
a blocking call or some long computation, it will not slow down
|
|
||||||
other connections.
|
|
||||||
|
|
||||||
@@ -4,7 +4,7 @@ decl_name: "mg_event_handler_t"
|
|||||||
symbol_kind: "typedef"
|
symbol_kind: "typedef"
|
||||||
signature: |
|
signature: |
|
||||||
typedef void (*mg_event_handler_t)(struct mg_connection *nc, int ev,
|
typedef void (*mg_event_handler_t)(struct mg_connection *nc, int ev,
|
||||||
void *ev_data);
|
void *ev_data MG_UD_ARG(void *user_data));
|
||||||
---
|
---
|
||||||
|
|
||||||
Callback function (event handler) prototype. Must be defined by the user.
|
Callback function (event handler) prototype. Must be defined by the user.
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ title: "mg_next()"
|
|||||||
decl_name: "mg_next"
|
decl_name: "mg_next"
|
||||||
symbol_kind: "func"
|
symbol_kind: "func"
|
||||||
signature: |
|
signature: |
|
||||||
struct mg_connection *mg_next(struct mg_mgr *, struct mg_connection *);
|
struct mg_connection *mg_next(struct mg_mgr *mgr, struct mg_connection *c);
|
||||||
---
|
---
|
||||||
|
|
||||||
Iterates over all active connections.
|
Iterates over all active connections.
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ signature: |
|
|||||||
unsigned int flags; /* Extra connection flags */
|
unsigned int flags; /* Extra connection flags */
|
||||||
const char **error_string; /* Placeholder for the error string */
|
const char **error_string; /* Placeholder for the error string */
|
||||||
struct mg_iface *iface; /* Interface instance */
|
struct mg_iface *iface; /* Interface instance */
|
||||||
|
const char *nameserver; /* DNS server to use, NULL for default */
|
||||||
#if MG_ENABLE_SSL
|
#if MG_ENABLE_SSL
|
||||||
/*
|
/*
|
||||||
* SSL settings.
|
* SSL settings.
|
||||||
@@ -44,6 +45,15 @@ signature: |
|
|||||||
* name verification.
|
* name verification.
|
||||||
*/
|
*/
|
||||||
const char *ssl_server_name;
|
const char *ssl_server_name;
|
||||||
|
/*
|
||||||
|
* PSK identity and key. Identity is a NUL-terminated string and key is a hex
|
||||||
|
* string. Key must be either 16 or 32 bytes (32 or 64 hex digits) for AES-128
|
||||||
|
* or AES-256 respectively.
|
||||||
|
* Note: Default list of cipher suites does not include PSK suites, if you
|
||||||
|
* want to use PSK you will need to set ssl_cipher_suites as well.
|
||||||
|
*/
|
||||||
|
const char *ssl_psk_identity;
|
||||||
|
const char *ssl_psk_key;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
---
|
---
|
||||||
|
|||||||
@@ -31,8 +31,8 @@ signature: |
|
|||||||
* void pointers, since some archs might have fat pointers for functions.
|
* void pointers, since some archs might have fat pointers for functions.
|
||||||
*/
|
*/
|
||||||
mg_event_handler_t f;
|
mg_event_handler_t f;
|
||||||
} priv_1; /* Used by mg_enable_multithreading() */
|
} priv_1;
|
||||||
void *priv_2; /* Used by mg_enable_multithreading() */
|
void *priv_2;
|
||||||
void *mgr_data; /* Implementation-specific event manager's data. */
|
void *mgr_data; /* Implementation-specific event manager's data. */
|
||||||
struct mg_iface *iface;
|
struct mg_iface *iface;
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
|
|||||||
@@ -14,9 +14,7 @@ signature: |
|
|||||||
void *user_data; /* User data */
|
void *user_data; /* User data */
|
||||||
int num_ifaces;
|
int num_ifaces;
|
||||||
struct mg_iface **ifaces; /* network interfaces */
|
struct mg_iface **ifaces; /* network interfaces */
|
||||||
#if MG_ENABLE_JAVASCRIPT
|
const char *nameserver; /* DNS server to use */
|
||||||
struct v7 *v7;
|
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@@ -4,9 +4,10 @@ decl_name: "struct mg_mgr_init_opts"
|
|||||||
symbol_kind: "struct"
|
symbol_kind: "struct"
|
||||||
signature: |
|
signature: |
|
||||||
struct mg_mgr_init_opts {
|
struct mg_mgr_init_opts {
|
||||||
struct mg_iface_vtable *main_iface;
|
const struct mg_iface_vtable *main_iface;
|
||||||
int num_ifaces;
|
int num_ifaces;
|
||||||
struct mg_iface_vtable **ifaces;
|
const struct mg_iface_vtable **ifaces;
|
||||||
|
const char *nameserver;
|
||||||
};
|
};
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
---
|
|
||||||
title: "struct mg_multithreading_opts"
|
|
||||||
decl_name: "struct mg_multithreading_opts"
|
|
||||||
symbol_kind: "struct"
|
|
||||||
signature: |
|
|
||||||
struct mg_multithreading_opts {
|
|
||||||
int poll_timeout; /* Polling interval */
|
|
||||||
};
|
|
||||||
---
|
|
||||||
|
|
||||||
Optional parameters for mg_enable_multithreading_opt()
|
|
||||||
|
|
||||||
@@ -6,6 +6,7 @@ items:
|
|||||||
- { name: mg_resolve_async.md }
|
- { name: mg_resolve_async.md }
|
||||||
- { name: mg_resolve_async_opt.md }
|
- { name: mg_resolve_async_opt.md }
|
||||||
- { name: mg_resolve_from_hosts_file.md }
|
- { name: mg_resolve_from_hosts_file.md }
|
||||||
|
- { name: mg_set_nameserver.md }
|
||||||
- { name: struct_mg_resolve_async_opts.md }
|
- { name: struct_mg_resolve_async_opts.md }
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
---
|
||||||
|
title: "mg_set_nameserver()"
|
||||||
|
decl_name: "mg_set_nameserver"
|
||||||
|
symbol_kind: "func"
|
||||||
|
signature: |
|
||||||
|
void mg_set_nameserver(struct mg_mgr *mgr, const char *nameserver);
|
||||||
|
---
|
||||||
|
|
||||||
|
Set default DNS server
|
||||||
|
|
||||||
@@ -4,7 +4,7 @@ decl_name: "struct mg_resolve_async_opts"
|
|||||||
symbol_kind: "struct"
|
symbol_kind: "struct"
|
||||||
signature: |
|
signature: |
|
||||||
struct mg_resolve_async_opts {
|
struct mg_resolve_async_opts {
|
||||||
const char *nameserver_url;
|
const char *nameserver;
|
||||||
int max_retries; /* defaults to 2 if zero */
|
int max_retries; /* defaults to 2 if zero */
|
||||||
int timeout; /* in seconds; defaults to 5 if zero */
|
int timeout; /* in seconds; defaults to 5 if zero */
|
||||||
int accept_literal; /* pseudo-resolve literal ipv4 and ipv6 addrs */
|
int accept_literal; /* pseudo-resolve literal ipv4 and ipv6 addrs */
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ title: "URI"
|
|||||||
symbol_kind: "intro"
|
symbol_kind: "intro"
|
||||||
decl_name: "uri.h"
|
decl_name: "uri.h"
|
||||||
items:
|
items:
|
||||||
|
- { name: mg_assemble_uri.md }
|
||||||
- { name: mg_parse_uri.md }
|
- { name: mg_parse_uri.md }
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
---
|
||||||
|
title: "mg_assemble_uri()"
|
||||||
|
decl_name: "mg_assemble_uri"
|
||||||
|
symbol_kind: "func"
|
||||||
|
signature: |
|
||||||
|
int mg_assemble_uri(const struct mg_str *scheme, const struct mg_str *user_info,
|
||||||
|
const struct mg_str *host, unsigned int port,
|
||||||
|
const struct mg_str *path, const struct mg_str *query,
|
||||||
|
const struct mg_str *fragment, int normalize_path,
|
||||||
|
struct mg_str *uri);
|
||||||
|
---
|
||||||
|
|
||||||
|
Assemble URI from parts. Any of the inputs can be NULL or zero-length mg_str.
|
||||||
|
|
||||||
|
If normalize_path is true, path is normalized by resolving relative refs.
|
||||||
|
|
||||||
|
Result is a heap-allocated string (uri->p must be free()d after use).
|
||||||
|
|
||||||
|
Returns 0 on success, -1 on error.
|
||||||
|
|
||||||
@@ -3,7 +3,7 @@ title: "mg_parse_uri()"
|
|||||||
decl_name: "mg_parse_uri"
|
decl_name: "mg_parse_uri"
|
||||||
symbol_kind: "func"
|
symbol_kind: "func"
|
||||||
signature: |
|
signature: |
|
||||||
int mg_parse_uri(struct mg_str uri, struct mg_str *scheme,
|
int mg_parse_uri(const struct mg_str uri, struct mg_str *scheme,
|
||||||
struct mg_str *user_info, struct mg_str *host,
|
struct mg_str *user_info, struct mg_str *host,
|
||||||
unsigned int *port, struct mg_str *path, struct mg_str *query,
|
unsigned int *port, struct mg_str *path, struct mg_str *query,
|
||||||
struct mg_str *fragment);
|
struct mg_str *fragment);
|
||||||
|
|||||||
@@ -8,19 +8,21 @@ items:
|
|||||||
- { name: mg_basic_auth_header.md }
|
- { name: mg_basic_auth_header.md }
|
||||||
- { name: mg_conn_addr_to_str.md }
|
- { name: mg_conn_addr_to_str.md }
|
||||||
- { name: mg_fopen.md }
|
- { name: mg_fopen.md }
|
||||||
|
- { name: mg_fread.md }
|
||||||
|
- { name: mg_fwrite.md }
|
||||||
- { name: mg_hexdump.md }
|
- { name: mg_hexdump.md }
|
||||||
- { name: mg_hexdump_connection.md }
|
- { name: mg_hexdump_connection.md }
|
||||||
|
- { name: mg_hexdumpf.md }
|
||||||
- { name: mg_is_big_endian.md }
|
- { name: mg_is_big_endian.md }
|
||||||
- { name: mg_match_prefix.md }
|
|
||||||
- { name: mg_mbuf_append_base64.md }
|
- { name: mg_mbuf_append_base64.md }
|
||||||
- { name: mg_mbuf_append_base64_putc.md }
|
- { name: mg_mbuf_append_base64_putc.md }
|
||||||
- { name: mg_next_comma_list_entry.md }
|
|
||||||
- { name: mg_open.md }
|
- { name: mg_open.md }
|
||||||
- { name: mg_skip.md }
|
- { name: mg_skip.md }
|
||||||
- { name: mg_sock_addr_to_str.md }
|
- { name: mg_sock_addr_to_str.md }
|
||||||
- { name: mg_sock_to_str.md }
|
- { name: mg_sock_to_str.md }
|
||||||
- { name: mg_start_thread.md }
|
- { name: mg_start_thread.md }
|
||||||
- { name: mg_stat.md }
|
- { name: mg_stat.md }
|
||||||
|
- { name: mg_url_encode.md }
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,8 @@ title: "mg_basic_auth_header()"
|
|||||||
decl_name: "mg_basic_auth_header"
|
decl_name: "mg_basic_auth_header"
|
||||||
symbol_kind: "func"
|
symbol_kind: "func"
|
||||||
signature: |
|
signature: |
|
||||||
void mg_basic_auth_header(const char *user, const char *pass, struct mbuf *buf);
|
void mg_basic_auth_header(const struct mg_str user, const struct mg_str pass,
|
||||||
|
struct mbuf *buf);
|
||||||
---
|
---
|
||||||
|
|
||||||
Generate a Basic Auth header and appends it to buf.
|
Generate a Basic Auth header and appends it to buf.
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ title: "mg_conn_addr_to_str()"
|
|||||||
decl_name: "mg_conn_addr_to_str"
|
decl_name: "mg_conn_addr_to_str"
|
||||||
symbol_kind: "func"
|
symbol_kind: "func"
|
||||||
signature: |
|
signature: |
|
||||||
void mg_conn_addr_to_str(struct mg_connection *nc, char *buf, size_t len,
|
int mg_conn_addr_to_str(struct mg_connection *c, char *buf, size_t len,
|
||||||
int flags);
|
int flags);
|
||||||
---
|
---
|
||||||
|
|
||||||
Converts a connection's local or remote address into string.
|
Converts a connection's local or remote address into string.
|
||||||
@@ -17,5 +17,6 @@ see `MG_SOCK_STRINGIFY_*` definitions.
|
|||||||
- MG_SOCK_STRINGIFY_REMOTE - print remote peer's IP/port, not local address
|
- MG_SOCK_STRINGIFY_REMOTE - print remote peer's IP/port, not local address
|
||||||
|
|
||||||
If both port number and IP address are printed, they are separated by `:`.
|
If both port number and IP address are printed, they are separated by `:`.
|
||||||
If compiled with `-DMG_ENABLE_IPV6`, IPv6 addresses are supported.
|
If compiled with `-DMG_ENABLE_IPV6`, IPv6 addresses are supported.
|
||||||
|
Return length of the stringified address.
|
||||||
|
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
---
|
||||||
|
title: "mg_fread()"
|
||||||
|
decl_name: "mg_fread"
|
||||||
|
symbol_kind: "func"
|
||||||
|
signature: |
|
||||||
|
size_t mg_fread(void *ptr, size_t size, size_t count, FILE *f);
|
||||||
|
---
|
||||||
|
|
||||||
|
Reads data from the given file stream.
|
||||||
|
|
||||||
|
Return value is a number of bytes readen.
|
||||||
|
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
---
|
||||||
|
title: "mg_fwrite()"
|
||||||
|
decl_name: "mg_fwrite"
|
||||||
|
symbol_kind: "func"
|
||||||
|
signature: |
|
||||||
|
size_t mg_fwrite(const void *ptr, size_t size, size_t count, FILE *f);
|
||||||
|
---
|
||||||
|
|
||||||
|
Writes data to the given file stream.
|
||||||
|
|
||||||
|
Return value is a number of bytes wtitten.
|
||||||
|
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
---
|
||||||
|
title: "mg_hexdumpf()"
|
||||||
|
decl_name: "mg_hexdumpf"
|
||||||
|
symbol_kind: "func"
|
||||||
|
signature: |
|
||||||
|
void mg_hexdumpf(FILE *fp, const void *buf, int len);
|
||||||
|
---
|
||||||
|
|
||||||
|
Same as mg_hexdump, but with output going to file instead of a buffer.
|
||||||
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
---
|
|
||||||
title: "mg_match_prefix()"
|
|
||||||
decl_name: "mg_match_prefix"
|
|
||||||
symbol_kind: "func"
|
|
||||||
signature: |
|
|
||||||
int mg_match_prefix(const char *pattern, int pattern_len, const char *str);
|
|
||||||
---
|
|
||||||
|
|
||||||
Matches 0-terminated string (mg_match_prefix) or string with given length
|
|
||||||
mg_match_prefix_n against a glob pattern.
|
|
||||||
|
|
||||||
Match is case-insensitive. Returns number of bytes matched, or -1 if no
|
|
||||||
match.
|
|
||||||
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
---
|
|
||||||
title: "mg_next_comma_list_entry()"
|
|
||||||
decl_name: "mg_next_comma_list_entry"
|
|
||||||
symbol_kind: "func"
|
|
||||||
signature: |
|
|
||||||
const char *mg_next_comma_list_entry(const char *list, struct mg_str *val,
|
|
||||||
struct mg_str *eq_val);
|
|
||||||
---
|
|
||||||
|
|
||||||
A helper function for traversing a comma separated list of values.
|
|
||||||
It returns a list pointer shifted to the next value or NULL if the end
|
|
||||||
of the list found.
|
|
||||||
The value is stored in a val vector. If the value has a form "x=y", then
|
|
||||||
eq_val vector is initialised to point to the "y" part, and val vector length
|
|
||||||
is adjusted to point only to "x".
|
|
||||||
If the list is just a comma separated list of entries, like "aa,bb,cc" then
|
|
||||||
`eq_val` will contain zero-length string.
|
|
||||||
|
|
||||||
The purpose of this function is to parse comma separated string without
|
|
||||||
any copying/memory allocation.
|
|
||||||
|
|
||||||
@@ -3,8 +3,8 @@ title: "mg_sock_addr_to_str()"
|
|||||||
decl_name: "mg_sock_addr_to_str"
|
decl_name: "mg_sock_addr_to_str"
|
||||||
symbol_kind: "func"
|
symbol_kind: "func"
|
||||||
signature: |
|
signature: |
|
||||||
void mg_sock_addr_to_str(const union socket_address *sa, char *buf, size_t len,
|
int mg_sock_addr_to_str(const union socket_address *sa, char *buf, size_t len,
|
||||||
int flags);
|
int flags);
|
||||||
---
|
---
|
||||||
|
|
||||||
Convert the socket's address into string.
|
Convert the socket's address into string.
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
---
|
||||||
|
title: "mg_url_encode()"
|
||||||
|
decl_name: "mg_url_encode"
|
||||||
|
symbol_kind: "func"
|
||||||
|
signature: |
|
||||||
|
struct mg_str mg_url_encode(const struct mg_str src);
|
||||||
|
---
|
||||||
|
|
||||||
|
URL-escape the specified string.
|
||||||
|
All non-printable characters are escaped, plus `._-$,;~()/`.
|
||||||
|
Input need not be NUL-terminated, but the returned string is.
|
||||||
|
Returned string is heap-allocated and must be free()'d.
|
||||||
|
|
||||||
@@ -2,4 +2,6 @@
|
|||||||
title: DNS client example
|
title: DNS client example
|
||||||
---
|
---
|
||||||
|
|
||||||
TBD
|
See https://github.com/cesanta/mongoose/blob/master/mongoose.c and search
|
||||||
|
for the `mg_resolve_async_eh()` function - that is the core of
|
||||||
|
built-in Mongoose async DNS resolver.
|
||||||
@@ -2,4 +2,8 @@
|
|||||||
title: Overview
|
title: Overview
|
||||||
---
|
---
|
||||||
|
|
||||||
TBD
|
Mongoose uses non-blocking DNS resolver. For each name to be resolved,
|
||||||
|
it first checks the `/etc/hosts` file (or, `hosts` on Windows).
|
||||||
|
If the entry is not found there, then the `8.8.8.8` DNS server is queried.
|
||||||
|
When IP address is found, Mongoose proceeds with making the connection
|
||||||
|
with the resolved IP address.
|
||||||
+5
-1
@@ -16,7 +16,7 @@ CGI file must be executable. Mongoose honours the shebang line - see
|
|||||||
http://en.wikipedia.org/wiki/Shebang_(Unix).
|
http://en.wikipedia.org/wiki/Shebang_(Unix).
|
||||||
|
|
||||||
For example, if both PHP and Perl CGIs are used, then
|
For example, if both PHP and Perl CGIs are used, then
|
||||||
``#!/path/to/php-cgi.exe` and ``#!/path/to/perl.exe` must be the first lines
|
`#!/path/to/php-cgi.exe` and `#!/path/to/perl.exe` must be the first lines
|
||||||
of the respective CGI scripts.
|
of the respective CGI scripts.
|
||||||
|
|
||||||
It is possible to hardcode the path to the CGI interpreter for all
|
It is possible to hardcode the path to the CGI interpreter for all
|
||||||
@@ -29,3 +29,7 @@ Example:
|
|||||||
```c
|
```c
|
||||||
opts.cgi_interpreter = "C:\\ruby\\ruby.exe";
|
opts.cgi_interpreter = "C:\\ruby\\ruby.exe";
|
||||||
```
|
```
|
||||||
|
NOTE: In the CGI handler we don't use explicitly a system call waitpid() for
|
||||||
|
reaping zombie processes. Instead, we set the SIGCHLD handler to SIG_IGN.
|
||||||
|
It will cause zombie processes to be reaped automatically.
|
||||||
|
CAUTION: not all OSes (e.g. QNX) reap zombies if SIGCHLD is ignored.
|
||||||
@@ -18,8 +18,9 @@ static int exit_flag = 0;
|
|||||||
|
|
||||||
static void ev_handler(struct mg_connection *c, int ev, void *p) {
|
static void ev_handler(struct mg_connection *c, int ev, void *p) {
|
||||||
if (ev == MG_EV_HTTP_REPLY) {
|
if (ev == MG_EV_HTTP_REPLY) {
|
||||||
|
struct http_message *hm = (struct http_message *)p;
|
||||||
c->flags |= MG_F_CLOSE_IMMEDIATELY;
|
c->flags |= MG_F_CLOSE_IMMEDIATELY;
|
||||||
fwrite(hm->message.p, 1, hm->message.len, stdout);
|
fwrite(hm->message.p, 1, (int)hm->message.len, stdout);
|
||||||
putchar('\n');
|
putchar('\n');
|
||||||
exit_flag = 1;
|
exit_flag = 1;
|
||||||
} else if (ev == MG_EV_CLOSE) {
|
} else if (ev == MG_EV_CLOSE) {
|
||||||
@@ -31,7 +32,7 @@ int main(void) {
|
|||||||
struct mg_mgr mgr;
|
struct mg_mgr mgr;
|
||||||
|
|
||||||
mg_mgr_init(&mgr, NULL);
|
mg_mgr_init(&mgr, NULL);
|
||||||
mg_connect_http(mgr, ev_handler, url, NULL, NULL);
|
mg_connect_http(&mgr, ev_handler, url, NULL, NULL);
|
||||||
|
|
||||||
|
|
||||||
while (exit_flag == 0) {
|
while (exit_flag == 0) {
|
||||||
|
|||||||
@@ -2,4 +2,15 @@
|
|||||||
title: Digest Authentication
|
title: Digest Authentication
|
||||||
---
|
---
|
||||||
|
|
||||||
TBD
|
Mongoose has a built-in Digest (MD5) authentication support. In order to
|
||||||
|
enable Digest authentication, create a file `.htpasswd` in the directory
|
||||||
|
you would like to protect. That file should be in the format that Apache's
|
||||||
|
`htdigest` utility.
|
||||||
|
|
||||||
|
You can use either Apache `htdigest` utility, or
|
||||||
|
Mongoose pre-build binary (https://www.cesanta.com/products/binary)
|
||||||
|
to add new users into that file:
|
||||||
|
|
||||||
|
```
|
||||||
|
mongoose -A /path/to/.htdigest mydomain.com joe joes_password
|
||||||
|
```
|
||||||
@@ -30,8 +30,8 @@ static void ev_handler(struct mg_connection *c, int ev, void *p) {
|
|||||||
|
|
||||||
// We have received an HTTP request. Parsed request is contained in `hm`.
|
// We have received an HTTP request. Parsed request is contained in `hm`.
|
||||||
// Send HTTP reply to the client which shows full original request.
|
// Send HTTP reply to the client which shows full original request.
|
||||||
mg_send_head(c, 200, hm.message.len, "Content-Type: text/plain");
|
mg_send_head(c, 200, hm->message.len, "Content-Type: text/plain");
|
||||||
mg_printf(c, "%.*s", hm.message.len, hm.message.p);
|
mg_printf(c, "%.*s", (int)hm->message.len, hm->message.p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -35,7 +35,7 @@ The exec directive is used to execute a command on a server,
|
|||||||
and show command's output. Example: `<!--#exec "ls -l" -->`
|
and show command's output. Example: `<!--#exec "ls -l" -->`
|
||||||
|
|
||||||
The call directive is a way to invoke a C handler from the HTML page.
|
The call directive is a way to invoke a C handler from the HTML page.
|
||||||
On each occurence of `<!--#call PARAMS -->` directive,
|
On each occurrence of `<!--#call PARAMS -->` directive,
|
||||||
Mongoose calls a registered event handler with `MG_EV_SSI_CALL` event.
|
Mongoose calls a registered event handler with `MG_EV_SSI_CALL` event.
|
||||||
Event parameter will point to the `PARAMS` string.
|
Event parameter will point to the `PARAMS` string.
|
||||||
An event handler can output any text, for example by calling
|
An event handler can output any text, for example by calling
|
||||||
|
|||||||
+1
-1
@@ -30,4 +30,4 @@ int main(void) {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
For the full example, please see the [Simplest HTTPS server example](https://github.com/cesanta/dev/tree/master/mongoose/examples/simplest_web_server_ssl).
|
For the full example, please see the [Simplest HTTPS server example](https://github.com/cesanta/mongoose/tree/master/examples/simplest_web_server_ssl).
|
||||||
@@ -2,4 +2,4 @@
|
|||||||
title: MQTT client example
|
title: MQTT client example
|
||||||
---
|
---
|
||||||
|
|
||||||
TBD
|
See https://github.com/cesanta/mongoose/tree/master/examples/mqtt_client
|
||||||
@@ -2,4 +2,4 @@
|
|||||||
title: MQTT server example
|
title: MQTT server example
|
||||||
---
|
---
|
||||||
|
|
||||||
TBD
|
See https://github.com/cesanta/mongoose/tree/master/examples/mqtt_broker
|
||||||
@@ -3,6 +3,6 @@ title: Disabling flags
|
|||||||
---
|
---
|
||||||
|
|
||||||
- `MG_DISABLE_HTTP_DIGEST_AUTH` disable HTTP Digest (MD5) authorisation support
|
- `MG_DISABLE_HTTP_DIGEST_AUTH` disable HTTP Digest (MD5) authorisation support
|
||||||
- `MG_DISABLE_SHA1` disable SHA1 support (used by WebSocket)
|
- `CS_DISABLE_SHA1` disable SHA1 support (used by WebSocket)
|
||||||
- `MG_DISABLE_MD5` disable MD5 support (used by HTTP auth)
|
- `CS_DISABLE_MD5` disable MD5 support (used by HTTP auth)
|
||||||
- `MG_DISABLE_HTTP_KEEP_ALIVE` useful for embedded systems to save resources
|
- `MG_DISABLE_HTTP_KEEP_ALIVE` useful for embedded systems to save resources
|
||||||
@@ -9,3 +9,4 @@ title: Tunables
|
|||||||
- `MG_SSL_CRYPTO_MODERN`, `MG_SSL_CRYPTO_OLD` - choose either "Modern" or "Old" ciphers
|
- `MG_SSL_CRYPTO_MODERN`, `MG_SSL_CRYPTO_OLD` - choose either "Modern" or "Old" ciphers
|
||||||
instead of the default "Intermediate" setting.
|
instead of the default "Intermediate" setting.
|
||||||
See [this article](https://wiki.mozilla.org/Security/Server_Side_TLS#Recommended_configurations) for details.
|
See [this article](https://wiki.mozilla.org/Security/Server_Side_TLS#Recommended_configurations) for details.
|
||||||
|
- `MG_USER_FILE_FUNCTIONS` allow you to use custom file operation, by defining you own `mg_stat`, `mg_fopen`, `mg_open`, `mg_fread` and `mg_fwrite` functions
|
||||||
@@ -1 +0,0 @@
|
|||||||
*.exe
|
|
||||||
@@ -22,7 +22,7 @@ IPATH = . ../.. $(REPO_PATH)
|
|||||||
|
|
||||||
VPATH = ../..
|
VPATH = ../..
|
||||||
|
|
||||||
MONGOOSE_FEATURES = -DMG_ENABLE_SSL -DMG_ENABLE_HTTP_STREAMING_MULTIPART
|
MONGOOSE_FEATURES = -DMG_ENABLE_SSL -DMG_ENABLE_HTTP_STREAMING_MULTIPART -DMG_MODULE_LINES
|
||||||
|
|
||||||
SDK_FLAGS = -DUSE_FREERTOS -DSL_PLATFORM_MULTI_THREADED
|
SDK_FLAGS = -DUSE_FREERTOS -DSL_PLATFORM_MULTI_THREADED
|
||||||
# -DTARGET_IS_CC3200 would reduce code size by using functions in ROM
|
# -DTARGET_IS_CC3200 would reduce code size by using functions in ROM
|
||||||
@@ -58,11 +58,11 @@ $(FW_DIR):
|
|||||||
$(FW_ZIP): $(FW_ELF) $(FW_BIN) $(SLFS_FILES)
|
$(FW_ZIP): $(FW_ELF) $(FW_BIN) $(SLFS_FILES)
|
||||||
@echo " Code size: $(shell ls -l $(FW_BIN) | awk '{print $$5}')"
|
@echo " Code size: $(shell ls -l $(FW_BIN) | awk '{print $$5}')"
|
||||||
@echo " GEN $(FW_MANIFEST)"
|
@echo " GEN $(FW_MANIFEST)"
|
||||||
@fw_meta gen_build_info \
|
@fw_meta.py gen_build_info \
|
||||||
--json_output=$(BUILD_INFO_JSON)
|
--json_output=$(BUILD_INFO_JSON)
|
||||||
@cp -v $(SLFS_FILES) out/
|
@cp -v $(SLFS_FILES) out/
|
||||||
@cp $(CC3200_SP_FILE)* $(FW_DIR)
|
@cp $(CC3200_SP_FILE)* $(FW_DIR)
|
||||||
@fw_meta create_manifest \
|
@fw_meta.py create_manifest \
|
||||||
--name=$(PROG) --platform=$(PLATFORM) \
|
--name=$(PROG) --platform=$(PLATFORM) \
|
||||||
--build_info=$(BUILD_INFO_JSON) \
|
--build_info=$(BUILD_INFO_JSON) \
|
||||||
--output=$(FW_MANIFEST) \
|
--output=$(FW_MANIFEST) \
|
||||||
@@ -72,14 +72,14 @@ $(FW_ZIP): $(FW_ELF) $(FW_BIN) $(SLFS_FILES)
|
|||||||
/sys/mcuimg.bin:type=app,src=$(notdir $(FW_BIN)) \
|
/sys/mcuimg.bin:type=app,src=$(notdir $(FW_BIN)) \
|
||||||
$(foreach f,$(SLFS_FILES), $(notdir $(f)):type=slfile,src=$(notdir $(f)))
|
$(foreach f,$(SLFS_FILES), $(notdir $(f)):type=slfile,src=$(notdir $(f)))
|
||||||
@echo " ZIP $@"
|
@echo " ZIP $@"
|
||||||
@fw_meta create_fw \
|
@fw_meta.py create_fw \
|
||||||
--manifest=$(FW_MANIFEST) \
|
--manifest=$(FW_MANIFEST) \
|
||||||
--src_dir=$(FW_DIR) \
|
--src_dir=$(FW_DIR) \
|
||||||
--output=$@
|
--output=$@
|
||||||
|
|
||||||
FREERTOS_SRCS = timers.c list.c queue.c tasks.c port.c heap_3.c osi_freertos.c
|
FREERTOS_SRCS = timers.c list.c queue.c tasks.c port.c heap_3.c osi_freertos.c
|
||||||
DRIVER_SRCS = cpu.c gpio.c gpio_if.c i2c.c i2c_if.c interrupt.c pin.c prcm.c spi.c uart.c udma.c utils.c
|
DRIVER_SRCS = cpu.c gpio.c gpio_if.c i2c.c i2c_if.c interrupt.c pin.c prcm.c spi.c uart.c udma.c utils.c
|
||||||
SL_SRCS = socket.c wlan.c driver.c device.c netapp.c netcfg.c network_common.c cc_pal.c fs.c
|
SL_SRCS = socket.c wlan.c driver.c device.c netapp.c netcfg.c network_common.c timer.c cc_pal.c fs.c
|
||||||
SDK_SRCS = startup_gcc.c $(FREERTOS_SRCS) $(DRIVER_SRCS) $(SL_SRCS)
|
SDK_SRCS = startup_gcc.c $(FREERTOS_SRCS) $(DRIVER_SRCS) $(SL_SRCS)
|
||||||
IPATH += $(SDK_PATH) $(SDK_PATH)/inc $(SDK_PATH)/driverlib \
|
IPATH += $(SDK_PATH) $(SDK_PATH)/inc $(SDK_PATH)/driverlib \
|
||||||
$(SDK_PATH)/example/common $(SDK_PATH)/oslib \
|
$(SDK_PATH)/example/common $(SDK_PATH)/oslib \
|
||||||
|
|||||||
@@ -40,22 +40,22 @@ void cs_log_set_level(enum cs_log_level level);
|
|||||||
|
|
||||||
void cs_log_set_file(FILE *file);
|
void cs_log_set_file(FILE *file);
|
||||||
|
|
||||||
extern enum cs_log_level cs_log_level;
|
extern enum cs_log_level cs_log_threshold;
|
||||||
void cs_log_print_prefix(const char *func);
|
void cs_log_print_prefix(const char *func);
|
||||||
void cs_log_printf(const char *fmt, ...);
|
void cs_log_printf(const char *fmt, ...);
|
||||||
|
|
||||||
#define LOG(l, x) \
|
#define LOG(l, x) \
|
||||||
if (cs_log_level >= l) { \
|
if (cs_log_threshold >= l) { \
|
||||||
cs_log_print_prefix(__func__); \
|
cs_log_print_prefix(__func__); \
|
||||||
cs_log_printf x; \
|
cs_log_printf x; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef CS_NDEBUG
|
#ifndef CS_NDEBUG
|
||||||
|
|
||||||
#define DBG(x) \
|
#define DBG(x) \
|
||||||
if (cs_log_level >= LL_VERBOSE_DEBUG) { \
|
if (cs_log_threshold >= LL_VERBOSE_DEBUG) { \
|
||||||
cs_log_print_prefix(__func__); \
|
cs_log_print_prefix(__func__); \
|
||||||
cs_log_printf x; \
|
cs_log_printf x; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#else /* NDEBUG */
|
#else /* NDEBUG */
|
||||||
|
|||||||
@@ -294,3 +294,16 @@ void SimpleLinkGeneralEventHandler(SlDeviceEvent_t *e) {
|
|||||||
LOG(LL_ERROR, ("status %d sender %d", e->EventData.deviceEvent.status,
|
LOG(LL_ERROR, ("status %d sender %d", e->EventData.deviceEvent.status,
|
||||||
e->EventData.deviceEvent.sender));
|
e->EventData.deviceEvent.sender));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef __TI_COMPILER_VERSION__
|
||||||
|
int _gettimeofday_r(struct _reent *r, struct timeval *tp, void *tz) {
|
||||||
|
#else
|
||||||
|
int gettimeofday(struct timeval *tp, void *tz) {
|
||||||
|
#endif
|
||||||
|
unsigned long sec;
|
||||||
|
unsigned short msec;
|
||||||
|
MAP_PRCMRTCGet(&sec, &msec);
|
||||||
|
tp->tv_sec = sec;
|
||||||
|
tp->tv_usec = ((unsigned long) msec) * 1000;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -1 +1 @@
|
|||||||
docker.cesanta.com/cc3200-build:1.2.0-r8
|
docker.cesanta.com/cc3200-build:1.3.0-r2
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
SDK_VER=$(shell cat sdk.version)
|
||||||
|
|
||||||
|
.PHONY: all
|
||||||
|
|
||||||
|
MG_PATH = $(realpath $(PWD)/../../)
|
||||||
|
|
||||||
|
all:
|
||||||
|
docker run --rm -it -v $(MG_PATH):/esp32_idf \
|
||||||
|
$(SDK_VER) \
|
||||||
|
bash -c "cd esp32_idf/examples/ESP32_IDF && \
|
||||||
|
make -f Makefile.build defconfig && make -f Makefile.build"
|
||||||
|
|
||||||
|
clean:
|
||||||
|
docker run --rm -it -v $(MG_PATH):/esp32_idf \
|
||||||
|
$(SDK_VER) \
|
||||||
|
bash -c "rm -rf esp32_idf/examples/ESP32_IDF/build"
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
#
|
||||||
|
# This is a project Makefile. It is assumed the directory this Makefile resides in is a
|
||||||
|
# project subdirectory.
|
||||||
|
#
|
||||||
|
|
||||||
|
PROJECT_NAME := esp32_idf
|
||||||
|
|
||||||
|
include $(IDF_PATH)/make/project.mk
|
||||||
|
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
This is a Mongoose "Hello, world" that can be compiled under Espressif IoT Development Framework for ESP32
|
||||||
|
|
||||||
|
It connects to WiFi network and serves a "hello world" page.
|
||||||
|
|
||||||
|
Most of the the boilerplate comes from [project_template](https://github.com/espressif/esp-idf-template) with minimal changes.
|
||||||
|
|
||||||
|
For building the example, you need to have [Docker](https://www.docker.com/products/docker) and use our pre-built SDK container.
|
||||||
|
To build just run in the example directory
|
||||||
|
```
|
||||||
|
$ make
|
||||||
|
```
|
||||||
|
|
||||||
|
Note: before building, change `WIFI_SSID` and `WIFI_PASS` macros in main/main.c file
|
||||||
|
|
||||||
|
Once built, use [esptool](https://github.com/espressif/esptool) for flashing
|
||||||
|
```
|
||||||
|
$ python esptool.py --chip esp32 --port /dev/ttyUSB0 --baud 115200 --before default_reset --after hard_reset write_flash -u --flash_mode dio --flash_freq 40m --flash_size detect 0x1000 build/bootloader/bootloader.bin 0x10000 build/esp32_idf.bin 0x8000 build/partitions_singleapp.bin
|
||||||
|
```
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
#
|
||||||
|
# Main component makefile.
|
||||||
|
#
|
||||||
|
# This Makefile can be left empty. By default, it will take the sources in the
|
||||||
|
# src/ directory, compile them and link them into lib(subdirectory_name).a
|
||||||
|
# in the build directory. This behaviour is entirely configurable,
|
||||||
|
# please read the ESP-IDF documents if you need to do this.
|
||||||
|
#
|
||||||
|
|
||||||
|
COMPONENT_OBJS = main.o mongoose.o
|
||||||
|
|
||||||
|
mongoose.o: ../../../../mongoose.c
|
||||||
|
$(summary) "CC $@"
|
||||||
|
$(CC) $(CFLAGS) $(CPPFLAGS) \
|
||||||
|
$(addprefix -I ,$(COMPONENT_INCLUDES)) \
|
||||||
|
$(addprefix -I ,$(COMPONENT_EXTRA_INCLUDES)) \
|
||||||
|
-c $< -o $@
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "freertos/FreeRTOS.h"
|
||||||
|
|
||||||
|
#include "esp_event.h"
|
||||||
|
#include "esp_event_loop.h"
|
||||||
|
#include "esp_system.h"
|
||||||
|
#include "esp_wifi.h"
|
||||||
|
#include "nvs_flash.h"
|
||||||
|
|
||||||
|
#include "./../../../mongoose.h"
|
||||||
|
|
||||||
|
#define WIFI_SSID "ssid"
|
||||||
|
#define WIFI_PASS "pass"
|
||||||
|
|
||||||
|
#define MG_LISTEN_ADDR "80"
|
||||||
|
|
||||||
|
static esp_err_t event_handler(void *ctx, system_event_t *event) {
|
||||||
|
(void) ctx;
|
||||||
|
(void) event;
|
||||||
|
return ESP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void mg_ev_handler(struct mg_connection *nc, int ev, void *p) {
|
||||||
|
static const char *reply_fmt =
|
||||||
|
"HTTP/1.0 200 OK\r\n"
|
||||||
|
"Connection: close\r\n"
|
||||||
|
"Content-Type: text/plain\r\n"
|
||||||
|
"\r\n"
|
||||||
|
"Hello %s\n";
|
||||||
|
|
||||||
|
switch (ev) {
|
||||||
|
case MG_EV_ACCEPT: {
|
||||||
|
char addr[32];
|
||||||
|
mg_sock_addr_to_str(&nc->sa, addr, sizeof(addr),
|
||||||
|
MG_SOCK_STRINGIFY_IP | MG_SOCK_STRINGIFY_PORT);
|
||||||
|
printf("Connection %p from %s\n", nc, addr);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case MG_EV_HTTP_REQUEST: {
|
||||||
|
char addr[32];
|
||||||
|
struct http_message *hm = (struct http_message *) p;
|
||||||
|
mg_sock_addr_to_str(&nc->sa, addr, sizeof(addr),
|
||||||
|
MG_SOCK_STRINGIFY_IP | MG_SOCK_STRINGIFY_PORT);
|
||||||
|
printf("HTTP request from %s: %.*s %.*s\n", addr, (int) hm->method.len,
|
||||||
|
hm->method.p, (int) hm->uri.len, hm->uri.p);
|
||||||
|
mg_printf(nc, reply_fmt, addr);
|
||||||
|
nc->flags |= MG_F_SEND_AND_CLOSE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case MG_EV_CLOSE: {
|
||||||
|
printf("Connection %p closed\n", nc);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void app_main(void) {
|
||||||
|
nvs_flash_init();
|
||||||
|
tcpip_adapter_init();
|
||||||
|
ESP_ERROR_CHECK(esp_event_loop_init(event_handler, NULL));
|
||||||
|
|
||||||
|
/* Initializing WiFi */
|
||||||
|
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||||
|
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
|
||||||
|
ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM));
|
||||||
|
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
|
||||||
|
wifi_config_t sta_config = {
|
||||||
|
.sta = {.ssid = WIFI_SSID, .password = WIFI_PASS, .bssid_set = false}};
|
||||||
|
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &sta_config));
|
||||||
|
ESP_ERROR_CHECK(esp_wifi_start());
|
||||||
|
ESP_ERROR_CHECK(esp_wifi_connect());
|
||||||
|
|
||||||
|
/* Starting Mongoose */
|
||||||
|
struct mg_mgr mgr;
|
||||||
|
struct mg_connection *nc;
|
||||||
|
|
||||||
|
printf("Starting web-server on port %s\n", MG_LISTEN_ADDR);
|
||||||
|
|
||||||
|
mg_mgr_init(&mgr, NULL);
|
||||||
|
|
||||||
|
nc = mg_bind(&mgr, MG_LISTEN_ADDR, mg_ev_handler);
|
||||||
|
if (nc == NULL) {
|
||||||
|
printf("Error setting up listener!\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mg_set_protocol_http_websocket(nc);
|
||||||
|
|
||||||
|
/* Processing events */
|
||||||
|
while (1) {
|
||||||
|
mg_mgr_poll(&mgr, 1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
docker.cesanta.com/esp32-build:1.0-r13
|
||||||
@@ -56,7 +56,7 @@ LINKFLAGS_eagle.app.v6 = \
|
|||||||
-Wl,-static \
|
-Wl,-static \
|
||||||
-Wl,--start-group \
|
-Wl,--start-group \
|
||||||
-lcirom \
|
-lcirom \
|
||||||
-lgcc \
|
-lgcc_sdk \
|
||||||
-lhal \
|
-lhal \
|
||||||
-lphy \
|
-lphy \
|
||||||
-lpp \
|
-lpp \
|
||||||
@@ -116,3 +116,23 @@ sinclude $(SDK_PATH)/Makefile
|
|||||||
.PHONY: FORCE
|
.PHONY: FORCE
|
||||||
FORCE:
|
FORCE:
|
||||||
|
|
||||||
|
fw.zip:
|
||||||
|
@/usr/local/bin/fw_meta* create_manifest \
|
||||||
|
--platform=esp8266 \
|
||||||
|
--name=mongoose_example \
|
||||||
|
--build_info='{"build_version": "1.0", "build_id": "test"}' \
|
||||||
|
--staging_dir=$(ODIR) \
|
||||||
|
--output=$(ODIR)/manifest.json \
|
||||||
|
iram:addr=0,src=$(BIN_PATH)/eagle.flash.bin \
|
||||||
|
irom:addr=0x20000,src=$(BIN_PATH)/eagle.irom0text.bin \
|
||||||
|
sysparams:addr=0x7e000,type=sys_params,src=$(SDK_PATH)/bin/esp_init_data_default.bin
|
||||||
|
@/usr/local/bin/fw_meta* create_fw \
|
||||||
|
--manifest=$(ODIR)/manifest.json \
|
||||||
|
--src_dir=$(ODIR) \
|
||||||
|
--output=$@
|
||||||
|
@echo
|
||||||
|
@echo " $@ built. Use \"mos flash $@\" to flash."
|
||||||
|
@echo
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -rf fw.zip $(BIN_PATH) $(ODIR) user/.output
|
||||||
@@ -6,19 +6,29 @@ Most of the the boilerplate comes from [project_template](https://github.com/esp
|
|||||||
|
|
||||||
To build with no changes to the SDK, you will need a module with 1MB (8Mb) flash or more.
|
To build with no changes to the SDK, you will need a module with 1MB (8Mb) flash or more.
|
||||||
|
|
||||||
Compile (for NodeMCU 1.0):
|
For building the example, you have two options:
|
||||||
|
|
||||||
|
* Using [Docker](https://www.docker.com/products/docker) and use our pre-built SDK container:
|
||||||
|
```
|
||||||
|
$ ./build.sh
|
||||||
|
```
|
||||||
|
* Use SDK and toolchain installed separately as explained [here](https://github.com/espressif/ESP8266_RTOS_SDK#esp8266_rtos_sdk):
|
||||||
```
|
```
|
||||||
$ export SDK_PATH=/path/to/ESP8266_RTOS_SDK
|
$ export SDK_PATH=/path/to/ESP8266_RTOS_SDK
|
||||||
$ export BIN_PATH=./bin
|
$ export BIN_PATH=./bin
|
||||||
$ make clean; make BOOT=none APP=0 SPI_SPEED=40 SPI_MODE=dio SPI_SIZE_MAP=0
|
$ make clean; make BOOT=none APP=0 SPI_SPEED=40 SPI_MODE=dio SPI_SIZE_MAP=0
|
||||||
```
|
```
|
||||||
|
|
||||||
Flash (using [esptool](https://github.com/themadinventor/esptool)):
|
Once built, there are two options for flashing:
|
||||||
|
|
||||||
|
* Using the Mongoose OS [mos](https://mongoose-os.com/software.html) tool:
|
||||||
|
```
|
||||||
|
$ make fw.zip && mos flash fw.zip
|
||||||
|
```
|
||||||
|
* Using [esptool](https://github.com/themadinventor/esptool):
|
||||||
```
|
```
|
||||||
$ esptool.py --port /dev/ttyUSB0 --baud 230400 \
|
$ esptool.py --port /dev/ttyUSB0 --baud 230400 \
|
||||||
write_flash --flash_mode=qio --flash_size=4m \
|
write_flash --flash_mode=dio --flash_size=4m \
|
||||||
0x00000 ${BIN_PATH}/eagle.flash.bin \
|
0x00000 ${BIN_PATH}/eagle.flash.bin \
|
||||||
0x20000 ${BIN_PATH}/eagle.irom0text.bin \
|
0x20000 ${BIN_PATH}/eagle.irom0text.bin \
|
||||||
0x7e000 ${SDK_PATH}/bin/esp_init_data_default.bin
|
0x7e000 ${SDK_PATH}/bin/esp_init_data_default.bin
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
REPO=$(cd ../.. && pwd)
|
||||||
|
|
||||||
docker run \
|
docker run \
|
||||||
--rm -i -v $(realpath ${PWD}/../..):/src \
|
--rm -i -v $REPO:/src \
|
||||||
--entrypoint=/bin/bash $(cat sdk.version) -l -c -x '
|
--entrypoint=/bin/bash $(cat sdk.version) -l -c -x '
|
||||||
export SDK_PATH=/opt/Espressif/ESP8266_SDK;
|
export SDK_PATH=/opt/Espressif/ESP8266_RTOS_SDK;
|
||||||
export BIN_PATH=./bin;
|
export BIN_PATH=./bin;
|
||||||
cd /src/examples/ESP8266_RTOS &&
|
cd /src/examples/ESP8266_RTOS &&
|
||||||
mkdir -p ./bin && make clean &&
|
make clean &&
|
||||||
make BOOT=none APP=0 SPI_SPEED=40 SPI_MODE=qio SPI_SIZE_MAP=0'
|
make BOOT=none APP=0 SPI_SPEED=40 SPI_MODE=dio SPI_SIZE_MAP=0 &&
|
||||||
|
make fw.zip'
|
||||||
@@ -1 +1 @@
|
|||||||
docker.cesanta.com/esp8266-build-rtos:1.4.0-r2
|
docker.cesanta.com/esp8266-build:2.0.0-1.5.0-r1
|
||||||
@@ -12,7 +12,7 @@
|
|||||||
#define AP_CHAN 9
|
#define AP_CHAN 9
|
||||||
#define MG_LISTEN_ADDR "80"
|
#define MG_LISTEN_ADDR "80"
|
||||||
|
|
||||||
#define MG_TASK_STACK_SIZE 4096
|
#define MG_TASK_STACK_SIZE 4096 /* bytes */
|
||||||
#define MGOS_TASK_PRIORITY 1
|
#define MGOS_TASK_PRIORITY 1
|
||||||
|
|
||||||
void uart_div_modify(int uart_no, unsigned int freq);
|
void uart_div_modify(int uart_no, unsigned int freq);
|
||||||
@@ -82,7 +82,8 @@ static void mg_task(void *arg) {
|
|||||||
struct mg_mgr mgr;
|
struct mg_mgr mgr;
|
||||||
struct mg_connection *nc;
|
struct mg_connection *nc;
|
||||||
|
|
||||||
printf("SDK version: %s\n", system_get_sdk_version());
|
printf("\r\n\r\nSDK version: %s\r\n", system_get_sdk_version());
|
||||||
|
printf("Free RAM: %d\r\n", system_get_free_heap_size());
|
||||||
setup_ap();
|
setup_ap();
|
||||||
|
|
||||||
mg_mgr_init(&mgr, NULL);
|
mg_mgr_init(&mgr, NULL);
|
||||||
@@ -99,11 +100,15 @@ static void mg_task(void *arg) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
xTaskHandle s_mg_task_handle;
|
|
||||||
|
|
||||||
void user_init(void) {
|
void user_init(void) {
|
||||||
uart_div_modify(0, UART_CLK_FREQ / 115200);
|
uart_div_modify(0, UART_CLK_FREQ / 115200);
|
||||||
|
|
||||||
xTaskCreate(mg_task, (const signed char *) "mongoose", MG_TASK_STACK_SIZE,
|
printf("Free RAM: %d\r\n", system_get_free_heap_size());
|
||||||
NULL, MGOS_TASK_PRIORITY, &s_mg_task_handle);
|
xTaskCreate(mg_task, (const signed char *) "mongoose",
|
||||||
|
MG_TASK_STACK_SIZE / 4, /* in 32-bit words */
|
||||||
|
NULL, MGOS_TASK_PRIORITY, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t user_rf_cal_sector_set(void) {
|
||||||
|
return 0xfb; /* 0xfb000, just before system data for 8Mbit flash. */
|
||||||
}
|
}
|
||||||
+1
-1
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
# `wildcard ./*/` works in both linux and linux/wine, while `wildcard */` enumerates nothing under wine
|
# `wildcard ./*/` works in both linux and linux/wine, while `wildcard */` enumerates nothing under wine
|
||||||
SUBDIRS = $(sort $(dir $(wildcard ./*/)))
|
SUBDIRS = $(sort $(dir $(wildcard ./*/)))
|
||||||
SUBDIRS:=$(filter-out ./ ./CC3200/ ./ESP8266_RTOS/ ./mbed/ ./MSP432/ ./nRF51/ ./nRF52/ ./NXP_K64/ ./NXP_LPC4088/ ./PIC32/ ./STM32F4_CC3100/ ./TM4C129/ ./WinCE/, $(SUBDIRS))
|
SUBDIRS:=$(filter-out ./ ./CC3200/ ./ESP32_IDF/ ./ESP8266_RTOS/ ./mbed/ ./MSP432/ ./nRF51/ ./nRF52/ ./NXP_K64/ ./NXP_LPC4088/ ./PIC32/ ./STM32F4_CC3100/ ./TM4C129/ ./WinCE/, $(SUBDIRS))
|
||||||
|
|
||||||
ifeq ($(OS), Windows_NT)
|
ifeq ($(OS), Windows_NT)
|
||||||
SUBDIRS:=$(filter-out ./netcat/ ./raspberry_pi_mjpeg_led/ ./captive_dns_server/, $(SUBDIRS))
|
SUBDIRS:=$(filter-out ./netcat/ ./raspberry_pi_mjpeg_led/ ./captive_dns_server/, $(SUBDIRS))
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
SDK ?= $(shell cat sdk.version)
|
SDK ?= $(shell cat sdk.version)
|
||||||
SRC_DIR ?= $(realpath ../../..)
|
SRC_DIR ?= $(realpath ../..)
|
||||||
|
|
||||||
.PHONY: all clean
|
.PHONY: all clean
|
||||||
|
|
||||||
@@ -8,6 +8,5 @@ MAKEFLAGS += w
|
|||||||
all clean:
|
all clean:
|
||||||
docker run --rm -i -v $(SRC_DIR):/src $(SDK) \
|
docker run --rm -i -v $(SRC_DIR):/src $(SDK) \
|
||||||
/bin/bash -c "\
|
/bin/bash -c "\
|
||||||
make -C /src/mongoose mongoose.c mongoose.h && \
|
make -C /src/examples/STM32F4_CC3100 -f Makefile.build $@ -$(MAKEFLAGS) \
|
||||||
make -C /src/mongoose/examples/STM32F4_CC3100 -f Makefile.build $@ -$(MAKEFLAGS) \
|
|
||||||
"
|
"
|
||||||
@@ -11,9 +11,9 @@ STM32F4_SRCS = stm32f4xx_hal_spi.c stm32f4xx_hal_gpio.c stm32f4xx_hal_cortex.c\
|
|||||||
stm32f4xx_hal_uart.c stm32f4xx_hal_tim.c \
|
stm32f4xx_hal_uart.c stm32f4xx_hal_tim.c \
|
||||||
stm32f4xx_hal_tim_ex.c stm32f4xx_hal_rtc_ex.c stm32f4xx_hal_rtc.c
|
stm32f4xx_hal_tim_ex.c stm32f4xx_hal_rtc_ex.c stm32f4xx_hal_rtc.c
|
||||||
|
|
||||||
SRCS = main.c mongoose.c startup_utils.c ${CC3100_DRV_SRCS} ${CC3100_PLATFORM_SRCS} ${STM32F4_SRCS}
|
SRCS = main.c mongoose.c startup_utils.c ${CC3100_DRV_SRCS} ${CC3100_PLATFORM_SRCS} ${STM32F4_SRCS}
|
||||||
|
|
||||||
REPO_ROOT=./../../../
|
REPO_ROOT=./../../
|
||||||
CC3100_SDKROOT=/opt/CC3100SDK_1.2.0/cc3100-sdk
|
CC3100_SDKROOT=/opt/CC3100SDK_1.2.0/cc3100-sdk
|
||||||
STM32CUBEF4_ROOT=/opt/STM32CubeF4
|
STM32CUBEF4_ROOT=/opt/STM32CubeF4
|
||||||
STM32CUBEF4_DRV_PATH=${STM32CUBEF4_ROOT}/Drivers
|
STM32CUBEF4_DRV_PATH=${STM32CUBEF4_ROOT}/Drivers
|
||||||
@@ -22,7 +22,7 @@ CC = arm-none-eabi-gcc
|
|||||||
OBJCOPY = arm-none-eabi-objcopy
|
OBJCOPY = arm-none-eabi-objcopy
|
||||||
|
|
||||||
FP_FLAGS = -mfloat-abi=hard -mfpu=fpv4-sp-d16
|
FP_FLAGS = -mfloat-abi=hard -mfpu=fpv4-sp-d16
|
||||||
ARCH_FLAGS = -mthumb -mcpu=cortex-m4
|
ARCH_FLAGS = -mthumb -mcpu=cortex-m4
|
||||||
|
|
||||||
BUILD_DIR=.build
|
BUILD_DIR=.build
|
||||||
OUT_DIR=out
|
OUT_DIR=out
|
||||||
@@ -36,21 +36,20 @@ OBJS = $(addprefix $(BUILD_DIR)/,$(patsubst %.c,%.o,$(SRCS)) $(patsubst %.s,%.o,
|
|||||||
|
|
||||||
VPATH = ${CC3100_SDKROOT}/simplelink/source\
|
VPATH = ${CC3100_SDKROOT}/simplelink/source\
|
||||||
${CC3100_SDKROOT}/platform/stm32discovery\
|
${CC3100_SDKROOT}/platform/stm32discovery\
|
||||||
${STM32CUBEF4_ROOT}/Drivers/STM32F4xx_HAL_Driver/Src\
|
${STM32CUBEF4_ROOT}/Drivers/STM32F4xx_HAL_Driver/Src\
|
||||||
${STM32CUBEF4_ROOT}/Drivers/BSP/STM32F4-Discovery\
|
${STM32CUBEF4_ROOT}/Drivers/BSP/STM32F4-Discovery\
|
||||||
${REPO_ROOT}/mongoose
|
${REPO_ROOT}
|
||||||
|
|
||||||
# CC3100 SDK and STM32 SDK include headers w/out path, just like
|
# CC3100 SDK and STM32 SDK include headers w/out path, just like
|
||||||
# #include "simplelink.h". As result, we have to add all required directories
|
# #include "simplelink.h". As result, we have to add all required directories
|
||||||
# into IPATH
|
# into IPATH
|
||||||
|
|
||||||
IPATH = . \
|
IPATH = . ${CC3100_SDKROOT}/simplelink/include\
|
||||||
${CC3100_SDKROOT}/simplelink/include\
|
${CC3100_SDKROOT}/platform/stm32discovery\
|
||||||
${CC3100_SDKROOT}/platform/stm32discovery\
|
${STM32CUBEF4_DRV_PATH}/BSP/STM32F4-Discovery\
|
||||||
${STM32CUBEF4_DRV_PATH}/BSP/STM32F4-Discovery\
|
${STM32CUBEF4_DRV_PATH}/STM32F4xx_HAL_Driver/Inc\
|
||||||
${STM32CUBEF4_DRV_PATH}/STM32F4xx_HAL_Driver/Inc\
|
${STM32CUBEF4_DRV_PATH}/CMSIS/Include\
|
||||||
${STM32CUBEF4_DRV_PATH}/CMSIS/Include\
|
${STM32CUBEF4_DRV_PATH}/CMSIS/Device/ST/STM32F4xx/Include
|
||||||
${STM32CUBEF4_DRV_PATH}/CMSIS/Device/ST/STM32F4xx/Include
|
|
||||||
|
|
||||||
LDFLAGS = --static -nostartfiles
|
LDFLAGS = --static -nostartfiles
|
||||||
LDLIBS = -Wl,--start-group -lc -lgcc -lnosys -Wl,--end-group
|
LDLIBS = -Wl,--start-group -lc -lgcc -lnosys -Wl,--end-group
|
||||||
@@ -59,13 +58,13 @@ LDSCRIPT = stm32f429xx.ld
|
|||||||
INCDIRS = $(addprefix -I,$(IPATH))
|
INCDIRS = $(addprefix -I,$(IPATH))
|
||||||
|
|
||||||
CFLAGS = ${FP_FLAGS} ${ARCH_FLAGS} ${INCDIRS}\
|
CFLAGS = ${FP_FLAGS} ${ARCH_FLAGS} ${INCDIRS}\
|
||||||
-D${BOARD} -DEXT_LIB_REGISTERED_GENERAL_EVENTS \
|
-D${BOARD} -DEXT_LIB_REGISTERED_GENERAL_EVENTS \
|
||||||
-DSL_FULL\
|
-DSL_FULL\
|
||||||
-DCS_PLATFORM=6 \
|
-DCS_PLATFORM=6 \
|
||||||
-D__STM32F407xx_H \
|
-D__STM32F407xx_H \
|
||||||
-DMG_SIMPLELINK_NO_OSI \
|
-DMG_SIMPLELINK_NO_OSI \
|
||||||
-DMG_ENABLE_MQTT \
|
-DMG_ENABLE_MQTT \
|
||||||
-g -fno-common -ffunction-sections -fdata-sections \
|
-g -fno-common -ffunction-sections -fdata-sections \
|
||||||
|
|
||||||
ELF = ${BUILD_DIR}/${PROJECT}.elf
|
ELF = ${BUILD_DIR}/${PROJECT}.elf
|
||||||
BIN = ${OUT_DIR}/${PROJECT}.bin
|
BIN = ${OUT_DIR}/${PROJECT}.bin
|
||||||
@@ -79,15 +78,15 @@ ${OUT_DIR}:
|
|||||||
mkdir -p $@
|
mkdir -p $@
|
||||||
|
|
||||||
$(BUILD_DIR)/%.o: %.c
|
$(BUILD_DIR)/%.o: %.c
|
||||||
$(CC) ${CFLAGS} $^ -c -o $@
|
$(CC) ${CFLAGS} $^ -c -o $@
|
||||||
|
|
||||||
$(BUILD_DIR)/%.o: %.s
|
$(BUILD_DIR)/%.o: %.s
|
||||||
$(CC) ${CFLAGS} $^ -c -o $@
|
$(CC) ${CFLAGS} $^ -c -o $@
|
||||||
|
|
||||||
${ELF}: ${OBJS}
|
${ELF}: ${OBJS}
|
||||||
$(CC) ${ARCH_FLAGS} ${FP_FLAGS} $(LDFLAGS) $(OBJS) $(LDLIBS) -T$(LDSCRIPT) -o $@
|
$(CC) ${ARCH_FLAGS} ${FP_FLAGS} $(LDFLAGS) $(OBJS) $(LDLIBS) -T$(LDSCRIPT) -o $@
|
||||||
|
|
||||||
${BIN}: ${ELF}
|
${BIN}: ${ELF}
|
||||||
$(OBJCOPY) -Obinary $^ $@
|
$(OBJCOPY) -Obinary $^ $@
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
|
|||||||
@@ -1,2 +0,0 @@
|
|||||||
# This "makefile" is only intended to prevent errors during main makefile execution
|
|
||||||
all:
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
# Arduino Restful Client
|
|
||||||
|
|
||||||
This example demonstrates how to use [Mongoose](https://www.cesanta.com/mongoose) to send HTTP commands from Arduino.
|
|
||||||
|
|
||||||
Example sends free memory size and current board uptime, but it can be modified to send any user-specific data.
|
|
||||||
|
|
||||||
At the moment this example supports [Arduino Mega 2560](http://arduino.cc/en/Main/ArduinoBoardMega2560) board (and compatible) with either W5100-based
|
|
||||||
network shield (like [Arduino Ethernet Shield](http://arduino.cc/en/Main/ArduinoEthernetShield)) or [CC3000](http://www.ti.com/product/cc3000)-based WIFI Shield.
|
|
||||||
|
|
||||||
## Build and run instructions:
|
|
||||||
|
|
||||||
###To run with Arduino Ethernet (W5100) shield:
|
|
||||||
1. Add (Sketch->Add file...) the following files to sketch:
|
|
||||||
- /mongoose/mongoose.h
|
|
||||||
- /mongoose/mongoose.c
|
|
||||||
- /mongoose/platforms/arduino_ethernet_W5100/avrsupport.h
|
|
||||||
- /mongoose/platforms/arduino_ethernet_W5100/avrsupport.cpp
|
|
||||||
3. Buils and start (in console) /Users/alex/Projects/mongoose/examples/restful_server example
|
|
||||||
4. Make `board_ip` and `board_mac` variables suitable for your network and board
|
|
||||||
5. Change IP address in `s_target_address` variable to IP address of host running restful_server
|
|
||||||
6. Uncomment line `#include <Ethernet.h>`
|
|
||||||
7. Compile and flash sketch
|
|
||||||
8. restful_server will start to show current uptime and free memory size (with 5 seconds interval)
|
|
||||||
|
|
||||||
###To run with Adafruit WiFi (CC3000) shield:
|
|
||||||
1. Add (Sketch->Add files...) the following files to sketch:
|
|
||||||
- /mongoose/mongoose.h
|
|
||||||
- /mongoose/mongoose.c
|
|
||||||
- /mongoose/platforms/arduino_ethernet_W5100/avrsupport.h
|
|
||||||
- /mongoose/platforms/arduino_ethernet_W5100/avrsupport.cpp
|
|
||||||
2. Import Adafruit CC3000 library for mongoose
|
|
||||||
(select Sketch->Import Library...->Add library... and point
|
|
||||||
/mongoose/platforms/arduino_wifi_CC3000/adafruit_CC3000_lib_mongoose folder)
|
|
||||||
3. Buils and start (in console) /Users/alex/Projects/mongoose/examples/restful_server example
|
|
||||||
4. Make the following variables suitable for your network
|
|
||||||
- `board_ip`
|
|
||||||
- `subnet_mask`
|
|
||||||
- `gateway`
|
|
||||||
- `dns`
|
|
||||||
- `wlan_ssid`
|
|
||||||
- `wlan_pwd`
|
|
||||||
- `wlan_security`
|
|
||||||
5. Change IP address in `s_target_address` variable to IP address of host running restful_server
|
|
||||||
6. Uncomment line `#include <Adafruit_CC3000.h>`
|
|
||||||
8. Compile and flash sketch
|
|
||||||
9. restful_server will start to show current uptime and free memory size (with 5 seconds interval)
|
|
||||||
@@ -1,141 +0,0 @@
|
|||||||
|
|
||||||
/*
|
|
||||||
* Copyright (c) 2015 Cesanta Software Limited
|
|
||||||
* All rights reserved
|
|
||||||
*
|
|
||||||
* Build and run instructions:
|
|
||||||
* To run with Arduino Ethernet (W5100) shield:
|
|
||||||
* -----------------------------------------------------------
|
|
||||||
* 1. Add (Sketch->Add file...) the following files to sketch:
|
|
||||||
* - /mongoose/mongoose.h
|
|
||||||
* - /mongoose/mongoose.c
|
|
||||||
* - /mongoose/platforms/arduino_ethernet_W5100/avrsupport.h
|
|
||||||
* - /mongoose/platforms/arduino_ethernet_W5100/avrsupport.cpp
|
|
||||||
* 2. Buils and run in console /Users/alex/Projects/mongoose/examples/restful_server example
|
|
||||||
* 3. Make board_ip and board_mac variables suitable for your network and board
|
|
||||||
* 4. Uncomment line #include <Ethernet.h>
|
|
||||||
* 5. Change IP address in s_target_address variable to IP address of host running restful_server
|
|
||||||
* 6. Compile & flash sketch
|
|
||||||
* 7. restful_server server will start to show current uptime and free memory size (with 5 second interval)
|
|
||||||
*
|
|
||||||
* To run with Adafruit WiFi (CC3000) shield:
|
|
||||||
* -----------------------------------------------------------
|
|
||||||
* 1. Add (Sketch->Add files...) the following files to sketch:
|
|
||||||
* - /mongoose/mongoose.h
|
|
||||||
* - /mongoose/mongoose.c
|
|
||||||
* - /mongoose/platforms/arduino_ethernet_W5100/avrsupport.h
|
|
||||||
* - /mongoose/platforms/arduino_ethernet_W5100/avrsupport.cpp
|
|
||||||
* 2. Import Adafruit CC3000 library for mongoose (select Sketch->Import Library...->Add library... and point
|
|
||||||
* /mongoose/platforms/arduino_wifi_CC3000/adafruit_CC3000_lib_mongoose folder
|
|
||||||
* 3. Buils and run in console /Users/alex/Projects/mongoose/examples/restful_server example
|
|
||||||
* 4. Make the following variables suitable for your network
|
|
||||||
* - board_ip
|
|
||||||
* - subnet_mask
|
|
||||||
* - gateway
|
|
||||||
* - dns
|
|
||||||
* - wlan_ssid
|
|
||||||
* - wlan_pwd
|
|
||||||
* - wlan_security
|
|
||||||
* 5. Uncomment line #include <Adafruit_CC3000.h>
|
|
||||||
* 6. Compile & flash sketch
|
|
||||||
* 7. restful_server server will start to show current uptime and free memory size (with 5 second interval) *
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
//#include <Ethernet.h>
|
|
||||||
//#include <Adafruit_CC3000.h>
|
|
||||||
#include <SPI.h>
|
|
||||||
#include "mongoose.h"
|
|
||||||
|
|
||||||
// CHANGE THESE VARIABLES
|
|
||||||
// NB: Devices with the same address must not end up on the same network.
|
|
||||||
// Use MAC address provided by device manufacturer (e.g. on a sticker).
|
|
||||||
// If there isn't one, use a random one from the locally administered range.
|
|
||||||
// See http://en.wikipedia.org/wiki/MAC_address for details.
|
|
||||||
static uint8_t board_mac[] = {
|
|
||||||
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
|
|
||||||
};
|
|
||||||
static uint8_t board_ip[] = {192, 168, 10, 177};
|
|
||||||
|
|
||||||
#ifdef WIFI_CC3000
|
|
||||||
static uint8_t subnet_mask[] = {255, 255, 255, 0};
|
|
||||||
static uint8_t gateway[] = {192, 168, 10, 254};
|
|
||||||
static uint8_t dns_ip[] = {192, 168, 10, 254};
|
|
||||||
|
|
||||||
static const char *wlan_ssid = "mynetwork";
|
|
||||||
static const char *wlan_pwd = "mypassword";
|
|
||||||
static int wlan_security = WLAN_SEC_WPA2;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static const char *s_target_address = "192.168.10.3:8000";
|
|
||||||
|
|
||||||
/////////////////////////////////////////////
|
|
||||||
|
|
||||||
static const char *s_request = "/printcontent";
|
|
||||||
|
|
||||||
static uint32_t IP2U32(uint8_t* iparr) {
|
|
||||||
return ((uint32_t)iparr[0] << 24) | ((uint32_t)iparr[1] << 16) | (iparr[2] << 8) | (iparr[3]);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int get_data_to_send(char* buf, int buf_size) {
|
|
||||||
// Adding data to send
|
|
||||||
// It could be any sensor data, now just put uptime & free memory size here
|
|
||||||
return snprintf(buf, buf_size, "Uptime: %lus Free memory: %db",
|
|
||||||
millis()/1000, get_freememsize());
|
|
||||||
}
|
|
||||||
static void rfc_ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
|
|
||||||
int connect_status;
|
|
||||||
|
|
||||||
switch (ev) {
|
|
||||||
case NS_CONNECT:
|
|
||||||
connect_status = * (int *) ev_data;
|
|
||||||
|
|
||||||
if (connect_status == 0) {
|
|
||||||
char buf[100];
|
|
||||||
int len = get_data_to_send(buf, sizeof(buf));
|
|
||||||
mg_printf(nc, "POST %s HTTP/1.0\r\nHost: %s\r\nContent-Lenght: %d"
|
|
||||||
"\r\n\r\n%s", s_request, s_target_address, len, buf);
|
|
||||||
nc->flags |= MG_F_SEND_AND_CLOSE;
|
|
||||||
} else {
|
|
||||||
nc->flags |= MG_F_CLOSE_IMMEDIATELY;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct mg_mgr mgr;
|
|
||||||
static struct mg_connection *nc;
|
|
||||||
|
|
||||||
void setup()
|
|
||||||
{
|
|
||||||
Serial.begin(9600);
|
|
||||||
Serial.println("Initialization...");
|
|
||||||
#if defined(ETHERNET_W5100)
|
|
||||||
avr_netinit(board_mac, board_ip);
|
|
||||||
#elif defined(WIFI_CC3000)
|
|
||||||
if (avr_netinit(wlan_ssid, wlan_pwd, wlan_security, IP2U32(board_ip),
|
|
||||||
IP2U32(subnet_mask), IP2U32(gateway), IP2U32(dns_ip)) != 0) {
|
|
||||||
Serial.println("Initialization error, check network settings");
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
mg_mgr_init(&mgr, NULL);
|
|
||||||
Serial.println("Initialization done");
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop() {
|
|
||||||
nc = mg_connect(&mgr, s_target_address, rfc_ev_handler);
|
|
||||||
if (nc != NULL) {
|
|
||||||
mg_set_protocol_http_websocket(nc);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t time_to_finish = millis() + 5000;
|
|
||||||
while (millis() < time_to_finish) {
|
|
||||||
mg_mgr_poll(&mgr, 1000);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
# This "makefile" is only intended to prevent errors during main makefile execution
|
|
||||||
all:
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
# Arduino Restful Server
|
|
||||||
|
|
||||||
This example demonstrates how to use [Mongoose](https://www.cesanta.com/mongoose) to control Arduino
|
|
||||||
using HTTP requests.
|
|
||||||
Example just blinks by LED when Mongoose receives HTTP command, but it can be modified to execute any user-specific code.
|
|
||||||
|
|
||||||
At the moment this example supports [Arduino Mega 2560](http://arduino.cc/en/Main/ArduinoBoardMega2560) board (and compatible) with either W5100-based
|
|
||||||
network shield (like [Arduino Ethernet Shield](http://arduino.cc/en/Main/ArduinoEthernetShield)) or [CC3000](http://www.ti.com/product/cc3000)-based WIFI Shield.
|
|
||||||
|
|
||||||
## Build and run instructions:
|
|
||||||
|
|
||||||
###To run with Arduino Ethernet (W5100) shield:
|
|
||||||
1. Add (Sketch->Add file...) the following files to sketch:
|
|
||||||
- /mongoose/mongoose.h
|
|
||||||
- /mongoose/mongoose.c
|
|
||||||
- /mongoose/platforms/arduino_ethernet_W5100/avrsupport.h
|
|
||||||
- /mongoose/platforms/arduino_ethernet_W5100/avrsupport.cpp
|
|
||||||
2. Make `board_ip` and `board_mac` variables suitable for your network and board
|
|
||||||
3. Uncomment line `#include <Ethernet.h>`
|
|
||||||
4. Compile and flash sketch
|
|
||||||
5. Run `curl http://<board_ip/blink`
|
|
||||||
LED attached to PIN 13 will blink and board free memory size and board uptime will be displayed.
|
|
||||||
|
|
||||||
|
|
||||||
###To run with Adafruit WiFi (CC3000) shield:
|
|
||||||
1. Add (Sketch->Add files...) the following files to sketch:
|
|
||||||
- /mongoose/mongoose.h
|
|
||||||
- /mongoose/mongoose.c
|
|
||||||
- /mongoose/platforms/arduino_ethernet_W5100/avrsupport.h
|
|
||||||
- /mongoose/platforms/arduino_ethernet_W5100/avrsupport.cpp
|
|
||||||
2. Import Adafruit CC3000 library for mongoose
|
|
||||||
(select Sketch->Import Library...->Add library... and point
|
|
||||||
/mongoose/platforms/arduino_wifi_CC3000/adafruit_CC3000_lib_mongoose folder)
|
|
||||||
3. Make the following variables suitable for your network
|
|
||||||
- `board_ip`
|
|
||||||
- `subnet_mask`
|
|
||||||
- `gateway`
|
|
||||||
- `dns`
|
|
||||||
- `wlan_ssid`
|
|
||||||
- `wlan_pwd`
|
|
||||||
- `wlan_security`
|
|
||||||
5. Uncomment line `#include <Adafruit_CC3000.h>`
|
|
||||||
4. Compile and flash sketch
|
|
||||||
5. Run curl `http://<board_ip/blink`
|
|
||||||
LED attached to PIN 13 will blink and board free memory size and board uptime will be displayed.
|
|
||||||
@@ -1,133 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2015 Cesanta Software Limited
|
|
||||||
* All rights reserved
|
|
||||||
*
|
|
||||||
* Build and run instructions:
|
|
||||||
* To run with Arduino Ethernet (W5100) shield:
|
|
||||||
* -----------------------------------------------------------
|
|
||||||
* 1. Add (Sketch->Add file...) the following files to sketch:
|
|
||||||
* - /mongoose/mongoose.h
|
|
||||||
* - /mongoose/mongoose.c
|
|
||||||
* - /mongoose/platforms/arduino_ethernet_W5100/avrsupport.h
|
|
||||||
* - /mongoose/platforms/arduino_ethernet_W5100/avrsupport.cpp
|
|
||||||
* 2. Make board_ip and board_mac variables suitable for your network and board
|
|
||||||
* 3. Uncomment line #include <Ethernet.h>
|
|
||||||
* 4. Compile & flash sketch
|
|
||||||
* 5. Run curl http://<board_ip/blink
|
|
||||||
* LED attached to PIN 13 will blink and board free memory size and uptime will responsed
|
|
||||||
*
|
|
||||||
* To run with Adafruit WiFi (CC3000) shield:
|
|
||||||
* -----------------------------------------------------------
|
|
||||||
* 1. Add (Sketch->Add files...) the following files to sketch:
|
|
||||||
* - /mongoose/mongoose.h
|
|
||||||
* - /mongoose/mongoose.c
|
|
||||||
* - /mongoose/platforms/arduino_ethernet_W5100/avrsupport.h
|
|
||||||
* - /mongoose/platforms/arduino_ethernet_W5100/avrsupport.cpp
|
|
||||||
* 2. Import Adafruit CC3000 library for mongoose (select Sketch->Import Library...->Add library... and point
|
|
||||||
* /mongoose/platforms/arduino_wifi_CC3000/adafruit_CC3000_lib_mongoose folder
|
|
||||||
* 3. Make the following variables suitable for your network
|
|
||||||
* - board_ip
|
|
||||||
* - subnet_mask
|
|
||||||
* - gateway
|
|
||||||
* - dns
|
|
||||||
* - wlan_ssid
|
|
||||||
* - wlan_pwd
|
|
||||||
* - wlan_security
|
|
||||||
* 5. Uncomment line #include <Adafruit_CC3000.h>
|
|
||||||
* 4. Compile & flash sketch
|
|
||||||
* 5. Run curl http://<board_ip/blink
|
|
||||||
* LED attached to PIN 13 will blink and board free memory size and uptime will responsed
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
//#include <Ethernet.h>
|
|
||||||
//#include <Adafruit_CC3000.h>
|
|
||||||
#include <SPI.h>
|
|
||||||
#include "mongoose.h"
|
|
||||||
|
|
||||||
// CHANGE THESE VARIABLES
|
|
||||||
// NB: Devices with the same address must not end up on the same network.
|
|
||||||
// Use MAC address provided by device manufacturer (e.g. on a sticker).
|
|
||||||
// If there isn't one, use a random one from the locally administered range.
|
|
||||||
// See http://en.wikipedia.org/wiki/MAC_address for details.
|
|
||||||
static uint8_t board_mac[] = {
|
|
||||||
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
|
|
||||||
};
|
|
||||||
|
|
||||||
static uint8_t board_ip[] = {192, 168, 10, 8};
|
|
||||||
|
|
||||||
#ifdef WIFI_CC3000
|
|
||||||
static uint8_t subnet_mask[] = {255, 255, 255, 0};
|
|
||||||
static uint8_t gateway[] = {192, 168, 10, 254};
|
|
||||||
static uint8_t dns_ip[] = {192, 168, 10, 254};
|
|
||||||
|
|
||||||
static const char *wlan_ssid = "mynetwork";
|
|
||||||
static const char *wlan_pwd = "mypassword";
|
|
||||||
static int wlan_security = WLAN_SEC_WPA2;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
///////////////////////////////////////////////
|
|
||||||
|
|
||||||
static const char *s_http_port = "60000";
|
|
||||||
|
|
||||||
static uint32_t IP2U32(uint8_t* iparr) {
|
|
||||||
return ((uint32_t)iparr[0] << 24) | ((uint32_t)iparr[1] << 16) | (iparr[2] << 8) | (iparr[3]);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void rfs_ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
|
|
||||||
struct http_message *hm = (struct http_message *) ev_data;
|
|
||||||
char buf[100];
|
|
||||||
int clen;
|
|
||||||
|
|
||||||
switch (ev) {
|
|
||||||
case NS_HTTP_REQUEST:
|
|
||||||
if (mg_vcmp(&hm->uri, "/blink") == 0) {
|
|
||||||
blink(1, 500);
|
|
||||||
}
|
|
||||||
|
|
||||||
clen = snprintf(buf, sizeof(buf),
|
|
||||||
"Free memory size: %d Uptime: %d",
|
|
||||||
(int)get_freememsize(), (int)time(NULL));
|
|
||||||
|
|
||||||
mg_printf_http_chunk(nc, "HTTP/1.1 200 OK\r\n"
|
|
||||||
"Content-Length: %d\r\n"
|
|
||||||
"Transfer-Encoding: chunked\r\n\r\n"
|
|
||||||
"%s",
|
|
||||||
clen, buf);
|
|
||||||
|
|
||||||
mg_send_http_chunk(nc, "", 0);
|
|
||||||
break;
|
|
||||||
case NS_SEND:
|
|
||||||
nc->flags |= MG_F_CLOSE_IMMEDIATELY;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct mg_connection *nc;
|
|
||||||
static struct mg_mgr mgr;
|
|
||||||
|
|
||||||
void setup() {
|
|
||||||
Serial.begin(9600);
|
|
||||||
Serial.println("Initialization...");
|
|
||||||
#if defined(ETHERNET_W5100)
|
|
||||||
avr_netinit(board_mac, board_ip);
|
|
||||||
#elif defined(WIFI_CC3000)
|
|
||||||
if (avr_netinit(wlan_ssid, wlan_pwd, wlan_security, IP2U32(board_ip),
|
|
||||||
IP2U32(subnet_mask), IP2U32(gateway), IP2U32(dns_ip)) != 0) {
|
|
||||||
Serial.println("Initialization error, check network settings");
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
mg_mgr_init(&mgr, NULL);
|
|
||||||
nc = mg_bind(&mgr, s_http_port, rfs_ev_handler);
|
|
||||||
mg_set_protocol_http_websocket(nc);
|
|
||||||
Serial.println("Initialization done");
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop() {
|
|
||||||
mg_mgr_poll(&mgr, 1000);
|
|
||||||
}
|
|
||||||
@@ -10,28 +10,13 @@
|
|||||||
#include "mongoose.h"
|
#include "mongoose.h"
|
||||||
|
|
||||||
static const char *s_http_port = "8000";
|
static const char *s_http_port = "8000";
|
||||||
|
static struct mg_serve_http_opts s_http_server_opts;
|
||||||
|
|
||||||
struct file_writer_data {
|
struct file_writer_data {
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
size_t bytes_written;
|
size_t bytes_written;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void handle_request(struct mg_connection *nc) {
|
|
||||||
// This handler gets for all endpoints but /upload
|
|
||||||
mg_printf(nc, "%s",
|
|
||||||
"HTTP/1.1 200 OK\r\n"
|
|
||||||
"Content-Type: text/html\r\n"
|
|
||||||
"Connection: close\r\n"
|
|
||||||
"\r\n"
|
|
||||||
"<html><body>Upload example."
|
|
||||||
"<form method=\"POST\" action=\"/upload\" "
|
|
||||||
" enctype=\"multipart/form-data\">"
|
|
||||||
"<input type=\"file\" name=\"file\" /> <br/>"
|
|
||||||
"<input type=\"submit\" value=\"Upload\" />"
|
|
||||||
"</form></body></html>");
|
|
||||||
nc->flags |= MG_F_SEND_AND_CLOSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void handle_upload(struct mg_connection *nc, int ev, void *p) {
|
static void handle_upload(struct mg_connection *nc, int ev, void *p) {
|
||||||
struct file_writer_data *data = (struct file_writer_data *) nc->user_data;
|
struct file_writer_data *data = (struct file_writer_data *) nc->user_data;
|
||||||
struct mg_http_multipart_part *mp = (struct mg_http_multipart_part *) p;
|
struct mg_http_multipart_part *mp = (struct mg_http_multipart_part *) p;
|
||||||
@@ -82,25 +67,27 @@ static void handle_upload(struct mg_connection *nc, int ev, void *p) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
|
static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
|
||||||
(void) ev_data;
|
if (ev == MG_EV_HTTP_REQUEST) {
|
||||||
switch (ev) {
|
mg_serve_http(nc, ev_data, s_http_server_opts);
|
||||||
case MG_EV_HTTP_REQUEST:
|
|
||||||
// Invoked when the full HTTP request is in the buffer (including body).
|
|
||||||
handle_request(nc);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
struct mg_mgr mgr;
|
struct mg_mgr mgr;
|
||||||
struct mg_connection *nc;
|
struct mg_connection *c;
|
||||||
|
|
||||||
mg_mgr_init(&mgr, NULL);
|
mg_mgr_init(&mgr, NULL);
|
||||||
nc = mg_bind(&mgr, s_http_port, ev_handler);
|
c = mg_bind(&mgr, s_http_port, ev_handler);
|
||||||
|
if (c == NULL) {
|
||||||
|
fprintf(stderr, "Cannot start server on port %s\n", s_http_port);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
s_http_server_opts.document_root = "."; // Serve current directory
|
||||||
|
mg_register_http_endpoint(c, "/upload", handle_upload MG_UD_ARG(NULL));
|
||||||
|
|
||||||
mg_register_http_endpoint(nc, "/upload", handle_upload);
|
|
||||||
// Set up HTTP server parameters
|
// Set up HTTP server parameters
|
||||||
mg_set_protocol_http_websocket(nc);
|
mg_set_protocol_http_websocket(c);
|
||||||
|
|
||||||
printf("Starting web server on port %s\n", s_http_port);
|
printf("Starting web server on port %s\n", s_http_port);
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
|||||||
@@ -0,0 +1,54 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>AJAX Upload Example</title>
|
||||||
|
<script src="//code.jquery.com/jquery-1.9.1.js"></script>
|
||||||
|
<script type="text/javascript">
|
||||||
|
function updateProgress(evt) {
|
||||||
|
if (evt.lengthComputable) {
|
||||||
|
document.getElementById("output").textContent =
|
||||||
|
"Uploaded " + evt.loaded + " of " + evt.total + " bytes";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function uploadFile() {
|
||||||
|
var file_data = new FormData(document.getElementById('filename'));
|
||||||
|
$.ajax({
|
||||||
|
url: "/upload",
|
||||||
|
type: "POST",
|
||||||
|
data: file_data,
|
||||||
|
processData: false,
|
||||||
|
contentType: false,
|
||||||
|
cache: false,
|
||||||
|
xhr: function() {
|
||||||
|
myXhr = $.ajaxSettings.xhr();
|
||||||
|
if(myXhr.upload){
|
||||||
|
myXhr.upload.addEventListener('progress',updateProgress, false); // for handling the progress of the upload
|
||||||
|
}
|
||||||
|
return myXhr;
|
||||||
|
},
|
||||||
|
}).done(function(data) {
|
||||||
|
document.getElementById("output").textContent = "Result: " + data;
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<h1>Upload file using standard form upload</h1>
|
||||||
|
|
||||||
|
<form method="POST" action="/upload" enctype="multipart/form-data">
|
||||||
|
<label>Select a file:</label><br>
|
||||||
|
<input type="file" name="file" />
|
||||||
|
<input type="submit" value="Upload" />
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<h1>Upload file using Ajax - that also gives progress report</h1>
|
||||||
|
<form method="post" id="filename" name="filename" onsubmit="return uploadFile();">
|
||||||
|
<label>Select a file:</label><br>
|
||||||
|
<input type="file" id="file" name="file" required />
|
||||||
|
<input type="submit" value="Upload" />
|
||||||
|
</form>
|
||||||
|
<br><br><div id="output"></div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
PROG = captive_dns_server
|
PROG = captive_dns_server
|
||||||
MODULE_CFLAGS=-DMG_ENABLE_DNS_SERVER -DMG_ENABLE_IPV6
|
MODULE_CFLAGS=-DMG_ENABLE_DNS_SERVER -DMG_ENABLE_IPV6
|
||||||
SSL_LIB=openssl
|
|
||||||
include ../examples.mk
|
include ../examples.mk
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 5.7 KiB After Width: | Height: | Size: 2.4 KiB |
Loaded 100 of 126 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user