diff --git a/ChangeLog.txt b/ChangeLog.txt index ad6bd333..e3d053b8 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -60,6 +60,7 @@ Client library: Client: - Add -F to mosquitto_sub to allow the user to choose the output format. - Add -U to mosquitto_sub for unsubscribing from topics. +- Add -c (clean session) to mosquitto_pub. - Add --retained-only to mosquitto_sub to exit after receiving all retained messages. - Connections now default to using MQTT v3.1.1. diff --git a/client/client_shared.c b/client/client_shared.c index 4354e52f..28e8e5df 100644 --- a/client/client_shared.c +++ b/client/client_shared.c @@ -317,11 +317,12 @@ int client_config_load(struct mosq_config *cfg, int pub_or_sub, int argc, char * } #endif + if(cfg->clean_session == false && (cfg->id_prefix || !cfg->id)){ + if(!cfg->quiet) fprintf(stderr, "Error: You must provide a client id if you are using the -c option.\n"); + return 1; + } + if(pub_or_sub == CLIENT_SUB){ - if(cfg->clean_session == false && (cfg->id_prefix || !cfg->id)){ - if(!cfg->quiet) fprintf(stderr, "Error: You must provide a client id if you are using the -c option.\n"); - return 1; - } if(cfg->topic_count == 0){ if(!cfg->quiet) fprintf(stderr, "Error: You must specify a topic to subscribe to.\n"); return 1; @@ -834,9 +835,6 @@ int client_config_line_proc(struct mosq_config *cfg, int pub_or_sub, int argc, c } i++; }else if(!strcmp(argv[i], "-c") || !strcmp(argv[i], "--disable-clean-session")){ - if(pub_or_sub == CLIENT_PUB){ - goto unknown_option; - } cfg->clean_session = false; }else if(!strcmp(argv[i], "-N")){ if(pub_or_sub == CLIENT_PUB){ diff --git a/client/client_shared.h b/client/client_shared.h index 72de536f..88fdba13 100644 --- a/client/client_shared.h +++ b/client/client_shared.h @@ -71,7 +71,7 @@ struct mosq_config { char *psk_identity; # endif #endif - bool clean_session; /* sub */ + bool clean_session; char **topics; /* sub */ int topic_count; /* sub */ bool no_retain; /* sub */ diff --git a/client/pub_client.c b/client/pub_client.c index c55e6de7..481e4333 100644 --- a/client/pub_client.c +++ b/client/pub_client.c @@ -207,7 +207,7 @@ void print_usage(void) printf("mosquitto_pub version %s running on libmosquitto %d.%d.%d.\n\n", VERSION, major, minor, revision); printf("Usage: mosquitto_pub {[-h host] [-p port] [-u username [-P password]] -t topic | -L URL}\n"); printf(" {-f file | -l | -n | -m message}\n"); - printf(" [-k keepalive] [-q qos] [-r]\n"); + printf(" [-c] [-k keepalive] [-q qos] [-r]\n"); #ifdef WITH_SRV printf(" [-A bind_address] [-S]\n"); #else diff --git a/man/mosquitto_pub.1.xml b/man/mosquitto_pub.1.xml index dca18ebc..b42771d1 100644 --- a/man/mosquitto_pub.1.xml +++ b/man/mosquitto_pub.1.xml @@ -30,6 +30,7 @@ URL bind_address + client_id client id prefix @@ -113,6 +114,19 @@ interface. + + + + + Disable the 'clean session' flag. This means that all + of the subscriptions for the client will be maintained + after it disconnects, along with subsequent QoS 1 and QoS 2 + messages that arrive. When the client reconnects, it will + receive all of the queued messages. + If using this option, the client id must be set + manually with + + diff --git a/man/mosquitto_sub.1.xml b/man/mosquitto_sub.1.xml index 68cc410a..c144c147 100644 --- a/man/mosquitto_sub.1.xml +++ b/man/mosquitto_sub.1.xml @@ -23,7 +23,7 @@ port number username - password + earg> password message-topic @@ -131,8 +131,8 @@ after it disconnects, along with subsequent QoS 1 and QoS 2 messages that arrive. When the client reconnects, it will receive all of the queued messages. - If using this option, it is recommended that the - client id is set manually with + If using this option, the client id must be set + manually with