:xDefault client is no more empty
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
name=TinyMqtt
|
name=TinyMqtt
|
||||||
version=0.9.6
|
version=0.9.7
|
||||||
author=Francois BIOT, HSaturn, <hsaturn@gmail.com>
|
author=Francois BIOT, HSaturn, <hsaturn@gmail.com>
|
||||||
maintainer=Francois BIOT, HSaturn, <hsaturn@gmail.com>
|
maintainer=Francois BIOT, HSaturn, <hsaturn@gmail.com>
|
||||||
sentence=A tiny broker and client library for MQTT messaging.
|
sentence=A tiny broker and client library for MQTT messaging.
|
||||||
|
|||||||
@@ -35,6 +35,8 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include "StringIndexer.h"
|
#include "StringIndexer.h"
|
||||||
|
|
||||||
|
#define TINY_MQTT_DEFAULT_CLIENT_ID "Tiny"
|
||||||
|
|
||||||
#if TINY_MQTT_DEBUG
|
#if TINY_MQTT_DEBUG
|
||||||
#include <TinyStreaming.h>
|
#include <TinyStreaming.h>
|
||||||
#include <TinyConsole.h> // https://github.com/hsaturn/TinyConsole
|
#include <TinyConsole.h> // https://github.com/hsaturn/TinyConsole
|
||||||
@@ -174,7 +176,7 @@ class MqttClient
|
|||||||
public:
|
public:
|
||||||
/** Constructor. Broker is the adress of a local broker if not null
|
/** Constructor. Broker is the adress of a local broker if not null
|
||||||
If you want to connect elsewhere, leave broker null and use connect() **/
|
If you want to connect elsewhere, leave broker null and use connect() **/
|
||||||
MqttClient(MqttBroker* broker = nullptr, const std::string& id="");
|
MqttClient(MqttBroker* broker = nullptr, const std::string& id = TINY_MQTT_DEFAULT_CLIENT_ID);
|
||||||
MqttClient(const std::string& id) : MqttClient(nullptr, id){}
|
MqttClient(const std::string& id) : MqttClient(nullptr, id){}
|
||||||
|
|
||||||
~MqttClient();
|
~MqttClient();
|
||||||
@@ -183,7 +185,7 @@ class MqttClient
|
|||||||
void connect(std::string broker, uint16_t port, uint16_t keep_alive = 10);
|
void connect(std::string broker, uint16_t port, uint16_t keep_alive = 10);
|
||||||
|
|
||||||
// TODO it seems that connected returns true in tcp mode even if
|
// TODO it seems that connected returns true in tcp mode even if
|
||||||
// no negociation occured
|
// no negociation occurred
|
||||||
bool connected()
|
bool connected()
|
||||||
{
|
{
|
||||||
return (local_broker!=nullptr and client==nullptr) or (client and client->connected());
|
return (local_broker!=nullptr and client==nullptr) or (client and client->connected());
|
||||||
@@ -195,7 +197,7 @@ class MqttClient
|
|||||||
}
|
}
|
||||||
|
|
||||||
const std::string& id() const { return clientId; }
|
const std::string& id() const { return clientId; }
|
||||||
void id(std::string& new_id) { clientId = new_id; }
|
void id(const std::string& new_id) { clientId = new_id; }
|
||||||
|
|
||||||
/** Should be called in main loop() */
|
/** Should be called in main loop() */
|
||||||
void loop();
|
void loop();
|
||||||
|
|||||||
@@ -301,8 +301,8 @@ test(network_publish_should_be_dispatched)
|
|||||||
publisher.publish("a/c");
|
publisher.publish("a/c");
|
||||||
|
|
||||||
assertEqual(published.size(), (size_t)1); // 1 client has received something
|
assertEqual(published.size(), (size_t)1); // 1 client has received something
|
||||||
assertEqual(published[""]["a/b"], 1);
|
assertEqual(published[TINY_MQTT_DEFAULT_CLIENT_ID]["a/b"], 1);
|
||||||
assertEqual(published[""]["a/c"], 2);
|
assertEqual(published[TINY_MQTT_DEFAULT_CLIENT_ID]["a/c"], 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
test(network_publish_should_be_dispatched_to_clients)
|
test(network_publish_should_be_dispatched_to_clients)
|
||||||
@@ -347,7 +347,7 @@ test(network_unsubscribe)
|
|||||||
publisher.publish("a/b"); // Those one, no (unsubscribed)
|
publisher.publish("a/b"); // Those one, no (unsubscribed)
|
||||||
publisher.publish("a/b");
|
publisher.publish("a/b");
|
||||||
|
|
||||||
assertEqual(published[""]["a/b"], 1); // Only one publish has been received
|
assertEqual(published[TINY_MQTT_DEFAULT_CLIENT_ID]["a/b"], 1); // Only one publish has been received
|
||||||
}
|
}
|
||||||
|
|
||||||
test(network_nocallback_when_destroyed)
|
test(network_nocallback_when_destroyed)
|
||||||
|
|||||||
@@ -65,8 +65,8 @@ test(nowifi_publish_should_be_dispatched)
|
|||||||
publisher.publish("a/c");
|
publisher.publish("a/c");
|
||||||
|
|
||||||
assertEqual(published.size(), (size_t)1); // 1 client has received something
|
assertEqual(published.size(), (size_t)1); // 1 client has received something
|
||||||
assertEqual(published[""]["a/b"], 1);
|
assertEqual(published[TINY_MQTT_DEFAULT_CLIENT_ID]["a/b"], 1);
|
||||||
assertEqual(published[""]["a/c"], 2);
|
assertEqual(published[TINY_MQTT_DEFAULT_CLIENT_ID]["a/c"], 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
test(nowifi_publish_should_be_dispatched_to_clients)
|
test(nowifi_publish_should_be_dispatched_to_clients)
|
||||||
@@ -209,7 +209,7 @@ test(nowifi_unsubscribe)
|
|||||||
publisher.publish("a/b"); // Those one, no (unsubscribed)
|
publisher.publish("a/b"); // Those one, no (unsubscribed)
|
||||||
publisher.publish("a/b");
|
publisher.publish("a/b");
|
||||||
|
|
||||||
assertEqual(published[""]["a/b"], 1); // Only one publish has been received
|
assertEqual(published[TINY_MQTT_DEFAULT_CLIENT_ID]["a/b"], 1); // Only one publish has been received
|
||||||
}
|
}
|
||||||
|
|
||||||
test(nowifi_nocallback_when_destroyed)
|
test(nowifi_nocallback_when_destroyed)
|
||||||
|
|||||||
Reference in New Issue
Block a user