Compare commits

...
113 Commits
Author SHA1 Message Date
Deomid Ryabkov acfc66cd60 Correctly report bytes sent via SSL
This prevented hexdump from showing data sent over SSL when using LWIP net_if

PUBLISHED_FROM=aa520a27bdd21294484c52bf33c8580f3b4bad65
2017-05-11 10:07:09 +00:00
Deomid Ryabkov 6f140202ad Fix LWIP net_if when RTOS is used; use for ESP32
All calls to core LWIP APIs should go through the tcpip thread.

PUBLISHED_FROM=ebe8c7f043394a75a46810f2b6626582c63b9e68
2017-05-09 16:27:53 +00:00
Sergey Lyubka cfe77a3d58 Move struct http_message::body
Rationale: this is the optimisation to make JS FFI-ed API
work nicer. We don't have strucuture introspection now,
and do not generate offsets automatially. Thus, using a
stable well-known location of the parsed message body is
better, in case of number of HTTP headers macro changes.

PUBLISHED_FROM=55bf25ac77060a9c81dfecd6601f037562530801
2017-05-06 11:26:53 +00:00
Sergey Lyubka a0527a7f0e Fix esp8266 rtos example build
PUBLISHED_FROM=80055394237617605c57a07ac29c43d5197cbf5c
2017-05-05 10:25:41 +00:00
Sergey Lyubka c90cffa688 Fix docker invocation
PUBLISHED_FROM=064b5e508017b0115239fc880f21ca08b9422a25
2017-05-05 09:55:12 +00:00
Deomid Ryabkov d7a633bfa3 Fix timers when polling loop gets delayed
Past due timers should be brought forward to restore interval.

PUBLISHED_FROM=dbe1b8b98804cf8de81e1dbe814222422363278f
2017-05-03 12:51:15 +00:00
Deomid Ryabkov 0ea3cdd228 Implement sending stdout and stderr to MQTT topics
Configured via `debug.std{out,err}_topic`

PUBLISHED_FROM=66c581c38c5039aa9ecc406f8aac0b7e3c6541fc
2017-05-02 21:23:58 +00:00
Deomid Ryabkov ddef065493 Enable SNTP on CC3200
PUBLISHED_FROM=cea0fc4db21f5b68fd3e779334989fef84a1637a
2017-05-02 21:05:40 +00:00
Ruslan Valiullin ac857d18db Add mg multithreaded example
PUBLISHED_FROM=8a3424ba6260b0351d7c06270dc141d804ae7f77
2017-05-02 15:55:53 +00:00
Deomid Ryabkov 663e928d65 Fix mg_strdup_nul
PUBLISHED_FROM=25bc4d20016bcb71c4e2e4b7be8d2d0566fdfa2e
2017-04-27 14:39:46 +00:00
Deomid Ryabkov 189cd8c5f6 Add mg_assemble_uri
PUBLISHED_FROM=533e134a48e0fca55509c3eb16b0a6b64c1188e8
2017-04-27 13:50:33 +00:00
Deomid Ryabkov 692f436b3d Make mg_connect_ws accept http:// URLs
As well as URLs without prefix

PUBLISHED_FROM=ee298f6575603c8b384888633fe16413695ba70d
2017-04-27 10:51:31 +00:00
Deomid Ryabkov 2e65ce8272 Fix mg_parse_uri for URIs with fragment but no qs
PUBLISHED_FROM=8fb53581e8979c28026f9c2bcacb89de740c18cf
2017-04-26 14:50:38 +00:00
Deomid Ryabkov a35e5bd966 A function to make a NUL-terminated copy of mg_str
PUBLISHED_FROM=c1310b7d62f3ad6e2f24fea9f5229588c56b0bbe
2017-04-25 10:47:30 +00:00
Deomid Ryabkov 83fe5a17f3 Make mg_connect_{http,ws} use mg_parse_uri
Remove the specialized URI parser, clean up code a bit.

