Compare commits

...

8 Commits
0.9.4 ... 0.9.5

Author SHA1 Message Date
hsaturn
d12096ef51 Ooops bad tag 2022-11-23 13:01:24 +01:00
hsaturn
ea56d21190 Merge branch 'main' of github.com:hsaturn/TinyMqtt into main 2022-11-23 12:56:35 +01:00
hsaturn
c802c895b6 Version 0.9.6 bump 2022-11-23 12:54:15 +01:00
hsaturn
074bca971f Update README.md 2022-11-23 12:51:12 +01:00
hsaturn
7bd9c27b89 Merge branch 'main' of github.com:hsaturn/TinyMqtt into main 2022-11-21 04:42:30 +01:00
hsaturn
3e73673302 [tinymqtt-test] Fix lot of errors
- TINY_MQTT_DEBUG was not set (no dump)
  - MqttClient::counter has disapeared (compilation error)
  - payload was badly displayed
  - broker/client names could be reused for client/brokers
2022-11-21 04:42:16 +01:00
hsaturn
4b12aaa198 Update README.md
Unit tests in features
2022-11-21 01:47:47 +01:00
hsaturn
5f9cab8992 Update README.md
Wildcards
2022-11-21 01:44:54 +01:00
3 changed files with 50 additions and 24 deletions

View File

