Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6fcfc9dfc0 | ||
|
|
a6596ffc89 | ||
|
|
533ab0c70d | ||
|
|
792a28e831 | ||
|
|
9407193454 | ||
|
|
602050f309 | ||
|
|
1a70c90af2 | ||
|
|
ed4091c53e | ||
|
|
f2a805f724 | ||
|
|
3083bcf071 | ||
|
|
d01f46dbc1 | ||
|
|
39b2257619 | ||
|
|
60d385189b | ||
|
|
3f2c1c57e1 | ||
|
|
e550197d0a | ||
|
|
253bc9b3f5 | ||
|
|
96d8018960 | ||
|
|
505cacc2df | ||
|
|
62848056a2 |
28
.github/workflows/aunit.yml
vendored
Normal file
28
.github/workflows/aunit.yml
vendored
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
# 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
|
||||||
1
.github/workflows/superlinter.yml
vendored
1
.github/workflows/superlinter.yml
vendored
@@ -1,6 +1,7 @@
|
|||||||
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:
|
||||||
|
|||||||
11
README.md
11
README.md
@@ -1,10 +1,10 @@
|
|||||||
# TinyMqtt
|
# TinyMqtt
|
||||||
|
|
||||||

|

|
||||||

|

|
||||||

|

|
||||||

|

|
||||||

|

|
||||||
|
|
||||||
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,6 +26,7 @@ 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~~
|
||||||
|
|||||||
@@ -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.0",
|
"version": "0.7.1",
|
||||||
"exclude": "",
|
"exclude": "",
|
||||||
"examples": "examples/*/*.ino",
|
"examples": "examples/*/*.ino",
|
||||||
"frameworks": "arduino",
|
"frameworks": "arduino",
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
name=TinyMqtt
|
name=TinyMqtt
|
||||||
version=0.7.0
|
version=0.7.1
|
||||||
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.
|
||||||
|
|||||||
@@ -41,7 +41,6 @@ MqttClient::~MqttClient()
|
|||||||
{
|
{
|
||||||
close();
|
close();
|
||||||
delete client;
|
delete client;
|
||||||
Serial << "Client deleted" << endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MqttClient::close(bool bSendDisconnect)
|
void MqttClient::close(bool bSendDisconnect)
|
||||||
@@ -269,24 +268,42 @@ MqttError MqttClient::subscribe(Topic topic, uint8_t qos)
|
|||||||
|
|
||||||
subscriptions.insert(topic);
|
subscriptions.insert(topic);
|
||||||
|
|
||||||
if (parent==nullptr) // remote broker ?
|
if (parent==nullptr) // remote broker
|
||||||
{
|
{
|
||||||
debug("remote subscribe");
|
return sendTopic(topic, MqttMessage::Type::Subscribe, qos);
|
||||||
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()
|
||||||
|
|||||||
@@ -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=" << (int32_t) parent
|
Serial << "MqttClient (" << clientId.c_str() << ") p=" << (uint64_t) parent
|
||||||
<< " c=" << (int32_t)client << (connected() ? " ON " : " OFF");
|
<< " c=" << (uint64_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,6 +178,7 @@ 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;
|
||||||
|
|||||||
20
tests/Makefile
Normal file
20
tests/Makefile
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
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
|
||||||
6
tests/local-tests/Makefile
Normal file
6
tests/local-tests/Makefile
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
# 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
|
||||||
@@ -96,8 +96,9 @@ test(local_unsubscribe)
|
|||||||
MqttClient publisher(&broker);
|
MqttClient publisher(&broker);
|
||||||
publisher.publish("a/b");
|
publisher.publish("a/b");
|
||||||
|
|
||||||
// subscriber.unsubscribe("a/b"); TODO not yet implemented
|
subscriber.unsubscribe("a/b");
|
||||||
|
|
||||||
|
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
|
||||||
@@ -120,7 +121,6 @@ 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() {
|
||||||
Reference in New Issue
Block a user