Compare commits

...

1 Commits
0.9.6 ... 0.9.7

Author SHA1 Message Date
HSaturn
18ce34c458 :xDefault client is no more empty 2022-12-17 18:36:32 +01:00
4 changed files with 12 additions and 10 deletions

View File

@@ -1,5 +1,5 @@
name=TinyMqtt
version=0.9.6
version=0.9.7
author=Francois BIOT, HSaturn, <hsaturn@gmail.com>
maintainer=Francois BIOT, HSaturn, <hsaturn@gmail.com>
sentence=A tiny broker and client library for MQTT messaging.

View File

@@ -35,6 +35,8 @@
#include <string>
#include "StringIndexer.h"
#define TINY_MQTT_DEFAULT_CLIENT_ID "Tiny"
#if TINY_MQTT_DEBUG
#include <TinyStreaming.h>
#include <TinyConsole.h> // https://github.com/hsaturn/TinyConsole
@@ -174,7 +176,7 @@ class MqttClient
public:
/** Constructor. Broker is the adress of a local broker if not null
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();
@@ -183,7 +185,7 @@ class MqttClient
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
// no negociation occured
// no negociation occurred
bool 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; }
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() */
void loop();

View File

@@ -301,8 +301,8 @@ test(network_publish_should_be_dispatched)
publisher.publish("a/c");
assertEqual(published.size(), (size_t)1); // 1 client has received something
assertEqual(published[""]["a/b"], 1);
assertEqual(published[""]["a/c"], 2);
assertEqual(published[TINY_MQTT_DEFAULT_CLIENT_ID]["a/b"], 1);
assertEqual(published[TINY_MQTT_DEFAULT_CLIENT_ID]["a/c"], 2);
}
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");
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)

View File

@@ -65,8 +65,8 @@ test(nowifi_publish_should_be_dispatched)
publisher.publish("a/c");
assertEqual(published.size(), (size_t)1); // 1 client has received something
assertEqual(published[""]["a/b"], 1);
assertEqual(published[""]["a/c"], 2);
assertEqual(published[TINY_MQTT_DEFAULT_CLIENT_ID]["a/b"], 1);
assertEqual(published[TINY_MQTT_DEFAULT_CLIENT_ID]["a/c"], 2);
}
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");
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)