@@ -17,12 +17,15 @@ TinyMqtt is a small, fast and capable Mqtt Broker and Client for Esp8266 / Esp32
The max I've seen was 2k msg/s (1 client 1 subscription) The max I've seen was 2k msg/s (1 client 1 subscription)
- Act as as a mqtt broker and/or a mqtt client - Act as as a mqtt broker and/or a mqtt client
- Mqtt 3.1.1 / Qos 0 supported - Mqtt 3.1.1 / Qos 0 supported
- Wildcards supported (+ # $ and * (even if not part of the spec...))
- Standalone (can work without WiFi) (degraded/local mode) - Standalone (can work without WiFi) (degraded/local mode)
- Brokers can connect to another broker and becomes then a - Brokers can connect to another broker and becomes then a
proxy for clients that are connected to it. proxy for clients that are connected to it.
- zeroconf, this is a strange but very powerful mode where - zeroconf, this is a strange but very powerful mode where
all brokers tries to connect together on the same local network. all brokers tries to connect together on the same local network.
- small memory footprint (very efficient topic storage) - small memory footprint (very efficient topic storage)
- long messages are supported (>127 bytes)
- TinyMQTT is largely unit tested, so once a bug is fixed, it is fixed forever
## Limitations ## Limitations
@@ -66,7 +69,7 @@ no need for having tons of clients (also RAM is the problem with many clients)
* ~~MqttClient auto re-subscribe (::resubscribe works bad on broker.emqx.io)~~ * ~~MqttClient auto re-subscribe (::resubscribe works bad on broker.emqx.io)~~
* MqttClient auto reconnection * MqttClient auto reconnection
* MqttClient user/password * MqttClient user/password
* Wildcards (I may implement only # as I'm not interrested by a clever and cpu consuming matching) * ~~Wildcards (I may implement only # as I'm not interrested by a clever and cpu consuming matching)~~
* I suspect that MqttClient::parent could be removed and replaced with a simple boolean * I suspect that MqttClient::parent could be removed and replaced with a simple boolean
(this'll need to rewrite a few functions) (this'll need to rewrite a few functions)

View File

@@ -1,3 +1,5 @@
// vim: ts=2 sw=2
#define TINY_MQTT_DEBUG
#include <TinyMqtt.h> // https://github.com/hsaturn/TinyMqtt #include <TinyMqtt.h> // https://github.com/hsaturn/TinyMqtt
#include <MqttStreaming.h> #include <MqttStreaming.h>
#if defined(ESP8266) #if defined(ESP8266)
@@ -33,14 +35,19 @@ std::string topic="sensor/temperature";
void onPublish(const MqttClient* srce, const Topic& topic, const char* payload, size_t length) void onPublish(const MqttClient* srce, const Topic& topic, const char* payload, size_t length)
{ {
Serial << "--> " << srce->id().c_str() << ": ======> received " << topic.c_str(); Serial << "--> " << srce->id().c_str() << ": ======> received " << topic.c_str();
if (payload) Serial << ", payload[" << length << "]=["; if (payload)
while(length--)
{ {
const char c=*payload++; Serial << ", payload[" << length << "]=[";
if (c!=10 and c!=13 and c <32) Serial << '?'; while(length--)
Serial << *payload++; {
const char c=*payload++;
if (c<32)
Serial << '?';
else
Serial << c;
}
Serial << ']' << endl;
} }
Serial<< endl;
} }
std::map<std::string, MqttClient*> clients; std::map<std::string, MqttClient*> clients;
@@ -673,7 +680,12 @@ void eval(std::string& cmd)
else if (compare(s, "broker")) else if (compare(s, "broker"))
{ {
std::string id=getword(cmd); std::string id=getword(cmd);
if (id.length() or brokers.find(id)!=brokers.end()) if (clients.find(id) != clients.end())
{
Serial << "A client already have that name" << endl;
cmd.clear();
}
else if (id.length() or brokers.find(id)!=brokers.end())
{ {
int port=getint(cmd, 0); int port=getint(cmd, 0);
if (port) if (port)
@@ -685,16 +697,26 @@ void eval(std::string& cmd)
Serial << "new broker (" << id.c_str() << ")" << endl; Serial << "new broker (" << id.c_str() << ")" << endl;
} }
else else
{
Serial << "Missing port" << endl; Serial << "Missing port" << endl;
cmd.clear();
}
} }
else else
{
Serial << "Missing or existing broker name (" << id.c_str() << ")" << endl; Serial << "Missing or existing broker name (" << id.c_str() << ")" << endl;
cmd+=" ls"; cmd.clear();
}
} }
else if (compare(s, "client")) else if (compare(s, "client"))
{ {
std::string id=getword(cmd); std::string id=getword(cmd);
if (id.length() or clients.find(id)!=clients.end()) if (brokers.find(id) != brokers.end())
{
Serial << "A broker have that name" << endl;
cmd.clear();
}
else if (id.length() or clients.find(id)!=clients.end())
{ {
s=getword(cmd); // broker name s=getword(cmd); // broker name
if (s=="" or brokers.find(s) != brokers.end()) if (s=="" or brokers.find(s) != brokers.end())
@@ -711,11 +733,14 @@ void eval(std::string& cmd)
else if (s.length()) else if (s.length())
{ {
Serial << " not found." << endl; Serial << " not found." << endl;
cmd.clear();
} }
} }
else else
{
Serial << "Missing or existing client name" << endl; Serial << "Missing or existing client name" << endl;
cmd+=" ls"; cmd.clear();
}
} }
else if (compare(s, "set")) else if (compare(s, "set"))
{ {
@@ -766,7 +791,9 @@ void eval(std::string& cmd)
{ {
Serial << "syntax:" << endl; Serial << "syntax:" << endl;
Serial << " MqttBroker:" << endl; Serial << " MqttBroker:" << endl;
Serial << " broker {name} {port} : create a new broker" << endl; Serial << " broker {broker_name} {port} : create a new broker" << endl;
Serial << " broker_name.delete : delete a broker (buggy)" << endl;
Serial << " broker_name.view : dump a broker" << endl;
Serial << endl; Serial << endl;
Serial << " MqttClient:" << endl; Serial << " MqttClient:" << endl;
Serial << " client {name} {parent broker} : create a client then" << endl; Serial << " client {name} {parent broker} : create a client then" << endl;
@@ -775,17 +802,18 @@ void eval(std::string& cmd)
Serial << " name.publish [topic][payload]" << endl; Serial << " name.publish [topic][payload]" << endl;
Serial << " name.view" << endl; Serial << " name.view" << endl;
Serial << " name.delete" << endl; Serial << " name.delete" << endl;
Serial << endl;
automatic::help(); automatic::help();
Serial << endl; Serial << endl;
Serial << " help" << endl; Serial << " help" << endl;
Serial << " blink [Dx on_ms off_ms]" << endl; Serial << " blink [Dx on_ms off_ms] : make pin blink" << endl;
Serial << " ls / ip / reset" << endl; Serial << " ls / ip / reset" << endl;
Serial << " set [name][value]" << endl; Serial << " set [name][value]" << endl;
Serial << " ! repeat last command" << endl; Serial << " ! repeat last command" << endl;
Serial << endl; Serial << endl;
Serial << " echo [on|off] or strings" << endl; Serial << " echo [on|off] or strings" << endl;
Serial << " every ms [command]; every list; every remove [nr|all], every (on|off) [#]" << endl; Serial << " every ms [command]; every list; every remove [nr|all]; every (on|off) [#]" << endl;
Serial << " on {output}; off {output}" << endl; Serial << " on {output}; off {output}" << endl;
Serial << " $id : name of the client." << endl; Serial << " $id : name of the client." << endl;
Serial << " rnd[(min[,max])] random number." << endl; Serial << " rnd[(min[,max])] random number." << endl;
@@ -855,11 +883,6 @@ void loop()
MDNS.update(); MDNS.update();
#endif #endif
if (MqttClient::counter != count)
{
Serial << "# " << MqttClient::counter << endl;
count = MqttClient::counter;
}
for(auto it: brokers) for(auto it: brokers)
it.second->loop(); it.second->loop();

View File

@@ -1,5 +1,5 @@
name=TinyMqtt name=TinyMqtt
version=0.9.3 version=0.9.5
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.