Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
883f1e27e6 | ||
|
|
e7fc147424 | ||
|
|
2147b147fc | ||
|
|
f5e9a43461 | ||
|
|
cabb56fc8c | ||
|
|
58786eb6d9 |
@@ -22,6 +22,12 @@ TinyMqtt is a small, fast and capable Mqtt Broker and Client for Esp8266 / Esp32
|
|||||||
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)
|
||||||
|
|
||||||
|
## Limitations
|
||||||
|
|
||||||
|
- Max of 255 different topics can be stored (change index_t type to allow more)
|
||||||
|
- No Qos because messages are not queued but immediately sent to clients
|
||||||
|
|
||||||
## Quickstart
|
## Quickstart
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
name=TinyMqtt
|
name=TinyMqtt
|
||||||
version=0.9.1
|
version=0.9.3
|
||||||
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.
|
||||||
@@ -8,4 +8,3 @@ category=Communication
|
|||||||
url=https://github.com/hsaturn/TinyMqtt
|
url=https://github.com/hsaturn/TinyMqtt
|
||||||
architectures=*
|
architectures=*
|
||||||
includes=TinyMqtt.h
|
includes=TinyMqtt.h
|
||||||
depends=AsyncTCP
|
|
||||||
|
|||||||
@@ -26,30 +26,7 @@ class StringIndexer
|
|||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
public:
|
public:
|
||||||
using index_t=uint8_t;
|
using index_t = uint8_t;
|
||||||
|
|
||||||
static index_t strToIndex(const char* str, uint8_t len)
|
|
||||||
{
|
|
||||||
for(auto it=strings.begin(); it!=strings.end(); it++)
|
|
||||||
{
|
|
||||||
if (strncmp(it->second.str.c_str(), str, len)==0)
|
|
||||||
{
|
|
||||||
it->second.used++;
|
|
||||||
return it->first;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for(index_t index=1; index; index++)
|
|
||||||
{
|
|
||||||
if (strings.find(index)==strings.end())
|
|
||||||
{
|
|
||||||
strings[index].str = std::string(str, len);
|
|
||||||
strings[index].used++;
|
|
||||||
// Serial << "Creating index " << index << " for (" << strings[index].str.c_str() << ") len=" << len << endl;
|
|
||||||
return index;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0; // TODO out of indexes
|
|
||||||
}
|
|
||||||
|
|
||||||
static const std::string& str(const index_t& index)
|
static const std::string& str(const index_t& index)
|
||||||
{
|
{
|
||||||
@@ -82,6 +59,32 @@ class StringIndexer
|
|||||||
static uint16_t count() { return strings.size(); }
|
static uint16_t count() { return strings.size(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
friend class IndexedString;
|
||||||
|
|
||||||
|
// increment use of str or create a new index
|
||||||
|
static index_t strToIndex(const char* str, uint8_t len)
|
||||||
|
{
|
||||||
|
for(auto it=strings.begin(); it!=strings.end(); it++)
|
||||||
|
{
|
||||||
|
if (it->second.str.length() == len && strcmp(it->second.str.c_str(), str)==0)
|
||||||
|
{
|
||||||
|
it->second.used++;
|
||||||
|
return it->first;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(index_t index=1; index; index++)
|
||||||
|
{
|
||||||
|
if (strings.find(index)==strings.end())
|
||||||
|
{
|
||||||
|
strings[index].str = std::string(str, len);
|
||||||
|
strings[index].used++;
|
||||||
|
// Serial << "Creating index " << index << " for (" << strings[index].str.c_str() << ") len=" << len << endl;
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0; // TODO out of indexes
|
||||||
|
}
|
||||||
|
|
||||||
static std::map<index_t, StringCounter> strings;
|
static std::map<index_t, StringCounter> strings;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
# See https://github.com/bxparks/EpoxyDuino for documentation about this
|
# See https://github.com/bxparks/EpoxyDuino for documentation about this
|
||||||
# Makefile to compile and run Arduino programs natively on Linux or MacOS.
|
# Makefile to compile and run Arduino programs natively on Linux or MacOS.
|
||||||
|
|
||||||
|
EXTRA_CXXFLAGS=-g3 -O0
|
||||||
|
|
||||||
APP_NAME := length-tests
|
APP_NAME := length-tests
|
||||||
ARDUINO_LIBS := AUnit AceCommon AceTime TinyMqtt EspMock ESP8266WiFi ESPAsyncTCP
|
ARDUINO_LIBS := AUnit AceCommon AceTime TinyMqtt EspMock ESP8266WiFi ESPAsyncTCP
|
||||||
ARDUINO_LIB_DIRS := ../../../EspMock/libraries
|
ARDUINO_LIB_DIRS := ../../../EspMock/libraries
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
# See https://github.com/bxparks/EpoxyDuino for documentation about this
|
# See https://github.com/bxparks/EpoxyDuino for documentation about this
|
||||||
# Makefile to compile and run Arduino programs natively on Linux or MacOS.
|
# Makefile to compile and run Arduino programs natively on Linux or MacOS.
|
||||||
|
|
||||||
|
EXTRA_CXXFLAGS=-g3 -O0
|
||||||
|
|
||||||
APP_NAME := string-indexer-tests
|
APP_NAME := string-indexer-tests
|
||||||
ARDUINO_LIBS := AUnit AceCommon AceTime TinyMqtt EspMock ESP8266WiFi ESPAsync
|
ARDUINO_LIBS := AUnit AceCommon AceTime TinyMqtt EspMock ESP8266WiFi ESPAsync
|
||||||
ARDUINO_LIB_DIRS := ../../../EspMock/libraries
|
ARDUINO_LIB_DIRS := ../../../EspMock/libraries
|
||||||
|
|||||||
@@ -62,6 +62,14 @@ test(indexer_same_strings_should_equal)
|
|||||||
assertTrue(one == two);
|
assertTrue(one == two);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test(indexer_compare_strings_with_same_beginning)
|
||||||
|
{
|
||||||
|
IndexedString two("one_two");
|
||||||
|
IndexedString one("one");
|
||||||
|
|
||||||
|
assertNotEqual(one.getIndex(), two.getIndex());
|
||||||
|
}
|
||||||
|
|
||||||
test(indexer_indexed_operator_eq)
|
test(indexer_indexed_operator_eq)
|
||||||
{
|
{
|
||||||
IndexedString one("one");
|
IndexedString one("one");
|
||||||
|
|||||||
Reference in New Issue
Block a user