Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fab242e212 | ||
|
|
56a2be621f | ||
|
|
c4cf39ab68 | ||
|
|
90dea36ab0 | ||
|
|
25a721e06a | ||
|
|
b228d35ab0 | ||
|
|
c70716a595 | ||
|
|
8d5cad5fec | ||
|
|
d5430228e5 | ||
|
|
91c1f96146 | ||
|
|
f04a2a07c0 | ||
|
|
38f306c170 | ||
|
|
024e80c9dc |
8
.github/workflows/aunit.yml
vendored
8
.github/workflows/aunit.yml
vendored
@@ -24,5 +24,11 @@ jobs:
|
|||||||
git clone https://github.com/hsaturn/EspMock
|
git clone https://github.com/hsaturn/EspMock
|
||||||
- name: Verify tests
|
- name: Verify tests
|
||||||
run: |
|
run: |
|
||||||
make -C tests
|
# Run tests for ESP8266
|
||||||
|
make -C tests ESP_LIBS="ESP8266WiFi ESPAsyncTCP" tests
|
||||||
make -C tests runtests
|
make -C tests runtests
|
||||||
|
make -C tests clean
|
||||||
|
# Run tests for ESP32
|
||||||
|
#make -C tests ESP_LIBS="ESP8266WiFi ESPAsyncTCP" tests
|
||||||
|
#make -C tests runtests
|
||||||
|
#make -C tests clean
|
||||||
|
|||||||
12
README.md
12
README.md
@@ -1,12 +1,12 @@
|
|||||||
# TinyMqtt
|
# TinyMqtt
|
||||||
|
|
||||||

