Adjust to timer API change, add root makefile

This commit is contained in:
Sergey Lyubka 2022-04-13 14:03:00 +01:00
parent d630ba743d
commit 186eb998ba
8 changed files with 24 additions and 20 deletions

8
examples/zephyr/Makefile Normal file
View File

@ -0,0 +1,8 @@
example:
true
build:
echo "Add Zephyr installation and call sub-makefiles to build examples"
clean:
rm -rf */*/mongoose.*

View File

@ -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));

View File

@ -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));

View File

@ -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));