diff --git a/examples/zephyr/Makefile b/examples/zephyr/Makefile new file mode 100644 index 00000000..07b4c689 --- /dev/null +++ b/examples/zephyr/Makefile @@ -0,0 +1,8 @@ +example: + true + +build: + echo "Add Zephyr installation and call sub-makefiles to build examples" + +clean: + rm -rf */*/mongoose.* diff --git a/examples/zephyr/http-client/src/main.c b/examples/zephyr/http-client/src/main.c index 76508660..2346a38f 100644 --- a/examples/zephyr/http-client/src/main.c +++ b/examples/zephyr/http-client/src/main.c @@ -1,8 +1,8 @@ // Copyright (c) 2020 Cesanta Software Limited // All rights reserved -#include "mongoose.h" #include "certs.h" +#include "mongoose.h" static const char *s_debug_level = "3"; static time_t s_boot_timestamp = 0; @@ -29,7 +29,7 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { // If s_url is https://, tell client connection to use TLS if (mg_url_is_ssl(s_url)) { - struct mg_tls_opts opts = {.ca = s_ca, .srvname = host }; + struct mg_tls_opts opts = {.ca = s_ca, .srvname = host}; mg_tls_init(c, &opts); } @@ -71,7 +71,7 @@ static void sfn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { // We need correct time in order to get HTTPs working, therefore, // making https request from SMTP callback - if(!s_connected) { + if (!s_connected) { MG_INFO(("Connecting to : [%s]", s_url)); mg_http_connect(&s_mgr, s_url, fn, NULL); // Create client connection s_connected = 1; @@ -98,9 +98,8 @@ int main(int argc, char *argv[]) { mg_log_set_callback(logfn, NULL); mg_mgr_init(&s_mgr); - - struct mg_timer t; - mg_timer_init(&t, 5000, MG_TIMER_REPEAT | MG_TIMER_RUN_NOW, timer_fn, &s_mgr); + mg_timer_add(&s_mgr, 5000, MG_TIMER_REPEAT | MG_TIMER_RUN_NOW, timer_fn, + &s_mgr); // Start infinite event loop MG_INFO(("Mongoose version : v%s", MG_VERSION)); diff --git a/examples/zephyr/mqtt-client-aws-client/CMakeLists.txt b/examples/zephyr/mqtt-aws-client/CMakeLists.txt similarity index 100% rename from examples/zephyr/mqtt-client-aws-client/CMakeLists.txt rename to examples/zephyr/mqtt-aws-client/CMakeLists.txt diff --git a/examples/zephyr/mqtt-client-aws-client/Makefile b/examples/zephyr/mqtt-aws-client/Makefile similarity index 100% rename from examples/zephyr/mqtt-client-aws-client/Makefile rename to examples/zephyr/mqtt-aws-client/Makefile diff --git a/examples/zephyr/mqtt-client-aws-client/prj.conf b/examples/zephyr/mqtt-aws-client/prj.conf similarity index 100% rename from examples/zephyr/mqtt-client-aws-client/prj.conf rename to examples/zephyr/mqtt-aws-client/prj.conf diff --git a/examples/zephyr/mqtt-client-aws-client/src/certs.h b/examples/zephyr/mqtt-aws-client/src/certs.h similarity index 100% rename from examples/zephyr/mqtt-client-aws-client/src/certs.h rename to examples/zephyr/mqtt-aws-client/src/certs.h diff --git a/examples/zephyr/mqtt-client-aws-client/src/main.c b/examples/zephyr/mqtt-aws-client/src/main.c similarity index 89% rename from examples/zephyr/mqtt-client-aws-client/src/main.c rename to examples/zephyr/mqtt-aws-client/src/main.c index cfa0b2d9..1364caea 100644 --- a/examples/zephyr/mqtt-client-aws-client/src/main.c +++ b/examples/zephyr/mqtt-aws-client/src/main.c @@ -1,15 +1,16 @@ // Copyright (c) 2020 Cesanta Software Limited // All rights reserved -#include "mongoose.h" #include "certs.h" +#include "mongoose.h" struct mg_mgr mgr; static const char *s_debug_level = "3"; static time_t s_boot_timestamp = 0; static struct mg_connection *s_sntp_conn = NULL; -static const char *s_url = "mqtts://a3nkain3cvvy7l-ats.iot.us-east-1.amazonaws.com"; +static const char *s_url = + "mqtts://a3nkain3cvvy7l-ats.iot.us-east-1.amazonaws.com"; static const char *s_rx_topic = "d/rx"; static const char *s_tx_topic = "d/tx"; @@ -24,8 +25,7 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { MG_ERROR(("%p %s", c->fd, (char *) ev_data)); } else if (ev == MG_EV_CONNECT) { // Set up 2-way TLS that is required by AWS IoT - struct mg_tls_opts opts = { - .ca = s_ca, .cert = s_cert, .certkey = s_key}; + struct mg_tls_opts opts = {.ca = s_ca, .cert = s_cert, .certkey = s_key}; mg_tls_init(c, &opts); } else if (ev == MG_EV_MQTT_OPEN) { // MQTT connect is successful @@ -67,10 +67,11 @@ static void sfn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { // We need correct time in order to get HTTPs working, therefore, // making https request from SMTP callback - if(!s_connected) { + if (!s_connected) { MG_INFO(("Connecting to : [%s]", s_url)); struct mg_mqtt_opts opts = {.clean = true}; - mg_mqtt_connect(&mgr, s_url, &opts, fn, NULL); // Create client connection + mg_mqtt_connect(&mgr, s_url, &opts, fn, + NULL); // Create client connection s_connected = 1; } } else if (ev == MG_EV_CLOSE) { @@ -95,9 +96,7 @@ int main(int argc, char *argv[]) { mg_log_set_callback(logfn, NULL); mg_mgr_init(&mgr); - - struct mg_timer t; - mg_timer_init(&t, 5000, MG_TIMER_REPEAT | MG_TIMER_RUN_NOW, timer_fn, &mgr); + mg_timer_add(&mgr, 5000, MG_TIMER_REPEAT | MG_TIMER_RUN_NOW, timer_fn, &mgr); // Start infinite event loop MG_INFO(("Mongoose version : v%s", MG_VERSION)); diff --git a/examples/zephyr/websocket-server/src/main.c b/examples/zephyr/websocket-server/src/main.c index eda67dfd..ee77a885 100644 --- a/examples/zephyr/websocket-server/src/main.c +++ b/examples/zephyr/websocket-server/src/main.c @@ -1,8 +1,8 @@ // Copyright (c) 2020 Cesanta Software Limited // All rights reserved -#include "mongoose.h" #include "certs.h" +#include "mongoose.h" static const char *s_debug_level = "3"; static const char *s_web_dir = "/"; @@ -29,7 +29,7 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { } else if (mg_http_match_uri(hm, "/rest")) { // Serve REST response mg_http_reply(c, 200, "", "{\"result\": %d}\n", 123); - } + } } else if (ev == MG_EV_WS_MSG) { // Got websocket frame. Received data is wm->data. Echo it back! struct mg_ws_message *wm = (struct mg_ws_message *) ev_data; @@ -77,9 +77,7 @@ int main(int argc, char *argv[]) { mg_mgr_init(&mgr); mg_http_listen(&mgr, s_ws_addr, fn, NULL); mg_http_listen(&mgr, s_wss_addr, fn, &mgr); - - struct mg_timer t; - mg_timer_init(&t, 5000, MG_TIMER_REPEAT | MG_TIMER_RUN_NOW, timer_fn, &mgr); + mg_timer_add(&mgr, 5000, MG_TIMER_REPEAT | MG_TIMER_RUN_NOW, timer_fn, &mgr); // Start infinite event loop MG_INFO(("Mongoose version : v%s", MG_VERSION));