Skip to content

Commit

Permalink
Problem: zmosq_server is supposed to connect to mqtt server only
Browse files Browse the repository at this point in the history
Solution: drop MOSQUITTO- prefix from protocol
  • Loading branch information
Michal Vyskocil committed Feb 8, 2017
1 parent 117b785 commit c02010a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
11 changes: 9 additions & 2 deletions include/zmosq_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ extern "C" {
//
// Connect to mosquitto broker
//
// zstr_sendx (zmosq_server, "MOSQUITTO-CONNECT", "host", "port", "keepalive", "bind_address", NULL);
// zstr_sendx (zmosq_server, "CONNECT", "host", "port", "keepalive", "bind_address", NULL);
//
// Subscribe on MQQT topic (can be repeated, or more topics can be specified here)
//
// zstr_sendx (zmosq_server, "MOSQUITTO-SUBSCRIBE", "topic", NULL);
// zstr_sendx (zmosq_server, "SUBSCRIBE", "topic", NULL);
//
// Start zmosq_server actor - all broker related commands must be called before!
//
Expand All @@ -48,6 +48,13 @@ extern "C" {
//
// zstr_sendx (zmosq_server, "STOP", NULL);
//
// MQQT messages are published on actor's pipe. They can be received as
// [topic|payload]
//
// zmsg_t *msg = zmsg_recv (zmosq_server);
//
// MQQT messages can be upblished as
// zsock_bsend (zmosq_server, "s11sp", "PUBLISH", qos, retain, "topic", "payload");
//
// This is the zmosq_server constructor as a zactor_fn;
ZMSQ_EXPORT void
Expand Down
4 changes: 2 additions & 2 deletions src/zmosq_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ zmosq_client_mqtt_connect (zmosq_client_t *self, const char *host, int port, int
assert (self);
assert (host);
assert (bind_address);
zstr_sendx (self->zmosq_server, "MOSQUITTO-CONNECT", host, port, keepalive, bind_address, NULL);
zstr_sendx (self->zmosq_server, "CONNECT", host, port, keepalive, bind_address, NULL);
// host
zstr_free (&self->mqtt_host);
self->mqtt_host = strdup (host);
Expand Down Expand Up @@ -203,7 +203,7 @@ zmosq_client_subscribe (zmosq_client_t *self, const char *topic)
assert (self);
assert (topic);
zlistx_add_end (self->topics, (void *) topic);
zstr_sendx (self->zmosq_server, "MOSQUITTO-SUBSCRIBE", topic, NULL);
zstr_sendx (self->zmosq_server, "SUBSCRIBE", topic, NULL);
}


Expand Down
8 changes: 4 additions & 4 deletions src/zmosq_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ zmosq_server_recv_api (zmosq_server_t *self)
if (streq (command, "VERBOSE"))
self->verbose = true;
else
if (streq (command, "MOSQUITTO-CONNECT")) {
if (streq (command, "CONNECT")) {
self->host = zmsg_popstr (request);
assert (self->host);

Expand All @@ -200,7 +200,7 @@ zmosq_server_recv_api (zmosq_server_t *self)
self->bind_address = strdup (self->host);
}
else
if (streq (command, "MOSQUITTO-SUBSCRIBE")) {
if (streq (command, "SUBSCRIBE")) {
char *topic = zmsg_popstr (request);
while (topic) {
zlist_append (self->topics, topic);
Expand Down Expand Up @@ -346,8 +346,8 @@ zmosq_server_test (bool verbose)
//int PORT = 1833;
//char *PORTA = "1833";
zactor_t *zmosq_server = zactor_new (zmosq_server_actor, NULL);
zstr_sendx (zmosq_server, "MOSQUITTO-CONNECT", "127.0.0.1", PORTA, "10", "127.0.0.1", NULL);
zstr_sendx (zmosq_server, "MOSQUITTO-SUBSCRIBE", "TEST", "TEST2", NULL);
zstr_sendx (zmosq_server, "CONNECT", "127.0.0.1", PORTA, "10", "127.0.0.1", NULL);
zstr_sendx (zmosq_server, "SUBSCRIBE", "TEST", "TEST2", NULL);
zstr_sendx (zmosq_server, "START", NULL);

mosquitto_t *client = mosquitto_new (
Expand Down

0 comments on commit c02010a

Please sign in to comment.