Fix parsing of URIs with IPv6 hosts (http://[2001:2:3::4]:567/)

PUBLISHED_FROM=968ad97585d928123106ce3828920ee073113f83
2017-04-24 14:59:52 +00:00
Deomid Ryabkov 49bbfaf130 Fix mg_lwip_if_get_conn_addr when there's no pcb
Connection may not (yet) have a TCP or UDP PCB associated with it.
mg_lwip_if_get_conn_addr should not crash in this case.

PUBLISHED_FROM=fd0ed683b18b3f549135c9d79eeadfc7348ab05a
2017-04-21 19:33:17 +00:00
Sergey Lyubka cd9c7dcbec Correct negative AAAA answer with NSEC RR
PUBLISHED_FROM=c7e3132d55e603f159019e3f0290e01b189e75e0
2017-04-19 12:57:45 +00:00
Deomid Ryabkov f868fc861b Enable hosts and resolv.conf lookups on UNIX only
Not relevant for other platforms

PUBLISHED_FROM=65b8959ee677555e2fb330c84d443e0a93d9fd1c
2017-04-18 22:39:24 +00:00
Deomid Ryabkov 84907d5bc4 Ignore tcp sent cb when there's no asscociated nc
TCP ACK may arrive after the we've corresponding mg_connection has already been closed.
Fixes cesanta/mongoose-os#235

PUBLISHED_FROM=8164b86131ef08c1b2a6a08630920d600b3f91ac
2017-04-18 14:38:08 +00:00
Deomid Ryabkov 1cee8a16b9 Fix mg_socket_if_get_conn_addr for UDP sockets
Remote address is not associated with an outgoing UDP socket.
Instead, it is stored in mg_connection.sa

PUBLISHED_FROM=16f82ee8a69b995d684ec96b8db6b5591cd400db
2017-04-18 12:41:54 +00:00
Deomid Ryabkov 57e32b87c7 Fix MQTT will_message length calculation
PUBLISHED_FROM=d2400f6ef4837411586fb27db0b1fa03d94283c6
2017-04-17 07:24:54 +00:00
Ruslan Valiullin 6926655513 add to cgi doc note about zombies
PUBLISHED_FROM=fb1796f11a595befd160bd5ab1088b6e39f16757
2017-04-15 06:44:43 +00:00
Ruslan Valiullin 8354319e72 websocket_chat added MG_EV_HTTP_REQUEST
PUBLISHED_FROM=6f5e1b4a97ada21025f892d3348808bffb469dfa
2017-04-14 12:57:30 +00:00
Deomid Ryabkov f9596cc1db Perform endpoint auth check on multipart requests
https://github.com/cesanta/mongoose-os/issues/229#issuecomment-293613426

PUBLISHED_FROM=1c34db7ab2598eca1db0266cc6cdd31c32a16fff
2017-04-12 16:59:49 +00:00
Deomid Ryabkov b2e2ad9a45 Fix hexdump on ESP8266, deliver MG_EV_SEND [...]
[...] after handing data off to LWIP, do not wait for ACK.
We don't do it in net_if_socket, don't do it here either.
Also prevents multiple send attempt on the same send_mbuf data.

PUBLISHED_FROM=4e5a677ebda84af1514f34299e53ce856a537883
2017-04-12 15:54:29 +00:00
Deomid Ryabkov a07fb2be51 Log DNS failures in mOS
To aid disagnosing cases like https://forum.cesanta.com/index.php?p=/discussion/397/retries-connecting-to-aws-broker

PUBLISHED_FROM=98680b594dbed42234fc53050c9df292feb32f35
2017-04-11 15:51:27 +00:00
Deomid Ryabkov 7f259f2a79 Add optional digest auth to mOS HTTP server
If http.auth_{domain,file} are configured, all HTTP requests require valid digest authorization header.
This applies to files served by mg_http_serve as well as synamic endpoints such as /update and /rpc.

mongoose-os#229

PUBLISHED_FROM=824d594147cfeb2428b463d24478b207839aa5e2
2017-04-11 10:39:45 +00:00
Sergey Lyubka 8ce34af9f3 Clean send_mbuf in mg_if_sent_cb, fix hexdump
PUBLISHED_FROM=3d222e548a3323b957376666e6702b408843b5a3
2017-04-11 00:06:03 +00:00
Sergey Lyubka 82761bb875 Bobify format targets
PUBLISHED_FROM=2c1d372e4db856e23266c29195c07968abc2ec81
2017-04-10 22:50:30 +00:00
Deomid Ryabkov 08a10a8af5 Handle multiple MQTT messages per RECV event
PUBLISHED_FROM=fc98c51254dd94d3f443fb66e49449da7d9e754c
2017-04-10 15:51:13 +00:00
Dmitry Frank bd130136bc Commonize arg checking in cfunctions
Add `mjs_check_arg()` which checks whether argument is provided, and
checks its type. It simplifies code and makes it smaller (because
error strings are not ad-hoc, so they are not duplicated)

As part of that, also commonize type stringifying: implement
`mjs_stringify_type` and reimplement `mjs_typeof` on top of that.

Use `mjs_check_arg()` in `mjs_string_slice()` and
`mjs_string_char_code_at()`.

PUBLISHED_FROM=0b72cf479738ff405d991cbd4bf9e75edda0f111
2017-04-10 10:09:07 +00:00
Ruslan Valiullin fb04203b72 Fix eintr, zombie
PUBLISHED_FROM=f6d7d0f9c6de8ffeeb3bcd8aace6c1434281ddf7
2017-04-09 16:07:59 +00:00
Deomid Ryabkov 4172c190e5 Fix MQTT handshake; change to version 3.1.1
Differences between 3.1 and 3.1.1:
https://github.com/mqtt/mqtt.github.io/wiki/Differences-between-3.1.0-and-3.1.1

None of them are breaking.

PUBLISHED_FROM=cf2abd28deb1dabf787e07bcfdb335ff72462865
2017-04-08 07:21:01 +00:00
Deomid Ryabkov 920abd627b Minor SNTP fixes
PUBLISHED_FROM=03d04996f160f777339eec9528f2f187e1051ff9
2017-04-07 11:10:37 +00:00
Deomid Ryabkov 02b7399f9a Fix a typo
PUBLISHED_FROM=183a1bb571d0e2f5c23181107d30417f73c1eeb1
2017-04-03 14:20:16 +00:00
Alexander Alashkin b8402ed073 Fix crash in multipart handling
Close cesanta/dev#6974

PUBLISHED_FROM=4d4e4a46eceba10aec8dacb7f8f58bd078c92307
2017-04-03 09:25:12 +00:00
Deomid Ryabkov 06c5c4d2a4 Handle NULL tpcb in mg_lwip_tcp_write
This can happen if the underlying LWIP TCP PCB has been destroyed (we got tcp_error_cb).

PUBLISHED_FROM=7a060aa4ca2a0c5a818fe9bc6b08cd0733c0ef8f
2017-03-30 15:32:33 +00:00
Alexander Alashkin 57a4ec31d1 Fix MinGW compilation
PUBLISHED_FROM=66b2dee87dc50de5f2891dee789beec89c3f6fb4
2017-03-30 12:18:56 +00:00
Alexander Alashkin 511c9a6d4a Add simple mongoose/esp32 example (w/out mOS)
PUBLISHED_FROM=0e407a2fb328107540d753123fe027f43860d0ef
2017-03-29 13:53:25 +00:00
Ilia Penev 8ec47111d5 Fix COAP compilation
PUBLISHED_FROM=0a0ef6f68d743cbba91d9ba911f1c5be69e6aac7
2017-03-29 12:47:33 +00:00
Alexander Alashkin 8b67274cc0 Fix mg_get_http_var retval
PUBLISHED_FROM=257deff5ea20302627e77a0f29cf2359276a41d4
2017-03-24 13:24:37 +00:00
Dmitry Frank af22fb7a06 Include mg_mem.h into str_util
PUBLISHED_FROM=990564aa54946b2a5b52d3a9c31f80b8e93c6b44
2017-03-23 22:07:22 +00:00
David Hargat df5fff5e72 Consistent MG_MALLOC, MG_REALLOC and MG_FREE calls
PUBLISHED_FROM=e7f306b5d1a1366d3ec71fa238c5e18c03aadf8d
2017-03-23 18:54:06 +00:00
benrubson d9243d1c0b Fix MD5 disabling
PUBLISHED_FROM=bb03593fb2abfb79daa3118b786428ee3e693e3d
2017-03-21 10:50:32 +00:00
Alexander Alashkin 2fb145d39d Fix DISABLE_MD5 and DISABLE_SHA1 naming
PUBLISHED_FROM=2babde0d0c6add14aa500f4bf1c833715d979c6c
2017-03-21 10:24:11 +00:00
Yiming Sun 14094aaef7 Fix typo
PUBLISHED_FROM=56fdeaf4965ef26c398267c8656735bb52e45085
2017-03-21 08:50:43 +00:00
Alexander Alashkin ec752645ee Remove ajax_upload
PUBLISHED_FROM=599ccd99e7bf422cac5e8b1f5ccebe3cac2780e8
2017-03-21 07:35:52 +00:00
Sergey Lyubka ceb2f1da41 Update upload example
PUBLISHED_FROM=a28c1da3f0dd597792439246313ca39984ab7536
2017-03-20 17:23:38 +00:00
Alexander Alashkin aab857a66e Add ajax_upload to big_upload
PUBLISHED_FROM=7c919ba3a2afa74cec9947e78299b4bb7a64b4bc
2017-03-20 16:55:31 +00:00
Alexander Alashkin 066be0fe30 Add ajax_upload example
PUBLISHED_FROM=c5691d4321fff2e03f689b0195abd1ec6a188418
2017-03-20 10:51:24 +00:00
Alexander Alashkin 380e87ddfa Honor DNS server from DHCP
PUBLISHED_FROM=10772301ef115c31ada3521ff4235c33a421b782
2017-03-20 09:53:12 +00:00
Alexander Alashkin e9a7a2af18 Fix WinCE compilation
PUBLISHED_FROM=51d68829414739b04fafc9198d86b817c38d71d2
2017-03-17 15:19:29 +00:00
Deomid Ryabkov a83e7d8c42 Properly shut down the SSL connection
By sending close_notify

PUBLISHED_FROM=028a001cb9470a16cc7a6544805bfb042a435779
2017-03-15 23:12:57 +00:00
Dmitry Frank bf7dd7ac63 Add separate userdata for each http endpoint hdlr
PUBLISHED_FROM=29a204c2c7f35724b6f1e8435edb94869da2362c
2017-03-15 17:43:19 +00:00
Dmitry Frank 0fc3370859 First step towards separate userdata argument
PUBLISHED_FROM=93fe1cc2c5e2513509511a81e5919cbd37056b10
2017-03-15 00:52:59 +00:00
Deomid Ryabkov c416012f97 MGOS SNTP support for ESP8266 and ESP32
PUBLISHED_FROM=8e07541e7a3b951dcfd08381b46f6143773eae45
2017-03-13 17:53:35 +00:00
Deomid Ryabkov d3a8862bd8 Make interface vtables const
Frees up a bit of ram on ESP

PUBLISHED_FROM=0ea046cc63704481bca138b3096937669b94733d
2017-03-11 00:11:56 +00:00
Deomid Ryabkov 08353731ef Fix MQTT PUB{ACK,REC,REL,COMP} and UNSUBACK flags
Flags should be 0 for all of these, except PUBREL (flags = 2).

PUBLISHED_FROM=46bf63fe12020d4cb493e52ceb3bae0291484b40
2017-03-08 00:23:14 +00:00
Deomid Ryabkov 16700244b0 Fix parsing of MQTT QoS > 0 PUBLISH messages
Message ID comes after topic, not before.

PUBLISHED_FROM=1ec2a56e290b67061b18c745671dc7f089b9cc0d
2017-03-07 23:52:42 +00:00
Deomid Ryabkov 49ca223e9c Minor memory optimization
Release pbuf sooner: after copying data from, before invoking user code

PUBLISHED_FROM=b877c96ef602bbca26762b18b9dde17eb880d1f9
2017-03-07 17:19:47 +00:00
Sergey Lyubka 38efe632ae Squash warning
PUBLISHED_FROM=72d80f8ed2c10866b44d56d8133c76b22bc105b0
2017-03-06 21:51:43 +00:00
Deomid Ryabkov 39a3bb7e44 Log method and URI in mg_http_handler
PUBLISHED_FROM=34c3e49d523b0f5c7056f91e4b422f21f5694df9
2017-03-02 09:36:08 +00:00
Alexander Alashkin 920e8d9145 Add shims for mongoose file operations
PUBLISHED_FROM=b5b12cdf4273f21dbcdac9bfb6a06063152914c9
2017-03-01 10:06:47 +00:00
Alexander Alashkin aed6d05d8c Do not test reassembled buffer for WS_OP_CLOSE
PUBLISHED_FROM=0e8de208b553b63c8367f66893389587bd17359f
2017-03-01 10:06:46 +00:00
Alexander Alashkin d85d95a40b Fix potential out-of-bound
PUBLISHED_FROM=71b40189bcedbe9338915c1aad939835125dad26
2017-03-01 10:06:45 +00:00
Alexander Alashkin b5dd54a404 Fix doc typos
PUBLISHED_FROM=1bdacf793b35ebe70d0a3a9d64260dd2bd135c73
2017-03-01 06:19:58 +00:00
Yiming Sun f7c0a2ee15 Fix server_example.md
PUBLISHED_FROM=dfbfeaae983daa0412964ac0402759f632bf7aeb
2017-02-28 11:05:31 +00:00
Yiming Sun 874b5bfdbf Fix comment in mongoose.h
PUBLISHED_FROM=35e8f18aa611b45c271d0178d9197291bfa9726d
2017-02-28 10:50:21 +00:00
Yiming Sun 71d09722be Fix http_client doc
PUBLISHED_FROM=f415ddbac47e3069d3ab29467a23f6b8dab0066f
2017-02-27 20:20:33 +00:00
Dmitry Frank 349d25dccf Fix # matching logic
E.g. given the expression `foo/#`:

- `foo/bar` matches
- `foo/` should not match
- `foo` should not match

PUBLISHED_FROM=40f3290cb9a478b22d9f1ab6382884b5de70e266
2017-02-24 15:35:20 +00:00
Dmitry Frank 3942914945 Fix subscription to wildcard topics
`mg_mqtt_match_topic_expression()` and friends are public now.

So far, only `#` is supported.

PUBLISHED_FROM=20c031bcf34be84771c4a9c456318634eb9a517c
2017-02-24 14:21:33 +00:00
Dmitry Frank 60c16bbb5d Fix mos docker image name
PUBLISHED_FROM=91016ab1629a65976d2cc2f00aec4e1667cb4a8f
2017-02-23 21:35:24 +00:00
Sergey Lyubka 70b5f4130e Add http post example
PUBLISHED_FROM=94f830a5fa4b806fb2cf60c93a9e8744022ff8d7
2017-02-23 17:50:14 +00:00
Sergey Lyubka 17cfecc5c3 Mongoose examples fixes
PUBLISHED_FROM=b47a5b6987ee8d9e7c9bae2bd4d2943d2e7f76a9
2017-02-20 10:05:57 +00:00
Deomid Ryabkov ebdd18769b Add core dump and exception handling to RTOS port
PUBLISHED_FROM=dba64da598b45469c7fd458865c75d3eb6853c2d
2017-02-19 10:05:31 +00:00
Deomid Ryabkov f974fddd2a Fix ESP8266_RTOS example; add mos flashing
PUBLISHED_FROM=d87814d40f0acdc7a96fbd132c2157ccb499c7c6
2017-02-17 14:51:49 +00:00
Dmitry Frank b1a46da309 Implement Array.prototype.length
We don't have a real Array.prototype of course, just `[1,2,3].length`
behaves like we do.

PUBLISHED_FROM=456379377652cb60fc6f9521d8d358480237c58a
2017-02-17 14:51:48 +00:00
Deomid Ryabkov 81879be4be RTOS stability improvements
PUBLISHED_FROM=2992473e6c05c1dc95878cc549eccba7abcedccf
2017-02-16 16:05:22 +00:00
Deomid Ryabkov 0a094d4c1f Decouple mg_lwip_accept_cb from mg_if_accept_tcp_cb
Must be invoked on mongoose main task, not on LWIP

Also request immediate poll oif there is data to be sent and space to
send it.

PUBLISHED_FROM=53576651452d8d7193da9e63f5b97f6f8729c45b
2017-02-16 12:19:23 +00:00
Deomid Ryabkov 66a96410d4 ESP8266: Add RTOS SDK port (MGOS_ESP8266_RTOS=1)
PUBLISHED_FROM=ca5332e63700274ed9aeea9d9d1802e89fa788fa
2017-02-16 11:05:34 +00:00
Deomid Ryabkov d4b23f08b6 Implement client support for TLS-PSK
For both OpenSSL and mbedTLS

PUBLISHED_FROM=0bfd5f128b4c4c062cb6f0ca0da9b30790aa8bf8
2017-02-15 08:20:53 +00:00
Deomid Ryabkov d6d956b9d8 Do not prefix successfulresponse with "Error: "
It's confusing

PUBLISHED_FROM=9158ccd920dabf92963e76aa96a988753b9c427d
2017-02-13 15:05:11 +00:00
Deomid Ryabkov 383b2a48c5 Update logo in connected_device examples
PUBLISHED_FROM=6319df7f49dc921ddb672ba9789dfbbff8c25d9f
2017-02-13 14:05:04 +00:00
Sergey Lyubka ab1c464950 Fix https://github.com/cesanta/mongoose/issues/765
PUBLISHED_FROM=f7f8ce9421d96a5f0d90afe4c930c53662b4e907
2017-02-11 04:50:44 +00:00
Deomid Ryabkov f20b5191f2 Check UDP pbuf for being NULL
cesanta/mongoose-os#186

PUBLISHED_FROM=30460b56211eb0dff4d05bff45f256ac1da2caf4
2017-02-10 02:35:08 +00:00
Deomid Ryabkov fc113d64f5 Add mg_hexdumpf: mg_hexdump that outputs to a file
PUBLISHED_FROM=f0fe58c9f01ef0c7b491ed0e5f51b983e4119507
2017-02-09 10:33:33 +00:00
Deomid Ryabkov 6f6b12bee7 Lower verbosity of a debug message
PUBLISHED_FROM=6ff979319c31363df16cedf99b2432bd83db1473
2017-02-09 10:21:15 +00:00
Deomid Ryabkov 4e6c2867da UDP fixes: move recv callback into event loop, ...
...and fix a leak where UDP connections with SEND_AND_CLOSE set would not be closed

PUBLISHED_FROM=d60f1fc037e8e57671c7d3146fabc1f068bbb514
2017-02-09 10:21:12 +00:00
Alexander Alashkin 54989e819a Fix multipart parsing
Close cesanta/mongoose#770

PUBLISHED_FROM=ae55988f1c6ccdff172b8db405adb36c91289d95
2017-02-08 10:54:46 +00:00
Dmitry Frank bf505bb68d Update readme of nrf examples
And also fix `flash` target for nrf51

PUBLISHED_FROM=decc6242380eb7070bfbcb26c57780e756588cc3
2017-02-08 08:25:32 +00:00
Deomid Ryabkov 4072062b72 Add MG_SSL_IF_MBEDTLS_MAX_FRAG_LEN
And set to 1024 for mOS.

PUBLISHED_FROM=ee3a66ad935cfb50355ebd7bae59c8230914878d
2017-02-08 08:25:31 +00:00
Alexander Alashkin d6ba37dc3c Correct msg len for chunked encoding
Close cesanta/dev#6485

PUBLISHED_FROM=172ab4f18f1fb3e6110ad03eea18a7f87f2e531a
2017-02-07 12:25:06 +00:00
Alexander Alashkin a58d21aa28 Add overrun protection to mg_sock_to_str
Relate to cesanta/mongoose#780

PUBLISHED_FROM=145d94c52be03ac2d909eae8166774ffd40f0df1
2017-02-07 12:25:05 +00:00
Alexander Alashkin 6e8d4129b2 Use _exit in CGI. Close cesanta/mongoose#779
PUBLISHED_FROM=bfe62d3824ee3a6e66b7d1a57ee7bad3b726649d
2017-02-07 11:09:49 +00:00
Alexander Alashkin 2485a8f8d9 Fix signs comparison. Close cesanta/mongoose#774
PUBLISHED_FROM=a875606de6f4b2c202b25ce20efcb1ca33eb75b8
2017-02-07 08:25:31 +00:00
Sergey Lyubka 1ae908f6d5 Add mqtt codec
PUBLISHED_FROM=f780559966a6a955603e05aeaa5dde8455bff991
2017-02-06 17:39:02 +00:00
Alexander Alashkin 6b923bdff1 Add stm32/cube to hwtests
PUBLISHED_FROM=478792d0479ba2154f0a65eea066f6ae6f235f84
2017-02-06 17:25:16 +00:00
Alexander Alashkin d39969d1e6 Restore links to mongoose/examples
PUBLISHED_FROM=67dc5d1ed30dc2500032be73dcdb214bd62c59d0
2017-02-06 14:09:01 +00:00
Alexander Alashkin eaef5bd133 Revert "Stop publish examples to mongoose repo"
This reverts commit 1a17e17c462bdd4e1d26d8742f8b7087273e04c2.

PUBLISHED_FROM=80028de308c9a021955d1425d2bfee8feb85f193
2017-02-06 14:08:59 +00:00
Sergey Lyubka 7cc7df8c0e Merge pull request #778 from cesanta/remove_examples
Remove examples
2017-02-03 10:23:29 +00:00
Alexander Alashkin 551f393da7 Remove examples 2017-02-03 12:17:07 +02:00
Sergey Lyubka e81f8373a2 Update mongoose docs
PUBLISHED_FROM=cfd0018a5824c5ccac532558be86c17cda64ce50
2017-02-02 14:24:49 +00:00
Sergey Lyubka dfa83f2c85 Fix TCP close sequence
PUBLISHED_FROM=ed6cf7fd63b6f80d5c37ab93899ecd09bac6102b
2017-02-01 20:26:46 +00:00
Alexander Alashkin 91bdbc5193 Fix warn in mg_lwip_if_poll
PUBLISHED_FROM=0bcb3e892e1ba2329aef5d17375fe4d3879dc666
2017-01-31 13:39:29 +00:00
Alexander Alashkin 707b9ed2d6 Remove mg_enable_multithreading. Close cesanta/dev#6511
PUBLISHED_FROM=7864ffa26cb553f5d4a93248f67c288327ec23b0
2017-01-30 13:55:49 +00:00
Alexander Alashkin cd6b846e22 Fix mongoose/mbed compilation
PUBLISHED_FROM=c754e6961fc197d3057740169f55025b305b6936
2017-01-30 13:10:47 +00:00
Alexander Alashkin 807e4ea6ec Fix STM32F4_CC3100 Mongoose example compilation
PUBLISHED_FROM=7a67a67d2f0007e241e4ccb57bc24a43ba20bfde
2017-01-30 12:09:43 +00:00
Alexander Alashkin 507e8bfac9 Drop Arduino support
PUBLISHED_FROM=85768c0d2536d9c31885a5127710b9756e3229a3
2017-01-30 09:39:15 +00:00
Deomid Ryabkov 2ea63a0ea6 Limit len of prefix; makes log tidy w/ long names
PUBLISHED_FROM=570530179da327f8bb156bbbd7c557014c1630c1
2017-01-30 09:24:48 +00:00
Deomid Ryabkov 7988acbff4 Raise log level of mbedTLS socket evs to LL_DEBUG
PUBLISHED_FROM=ed0ac4133342c733977e7884a6bbadab7ee74127
2017-01-26 12:38:30 +00:00
Alexander Alashkin b8c3740446 Map STM32 pins to MOS pins
PUBLISHED_FROM=6724de19c28f972a785b0d5e7dd4b41889e04850
2017-01-25 09:08:43 +00:00
Deomid Ryabkov 7bdbd80552 Fix ESP32 encr. OTA; clean up {open,read,close}dir
Fixed a bunch of things to make OTA work on ESP32 with flash encryption:
writes to app aprtitions must be 32-byte aligned and mod 32 in size.
When merging filesystems during update, use spiffs_vfs_* functions so
that old fs is properly decrypted.

Refactored cs_dirent stuff: SPIFFS support moved to spiffs_vfs.c,
added dirent.h on ESP8266 and CC3200 which includes cs_dirent.h
Define DIR and dirent only if asked (ESP8266, CC3200, WIN32).

PUBLISHED_FROM=58b0d05cdc41b1a9e02d341e2a1cdcb012829232
2017-01-24 12:53:35 +00:00
Alexander Alashkin 577ad2599c Enable additional services for stm32/cube
PUBLISHED_FROM=b22a136bc630b7cf4a62fd9d91b85e0e939a7f82
2017-01-18 15:10:28 +00:00
108 changed files with 2912 additions and 2153 deletions

No files matched your search

+9
View File
@@ -0,0 +1,9 @@
binary/
deps/
docker/
docs/
examples/
platforms/
src/
test/
multilingual/
+1 -1
View File
@@ -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)
+1 -1
View File
@@ -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.
+1 -1
View File
@@ -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.
+1
View File
@@ -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 }
+2 -3
View File
@@ -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.
+2 -5
View File
@@ -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
+2 -1
View File
@@ -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.
+1 -3
View File
@@ -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 -5
View File
@@ -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.
+2 -1
View File
@@ -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: *");
+2
View File
@@ -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.
-2
View File
@@ -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 -1
View File
@@ -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 -3
View File
@@ -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 -2
View File
@@ -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.
+3 -3
View File
@@ -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`.
+2 -1
View File
@@ -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.
+1 -1
View File
@@ -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].
+2 -1
View File
@@ -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.
+2 -2
View File
@@ -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.
+1 -1
View File
@@ -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.
+1 -1
View File
@@ -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
};
---
+2 -2
View File
@@ -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;
+1
View File
@@ -17,6 +17,7 @@ signature: |
#if MG_ENABLE_JAVASCRIPT
struct v7 *v7;
#endif
const char *nameserver; /* DNS server to use */
};
---
+3 -2
View File
@@ -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()
+1
View File
@@ -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 }
---
+10
View File
@@ -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 */
+1
View File
@@ -3,6 +3,7 @@ title: "URI"
symbol_kind: "intro"
decl_name: "uri.h"
items:
- { name: mg_assemble_uri.md }
- { name: mg_parse_uri.md }
---
+20
View File
@@ -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.
+1 -1
View File
@@ -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);
+3
View File
@@ -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 }
+2 -1
View File
@@ -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.
+12
View File
@@ -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.
+12
View File
@@ -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.
+10
View File
@@ -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.
+3 -1
View File
@@ -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.
+5 -1
View File
@@ -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.
+4
View File
@@ -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.
+3 -2
View File
@@ -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) {
+12 -1
View File
@@ -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
```
+2 -2
View File
@@ -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);
}
}
+1 -1
View File
@@ -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
+1 -1
View File
@@ -2,4 +2,4 @@
title: MQTT client example
---
TBD
See https://github.com/cesanta/mongoose/tree/master/examples/mqtt_client
+1 -1
View File
@@ -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
+1
View File
@@ -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
View File
@@ -1 +0,0 @@
*.exe
+6 -6
View File
@@ -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 */
+16
View File
@@ -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"
+9
View File
@@ -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
+18
View File
@@ -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
```
+17
View File
@@ -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 $@
+93
View File
@@ -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);
}
}
+1
View File
@@ -0,0 +1 @@
docker.cesanta.com/esp32-build:1.0-r13
+21 -1
View File
@@ -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
+13 -3
View File
@@ -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
+6 -4
View File
@@ -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
View File
@@ -1 +1 @@
docker.cesanta.com/esp8266-build-rtos:1.4.0-r2
docker.cesanta.com/esp8266-build:2.0.0-1.5.0-r1
+11 -6
View File
@@ -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. */
}
+1 -1
View File
@@ -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))
+2 -3
View File
@@ -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) \
"
+22 -23
View File
@@ -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:
-2
View File
@@ -1,2 +0,0 @@
# This "makefile" is only intended to prevent errors during main makefile execution
all:
-46
View File
@@ -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);
}
}
-2
View File
@@ -1,2 +0,0 @@
# This "makefile" is only intended to prevent errors during main makefile execution
all:
-45
View File
@@ -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);
}
+13 -26
View File
@@ -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 (;;) {
+54
View File
@@ -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
View File
@@ -1,4 +1,3 @@
PROG = captive_dns_server
MODULE_CFLAGS=-DMG_ENABLE_DNS_SERVER -DMG_ENABLE_IPV6
SSL_LIB=openssl
include ../examples.mk
Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.7 KiB

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.7 KiB

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.7 KiB

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.7 KiB

After

Width:  |  Height:  |  Size: 2.4 KiB

+1 -1
View File
@@ -1,4 +1,4 @@
PROG = mqtt_client
MODULE_CFLAGS = -DMG_ENABLE_HTTP=0
SSL_LIB=openssl
#SSL_LIB=openssl
include ../examples.mk
+3
View File
@@ -0,0 +1,3 @@
PROG = multithreaded
MODULE_CFLAGS=-DMG_ENABLE_THREADS
include ../examples.mk
+124
View File
@@ -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;
}
+12 -1
View File
@@ -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
+2 -1
View File
@@ -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.
+12 -1
View File
@@ -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:
Loaded 100 of 108 files, more files were not shown because too many files have changed in this diff. Show more