Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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 | ||
|
|
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/
|
||||
@@ -12,7 +12,7 @@ Mongoose makes embedded network programming fast, robust, and easy.
|
||||
|
||||
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
|
||||
- [Study mongoose example code](https://github.com/cesanta/mongoose/tree/master/examples)
|
||||
|
||||
@@ -7,5 +7,5 @@ signature: |
|
||||
---
|
||||
|
||||
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
|
||||
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_handshake2.md }
|
||||
- { name: mg_send_websocket_handshake3.md }
|
||||
- { name: mg_send_websocket_handshake3v.md }
|
||||
- { name: mg_set_protocol_http_websocket.md }
|
||||
- { name: mg_url_decode.md }
|
||||
- { name: struct_http_message.md }
|
||||
|
||||
@@ -4,9 +4,8 @@ decl_name: "mg_connect_ws"
|
||||
symbol_kind: "func"
|
||||
signature: |
|
||||
struct mg_connection *mg_connect_ws(struct mg_mgr *mgr,
|
||||
mg_event_handler_t event_handler,
|
||||
const char *url, const char *protocol,
|
||||
const char *extra_headers);
|
||||
MG_CB(mg_event_handler_t event_handler,
|
||||
void *user_data);
|
||||
---
|
||||
|
||||
Helper function that creates an outbound WebSocket connection.
|
||||
|
||||
@@ -3,11 +3,8 @@ title: "mg_connect_ws_opt()"
|
||||
decl_name: "mg_connect_ws_opt"
|
||||
symbol_kind: "func"
|
||||
signature: |
|
||||
struct mg_connection *mg_connect_ws_opt(struct mg_mgr *mgr,
|
||||
mg_event_handler_t ev_handler,
|
||||
struct mg_connect_opts opts,
|
||||
const char *url, const char *protocol,
|
||||
const char *extra_headers);
|
||||
struct mg_connection *mg_connect_ws_opt(
|
||||
struct mg_mgr *mgr, MG_CB(mg_event_handler_t ev_handler, void *user_data);
|
||||
---
|
||||
|
||||
Helper function that creates an outbound WebSocket connection
|
||||
|
||||
@@ -9,5 +9,6 @@ signature: |
|
||||
|
||||
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
|
||||
`+` character is decoded as a blank space character. This function
|
||||
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.
|
||||
|
||||
@@ -5,6 +5,7 @@ symbol_kind: "struct"
|
||||
signature: |
|
||||
struct http_message {
|
||||
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) */
|
||||
struct mg_str method; /* "GET" */
|
||||
@@ -28,9 +29,6 @@ signature: |
|
||||
/* Headers */
|
||||
struct mg_str header_names[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"
|
||||
symbol_kind: "func"
|
||||
signature: |
|
||||
struct mg_connection *mg_connect_http(struct mg_mgr *mgr,
|
||||
mg_event_handler_t event_handler,
|
||||
const char *url,
|
||||
const char *extra_headers,
|
||||
const char *post_data);
|
||||
struct mg_connection *mg_connect_http(
|
||||
struct mg_mgr *mgr,
|
||||
MG_CB(mg_event_handler_t event_handler, void *user_data);
|
||||
---
|
||||
|
||||
Helper function that creates an outbound HTTP connection.
|
||||
|
||||
@@ -3,12 +3,8 @@ title: "mg_connect_http_opt()"
|
||||
decl_name: "mg_connect_http_opt"
|
||||
symbol_kind: "func"
|
||||
signature: |
|
||||
struct mg_connection *mg_connect_http_opt(struct mg_mgr *mgr,
|
||||
mg_event_handler_t ev_handler,
|
||||
struct mg_connect_opts opts,
|
||||
const char *url,
|
||||
const char *extra_headers,
|
||||
const char *post_data);
|
||||
struct mg_connection *mg_connect_http_opt(
|
||||
struct mg_mgr *mgr, MG_CB(mg_event_handler_t ev_handler, void *user_data);
|
||||
---
|
||||
|
||||
Helper function that creates an outbound HTTP connection.
|
||||
|
||||
@@ -4,7 +4,8 @@ decl_name: "mg_file_upload_handler"
|
||||
symbol_kind: "func"
|
||||
signature: |
|
||||
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.
|
||||
|
||||
@@ -12,5 +12,6 @@ Fetches a HTTP form variable.
|
||||
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
|
||||
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
|
||||
new location.
|
||||
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:
|
||||
|
||||
|
||||
@@ -4,7 +4,8 @@ decl_name: "mg_register_http_endpoint"
|
||||
symbol_kind: "func"
|
||||
signature: |
|
||||
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
|
||||
@@ -20,7 +21,7 @@ static void handle_hello1(struct mg_connection *nc, int ev, void *ev_data) {
|
||||
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;
|
||||
mg_printf(nc, "HTTP/1.0 200 OK\r\n\r\n[I am Hello2]");
|
||||
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.
|
||||
This function sends the buffer size as hex number + newline first, then
|
||||
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.
|
||||
|
||||
NOTE: The HTTP header "Transfer-Encoding: chunked" should be sent prior to
|
||||
|
||||
@@ -9,7 +9,7 @@ signature: |
|
||||
|
||||
Sends the response status line.
|
||||
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:
|
||||
|
||||
mg_send_response_line(nc, 200, "Access-Control-Allow-Origin: *");
|
||||
|
||||
@@ -5,6 +5,7 @@ decl_name: "mqtt.h"
|
||||
items:
|
||||
- { name: mg_mqtt_connack.md }
|
||||
- { name: mg_mqtt_disconnect.md }
|
||||
- { name: mg_mqtt_match_topic_expression.md }
|
||||
- { name: mg_mqtt_next_subscribe_topic.md }
|
||||
- { name: mg_mqtt_ping.md }
|
||||
- { name: mg_mqtt_pong.md }
|
||||
@@ -17,6 +18,7 @@ items:
|
||||
- { name: mg_mqtt_subscribe.md }
|
||||
- { name: mg_mqtt_unsuback.md }
|
||||
- { name: mg_mqtt_unsubscribe.md }
|
||||
- { name: mg_mqtt_vmatch_topic_expression.md }
|
||||
- { name: mg_send_mqtt_handshake.md }
|
||||
- { name: mg_send_mqtt_handshake_opt.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.
|
||||
|
||||
@@ -12,7 +12,6 @@ items:
|
||||
- { name: mg_connect.md }
|
||||
- { name: mg_connect_opt.md }
|
||||
- { name: mg_enable_javascript.md }
|
||||
- { name: mg_enable_multithreading.md }
|
||||
- { name: mg_mgr_free.md }
|
||||
- { name: mg_mgr_init.md }
|
||||
- { name: mg_mgr_init_opt.md }
|
||||
@@ -33,7 +32,6 @@ items:
|
||||
- { name: struct_mg_connection.md }
|
||||
- { name: struct_mg_mgr.md }
|
||||
- { name: struct_mg_mgr_init_opts.md }
|
||||
- { name: struct_mg_multithreading_opts.md }
|
||||
---
|
||||
|
||||
NOTE: Mongoose manager is single threaded. It does not protect
|
||||
|
||||
@@ -3,7 +3,9 @@ title: "mg_add_sock()"
|
||||
decl_name: "mg_add_sock"
|
||||
symbol_kind: "func"
|
||||
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
|
||||
|
||||
@@ -3,9 +3,9 @@ title: "mg_add_sock_opt()"
|
||||
decl_name: "mg_add_sock_opt"
|
||||
symbol_kind: "func"
|
||||
signature: |
|
||||
struct mg_connection *mg_add_sock_opt(struct mg_mgr *, sock_t,
|
||||
mg_event_handler_t,
|
||||
struct mg_add_sock_opts);
|
||||
struct mg_connection *mg_add_sock_opt(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
|
||||
|
||||
@@ -3,8 +3,9 @@ title: "mg_bind()"
|
||||
decl_name: "mg_bind"
|
||||
symbol_kind: "func"
|
||||
signature: |
|
||||
struct mg_connection *mg_bind(struct mg_mgr *, const char *,
|
||||
mg_event_handler_t);
|
||||
struct mg_connection *mg_bind(struct mg_mgr *mgr, const char *address,
|
||||
MG_CB(mg_event_handler_t handler,
|
||||
void *user_data);
|
||||
---
|
||||
|
||||
Creates a listening connection.
|
||||
|
||||
@@ -4,8 +4,8 @@ decl_name: "mg_bind_opt"
|
||||
symbol_kind: "func"
|
||||
signature: |
|
||||
struct mg_connection *mg_bind_opt(struct mg_mgr *mgr, const char *address,
|
||||
mg_event_handler_t handler,
|
||||
struct mg_bind_opts opts);
|
||||
MG_CB(mg_event_handler_t handler,
|
||||
void *user_data);
|
||||
---
|
||||
|
||||
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
|
||||
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://`
|
||||
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
|
||||
`udp`.
|
||||
|
||||
|
||||
@@ -3,7 +3,8 @@ title: "mg_broadcast()"
|
||||
decl_name: "mg_broadcast"
|
||||
symbol_kind: "func"
|
||||
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.
|
||||
|
||||
@@ -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,
|
||||
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
|
||||
link:https://en.wikipedia.org/wiki/Subnetwork[Wikipedia page on Subnetwork].
|
||||
|
||||
@@ -4,7 +4,8 @@ decl_name: "mg_connect"
|
||||
symbol_kind: "func"
|
||||
signature: |
|
||||
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.
|
||||
|
||||
@@ -4,8 +4,8 @@ decl_name: "mg_connect_opt"
|
||||
symbol_kind: "func"
|
||||
signature: |
|
||||
struct mg_connection *mg_connect_opt(struct mg_mgr *mgr, const char *address,
|
||||
mg_event_handler_t handler,
|
||||
struct mg_connect_opts opts);
|
||||
MG_CB(mg_event_handler_t handler,
|
||||
void *user_data);
|
||||
---
|
||||
|
||||
Connects to a remote host.
|
||||
|
||||
@@ -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"
|
||||
signature: |
|
||||
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.
|
||||
|
||||
@@ -3,7 +3,7 @@ title: "mg_next()"
|
||||
decl_name: "mg_next"
|
||||
symbol_kind: "func"
|
||||
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.
|
||||
|
||||
@@ -8,6 +8,7 @@ signature: |
|
||||
unsigned int flags; /* Extra connection flags */
|
||||
const char **error_string; /* Placeholder for the error string */
|
||||
struct mg_iface *iface; /* Interface instance */
|
||||
const char *nameserver; /* DNS server to use, NULL for default */
|
||||
#if MG_ENABLE_SSL
|
||||
/*
|
||||
* SSL settings.
|
||||
@@ -44,6 +45,15 @@ signature: |
|
||||
* name verification.
|
||||
*/
|
||||
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
|
||||
};
|
||||
---
|
||||
|
||||
@@ -31,8 +31,8 @@ signature: |
|
||||
* void pointers, since some archs might have fat pointers for functions.
|
||||
*/
|
||||
mg_event_handler_t f;
|
||||
} priv_1; /* Used by mg_enable_multithreading() */
|
||||
void *priv_2; /* Used by mg_enable_multithreading() */
|
||||
} priv_1;
|
||||
void *priv_2;
|
||||
void *mgr_data; /* Implementation-specific event manager's data. */
|
||||
struct mg_iface *iface;
|
||||
unsigned long flags;
|
||||
|
||||
@@ -17,6 +17,7 @@ signature: |
|
||||
#if MG_ENABLE_JAVASCRIPT
|
||||
struct v7 *v7;
|
||||
#endif
|
||||
const char *nameserver; /* DNS server to use */
|
||||
};
|
||||
---
|
||||
|
||||
|
||||
@@ -4,9 +4,10 @@ decl_name: "struct mg_mgr_init_opts"
|
||||
symbol_kind: "struct"
|
||||
signature: |
|
||||
struct mg_mgr_init_opts {
|
||||
struct mg_iface_vtable *main_iface;
|
||||
const struct mg_iface_vtable *main_iface;
|
||||
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_opt.md }
|
||||
- { name: mg_resolve_from_hosts_file.md }
|
||||
- { name: mg_set_nameserver.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"
|
||||
signature: |
|
||||
struct mg_resolve_async_opts {
|
||||
const char *nameserver_url;
|
||||
const char *nameserver;
|
||||
int max_retries; /* defaults to 2 if zero */
|
||||
int timeout; /* in seconds; defaults to 5 if zero */
|
||||
int accept_literal; /* pseudo-resolve literal ipv4 and ipv6 addrs */
|
||||
|
||||
@@ -3,6 +3,7 @@ title: "URI"
|
||||
symbol_kind: "intro"
|
||||
decl_name: "uri.h"
|
||||
items:
|
||||
- { name: mg_assemble_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"
|
||||
symbol_kind: "func"
|
||||
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,
|
||||
unsigned int *port, struct mg_str *path, struct mg_str *query,
|
||||
struct mg_str *fragment);
|
||||
|
||||
@@ -8,8 +8,11 @@ items:
|
||||
- { name: mg_basic_auth_header.md }
|
||||
- { name: mg_conn_addr_to_str.md }
|
||||
- { name: mg_fopen.md }
|
||||
- { name: mg_fread.md }
|
||||
- { name: mg_fwrite.md }
|
||||
- { name: mg_hexdump.md }
|
||||
- { name: mg_hexdump_connection.md }
|
||||
- { name: mg_hexdumpf.md }
|
||||
- { name: mg_is_big_endian.md }
|
||||
- { name: mg_match_prefix.md }
|
||||
- { name: mg_mbuf_append_base64.md }
|
||||
|
||||
@@ -3,7 +3,8 @@ title: "mg_basic_auth_header()"
|
||||
decl_name: "mg_basic_auth_header"
|
||||
symbol_kind: "func"
|
||||
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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -2,4 +2,6 @@
|
||||
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
|
||||
---
|
||||
|
||||
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.
|
||||
@@ -29,3 +29,7 @@ Example:
|
||||
```c
|
||||
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) {
|
||||
if (ev == MG_EV_HTTP_REPLY) {
|
||||
struct http_message *hm = (struct http_message *)p;
|
||||
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');
|
||||
exit_flag = 1;
|
||||
} else if (ev == MG_EV_CLOSE) {
|
||||
@@ -31,7 +32,7 @@ int main(void) {
|
||||
struct mg_mgr mgr;
|
||||
|
||||
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) {
|
||||
|
||||
@@ -2,4 +2,15 @@
|
||||
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`.
|
||||
// Send HTTP reply to the client which shows full original request.
|
||||
mg_send_head(c, 200, hm.message.len, "Content-Type: text/plain");
|
||||
mg_printf(c, "%.*s", hm.message.len, hm.message.p);
|
||||
mg_send_head(c, 200, hm->message.len, "Content-Type: text/plain");
|
||||
mg_printf(c, "%.*s", (int)hm->message.len, hm->message.p);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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" -->`
|
||||
|
||||
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.
|
||||
Event parameter will point to the `PARAMS` string.
|
||||
An event handler can output any text, for example by calling
|
||||
|
||||
@@ -2,4 +2,4 @@
|
||||
title: MQTT client example
|
||||
---
|
||||
|
||||
TBD
|
||||
See https://github.com/cesanta/mongoose/tree/master/examples/mqtt_client
|
||||
@@ -2,4 +2,4 @@
|
||||
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_SHA1` disable SHA1 support (used by WebSocket)
|
||||
- `MG_DISABLE_MD5` disable MD5 support (used by HTTP auth)
|
||||
- `CS_DISABLE_SHA1` disable SHA1 support (used by WebSocket)
|
||||
- `CS_DISABLE_MD5` disable MD5 support (used by HTTP auth)
|
||||
- `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
|
||||
instead of the default "Intermediate" setting.
|
||||
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
|
||||
@@ -40,22 +40,22 @@ void cs_log_set_level(enum cs_log_level level);
|
||||
|
||||
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_printf(const char *fmt, ...);
|
||||
|
||||
#define LOG(l, x) \
|
||||
if (cs_log_level >= l) { \
|
||||
if (cs_log_threshold >= l) { \
|
||||
cs_log_print_prefix(__func__); \
|
||||
cs_log_printf x; \
|
||||
}
|
||||
|
||||
#ifndef CS_NDEBUG
|
||||
|
||||
#define DBG(x) \
|
||||
if (cs_log_level >= LL_VERBOSE_DEBUG) { \
|
||||
cs_log_print_prefix(__func__); \
|
||||
cs_log_printf x; \
|
||||
#define DBG(x) \
|
||||
if (cs_log_threshold >= LL_VERBOSE_DEBUG) { \
|
||||
cs_log_print_prefix(__func__); \
|
||||
cs_log_printf x; \
|
||||
}
|
||||
|
||||
#else /* NDEBUG */
|
||||
|
||||
@@ -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,--start-group \
|
||||
-lcirom \
|
||||
-lgcc \
|
||||
-lgcc_sdk \
|
||||
-lhal \
|
||||
-lphy \
|
||||
-lpp \
|
||||
@@ -116,3 +116,23 @@ sinclude $(SDK_PATH)/Makefile
|
||||
.PHONY: 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.
|
||||
|
||||
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 BIN_PATH=./bin
|
||||
$ 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 \
|
||||
write_flash --flash_mode=qio --flash_size=4m \
|
||||
write_flash --flash_mode=dio --flash_size=4m \
|
||||
0x00000 ${BIN_PATH}/eagle.flash.bin \
|
||||
0x20000 ${BIN_PATH}/eagle.irom0text.bin \
|
||||
0x7e000 ${SDK_PATH}/bin/esp_init_data_default.bin
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
#!/bin/bash
|
||||
REPO=$(cd ../.. && pwd)
|
||||
|
||||
docker run \
|
||||
--rm -i -v $(realpath ${PWD}/../..):/src \
|
||||
--rm -i -v $REPO:/src \
|
||||
--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;
|
||||
cd /src/examples/ESP8266_RTOS &&
|
||||
mkdir -p ./bin && make clean &&
|
||||
make BOOT=none APP=0 SPI_SPEED=40 SPI_MODE=qio SPI_SIZE_MAP=0'
|
||||
make clean &&
|
||||
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 MG_LISTEN_ADDR "80"
|
||||
|
||||
#define MG_TASK_STACK_SIZE 4096
|
||||
#define MG_TASK_STACK_SIZE 4096 /* bytes */
|
||||
#define MGOS_TASK_PRIORITY 1
|
||||
|
||||
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_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();
|
||||
|
||||
mg_mgr_init(&mgr, NULL);
|
||||
@@ -99,11 +100,15 @@ static void mg_task(void *arg) {
|
||||
}
|
||||
}
|
||||
|
||||
xTaskHandle s_mg_task_handle;
|
||||
|
||||
void user_init(void) {
|
||||
uart_div_modify(0, UART_CLK_FREQ / 115200);
|
||||
|
||||
xTaskCreate(mg_task, (const signed char *) "mongoose", MG_TASK_STACK_SIZE,
|
||||
NULL, MGOS_TASK_PRIORITY, &s_mg_task_handle);
|
||||
printf("Free RAM: %d\r\n", system_get_free_heap_size());
|
||||
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. */
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
# `wildcard ./*/` works in both linux and linux/wine, while `wildcard */` enumerates nothing under wine
|
||||
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)
|
||||
SUBDIRS:=$(filter-out ./netcat/ ./raspberry_pi_mjpeg_led/ ./captive_dns_server/, $(SUBDIRS))
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
SDK ?= $(shell cat sdk.version)
|
||||
SRC_DIR ?= $(realpath ../../..)
|
||||
SRC_DIR ?= $(realpath ../..)
|
||||
|
||||
.PHONY: all clean
|
||||
|
||||
@@ -8,6 +8,5 @@ MAKEFLAGS += w
|
||||
all clean:
|
||||
docker run --rm -i -v $(SRC_DIR):/src $(SDK) \
|
||||
/bin/bash -c "\
|
||||
make -C /src/mongoose mongoose.c mongoose.h && \
|
||||
make -C /src/mongoose/examples/STM32F4_CC3100 -f Makefile.build $@ -$(MAKEFLAGS) \
|
||||
make -C /src/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_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
|
||||
STM32CUBEF4_ROOT=/opt/STM32CubeF4
|
||||
STM32CUBEF4_DRV_PATH=${STM32CUBEF4_ROOT}/Drivers
|
||||
@@ -22,7 +22,7 @@ CC = arm-none-eabi-gcc
|
||||
OBJCOPY = arm-none-eabi-objcopy
|
||||
|
||||
FP_FLAGS = -mfloat-abi=hard -mfpu=fpv4-sp-d16
|
||||
ARCH_FLAGS = -mthumb -mcpu=cortex-m4
|
||||
ARCH_FLAGS = -mthumb -mcpu=cortex-m4
|
||||
|
||||
BUILD_DIR=.build
|
||||
OUT_DIR=out
|
||||
@@ -36,21 +36,20 @@ OBJS = $(addprefix $(BUILD_DIR)/,$(patsubst %.c,%.o,$(SRCS)) $(patsubst %.s,%.o,
|
||||
|
||||
VPATH = ${CC3100_SDKROOT}/simplelink/source\
|
||||
${CC3100_SDKROOT}/platform/stm32discovery\
|
||||
${STM32CUBEF4_ROOT}/Drivers/STM32F4xx_HAL_Driver/Src\
|
||||
${STM32CUBEF4_ROOT}/Drivers/BSP/STM32F4-Discovery\
|
||||
${REPO_ROOT}/mongoose
|
||||
${STM32CUBEF4_ROOT}/Drivers/STM32F4xx_HAL_Driver/Src\
|
||||
${STM32CUBEF4_ROOT}/Drivers/BSP/STM32F4-Discovery\
|
||||
${REPO_ROOT}
|
||||
|
||||
# CC3100 SDK and STM32 SDK include headers w/out path, just like
|
||||
# #include "simplelink.h". As result, we have to add all required directories
|
||||
# into IPATH
|
||||
|
||||
IPATH = . \
|
||||
${CC3100_SDKROOT}/simplelink/include\
|
||||
${CC3100_SDKROOT}/platform/stm32discovery\
|
||||
${STM32CUBEF4_DRV_PATH}/BSP/STM32F4-Discovery\
|
||||
${STM32CUBEF4_DRV_PATH}/STM32F4xx_HAL_Driver/Inc\
|
||||
${STM32CUBEF4_DRV_PATH}/CMSIS/Include\
|
||||
${STM32CUBEF4_DRV_PATH}/CMSIS/Device/ST/STM32F4xx/Include
|
||||
IPATH = . ${CC3100_SDKROOT}/simplelink/include\
|
||||
${CC3100_SDKROOT}/platform/stm32discovery\
|
||||
${STM32CUBEF4_DRV_PATH}/BSP/STM32F4-Discovery\
|
||||
${STM32CUBEF4_DRV_PATH}/STM32F4xx_HAL_Driver/Inc\
|
||||
${STM32CUBEF4_DRV_PATH}/CMSIS/Include\
|
||||
${STM32CUBEF4_DRV_PATH}/CMSIS/Device/ST/STM32F4xx/Include
|
||||
|
||||
LDFLAGS = --static -nostartfiles
|
||||
LDLIBS = -Wl,--start-group -lc -lgcc -lnosys -Wl,--end-group
|
||||
@@ -59,13 +58,13 @@ LDSCRIPT = stm32f429xx.ld
|
||||
INCDIRS = $(addprefix -I,$(IPATH))
|
||||
|
||||
CFLAGS = ${FP_FLAGS} ${ARCH_FLAGS} ${INCDIRS}\
|
||||
-D${BOARD} -DEXT_LIB_REGISTERED_GENERAL_EVENTS \
|
||||
-DSL_FULL\
|
||||
-DCS_PLATFORM=6 \
|
||||
-D__STM32F407xx_H \
|
||||
-DMG_SIMPLELINK_NO_OSI \
|
||||
-DMG_ENABLE_MQTT \
|
||||
-g -fno-common -ffunction-sections -fdata-sections \
|
||||
-D${BOARD} -DEXT_LIB_REGISTERED_GENERAL_EVENTS \
|
||||
-DSL_FULL\
|
||||
-DCS_PLATFORM=6 \
|
||||
-D__STM32F407xx_H \
|
||||
-DMG_SIMPLELINK_NO_OSI \
|
||||
-DMG_ENABLE_MQTT \
|
||||
-g -fno-common -ffunction-sections -fdata-sections \
|
||||
|
||||
ELF = ${BUILD_DIR}/${PROJECT}.elf
|
||||
BIN = ${OUT_DIR}/${PROJECT}.bin
|
||||
@@ -79,15 +78,15 @@ ${OUT_DIR}:
|
||||
mkdir -p $@
|
||||
|
||||
$(BUILD_DIR)/%.o: %.c
|
||||
$(CC) ${CFLAGS} $^ -c -o $@
|
||||
$(CC) ${CFLAGS} $^ -c -o $@
|
||||
|
||||
$(BUILD_DIR)/%.o: %.s
|
||||
$(CC) ${CFLAGS} $^ -c -o $@
|
||||
$(CC) ${CFLAGS} $^ -c -o $@
|
||||
|
||||
${ELF}: ${OBJS}
|
||||
$(CC) ${ARCH_FLAGS} ${FP_FLAGS} $(LDFLAGS) $(OBJS) $(LDLIBS) -T$(LDSCRIPT) -o $@
|
||||
|
||||
${BIN}: ${ELF}
|
||||
${BIN}: ${ELF}
|
||||
$(OBJCOPY) -Obinary $^ $@
|
||||
|
||||
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"
|
||||
|
||||
static const char *s_http_port = "8000";
|
||||
static struct mg_serve_http_opts s_http_server_opts;
|
||||
|
||||
struct file_writer_data {
|
||||
FILE *fp;
|
||||
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) {
|
||||
struct file_writer_data *data = (struct file_writer_data *) nc->user_data;
|
||||
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) {
|
||||
(void) ev_data;
|
||||
switch (ev) {
|
||||
case MG_EV_HTTP_REQUEST:
|
||||
// Invoked when the full HTTP request is in the buffer (including body).
|
||||
handle_request(nc);
|
||||
break;
|
||||
if (ev == MG_EV_HTTP_REQUEST) {
|
||||
mg_serve_http(nc, ev_data, s_http_server_opts);
|
||||
}
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
struct mg_mgr mgr;
|
||||
struct mg_connection *nc;
|
||||
struct mg_connection *c;
|
||||
|
||||
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
|
||||
mg_set_protocol_http_websocket(nc);
|
||||
mg_set_protocol_http_websocket(c);
|
||||
|
||||
printf("Starting web server on port %s\n", s_http_port);
|
||||
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
|
||||
MODULE_CFLAGS=-DMG_ENABLE_DNS_SERVER -DMG_ENABLE_IPV6
|
||||
SSL_LIB=openssl
|
||||
include ../examples.mk
|
||||
|
Before Width: | Height: | Size: 5.7 KiB After Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 5.7 KiB After Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 5.7 KiB After Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 5.7 KiB After Width: | Height: | Size: 2.4 KiB |
@@ -1,4 +1,4 @@
|
||||
PROG = mqtt_client
|
||||
MODULE_CFLAGS = -DMG_ENABLE_HTTP=0
|
||||
SSL_LIB=openssl
|
||||
#SSL_LIB=openssl
|
||||
include ../examples.mk
|
||||
@@ -0,0 +1,3 @@
|
||||
PROG = multithreaded
|
||||
MODULE_CFLAGS=-DMG_ENABLE_THREADS
|
||||
include ../examples.mk
|
||||
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* Copyright (c) 2014-2017 Cesanta Software Limited
|
||||
* All rights reserved
|
||||
*/
|
||||
|
||||
#include "mongoose.h"
|
||||
|
||||
static sig_atomic_t s_received_signal = 0;
|
||||
static const char *s_http_port = "8000";
|
||||
static const int s_num_worker_threads = 5;
|
||||
static unsigned long s_next_id = 0;
|
||||
|
||||
static void signal_handler(int sig_num) {
|
||||
signal(sig_num, signal_handler);
|
||||
s_received_signal = sig_num;
|
||||
}
|
||||
static struct mg_serve_http_opts s_http_server_opts;
|
||||
static sock_t sock[2];
|
||||
|
||||
// This info is passed to the worker thread
|
||||
struct work_request {
|
||||
unsigned long conn_id; // needed to identify the connection where to send the reply
|
||||
// optionally, more data that could be required by worker
|
||||
};
|
||||
|
||||
// This info is passed by the worker thread to mg_broadcast
|
||||
struct work_result {
|
||||
unsigned long conn_id;
|
||||
int sleep_time;
|
||||
};
|
||||
|
||||
static void on_work_complete(struct mg_connection *nc, int ev, void *ev_data) {
|
||||
(void) ev;
|
||||
char s[32];
|
||||
struct mg_connection *c;
|
||||
for (c = mg_next(nc->mgr, NULL); c != NULL; c = mg_next(nc->mgr, c)) {
|
||||
if (c->user_data != NULL) {
|
||||
struct work_result *res = (struct work_result *)ev_data;
|
||||
if ((unsigned long)c->user_data == res->conn_id) {
|
||||
sprintf(s, "conn_id:%lu sleep:%d", res->conn_id, res->sleep_time);
|
||||
mg_send_head(c, 200, strlen(s), "Content-Type: text/plain");
|
||||
mg_printf(c, "%s", s);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void *worker_thread_proc(void *param) {
|
||||
struct mg_mgr *mgr = (struct mg_mgr *) param;
|
||||
struct work_request req = {0};
|
||||
|
||||
while (s_received_signal == 0) {
|
||||
if (read(sock[1], &req, sizeof(req)) < 0)
|
||||
perror("Reading worker sock");
|
||||
int r = rand() % 10;
|
||||
sleep(r);
|
||||
struct work_result res = {req.conn_id, r};
|
||||
mg_broadcast(mgr, on_work_complete, (void *)&res, sizeof(res));
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
|
||||
(void) nc;
|
||||
(void) ev_data;
|
||||
|
||||
switch (ev) {
|
||||
case MG_EV_ACCEPT:
|
||||
nc->user_data = (void *)++s_next_id;
|
||||
break;
|
||||
case MG_EV_HTTP_REQUEST: {
|
||||
struct work_request req = {(unsigned long)nc->user_data};
|
||||
|
||||
if (write(sock[0], &req, sizeof(req)) < 0)
|
||||
perror("Writing worker sock");
|
||||
break;
|
||||
}
|
||||
case MG_EV_CLOSE: {
|
||||
if (nc->user_data) nc->user_data = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
struct mg_mgr mgr;
|
||||
struct mg_connection *nc;
|
||||
int i;
|
||||
|
||||
if (mg_socketpair(sock, SOCK_STREAM) == 0) {
|
||||
perror("Opening socket pair");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
signal(SIGTERM, signal_handler);
|
||||
signal(SIGINT, signal_handler);
|
||||
|
||||
mg_mgr_init(&mgr, NULL);
|
||||
|
||||
nc = mg_bind(&mgr, s_http_port, ev_handler);
|
||||
if (nc == NULL) {
|
||||
printf("Failed to create listener\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
mg_set_protocol_http_websocket(nc);
|
||||
s_http_server_opts.document_root = "."; // Serve current directory
|
||||
s_http_server_opts.enable_directory_listing = "no";
|
||||
|
||||
for (i = 0; i < s_num_worker_threads; i++) {
|
||||
mg_start_thread(worker_thread_proc, &mgr);
|
||||
}
|
||||
|
||||
printf("Started on port %s\n", s_http_port);
|
||||
while (s_received_signal == 0) {
|
||||
mg_mgr_poll(&mgr, 200);
|
||||
}
|
||||
|
||||
mg_mgr_free(&mgr);
|
||||
|
||||
closesocket(sock[0]);
|
||||
closesocket(sock[1]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
PROG = multithreaded_restful_server
|
||||
MODULE_CFLAGS = -DMG_ENABLE_THREADS
|
||||
SSL_LIB=openssl
|
||||
include ../examples.mk
|
||||
@@ -1,53 +0,0 @@
|
||||
// Copyright (c) 2015 Cesanta Software Limited
|
||||
// All rights reserved
|
||||
|
||||
// This example shows how to handle long, blocking requests by
|
||||
// handing off computation to different threads. Here, each
|
||||
// request spawns a new thread. In a production scenario, a thread
|
||||
// pools can be used for efficiency, if required.
|
||||
// Long computation is simulated by sleeping for a random interval.
|
||||
|
||||
#include "mongoose.h"
|
||||
|
||||
static const char *s_http_port = "8000";
|
||||
|
||||
static void ev_handler(struct mg_connection *c, int ev, void *p) {
|
||||
if (ev == MG_EV_HTTP_REQUEST) {
|
||||
struct http_message *hm = (struct http_message *) p;
|
||||
char reply[100];
|
||||
|
||||
/* Simulate long calculation */
|
||||
sleep(3);
|
||||
|
||||
/* Send the reply */
|
||||
snprintf(reply, sizeof(reply), "{ \"uri\": \"%.*s\" }\n", (int) hm->uri.len,
|
||||
hm->uri.p);
|
||||
mg_printf(c,
|
||||
"HTTP/1.1 200 OK\r\n"
|
||||
"Content-Type: application/json\r\n"
|
||||
"Content-Length: %d\r\n"
|
||||
"\r\n"
|
||||
"%s",
|
||||
(int) strlen(reply), reply);
|
||||
}
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
struct mg_mgr mgr;
|
||||
struct mg_connection *nc;
|
||||
|
||||
mg_mgr_init(&mgr, NULL);
|
||||
nc = mg_bind(&mgr, s_http_port, ev_handler);
|
||||
mg_set_protocol_http_websocket(nc);
|
||||
|
||||
/* For each new connection, execute ev_handler in a separate thread */
|
||||
mg_enable_multithreading(nc);
|
||||
|
||||
printf("Starting multi-threaded server on port %s\n", s_http_port);
|
||||
for (;;) {
|
||||
mg_mgr_poll(&mgr, 3000);
|
||||
}
|
||||
mg_mgr_free(&mgr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -3,8 +3,19 @@
|
||||
This is a Mongoose "Hello, world" that can be compiled under nRF51 IoT SDK.
|
||||
|
||||
To make it work, you should download [nRF51 IoT SDK](http://www.nordicsemi.com/eng/Products/Bluetooth-low-energy/nRF51-IoT-SDK)
|
||||
and unpack it in the current directory as `nrf51_iot_sdk`.
|
||||
and unpack it in the current directory as `nrf51_iot_sdk` (so that
|
||||
`nrf51_iot_sdk` contains `components`, `external`, etc).
|
||||
|
||||
In order to build it with the provided Makefile and ARM GCC, you also need to
|
||||
edit the file `nrf51_iot_sdk/components/toolchain/gcc/Makefile.posix` (or
|
||||
`Makefile.windows` if you use Windows) : adjust arm-none-eabi path and version
|
||||
accordingly to your installation.
|
||||
|
||||
The project structure replicates that of the examples provided with the SDK:
|
||||
Keil uVision project is located at `boards/pca10028/arm5_no_packs`, ARM-GCC
|
||||
Makefile is located in `boards/pca10028/armgcc`..
|
||||
|
||||
E.g. in order to build it with ARM GCC, navigate to
|
||||
`http/boards/pca10028/armgcc` and type `make`. In order to flash: `make flash`.
|
||||
|
||||
For details, refer to an [article on Hackster](https://www.hackster.io/dfrank/mongoose-embedded-networking-library-on-nrf51-and-nrf52-547b15).
|
||||
@@ -3,7 +3,7 @@ PROJECT_NAME := iot_lwip_tcp_server_pca10028
|
||||
export OUTPUT_FILENAME
|
||||
#MAKEFILE_NAME := $(CURDIR)/$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
|
||||
MAKEFILE_NAME := $(MAKEFILE_LIST)
|
||||
MAKEFILE_DIR := $(dir $(MAKEFILE_NAME) )
|
||||
MAKEFILE_DIR := $(dir $(MAKEFILE_NAME) )
|
||||
|
||||
TEMPLATE_PATH = ../../../../nrf51_iot_sdk/components/toolchain/gcc
|
||||
ifeq ($(OS),Windows_NT)
|
||||
@@ -17,7 +17,7 @@ RM := rm -rf
|
||||
|
||||
#echo suspend
|
||||
ifeq ("$(VERBOSE)","1")
|
||||
NO_ECHO :=
|
||||
NO_ECHO :=
|
||||
else
|
||||
NO_ECHO := @
|
||||
endif
|
||||
@@ -118,7 +118,7 @@ BUILD_DIRECTORIES := $(sort $(OBJECT_DIRECTORY) $(OUTPUT_BINARY_DIRECTORY) $(LIS
|
||||
# Mongoose features
|
||||
MG_FEATURES_TINY = \
|
||||
-DMG_DISABLE_HTTP_DIGEST_AUTH \
|
||||
-DMG_DISABLE_MD5 \
|
||||
-DCS_DISABLE_MD5 \
|
||||
-DMG_DISABLE_HTTP_KEEP_ALIVE \
|
||||
-DMG_ENABLE_HTTP_SSI=0 \
|
||||
-DMG_ENABLE_HTTP_STREAMING_MULTIPART
|
||||
@@ -251,7 +251,7 @@ genbin:
|
||||
$(NO_ECHO)$(OBJCOPY) -O binary $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).bin
|
||||
|
||||
## Create binary .hex file from the .out file
|
||||
genhex:
|
||||
genhex:
|
||||
@echo Preparing: $(OUTPUT_FILENAME).hex
|
||||
$(NO_ECHO)$(OBJCOPY) -O ihex $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).hex
|
||||
|
||||
@@ -266,8 +266,8 @@ clean:
|
||||
cleanobj:
|
||||
$(RM) $(BUILD_DIRECTORIES)/*.o
|
||||
|
||||
flash: $(MAKECMDGOALS)
|
||||
flash: nrf51422_xxac_s1xx_iot
|
||||
@echo Flashing: $(OUTPUT_BINARY_DIRECTORY)/$<.hex
|
||||
nrfjprog --reset --program $(OUTPUT_BINARY_DIRECTORY)/$<.hex
|
||||
nrfjprog --reset --program $(OUTPUT_BINARY_DIRECTORY)/$<.hex -f nrf51 --sectorerase
|
||||
|
||||
## Flash softdevice
|
||||
@@ -1 +1,2 @@
|
||||
Please download the [nRF51 IoT SDK](http://www.nordicsemi.com/eng/Products/Bluetooth-low-energy/nRF51-IoT-SDK) and unpack it into this directory.
|
||||
Please download the [nRF51 IoT SDK](http://www.nordicsemi.com/eng/Products/Bluetooth-low-energy/nRF51-IoT-SDK)
|
||||
and unpack it into this directory, so that it contains `components`, `external`, etc.
|
||||
@@ -3,8 +3,19 @@
|
||||
This is a Mongoose "Hello, world" that can be compiled under nRF IoT SDK.
|
||||
|
||||
To make it work, you should download [nRF5 IoT SDK](http://developer.nordicsemi.com/nRF5_IoT_SDK/)
|
||||
and unpack it in the current directory as `nrf5_iot_sdk`.
|
||||
and unpack it in the current directory as `nrf5_iot_sdk` (so that
|
||||
`nrf5_iot_sdk` contains `components`, `external`, etc).
|
||||
|
||||
In order to build it with the provided Makefile and ARM GCC, you also need to
|
||||
edit the file `nrf5_iot_sdk/components/toolchain/gcc/Makefile.posix` (or
|
||||
`Makefile.windows` if you use Windows) : adjust arm-none-eabi path and version
|
||||
accordingly to your installation.
|
||||
|
||||
The project structure replicates that of the examples provided with the SDK:
|
||||
Keil uVision project is located at `boards/pca10040/arm5_no_packs`; ARM-GCC
|
||||
Makefile is located in `boards/pca10040/armgcc`.
|
||||
|
||||
E.g. in order to build it with ARM GCC, navigate to
|
||||
`http/boards/pca10040/armgcc` and type `make`. In order to flash: `make flash`.
|
||||
|
||||
For details, refer to an [article on Hackster](https://www.hackster.io/dfrank/mongoose-embedded-networking-library-on-nrf51-and-nrf52-547b15).
|
||||
@@ -3,7 +3,7 @@ PROJECT_NAME := iot_lwip_tcp_server_pca10040
|
||||
export OUTPUT_FILENAME
|
||||
#MAKEFILE_NAME := $(CURDIR)/$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
|
||||
MAKEFILE_NAME := $(MAKEFILE_LIST)
|
||||
MAKEFILE_DIR := $(dir $(MAKEFILE_NAME) )
|
||||
MAKEFILE_DIR := $(dir $(MAKEFILE_NAME) )
|
||||
|
||||
TEMPLATE_PATH = ../../../../nrf5_iot_sdk/components/toolchain/gcc
|
||||
ifeq ($(OS),Windows_NT)
|
||||
@@ -17,7 +17,7 @@ RM := rm -rf
|
||||
|
||||
#echo suspend
|
||||
ifeq ("$(VERBOSE)","1")
|
||||
NO_ECHO :=
|
||||
NO_ECHO :=
|
||||
else
|
||||
NO_ECHO := @
|
||||
endif
|
||||
@@ -165,7 +165,7 @@ BUILD_DIRECTORIES := $(sort $(OBJECT_DIRECTORY) $(OUTPUT_BINARY_DIRECTORY) $(LIS
|
||||
# Mongoose features
|
||||
MG_FEATURES_TINY = \
|
||||
-DMG_DISABLE_HTTP_DIGEST_AUTH \
|
||||
-DMG_DISABLE_MD5 \
|
||||
-DCS_DISABLE_MD5 \
|
||||
-DMG_DISABLE_HTTP_KEEP_ALIVE \
|
||||
-DMG_ENABLE_HTTP_SSI=0 \
|
||||
-DMG_ENABLE_HTTP_STREAMING_MULTIPART
|
||||
@@ -297,7 +297,7 @@ genbin:
|
||||
$(NO_ECHO)$(OBJCOPY) -O binary $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).bin
|
||||
|
||||
## Create binary .hex file from the .out file
|
||||
genhex:
|
||||
genhex:
|
||||
@echo Preparing: $(OUTPUT_FILENAME).hex
|
||||
$(NO_ECHO)$(OBJCOPY) -O ihex $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).hex
|
||||
echosize:
|
||||
|
||||