mirror of
https://github.com/cesanta/mongoose.git
synced 2026-10-27 12:26:24 +00:00
update to new API
This commit is contained in:
1 parent
199af33b30
commit
ed54b60ea3
11 files changed
+73
-54
No files matched your search
@@ -29,8 +29,8 @@ static const char *s_url =
|
||||
// 3. From the dialog box that appears, download:
|
||||
// xxx-certificate.pem.crt as cert.pem to the example directory
|
||||
// xxx-private.pem.key as key.pem to the example directory
|
||||
static const char *s_cert = "cert.pem";
|
||||
static const char *s_key = "key.pem";
|
||||
//static const char *s_cert = "cert.pem";
|
||||
//static const char *s_key = "key.pem";
|
||||
|
||||
static const char *s_rx_topic = "d/rx";
|
||||
static const char *s_tx_topic = "d/tx";
|
||||
@@ -44,11 +44,6 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
|
||||
} else if (ev == MG_EV_ERROR) {
|
||||
// On error, log error message
|
||||
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 = "ca.pem", .cert = s_cert, .certkey = s_key};
|
||||
mg_tls_init(c, &opts);
|
||||
} else if (ev == MG_EV_MQTT_OPEN) {
|
||||
// MQTT connect is successful
|
||||
struct mg_str topic = mg_str(s_rx_topic);
|
||||
@@ -92,6 +87,9 @@ int main(void) {
|
||||
struct mg_mqtt_opts opts = {.clean = true};
|
||||
bool done = false;
|
||||
mg_mgr_init(&mgr); // Initialise event manager
|
||||
struct mg_tls_opts topts = {.client_ca = mg_str(CA_ALL)};
|
||||
//TODO() 2-way auth and certificate loading
|
||||
mg_tls_ctx_init(&mgr, &topts);
|
||||
MG_INFO(("Connecting to %s", s_url)); // Inform that we're starting
|
||||
mg_mqtt_connect(&mgr, s_url, &opts, fn, &done); // Create client connection
|
||||
while (!done) mg_mgr_poll(&mgr, 1000); // Loop until done
|
||||
|
||||
Reference in new issue
Block a user