Compare commits

..

1 Commits

Author SHA1 Message Date
hsaturn
82c5b971e9 Release 0.7.0 2021-03-28 23:34:54 +02:00
10 changed files with 26 additions and 100 deletions

View File

@@ -1,28 +0,0 @@
# See https://docs.github.com/en/actions/guides for documentation about GitHub
# Actions.
name: AUnit Tests
# Run on all branches.
on: [push]
jobs:
build:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
- name: Setup
run: |
cd ..
git clone https://github.com/bxparks/EpoxyDuino
git clone https://github.com/bxparks/AceRoutine
git clone https://github.com/bxparks/AUnit
git clone https://github.com/bxparks/AceCommon
git clone https://github.com/hsaturn/EspMock
- name: Verify tests
run: |
make -C tests
make -C tests runtests

View File

@@ -1,7 +1,6 @@
name: Super-Linter name: Super-Linter
# Run this workflow every time a new commit pushed to your repository # Run this workflow every time a new commit pushed to your repository
#
on: push on: push
jobs: jobs:

View File

@@ -1,10 +1,10 @@
# TinyMqtt # TinyMqtt
![Release](https://img.shields.io/github/v/release/hsaturn/TinyMqtt) ![](https://img.shields.io/github/v/release/hsaturn/TinyMqtt)
![Issues](https://img.shields.io/github/issues/hsaturn/TinyMqtt) ![](https://img.shields.io/github/issues/hsaturn/TinyMqtt)
![Esp8266](https://img.shields.io/badge/platform-ESP8266-green) ![](https://img.shields.io/badge/platform-ESP8266-green)
![Gpl 3.0](https://img.shields.io/github/license/hsaturn/TinyMqtt) ![](https://img.shields.io/github/license/hsaturn/TinyMqtt)
![Mqtt 3.1.1](https://img.shields.io/badge/Mqtt-%203.1.1-yellow) ![](https://img.shields.io/badge/Mqtt-%203.1.1-yellow)
ESP 8266 is a small, fast and capable Mqtt Broker and Client ESP 8266 is a small, fast and capable Mqtt Broker and Client
@@ -26,7 +26,6 @@ ESP 8266 is a small, fast and capable Mqtt Broker and Client
* Implement zeroconf mode (needs async) * Implement zeroconf mode (needs async)
* Add a max_clients in MqttBroker. Used with zeroconf, there will be * Add a max_clients in MqttBroker. Used with zeroconf, there will be
no need for having tons of clients (also RAM is the problem with many clients) no need for having tons of clients (also RAM is the problem with many clients)
* Why not a 'global' TinyMqtt::loop() instead of having to call loop for all broker/clients instances
* Test what is the real max number of clients for broker. As far as I saw, 1k is needed per client which would make more than 30 clients critical. * Test what is the real max number of clients for broker. As far as I saw, 1k is needed per client which would make more than 30 clients critical.
* ~~MqttMessage uses a buffer 256 bytes which is usually far than needed.~~ * ~~MqttMessage uses a buffer 256 bytes which is usually far than needed.~~
* ~~MqttClient does not support more than one subscription at time~~ * ~~MqttClient does not support more than one subscription at time~~

View File

@@ -6,7 +6,7 @@
"type": "git", "type": "git",
"url": "https://github.com/hsaturn/TinyMqtt.git" "url": "https://github.com/hsaturn/TinyMqtt.git"
}, },
"version": "0.7.1", "version": "0.7.0",
"exclude": "", "exclude": "",
"examples": "examples/*/*.ino", "examples": "examples/*/*.ino",
"frameworks": "arduino", "frameworks": "arduino",

View File

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

View File

@@ -41,6 +41,7 @@ MqttClient::~MqttClient()
{ {
close(); close();
delete client; delete client;
Serial << "Client deleted" << endl;
} }
void MqttClient::close(bool bSendDisconnect) void MqttClient::close(bool bSendDisconnect)
@@ -268,42 +269,24 @@ MqttError MqttClient::subscribe(Topic topic, uint8_t qos)
subscriptions.insert(topic); subscriptions.insert(topic);
if (parent==nullptr) // remote broker if (parent==nullptr) // remote broker ?
{ {
return sendTopic(topic, MqttMessage::Type::Subscribe, qos); debug("remote subscribe");
MqttMessage msg(MqttMessage::Type::Subscribe, 2);
// TODO manage packet identifier
msg.add(0);
msg.add(0);
msg.add(topic);
msg.add(qos);
ret = msg.sendTo(this);
// TODO we should wait (state machine) for SUBACK
} }
return ret; return ret;
} }
MqttError MqttClient::unsubscribe(Topic topic)
{
auto it=subscriptions.find(topic);
if (it != subscriptions.end())
{
subscriptions.erase(it);
if (parent==nullptr) // remote broker
{
return sendTopic(topic, MqttMessage::Type::UnSubscribe, 0);
}
}
return MqttOk;
}
MqttError MqttClient::sendTopic(const Topic& topic, MqttMessage::Type type, uint8_t qos)
{
MqttMessage msg(type, 2);
// TODO manage packet identifier
msg.add(0);
msg.add(0);
msg.add(topic);
msg.add(qos);
// TODO instead we should wait (state machine) for SUBACK / UNSUBACK ?
return msg.sendTo(this);
}
long MqttClient::counter=0; long MqttClient::counter=0;
void MqttClient::processMessage() void MqttClient::processMessage()

View File

@@ -149,7 +149,7 @@ class MqttClient
MqttError publish(const Topic& t) { return publish(t, nullptr, 0);}; MqttError publish(const Topic& t) { return publish(t, nullptr, 0);};
MqttError subscribe(Topic topic, uint8_t qos=0); MqttError subscribe(Topic topic, uint8_t qos=0);
MqttError unsubscribe(Topic topic); MqttError unsubscribe(Topic& topic);
// connected to local broker // connected to local broker
// TODO seems to be useless // TODO seems to be useless
@@ -158,8 +158,8 @@ class MqttClient
void dump() void dump()
{ {
uint32_t ms=millis(); uint32_t ms=millis();
Serial << "MqttClient (" << clientId.c_str() << ") p=" << (uint64_t) parent Serial << "MqttClient (" << clientId.c_str() << ") p=" << (int32_t) parent
<< " c=" << (uint64_t)client << (connected() ? " ON " : " OFF"); << " c=" << (int32_t)client << (connected() ? " ON " : " OFF");
Serial << ", alive=" << (uint32_t)alive << '/' << ms << ", ka=" << keep_alive; Serial << ", alive=" << (uint32_t)alive << '/' << ms << ", ka=" << keep_alive;
Serial << (client && client->connected() ? "" : "dis") << "connected"; Serial << (client && client->connected() ? "" : "dis") << "connected";
message.hexdump("entrant msg"); message.hexdump("entrant msg");
@@ -178,7 +178,6 @@ class MqttClient
static long counter; // Number of messages sent static long counter; // Number of messages sent
private: private:
MqttError sendTopic(const Topic& topic, MqttMessage::Type type, uint8_t qos);
void resubscribe(); void resubscribe();
friend class MqttBroker; friend class MqttBroker;

View File

@@ -1,20 +0,0 @@
tests:
set -e; \
for i in *-tests/Makefile; do \
echo '==== Making:' $$(dirname $$i); \
$(MAKE) -C $$(dirname $$i) -j; \
done
runtests:
set -e; \
for i in *-tests/Makefile; do \
echo '==== Running:' $$(dirname $$i); \
$$(dirname $$i)/$$(dirname $$i).out; \
done
clean:
set -e; \
for i in *-tests/Makefile; do \
echo '==== Cleaning:' $$(dirname $$i); \
$(MAKE) -C $$(dirname $$i) clean; \
done

View File

@@ -1,6 +0,0 @@
# See https://github.com/bxparks/EpoxyDuino for documentation about this
# Makefile to compile and run Arduino programs natively on Linux or MacOS.
APP_NAME := local-tests
ARDUINO_LIBS := AUnit AceCommon AceTime TinyMqtt EspMock
include ../../../EpoxyDuino/EpoxyDuino.mk

View File

@@ -96,9 +96,8 @@ test(local_unsubscribe)
MqttClient publisher(&broker); MqttClient publisher(&broker);
publisher.publish("a/b"); publisher.publish("a/b");
subscriber.unsubscribe("a/b"); // subscriber.unsubscribe("a/b"); TODO not yet implemented
publisher.publish("a/b");
publisher.publish("a/b"); publisher.publish("a/b");
assertTrue(published[""]["a/b"] == 1); // Only one publish has been received assertTrue(published[""]["a/b"] == 1); // Only one publish has been received
@@ -121,6 +120,7 @@ test(local_nocallback_when_destroyed)
assertEqual(published.size(), (size_t)0); // Only one publish has been received assertEqual(published.size(), (size_t)0); // Only one publish has been received
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// setup() and loop() // setup() and loop()
void setup() { void setup() {