Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
82c5b971e9 |
28
.github/workflows/aunit.yml
vendored
28
.github/workflows/aunit.yml
vendored
@@ -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
|
||||
1
.github/workflows/superlinter.yml
vendored
1
.github/workflows/superlinter.yml
vendored
@@ -1,7 +1,6 @@
|
||||
name: Super-Linter
|
||||
|
||||
# Run this workflow every time a new commit pushed to your repository
|
||||
#
|
||||
on: push
|
||||
|
||||
jobs:
|
||||
|
||||
11
README.md
11
README.md
@@ -1,10 +1,10 @@
|
||||
# TinyMqtt
|
||||
|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||
|
||||
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)
|
||||
* 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)
|
||||
* 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.
|
||||
* ~~MqttMessage uses a buffer 256 bytes which is usually far than needed.~~
|
||||
* ~~MqttClient does not support more than one subscription at time~~
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/hsaturn/TinyMqtt.git"
|
||||
},
|
||||
"version": "0.7.1",
|
||||
"version": "0.7.0",
|
||||
"exclude": "",
|
||||
"examples": "examples/*/*.ino",
|
||||
"frameworks": "arduino",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
name=TinyMqtt
|
||||
version=0.7.1
|
||||
version=0.7.0
|
||||
author=Francois BIOT, HSaturn, <hsaturn@gmail.com>
|
||||
maintainer=Francois BIOT, HSaturn, <hsaturn@gmail.com>
|
||||
sentence=A tiny broker and client library for MQTT messaging.
|
||||
|
||||
@@ -41,6 +41,7 @@ MqttClient::~MqttClient()
|
||||
{
|
||||
close();
|
||||
delete client;
|
||||
Serial << "Client deleted" << endl;
|
||||
}
|
||||
|
||||
void MqttClient::close(bool bSendDisconnect)
|
||||
@@ -268,42 +269,24 @@ MqttError MqttClient::subscribe(Topic topic, uint8_t qos)
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
void MqttClient::processMessage()
|
||||
|
||||
@@ -149,7 +149,7 @@ class MqttClient
|
||||
MqttError publish(const Topic& t) { return publish(t, nullptr, 0);};
|
||||
|
||||
MqttError subscribe(Topic topic, uint8_t qos=0);
|
||||
MqttError unsubscribe(Topic topic);
|
||||
MqttError unsubscribe(Topic& topic);
|
||||
|
||||
// connected to local broker
|
||||
// TODO seems to be useless
|
||||
@@ -158,8 +158,8 @@ class MqttClient
|
||||
void dump()
|
||||
{
|
||||
uint32_t ms=millis();
|
||||
Serial << "MqttClient (" << clientId.c_str() << ") p=" << (uint64_t) parent
|
||||
<< " c=" << (uint64_t)client << (connected() ? " ON " : " OFF");
|
||||
Serial << "MqttClient (" << clientId.c_str() << ") p=" << (int32_t) parent
|
||||
<< " c=" << (int32_t)client << (connected() ? " ON " : " OFF");
|
||||
Serial << ", alive=" << (uint32_t)alive << '/' << ms << ", ka=" << keep_alive;
|
||||
Serial << (client && client->connected() ? "" : "dis") << "connected";
|
||||
message.hexdump("entrant msg");
|
||||
@@ -178,7 +178,6 @@ class MqttClient
|
||||
static long counter; // Number of messages sent
|
||||
|
||||
private:
|
||||
MqttError sendTopic(const Topic& topic, MqttMessage::Type type, uint8_t qos);
|
||||
void resubscribe();
|
||||
|
||||
friend class MqttBroker;
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -96,9 +96,8 @@ test(local_unsubscribe)
|
||||
MqttClient publisher(&broker);
|
||||
publisher.publish("a/b");
|
||||
|
||||
subscriber.unsubscribe("a/b");
|
||||
// subscriber.unsubscribe("a/b"); TODO not yet implemented
|
||||
|
||||
publisher.publish("a/b");
|
||||
publisher.publish("a/b");
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// setup() and loop()
|
||||
void setup() {
|
||||
Reference in New Issue
Block a user