Rewrite examples

This commit is contained in:
hsaturn
2021-04-12 00:23:08 +02:00
parent ce896f02c4
commit 5d313bbf5e
5 changed files with 61 additions and 23 deletions

View File

@@ -1,6 +1,8 @@
#include <TinyMqtt.h> // https://github.com/hsaturn/TinyMqtt #include <TinyMqtt.h> // https://github.com/hsaturn/TinyMqtt
/** /**
* Local broker that accept connections and two local clients
*
* *
* +-----------------------------+ * +-----------------------------+
* | ESP | * | ESP |
@@ -9,9 +11,10 @@
* | | +--------+ | * | | +--------+ |
* | | ^ | * | | ^ |
* | | | | * | | | |
* | v v | * | | | | -----
* | +----------+ +----------+ | * | v v | ---
* | | internal | | internal | | * | +----------+ +----------+ | -
* | | internal | | internal | +-------* Wifi
* | | client | | client | | * | | client | | client | |
* | +----------+ +----------+ | * | +----------+ +----------+ |
* | | * | |

View File

@@ -1,11 +1,29 @@
#include <TinyMqtt.h> // https://github.com/hsaturn/TinyMqtt #include <TinyMqtt.h> // https://github.com/hsaturn/TinyMqtt
/** TinyMQTT allows a disconnected mode: /** TinyMQTT allows a disconnected mode:
*
* +-----------------------------+
* | ESP |
* | +--------+ |
* | +-------->| broker | |
* | | +--------+ |
* | | ^ |
* | | | |
* | v v |
* | +----------+ +----------+ |
* | | internal | | internal | |
* | | client | | client | |
* | +----------+ +----------+ |
* | |
* +-----------------------------+
* *
* In this example, local clients A and B are talking together, no need to be connected. * In this example, local clients A and B are talking together, no need to be connected.
*
* A single ESP can use this to be able to comunicate with itself with the power * A single ESP can use this to be able to comunicate with itself with the power
* of MQTT, and once connected still continue to work with others. * of MQTT, and once connected still continue to work with others.
* *
* The broker may still be conected if wifi is on.
*
*/ */
std::string topic="sensor/temperature"; std::string topic="sensor/temperature";

View File

@@ -5,6 +5,16 @@
#define PORT 1883 #define PORT 1883
MqttBroker broker(PORT); MqttBroker broker(PORT);
/** Basic Mqtt Broker
*
* +-----------------------------+
* | ESP |
* | +--------+ |
* | | broker | | 1883 <--- External client/s
* | +--------+ |
* | |
* +-----------------------------+
*
void setup() void setup()
{ {
Serial.begin(115200); Serial.begin(115200);

View File

@@ -1,8 +1,20 @@
#include "TinyMqtt.h" // https://github.com/hsaturn/TinyMqtt #include "TinyMqtt.h" // https://github.com/hsaturn/TinyMqtt
/** Simple Client /** Simple Client (The simplest configuration)
* *
* This is the simplest Mqtt client configuration *
* +--------+
* +------>| broker |<--- < Other client
* | +--------+
* |
* +-----------------+
* | ESP | |
* | +----------+ |
* | | internal | |
* | | client | |
* | +----------+ |
* | |
* +-----------------+
* *
* 1 - edit my_credentials.h to setup wifi essid/password * 1 - edit my_credentials.h to setup wifi essid/password
* 2 - change BROKER values (or keep emqx.io test broker) * 2 - change BROKER values (or keep emqx.io test broker)

View File

@@ -5,18 +5,13 @@
#include <sstream> #include <sstream>
#include <map> #include <map>
/** /** Very complex example
* Console allowing to make any kind of test. * Console allowing to make any kind of test.
* *
* pros - Reduces internal latency (when publish is received by the same ESP) * Upload the sketch, the use the terminal.
* - Reduces wifi traffic * Press H for mini help.
* - No need to have an external broker
* - can still report to a 'main' broker (TODO see documentation that have to be written)
* - accepts external clients
*
* cons - Takes more memory
* - a bit hard to understand
* *
* TODO examples of scripts
*/ */
#include <my_credentials.h> #include <my_credentials.h>