|
[](https://github.com/hsaturn/TinyMqtt/releases)
|
||||||
[](https://github.com/hsaturn/TinyMqtt/actions/workflows/aunit.yml)
|
[](https://github.com/hsaturn/TinyMqtt/actions/workflows/aunit.yml)
|
||||||

|
[](https://github.com/hsaturn/TinyMqtt/issues)
|
||||||

|
[](https://www.espressif.com/en/products/socs/esp8266)
|
||||||

|
[](https://www.espressif.com/en/products/socs/esp32)
|
||||||

|
[](https://www.gnu.org/licenses/gpl-3.0.fr.html)
|
||||||

|
[](https://docs.oasis-open.org/mqtt/mqtt/v3.1.1/errata01/os/mqtt-v3.1.1-errata01-os-complete.html#_Toc442180822)
|
||||||
|
|
||||||
TinyMqtt is a small, fast and capable Mqtt Broker and Client for Esp8266 / Esp32 / Esp WROOM
|
TinyMqtt is a small, fast and capable Mqtt Broker and Client for Esp8266 / Esp32 / Esp WROOM
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,8 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <my_credentials.h>
|
const char *ssid = "";
|
||||||
|
const char *password = "";
|
||||||
|
|
||||||
std::string topic="sensor/temperature";
|
std::string topic="sensor/temperature";
|
||||||
|
|
||||||
@@ -40,11 +41,11 @@ MqttBroker broker(1883);
|
|||||||
MqttClient mqtt_a(&broker);
|
MqttClient mqtt_a(&broker);
|
||||||
MqttClient mqtt_b(&broker);
|
MqttClient mqtt_b(&broker);
|
||||||
|
|
||||||
void onPublishA(const MqttClient* source, const Topic& topic, const char* payload, size_t length)
|
void onPublishA(const MqttClient* /* source */, const Topic& topic, const char* payload, size_t /* length */)
|
||||||
{ Serial << endl << "---------> A Received " << topic.c_str() << endl; }
|
{ Serial << "--> client A received " << topic.c_str() << ", " << payload << endl; }
|
||||||
|
|
||||||
void onPublishB(const MqttClient* source, const Topic& topic, const char* payload, size_t length)
|
void onPublishB(const MqttClient* /* source */, const Topic& topic, const char* payload, size_t /* length */)
|
||||||
{ Serial << endl << "---------> B Received " << topic.c_str() << endl; }
|
{ Serial << "--> client B Received " << topic.c_str() << ", " << payload << endl; }
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
@@ -52,6 +53,9 @@ void setup()
|
|||||||
delay(500);
|
delay(500);
|
||||||
Serial << "Clients with wifi " << endl;
|
Serial << "Clients with wifi " << endl;
|
||||||
|
|
||||||
|
if (strlen(ssid)==0)
|
||||||
|
Serial << "****** PLEASE EDIT THE EXAMPLE AND MODIFY ssid/password *************" << endl;
|
||||||
|
|
||||||
WiFi.mode(WIFI_STA);
|
WiFi.mode(WIFI_STA);
|
||||||
WiFi.begin(ssid, password);
|
WiFi.begin(ssid, password);
|
||||||
|
|
||||||
@@ -76,14 +80,14 @@ void loop()
|
|||||||
mqtt_b.loop();
|
mqtt_b.loop();
|
||||||
|
|
||||||
// ============= client A publish ================
|
// ============= client A publish ================
|
||||||
static const int intervalA = 5000; // publishes every 5s
|
static const int intervalA = 5000; // publishes every 5s (please avoid usage of delay())
|
||||||
static uint32_t timerA = millis() + intervalA;
|
static uint32_t timerA = millis() + intervalA;
|
||||||
|
|
||||||
if (millis() > timerA)
|
if (millis() > timerA)
|
||||||
{
|
{
|
||||||
Serial << "A is publishing " << topic.c_str() << endl;
|
Serial << "A is publishing " << topic.c_str() << endl;
|
||||||
timerA += intervalA;
|
timerA += intervalA;
|
||||||
mqtt_a.publish(topic);
|
mqtt_a.publish(topic, " sent by A");
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============= client B publish ================
|
// ============= client B publish ================
|
||||||
@@ -92,8 +96,9 @@ void loop()
|
|||||||
|
|
||||||
if (millis() > timerB)
|
if (millis() > timerB)
|
||||||
{
|
{
|
||||||
|
static int temperature;
|
||||||
Serial << "B is publishing " << topic.c_str() << endl;
|
Serial << "B is publishing " << topic.c_str() << endl;
|
||||||
timerB += intervalB;
|
timerB += intervalB;
|
||||||
mqtt_b.publish(topic, std::string(String(15+millis()%10).c_str()));
|
mqtt_b.publish(topic, " sent by B: "+std::string(String(16+temperature++%6).c_str()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,11 +32,11 @@ MqttBroker broker(1883);
|
|||||||
MqttClient mqtt_a(&broker);
|
MqttClient mqtt_a(&broker);
|
||||||
MqttClient mqtt_b(&broker);
|
MqttClient mqtt_b(&broker);
|
||||||
|
|
||||||
void onPublishA(const MqttClient* srce, const Topic& topic, const char* payload, size_t length)
|
void onPublishA(const MqttClient* /* srce */, const Topic& topic, const char* payload, size_t /* length */)
|
||||||
{ Serial << "--> A Received " << topic.c_str() << endl; }
|
{ Serial << "--> Client A received msg on topic " << topic.c_str() << ", " << payload << endl; }
|
||||||
|
|
||||||
void onPublishB(const MqttClient* srce, const Topic& topic, const char* payload, size_t length)
|
void onPublishB(const MqttClient* /* srce */, const Topic& topic, const char* payload, size_t /* length */)
|
||||||
{ Serial << "--> B Received " << topic.c_str() << endl; }
|
{ Serial << "--> Client B received msg on topic " << topic.c_str() << ", " << payload << endl; }
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
@@ -53,7 +53,7 @@ void setup()
|
|||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
broker.loop();
|
broker.loop(); // Don't forget to call loop() for all brokers and clients
|
||||||
mqtt_a.loop();
|
mqtt_a.loop();
|
||||||
mqtt_b.loop();
|
mqtt_b.loop();
|
||||||
|
|
||||||
@@ -65,7 +65,7 @@ void loop()
|
|||||||
{
|
{
|
||||||
Serial << "A is publishing " << topic.c_str() << endl;
|
Serial << "A is publishing " << topic.c_str() << endl;
|
||||||
timerA += intervalA;
|
timerA += intervalA;
|
||||||
mqtt_a.publish(topic);
|
mqtt_a.publish(topic, "sent by A");
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============= client B publish ================
|
// ============= client B publish ================
|
||||||
@@ -76,6 +76,6 @@ void loop()
|
|||||||
{
|
{
|
||||||
Serial << "B is publishing " << topic.c_str() << endl;
|
Serial << "B is publishing " << topic.c_str() << endl;
|
||||||
timerB += intervalB;
|
timerB += intervalB;
|
||||||
mqtt_b.publish(topic);
|
mqtt_b.publish(topic, "sent by B");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
#include "TinyMqtt.h" // https://github.com/hsaturn/TinyMqtt
|
#include "TinyMqtt.h" // https://github.com/hsaturn/TinyMqtt
|
||||||
|
|
||||||
#include <my_credentials.h>
|
|
||||||
|
|
||||||
#define PORT 1883
|
#define PORT 1883
|
||||||
MqttBroker broker(PORT);
|
MqttBroker broker(PORT);
|
||||||
|
|
||||||
@@ -14,11 +12,22 @@ MqttBroker broker(PORT);
|
|||||||
* | +--------+ |
|
* | +--------+ |
|
||||||
* | |
|
* | |
|
||||||
* +-----------------------------+
|
* +-----------------------------+
|
||||||
|
*
|
||||||
|
* Your ESP will become a MqttBroker.
|
||||||
|
* You can test it with any client such as mqtt-spy for example
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
const char* ssid = "";
|
||||||
|
const char* password = "";
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
|
|
||||||
|
if (strlen(ssid)==0)
|
||||||
|
Serial << "****** PLEASE MODIFY ssid/password *************" << endl;
|
||||||
|
|
||||||
WiFi.mode(WIFI_STA);
|
WiFi.mode(WIFI_STA);
|
||||||
WiFi.begin(ssid, password);
|
WiFi.begin(ssid, password);
|
||||||
|
|
||||||
|
|||||||
@@ -16,8 +16,10 @@
|
|||||||
* | |
|
* | |
|
||||||
* +-----------------+
|
* +-----------------+
|
||||||
*
|
*
|
||||||
* 1 - edit my_credentials.h to setup wifi essid/password
|
* 1 - change the ssid/password
|
||||||
* 2 - change BROKER values (or keep emqx.io test broker)
|
* 2 - change BROKER values (or keep emqx.io test broker)
|
||||||
|
* 3 - you can use mqtt-spy to connect to the same broker and
|
||||||
|
* see the sensor/temperature updated by the client.
|
||||||
*
|
*
|
||||||
* pro - small memory footprint (both ram and flash)
|
* pro - small memory footprint (both ram and flash)
|
||||||
* - very simple to setup and use
|
* - very simple to setup and use
|
||||||
@@ -30,7 +32,8 @@
|
|||||||
const char* BROKER = "broker.emqx.io";
|
const char* BROKER = "broker.emqx.io";
|
||||||
const uint16_t BROKER_PORT = 1883;
|
const uint16_t BROKER_PORT = 1883;
|
||||||
|
|
||||||
#include <my_credentials.h>
|
const char* ssid = "";
|
||||||
|
const char* password = "";
|
||||||
|
|
||||||
static float temp=19;
|
static float temp=19;
|
||||||
static MqttClient client;
|
static MqttClient client;
|
||||||
@@ -39,7 +42,10 @@ void setup()
|
|||||||
{
|
{
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
delay(500);
|
delay(500);
|
||||||
|
|
||||||
Serial << "Simple clients with wifi " << endl;
|
Serial << "Simple clients with wifi " << endl;
|
||||||
|
if (strlen(ssid)==0)
|
||||||
|
Serial << "****** PLEASE MODIFY ssid/password *************" << endl;
|
||||||
|
|
||||||
WiFi.mode(WIFI_STA);
|
WiFi.mode(WIFI_STA);
|
||||||
WiFi.begin(ssid, password);
|
WiFi.begin(ssid, password);
|
||||||
@@ -54,15 +60,28 @@ void setup()
|
|||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
client.loop();
|
client.loop(); // Don't forget to call loop() for each broker and client
|
||||||
|
|
||||||
delay(1000);
|
// delay(1000); please avoid usage of delay (see below how this done using next_send and millis())
|
||||||
|
static auto next_send = millis();
|
||||||
|
|
||||||
|
if (millis() > next_send)
|
||||||
|
{
|
||||||
|
next_send += 1000;
|
||||||
|
|
||||||
|
if (not client.connected())
|
||||||
|
{
|
||||||
|
Serial << millis() << ": Not connected to broker" << endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
auto rnd=random(100);
|
auto rnd=random(100);
|
||||||
|
|
||||||
if (rnd > 66) temp += 0.1;
|
if (rnd > 66) temp += 0.1;
|
||||||
else if (rnd < 33) temp -= 0.1;
|
else if (rnd < 33) temp -= 0.1;
|
||||||
|
|
||||||
client.publish("sensor/temperature", String(temp));
|
Serial << "--> Publishing a new sensor/temperature value: " << temp << endl;
|
||||||
|
|
||||||
|
client.publish("sensor/temperature", String(temp));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#if defined(ESP8266)
|
#if defined(ESP8266)
|
||||||
#include <ESP8266mDNS.h>
|
#include <ESP8266mDNS.h>
|
||||||
#elif defined(ESP32)
|
#elif defined(ESP32)
|
||||||
|
#include <WiFi.h>
|
||||||
#include <ESPmDNS.h>
|
#include <ESPmDNS.h>
|
||||||
#else
|
#else
|
||||||
#error Unsupported platform
|
#error Unsupported platform
|
||||||
@@ -11,8 +12,11 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
|
bool echo_on = true;
|
||||||
|
|
||||||
/** Very complex example
|
/** Very complex example
|
||||||
* Console allowing to make any kind of test.
|
* Console allowing to make any kind of test,
|
||||||
|
* even some stress tests.
|
||||||
*
|
*
|
||||||
* Upload the sketch, the use the terminal.
|
* Upload the sketch, the use the terminal.
|
||||||
* Press H for mini help.
|
* Press H for mini help.
|
||||||
@@ -21,7 +25,8 @@
|
|||||||
* TODO examples of scripts
|
* TODO examples of scripts
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <my_credentials.h>
|
const char* ssid = "";
|
||||||
|
const char* password = "";
|
||||||
|
|
||||||
std::string topic="sensor/temperature";
|
std::string topic="sensor/temperature";
|
||||||
|
|
||||||
@@ -46,17 +51,32 @@ void setup()
|
|||||||
WiFi.persistent(false); // https://github.com/esp8266/Arduino/issues/1054
|
WiFi.persistent(false); // https://github.com/esp8266/Arduino/issues/1054
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
delay(500);
|
delay(500);
|
||||||
Serial << endl << endl << endl
|
|
||||||
<< "Connecting to '" << ssid << "' ";
|
|
||||||
|
|
||||||
|
Serial << endl << endl;
|
||||||
|
Serial << "***************************************************************" << endl;
|
||||||
|
Serial << "* Welcome to the TinyMqtt console" << endl;
|
||||||
|
Serial << endl;
|
||||||
|
Serial << "* The console allows to test all features of the libraries." << endl;
|
||||||
|
Serial << endl;
|
||||||
|
if (strlen(ssid)==0)
|
||||||
|
Serial << "* WARNING: You may want to modify ssid/password in order" << endl
|
||||||
|
<< " to reflect your Wifi configuration." << endl;
|
||||||
|
Serial << endl;
|
||||||
|
Serial << "* Enter help to view the list of commands." << endl;
|
||||||
|
Serial << "***************************************************************" << endl;
|
||||||
|
Serial << endl;
|
||||||
|
|
||||||
|
Serial << "Connecting to '" << ssid << "' ";
|
||||||
|
|
||||||
|
WiFi.mode(WIFI_STA);
|
||||||
|
WiFi.begin(ssid, password);
|
||||||
WiFi.mode(WIFI_STA);
|
WiFi.mode(WIFI_STA);
|
||||||
WiFi.begin(ssid, password);
|
WiFi.begin(ssid, password);
|
||||||
|
|
||||||
while (WiFi.status() != WL_CONNECTED)
|
while (WiFi.status() != WL_CONNECTED)
|
||||||
{ Serial << '-'; delay(500); }
|
{ Serial << '-'; delay(500); }
|
||||||
|
|
||||||
Serial << "Connected to " << ssid << "IP address: " << WiFi.localIP() << endl;
|
Serial << endl << "Connected to " << ssid << "IP address: " << WiFi.localIP() << endl;
|
||||||
Serial << "Type help for more..." << endl;
|
|
||||||
|
|
||||||
const char* name="tinytest";
|
const char* name="tinytest";
|
||||||
Serial << "Starting MDNS, name= " << name;
|
Serial << "Starting MDNS, name= " << name;
|
||||||
@@ -71,27 +91,67 @@ void setup()
|
|||||||
brokers["broker"] = broker;
|
brokers["broker"] = broker;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string getword(std::string& str, const char* if_empty=nullptr, char sep=' ');
|
||||||
|
|
||||||
int getint(std::string& str, const int if_empty=0)
|
int getint(std::string& str, const int if_empty=0)
|
||||||
{
|
{
|
||||||
std::string sword;
|
std::string str2=str;
|
||||||
while(str.length() && str[0]>='0' && str[0]<='9')
|
std::string sword = getword(str);
|
||||||
|
if (sword[0] and isdigit(sword[0]))
|
||||||
{
|
{
|
||||||
sword += str[0]; str.erase(0,1);
|
int ret=atoi(sword.c_str());
|
||||||
|
while(isdigit(sword[0]) or sword[0]==' ') sword.erase(0,1);
|
||||||
|
if (sword.length()) str = sword+' '+str;
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
while(str[0]==' ') str.erase(0,1);
|
str=str2;
|
||||||
if (if_empty and sword.length()==0) return if_empty;
|
return if_empty;
|
||||||
return atoi(sword.c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string getword(std::string& str, const char* if_empty=nullptr, char sep=' ')
|
std::string getword(std::string& str, const char* if_empty/*=nullptr*/, char sep/*=' '*/)
|
||||||
{
|
{
|
||||||
|
char quote=(str[0]=='"' or str[0]=='\'' ? str[0] : 0);
|
||||||
|
if (quote) str.erase(0,1);
|
||||||
std::string sword;
|
std::string sword;
|
||||||
while(str.length() && str[0]!=sep)
|
while(str.length() and (str[0]!=sep or quote))
|
||||||
{
|
{
|
||||||
sword += str[0]; str.erase(0,1);
|
if (str[0]==quote)
|
||||||
|
{
|
||||||
|
str.erase(0,1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
sword += str[0];
|
||||||
|
str.erase(0,1);
|
||||||
}
|
}
|
||||||
while(str[0]==sep) str.erase(0,1);
|
while(str[0]==sep) str.erase(0,1);
|
||||||
if (if_empty and sword.length()==0) return if_empty;
|
if (if_empty and sword.length()==0) return if_empty;
|
||||||
|
if (quote==false and sword.length()>=4 and sword.substr(0,3)=="rnd")
|
||||||
|
{
|
||||||
|
sword.erase(0,3);
|
||||||
|
if (sword[0]=='(')
|
||||||
|
{
|
||||||
|
int to = 100;
|
||||||
|
sword.erase(0,1);
|
||||||
|
int from=getint(sword);
|
||||||
|
if (sword[0]==',')
|
||||||
|
{
|
||||||
|
sword.erase(0,1);
|
||||||
|
to = getint(sword);
|
||||||
|
if (sword[0]!=')') Serial << "Missing ')'" << endl;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
to=from;
|
||||||
|
from=0;
|
||||||
|
}
|
||||||
|
return String(random(from,to)).c_str();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Serial << "Missing '('" << endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while(str[0]==' ') str.erase(0,1);
|
||||||
return sword;
|
return sword;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,7 +200,7 @@ std::set<std::string> commands = {
|
|||||||
"auto", "broker", "blink", "client", "connect",
|
"auto", "broker", "blink", "client", "connect",
|
||||||
"create", "delete", "help", "interval",
|
"create", "delete", "help", "interval",
|
||||||
"ls", "ip", "off", "on", "set",
|
"ls", "ip", "off", "on", "set",
|
||||||
"publish", "reset", "subscribe", "unsubscribe", "view", "every"
|
"publish", "reset", "subscribe", "unsubscribe", "view", "echo", "every"
|
||||||
};
|
};
|
||||||
|
|
||||||
void convertToCommand(std::string& search)
|
void convertToCommand(std::string& search)
|
||||||
@@ -179,7 +239,7 @@ void replace(const char* d, std::string& str, std::string srch, std::string to)
|
|||||||
{
|
{
|
||||||
str.erase(pos, srch.length());
|
str.erase(pos, srch.length());
|
||||||
str.insert(pos, to);
|
str.insert(pos, to);
|
||||||
pos += to.length();
|
pos += to.length()-1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -197,6 +257,7 @@ void replaceVars(std::string& cmd)
|
|||||||
}
|
}
|
||||||
cmd.erase(0, cmd.find_first_not_of(" "));
|
cmd.erase(0, cmd.find_first_not_of(" "));
|
||||||
cmd.erase(cmd.find_last_not_of(" ")+1);
|
cmd.erase(cmd.find_last_not_of(" ")+1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// publish at regular interval
|
// publish at regular interval
|
||||||
@@ -463,9 +524,7 @@ void eval(std::string& cmd)
|
|||||||
}
|
}
|
||||||
else if (compare(s,"publish"))
|
else if (compare(s,"publish"))
|
||||||
{
|
{
|
||||||
while (cmd[0]==' ') cmd.erase(0,1);
|
retval = client->publish(getword(cmd, topic.c_str()), getword(cmd));
|
||||||
retval = client->publish(getword(cmd, topic.c_str()), cmd.c_str(), cmd.length());
|
|
||||||
cmd.clear(); // remove payload
|
|
||||||
}
|
}
|
||||||
else if (compare(s,"subscribe"))
|
else if (compare(s,"subscribe"))
|
||||||
{
|
{
|
||||||
@@ -497,6 +556,22 @@ void eval(std::string& cmd)
|
|||||||
pinMode(pin, OUTPUT);
|
pinMode(pin, OUTPUT);
|
||||||
digitalWrite(pin, LOW);
|
digitalWrite(pin, LOW);
|
||||||
}
|
}
|
||||||
|
else if (compare(s, "echo"))
|
||||||
|
{
|
||||||
|
s=getword(cmd);
|
||||||
|
if (s=="on")
|
||||||
|
echo_on = true;
|
||||||
|
else if (s=="off")
|
||||||
|
echo_on = false;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Serial << s << ' ';
|
||||||
|
while(cmd.length())
|
||||||
|
{
|
||||||
|
Serial << getword(cmd) << ' ';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
else if (compare(s, "every"))
|
else if (compare(s, "every"))
|
||||||
{
|
{
|
||||||
uint32_t ms = getint(cmd, 0);
|
uint32_t ms = getint(cmd, 0);
|
||||||
@@ -517,37 +592,21 @@ void eval(std::string& cmd)
|
|||||||
else if (compare(cmd, "off") or compare(cmd, "on"))
|
else if (compare(cmd, "off") or compare(cmd, "on"))
|
||||||
{
|
{
|
||||||
bool active=getword(cmd)=="on";
|
bool active=getword(cmd)=="on";
|
||||||
uint8_t ever;
|
uint8_t ever=getint(cmd, 100);
|
||||||
if (compare(cmd, "all"))
|
|
||||||
ever=100;
|
|
||||||
else
|
|
||||||
ever=getint(cmd, 99);
|
|
||||||
uint8_t count=0;
|
uint8_t count=0;
|
||||||
if (ever == 99)
|
|
||||||
{
|
|
||||||
Serial << "Missing every number" << endl;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for(auto& every: everies)
|
for(auto& every: everies)
|
||||||
{
|
{
|
||||||
if (count==ever or (ever==100))
|
if (count==ever or (ever==100))
|
||||||
{
|
{
|
||||||
if (every.active != active)
|
if (every.active != active)
|
||||||
{
|
{
|
||||||
|
Serial << "every #" << count << (active ? " on" :" off") << endl;
|
||||||
every.active = active;
|
every.active = active;
|
||||||
every.underrun = 0;
|
every.underrun = 0;
|
||||||
}
|
}
|
||||||
ever = 99;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
if (ever != 99)
|
|
||||||
{
|
|
||||||
Serial << "Every not found" << endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (compare(cmd, "list") or cmd.length()==0)
|
else if (compare(cmd, "list") or cmd.length()==0)
|
||||||
{
|
{
|
||||||
@@ -725,9 +784,11 @@ void eval(std::string& cmd)
|
|||||||
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 << " every ms [command]; every list; every remove [nr|all], every [on|off] #" << endl;
|
Serial << " echo [on|off] or strings" << 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 << " default topic is '" << topic.c_str() << "'" << endl;
|
Serial << " default topic is '" << topic.c_str() << "'" << endl;
|
||||||
Serial << endl;
|
Serial << endl;
|
||||||
}
|
}
|
||||||
@@ -811,8 +872,10 @@ void loop()
|
|||||||
{
|
{
|
||||||
static std::string cmd;
|
static std::string cmd;
|
||||||
char c=Serial.read();
|
char c=Serial.read();
|
||||||
|
if (echo_on)
|
||||||
|
Serial << c;
|
||||||
|
|
||||||
if (c==10 or c==14)
|
if (c==10 or c==13)
|
||||||
{
|
{
|
||||||
Serial << "----------------[ " << cmd.c_str() << " ]--------------" << endl;
|
Serial << "----------------[ " << cmd.c_str() << " ]--------------" << endl;
|
||||||
static std::string last_cmd;
|
static std::string last_cmd;
|
||||||
|
|||||||
@@ -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.5",
|
"version": "0.7.6",
|
||||||
"exclude": "",
|
"exclude": "",
|
||||||
"examples": "examples/*/*.ino",
|
"examples": "examples/*/*.ino",
|
||||||
"frameworks": "arduino",
|
"frameworks": "arduino",
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
name=TinyMqtt
|
name=TinyMqtt
|
||||||
version=0.7.5
|
version=0.7.6
|
||||||
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.
|
||||||
|
|||||||
@@ -665,7 +665,7 @@ void MqttMessage::incoming(char in_byte)
|
|||||||
state = Length;
|
state = Length;
|
||||||
break;
|
break;
|
||||||
case Length:
|
case Length:
|
||||||
size = (size<<7) + (in_byte & 0x3F);
|
size = (size<<7) + (in_byte & 0x7F);
|
||||||
if (size > MaxBufferLength)
|
if (size > MaxBufferLength)
|
||||||
{
|
{
|
||||||
state = Error;
|
state = Error;
|
||||||
|
|||||||
@@ -10,10 +10,9 @@
|
|||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#endif
|
#endif
|
||||||
#elif defined(ESP32)
|
#elif defined(ESP32)
|
||||||
|
#include <WiFi.h>
|
||||||
#ifdef TCP_ASYNC
|
#ifdef TCP_ASYNC
|
||||||
#include <AsyncTCP.h> // https://github.com/me-no-dev/AsyncTCP
|
#include <AsyncTCP.h> // https://github.com/me-no-dev/AsyncTCP
|
||||||
#else
|
|
||||||
#include <WiFi.h>
|
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#ifdef EPOXY_DUINO
|
#ifdef EPOXY_DUINO
|
||||||
@@ -177,6 +176,7 @@ class MqttClient
|
|||||||
|
|
||||||
// Publish from client to the world
|
// Publish from client to the world
|
||||||
MqttError publish(const Topic&, const char* payload, size_t pay_length);
|
MqttError publish(const Topic&, const char* payload, size_t pay_length);
|
||||||
|
MqttError publish(const Topic& t, const char* payload) { return publish(t, payload, strlen(payload)); }
|
||||||
MqttError publish(const Topic& t, const String& s) { return publish(t, s.c_str(), s.length()); }
|
MqttError publish(const Topic& t, const String& s) { return publish(t, s.c_str(), s.length()); }
|
||||||
MqttError publish(const Topic& t, const std::string& s) { return publish(t,s.c_str(),s.length());}
|
MqttError publish(const Topic& t, const std::string& s) { return publish(t,s.c_str(),s.length());}
|
||||||
MqttError publish(const Topic& t) { return publish(t, nullptr, 0);};
|
MqttError publish(const Topic& t) { return publish(t, nullptr, 0);};
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
# Makefile to compile and run Arduino programs natively on Linux or MacOS.
|
# Makefile to compile and run Arduino programs natively on Linux or MacOS.
|
||||||
|
|
||||||
APP_NAME := local-tests
|
APP_NAME := local-tests
|
||||||
ARDUINO_LIBS := AUnit AceCommon AceTime TinyMqtt EspMock
|
ARDUINO_LIBS := AUnit AceCommon AceTime TinyMqtt EspMock ESP8266WiFi ESPAsyncTCP
|
||||||
ESP_LIBS = ESP8266WiFi ESPAsyncTCP
|
ARDUINO_LIB_DIRS := ../../../EspMock/libraries
|
||||||
include ../../../EspMock/EspMock.mk
|
EPOXY_CORE := EPOXY_CORE_ESP8266
|
||||||
|
include ../../../EpoxyDuino/EpoxyDuino.mk
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
# Makefile to compile and run Arduino programs natively on Linux or MacOS.
|
# Makefile to compile and run Arduino programs natively on Linux or MacOS.
|
||||||
|
|
||||||
APP_NAME := nowifi-tests
|
APP_NAME := nowifi-tests
|
||||||
ARDUINO_LIBS := AUnit AceCommon AceTime TinyMqtt EspMock
|
ARDUINO_LIBS := AUnit AceCommon AceTime TinyMqtt EspMock ESP8266WiFi ESPAsyncTCP
|
||||||
ESP_LIBS = ESP8266WiFi ESPAsyncTCP
|
ARDUINO_LIB_DIRS := ../../../EspMock/libraries
|
||||||
include ../../../EspMock/EspMock.mk
|
EPOXY_CORE := EPOXY_CORE_ESP8266
|
||||||
|
include ../../../EpoxyDuino/EpoxyDuino.mk
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
# Makefile to compile and run Arduino programs natively on Linux or MacOS.
|
# Makefile to compile and run Arduino programs natively on Linux or MacOS.
|
||||||
|
|
||||||
APP_NAME := string-indexer-tests
|
APP_NAME := string-indexer-tests
|
||||||
ARDUINO_LIBS := AUnit AceCommon AceTime TinyMqtt EspMock
|
ARDUINO_LIBS := AUnit AceCommon AceTime TinyMqtt EspMock ESP8266WiFi ESPAsync
|
||||||
ESP_LIBS = ESP8266WiFi ESPAsyncTCP
|
ARDUINO_LIB_DIRS := ../../../EspMock/libraries
|
||||||
include ../../../EspMock/EspMock.mk
|
EPOXY_CORE := EPOXY_CORE_ESP8266
|
||||||
|
include ../../../EpoxyDuino/EpoxyDuino.mk
|
||||||
|
|||||||
@@ -105,5 +105,5 @@ void setup() {
|
|||||||
void loop() {
|
void loop() {
|
||||||
aunit::TestRunner::run();
|
aunit::TestRunner::run();
|
||||||
|
|
||||||
if (Serial.available()) ESP.reset();
|
// if (Serial.available()) ESP.reset();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user