diff --git a/mongoose.h b/mongoose.h index c2a30096..c9c870e7 100644 --- a/mongoose.h +++ b/mongoose.h @@ -2832,7 +2832,7 @@ struct mg_tls_opts { // ``` // Full examples: // tutorials/http/http-server, tutorials/http/http-client, -// tutorials/mqtt/mqtt-client-aws-iot, tutorials/websocket/websocket-client +// tutorials/mqtt/mqtt-client, tutorials/websocket/websocket-client // Related APIs: // mg_http_listen(), mg_http_connect(), mg_ws_connect(), mg_mqtt_connect() // Notes: @@ -3606,8 +3606,7 @@ struct mg_mqtt_message { // struct mg_mqtt_opts opts = {.client_id = mg_str("device1")}; // mg_mqtt_connect(&mgr, "mqtt://broker:1883", &opts, fn, NULL); // Full examples: -// tutorials/mqtt/mqtt-client, tutorials/mqtt/mqtt-client-aws-iot, -// tutorials/mqtt/ota-over-mqtt +// tutorials/mqtt/mqtt-client, tutorials/mqtt/ota-over-mqtt // Related APIs: // mg_mqtt_pub(), mg_mqtt_sub(), mg_tls_init(), mg_mgr_poll() // Notes: @@ -3642,8 +3641,7 @@ void mg_mqtt_login(struct mg_connection *c, const struct mg_mqtt_opts *opts); // }; // uint16_t id = mg_mqtt_pub(c, &opts); // Full examples: -// tutorials/mqtt/mqtt-client, tutorials/mqtt/mqtt-client-aws-iot, -// tutorials/mqtt/ota-over-mqtt +// tutorials/mqtt/mqtt-client, tutorials/mqtt/ota-over-mqtt // Related APIs: // mg_mqtt_connect(), mg_mqtt_sub(), mg_mqtt_send_header() // Notes: @@ -3658,8 +3656,7 @@ uint16_t mg_mqtt_pub(struct mg_connection *c, const struct mg_mqtt_opts *opts); // struct mg_mqtt_opts opts = {.topic = mg_str("device/rx"), .qos = 1}; // mg_mqtt_sub(c, &opts); // Full examples: -// tutorials/mqtt/mqtt-client, tutorials/mqtt/mqtt-client-aws-iot, -// tutorials/mqtt/ota-over-mqtt +// tutorials/mqtt/mqtt-client, tutorials/mqtt/ota-over-mqtt // Related APIs: // mg_mqtt_connect(), mg_mqtt_pub(), mg_mqtt_unsub() // Notes: diff --git a/src/mqtt.h b/src/mqtt.h index 1c6f4082..1e14b669 100644 --- a/src/mqtt.h +++ b/src/mqtt.h @@ -117,8 +117,7 @@ struct mg_mqtt_message { // struct mg_mqtt_opts opts = {.client_id = mg_str("device1")}; // mg_mqtt_connect(&mgr, "mqtt://broker:1883", &opts, fn, NULL); // Full examples: -// tutorials/mqtt/mqtt-client, tutorials/mqtt/mqtt-client-aws-iot, -// tutorials/mqtt/ota-over-mqtt +// tutorials/mqtt/mqtt-client, tutorials/mqtt/ota-over-mqtt // Related APIs: // mg_mqtt_pub(), mg_mqtt_sub(), mg_tls_init(), mg_mgr_poll() // Notes: @@ -153,8 +152,7 @@ void mg_mqtt_login(struct mg_connection *c, const struct mg_mqtt_opts *opts); // }; // uint16_t id = mg_mqtt_pub(c, &opts); // Full examples: -// tutorials/mqtt/mqtt-client, tutorials/mqtt/mqtt-client-aws-iot, -// tutorials/mqtt/ota-over-mqtt +// tutorials/mqtt/mqtt-client, tutorials/mqtt/ota-over-mqtt // Related APIs: // mg_mqtt_connect(), mg_mqtt_sub(), mg_mqtt_send_header() // Notes: @@ -169,8 +167,7 @@ uint16_t mg_mqtt_pub(struct mg_connection *c, const struct mg_mqtt_opts *opts); // struct mg_mqtt_opts opts = {.topic = mg_str("device/rx"), .qos = 1}; // mg_mqtt_sub(c, &opts); // Full examples: -// tutorials/mqtt/mqtt-client, tutorials/mqtt/mqtt-client-aws-iot, -// tutorials/mqtt/ota-over-mqtt +// tutorials/mqtt/mqtt-client, tutorials/mqtt/ota-over-mqtt // Related APIs: // mg_mqtt_connect(), mg_mqtt_pub(), mg_mqtt_unsub() // Notes: diff --git a/src/tls.h b/src/tls.h index 71dc19a3..437ee258 100644 --- a/src/tls.h +++ b/src/tls.h @@ -66,7 +66,7 @@ struct mg_tls_opts { // ``` // Full examples: // tutorials/http/http-server, tutorials/http/http-client, -// tutorials/mqtt/mqtt-client-aws-iot, tutorials/websocket/websocket-client +// tutorials/mqtt/mqtt-client, tutorials/websocket/websocket-client // Related APIs: // mg_http_listen(), mg_http_connect(), mg_ws_connect(), mg_mqtt_connect() // Notes: diff --git a/tutorials/mqtt/mqtt-client-aws-iot/Makefile b/tutorials/mqtt/mqtt-client-aws-iot/Makefile deleted file mode 100644 index bbb6d241..00000000 --- a/tutorials/mqtt/mqtt-client-aws-iot/Makefile +++ /dev/null @@ -1,43 +0,0 @@ -REPO_ROOT ?= ../../.. - -PROG ?= client # Program we are building -DELETE = rm -rf # Command to remove files -OUT ?= -o $(PROG) # Compiler argument for output file -CFLAGS = -I$(REPO_ROOT) -W -Wall -Wextra -g -I. # Build options -SOURCES = main.c $(REPO_ROOT)/mongoose.c mongoose_fs.c - -CFLAGS_EXTRA ?= -DMG_TLS=MG_TLS_BUILTIN - -# Mongoose build options. See https://mongoose.ws/docs/getting-started/build-environment/ -# CFLAGS_MONGOOSE += - -ifeq ($(OS),Windows_NT) # Windows settings. Assume MinGW compiler. To use VC: make CC=cl CFLAGS=/MD OUT=/Feprog.exe - PROG ?= client.exe # Use .exe suffix for the binary - CC = gcc # Use MinGW gcc compiler - CFLAGS += -lws2_32 # Link against Winsock library - DELETE = cmd /C del /Q /F /S # Command prompt command to delete files - OUT ?= -o $(PROG) # Build output - MAKE += WINDOWS=1 CC=$(CC) -endif - -all: $(PROG) - $(RUN) ./$(PROG) $(ARGS) - -$(PROG): $(SOURCES) Makefile - $(CC) $(SOURCES) $(CFLAGS) $(CFLAGS_MONGOOSE) $(CFLAGS_EXTRA) $(OUT) - -csr: FORCE - openssl ecparam -noout -name prime256v1 -genkey -out key.pem - openssl req -new -key key.pem -subj /CN=Mongoose -out crt.csr - -mongoose_fs.c: ca.pem crt.pem key.pem - node ../../../test/pack.js ca.pem crt.pem key.pem > $@ - -clean: - $(DELETE) $(PROG) *.o *.obj *.exe *.dSYM mbedtls - -# For automated test purposes only -example: FORCE - touch mongoose_fs.c - -FORCE: diff --git a/tutorials/mqtt/mqtt-client-aws-iot/README.md b/tutorials/mqtt/mqtt-client-aws-iot/README.md deleted file mode 100644 index a313718b..00000000 --- a/tutorials/mqtt/mqtt-client-aws-iot/README.md +++ /dev/null @@ -1,2 +0,0 @@ -- This example requires generating AWS and user credentials and downloading certificates -- This example requires building with TLS support; before running, see detailed tutorial at https://mongoose.ws/tutorials/mqtt/mqtt-client-aws-iot/ diff --git a/tutorials/mqtt/mqtt-client-aws-iot/main.c b/tutorials/mqtt/mqtt-client-aws-iot/main.c deleted file mode 100644 index 2b8ceee3..00000000 --- a/tutorials/mqtt/mqtt-client-aws-iot/main.c +++ /dev/null @@ -1,102 +0,0 @@ -// Copyright (c) 2020 Cesanta Software Limited -// All rights reserved -// -// Example MQTT client. It performs the following steps: -// 1. Connects to the AWS IoT MQTT server -// 2. When connected, subscribes to the topic `s_rx_topic` -// 3. Publishes message `hello` to the `s_tx_topic` periodically -// - -// How to build and run this example: -// 1. Login to AWS IoT -// 2. Click "Settings" on the left bar, copy the domain, change s_url below -// 3. Click Security -> Policies -> Create Policy, fill fields: -// Name : PolicyAllow -// Action : iot:* -// Resource ARN: * -// Effect : allow -// then, click "Create" -// 4. Create EC private key file and CSR (Certificate Signing Request) -// type "make csr", see Makefile -// 5. Click Security -> Certificates -> Add Certificate -> Create Certificate -// Choose "Create certificate with certificate signing request (CSR)" -// Choose "crt.csr" created on a previous step -// Choose "Active" to activate certificate -// Click Create -// Attach PolicyAllow policy to the created certificate -// Downoad AmazonRootCA1.pem as ca.pem and generated certificate as crt.pem -// Select certificate, attach PolicyAllow to it -// 6. Type "make" to build and run the example - -static const char *s_url = - "mqtts://a1pjwh2bop1ojt-ats.iot.eu-west-1.amazonaws.com"; -static const char *s_rx_topic = "d/rx"; -static const char *s_tx_topic = "d/tx"; -static int s_qos = 1; - -#include "mongoose.h" - -static void fn(struct mg_connection *c, int ev, void *ev_data) { - if (ev == MG_EV_OPEN) { - // c->is_hexdumping = 1; - } else if (ev == MG_EV_CONNECT) { - if (c->is_tls) { - struct mg_tls_opts opts = {.ca = mg_unpacked("/ca.pem"), - .cert = mg_unpacked("/crt.pem"), - .key = mg_unpacked("/key.pem"), - .name = mg_url_host(s_url)}; - mg_tls_init(c, &opts); - } - } 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_MQTT_OPEN) { - // MQTT connect is successful - struct mg_str topic = mg_str(s_rx_topic); - MG_INFO(("Connected to %s", s_url)); - MG_INFO(("Subscribing to %s", s_rx_topic)); - struct mg_mqtt_opts sub_opts; - memset(&sub_opts, 0, sizeof(sub_opts)); - sub_opts.topic = topic; - sub_opts.qos = s_qos; - mg_mqtt_sub(c, &sub_opts); - c->data[0] = 'X'; // Set a label that we're logged in - } else if (ev == MG_EV_MQTT_MSG) { - // When we receive MQTT message, print it - struct mg_mqtt_message *mm = (struct mg_mqtt_message *) ev_data; - MG_INFO(("Received on %.*s : %.*s", (int) mm->topic.len, mm->topic.buf, - (int) mm->data.len, mm->data.buf)); - } else if (ev == MG_EV_POLL && c->data[0] == 'X') { - static unsigned long prev_second; - unsigned long now_second = (*(unsigned long *) ev_data) / 1000; - if (now_second != prev_second) { - struct mg_str topic = mg_str(s_tx_topic), data = mg_str("{\"a\":123}"); - MG_INFO(("Publishing to %s", s_tx_topic)); - struct mg_mqtt_opts pub_opts; - memset(&pub_opts, 0, sizeof(pub_opts)); - pub_opts.topic = topic; - pub_opts.message = data; - pub_opts.qos = s_qos, pub_opts.retain = false; - mg_mqtt_pub(c, &pub_opts); - prev_second = now_second; - } - } - - if (ev == MG_EV_ERROR || ev == MG_EV_CLOSE) { - MG_INFO(("Got event %d, stopping...", ev)); - *(bool *) c->fn_data = true; // Signal that we're done - } -} - -int main(void) { - struct mg_mgr mgr; - struct mg_mqtt_opts opts = {.clean = true}; - bool done = false; - mg_log_set(MG_LL_DEBUG); - mg_mgr_init(&mgr); // Initialise event manager - 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 - mg_mgr_free(&mgr); // Finished, cleanup - return 0; -}