mirror of
https://gitlab.com/wirelos/sprocket-plugin-mqtt.git
synced 2025-12-14 13:51:27 +01:00
Add user and pass
This commit is contained in:
0
.gitignore
vendored
Normal file → Executable file
0
.gitignore
vendored
Normal file → Executable file
0
.gitlab-ci.yml
Normal file → Executable file
0
.gitlab-ci.yml
Normal file → Executable file
0
.travis.yml
Normal file → Executable file
0
.travis.yml
Normal file → Executable file
0
.vscode/extensions.json
vendored
Normal file → Executable file
0
.vscode/extensions.json
vendored
Normal file → Executable file
BIN
.vscode/ipch/5621cedcfe4a1a0f/mmap_address.bin
vendored
Normal file
BIN
.vscode/ipch/5621cedcfe4a1a0f/mmap_address.bin
vendored
Normal file
Binary file not shown.
BIN
.vscode/ipch/96c62a1ecada60cd/main.ipch
vendored
Normal file
BIN
.vscode/ipch/96c62a1ecada60cd/main.ipch
vendored
Normal file
Binary file not shown.
BIN
.vscode/ipch/96c62a1ecada60cd/mmap_address.bin
vendored
Normal file
BIN
.vscode/ipch/96c62a1ecada60cd/mmap_address.bin
vendored
Normal file
Binary file not shown.
BIN
.vscode/ipch/ac952b37c792bcdd/main.ipch
vendored
Normal file
BIN
.vscode/ipch/ac952b37c792bcdd/main.ipch
vendored
Normal file
Binary file not shown.
BIN
.vscode/ipch/ac952b37c792bcdd/mmap_address.bin
vendored
Normal file
BIN
.vscode/ipch/ac952b37c792bcdd/mmap_address.bin
vendored
Normal file
Binary file not shown.
BIN
.vscode/ipch/b83158c58eaf72d2/mmap_address.bin
vendored
Normal file
BIN
.vscode/ipch/b83158c58eaf72d2/mmap_address.bin
vendored
Normal file
Binary file not shown.
BIN
.vscode/ipch/cedfd36b17bccdfe/MqttPlugin.ipch
vendored
Normal file
BIN
.vscode/ipch/cedfd36b17bccdfe/MqttPlugin.ipch
vendored
Normal file
Binary file not shown.
BIN
.vscode/ipch/cedfd36b17bccdfe/mmap_address.bin
vendored
Normal file
BIN
.vscode/ipch/cedfd36b17bccdfe/mmap_address.bin
vendored
Normal file
Binary file not shown.
2
.vscode/settings.json
vendored
Normal file → Executable file
2
.vscode/settings.json
vendored
Normal file → Executable file
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"terminal.integrated.env.linux": {
|
"terminal.integrated.env.linux": {
|
||||||
"PATH": "/home/master/.platformio/penv/bin:/home/master/.platformio/penv:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl",
|
"PATH": "/home/master/.platformio/penv/bin:/home/master/.platformio/penv:/home/master/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/sbin:/usr/sbin",
|
||||||
"PLATFORMIO_CALLER": "vscode"
|
"PLATFORMIO_CALLER": "vscode"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
2
data/config.json
Normal file → Executable file
2
data/config.json
Normal file → Executable file
@@ -4,7 +4,7 @@
|
|||||||
"apSSID": "sprocket",
|
"apSSID": "sprocket",
|
||||||
"apPassword": "th3r31sn0Sp00n",
|
"apPassword": "th3r31sn0Sp00n",
|
||||||
"connectTimeout": 20000,
|
"connectTimeout": 20000,
|
||||||
"stationSSID": "MyAP",
|
"stationSSID": "th1ngs4p",
|
||||||
"stationPassword": "th3r31sn0Sp00n",
|
"stationPassword": "th3r31sn0Sp00n",
|
||||||
"meshSSID": "whateverYouLike",
|
"meshSSID": "whateverYouLike",
|
||||||
"meshPassword": "somethingSneaky",
|
"meshPassword": "somethingSneaky",
|
||||||
|
|||||||
4
data/mqttConfig.json
Normal file → Executable file
4
data/mqttConfig.json
Normal file → Executable file
@@ -2,5 +2,7 @@
|
|||||||
"mqttClientName" : "sprocket",
|
"mqttClientName" : "sprocket",
|
||||||
"mqttBrokerHost" : "192.168.1.2",
|
"mqttBrokerHost" : "192.168.1.2",
|
||||||
"mqttBrokerPort" : 1883,
|
"mqttBrokerPort" : 1883,
|
||||||
"mqttRootTopic" : "wirelos/sprocket"
|
"mqttRootTopic" : "wirelos/sprocket",
|
||||||
|
"mqttUser": "",
|
||||||
|
"mqttPass": ""
|
||||||
}
|
}
|
||||||
0
lib/readme.txt
Normal file → Executable file
0
lib/readme.txt
Normal file → Executable file
0
library.json
Normal file → Executable file
0
library.json
Normal file → Executable file
11
platformio.ini
Normal file → Executable file
11
platformio.ini
Normal file → Executable file
@@ -12,7 +12,6 @@ lib_deps =
|
|||||||
TaskScheduler
|
TaskScheduler
|
||||||
SPIFFS
|
SPIFFS
|
||||||
ArduinoJson
|
ArduinoJson
|
||||||
ArduinoOTA
|
|
||||||
https://gitlab.com/wirelos/sprocket-lib.git#develop
|
https://gitlab.com/wirelos/sprocket-lib.git#develop
|
||||||
https://gitlab.com/wirelos/sprocket-network-wifi.git
|
https://gitlab.com/wirelos/sprocket-network-wifi.git
|
||||||
|
|
||||||
@@ -35,3 +34,13 @@ monitor_baud = ${common.monitor_baud}
|
|||||||
framework = ${common.framework}
|
framework = ${common.framework}
|
||||||
lib_deps = ${common.lib_deps}
|
lib_deps = ${common.lib_deps}
|
||||||
PubSubClient
|
PubSubClient
|
||||||
|
|
||||||
|
[env:chat-esp01]
|
||||||
|
src_filter = +<*> -<examples/> +<examples/chat/>
|
||||||
|
platform = ${common.platform}
|
||||||
|
board = esp01
|
||||||
|
upload_speed = ${common.upload_speed}
|
||||||
|
monitor_baud = ${common.monitor_baud}
|
||||||
|
framework = ${common.framework}
|
||||||
|
lib_deps = ${common.lib_deps}
|
||||||
|
PubSubClient
|
||||||
8
src/MqttConfig.h
Normal file → Executable file
8
src/MqttConfig.h
Normal file → Executable file
@@ -7,6 +7,8 @@
|
|||||||
#define JSON_MQTT_BROKER_HOST "mqttBrokerHost"
|
#define JSON_MQTT_BROKER_HOST "mqttBrokerHost"
|
||||||
#define JSON_MQTT_BROKER_PORT "mqttBrokerPort"
|
#define JSON_MQTT_BROKER_PORT "mqttBrokerPort"
|
||||||
#define JSON_MQTT_TOPIC_ROOT "mqttRootTopic"
|
#define JSON_MQTT_TOPIC_ROOT "mqttRootTopic"
|
||||||
|
#define JSON_MQTT_USER "mqttUser"
|
||||||
|
#define JSON_MQTT_PASS "mqttPass"
|
||||||
|
|
||||||
struct MqttConfig
|
struct MqttConfig
|
||||||
{
|
{
|
||||||
@@ -14,6 +16,8 @@ struct MqttConfig
|
|||||||
const char *brokerHost;
|
const char *brokerHost;
|
||||||
int brokerPort;
|
int brokerPort;
|
||||||
const char *topicRoot;
|
const char *topicRoot;
|
||||||
|
const char *user;
|
||||||
|
const char *pass;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct MqttConfigJson : public MqttConfig, public JsonStruct
|
struct MqttConfigJson : public MqttConfig, public JsonStruct
|
||||||
@@ -24,6 +28,8 @@ struct MqttConfigJson : public MqttConfig, public JsonStruct
|
|||||||
root[JSON_MQTT_BROKER_HOST] = brokerHost;
|
root[JSON_MQTT_BROKER_HOST] = brokerHost;
|
||||||
root[JSON_MQTT_BROKER_PORT] = brokerPort;
|
root[JSON_MQTT_BROKER_PORT] = brokerPort;
|
||||||
root[JSON_MQTT_TOPIC_ROOT] = topicRoot;
|
root[JSON_MQTT_TOPIC_ROOT] = topicRoot;
|
||||||
|
root[JSON_MQTT_USER] = user;
|
||||||
|
root[JSON_MQTT_PASS] = pass;
|
||||||
}
|
}
|
||||||
void fromJsonObject(JsonObject &json)
|
void fromJsonObject(JsonObject &json)
|
||||||
{
|
{
|
||||||
@@ -37,6 +43,8 @@ struct MqttConfigJson : public MqttConfig, public JsonStruct
|
|||||||
brokerHost = getAttr(json, JSON_MQTT_BROKER_HOST);
|
brokerHost = getAttr(json, JSON_MQTT_BROKER_HOST);
|
||||||
brokerPort = getIntAttrFromJson(json, JSON_MQTT_BROKER_PORT);
|
brokerPort = getIntAttrFromJson(json, JSON_MQTT_BROKER_PORT);
|
||||||
topicRoot = getAttr(json, JSON_MQTT_TOPIC_ROOT);
|
topicRoot = getAttr(json, JSON_MQTT_TOPIC_ROOT);
|
||||||
|
user = getAttr(json, JSON_MQTT_USER);
|
||||||
|
pass = getAttr(json, JSON_MQTT_PASS);
|
||||||
valid = 1;
|
valid = 1;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
10
src/MqttPlugin.cpp
Normal file → Executable file
10
src/MqttPlugin.cpp
Normal file → Executable file
@@ -12,6 +12,8 @@ void MqttPlugin::applyConfig(MqttConfig cfg) {
|
|||||||
brokerPort = cfg.brokerPort;
|
brokerPort = cfg.brokerPort;
|
||||||
clientName = String(cfg.clientName);
|
clientName = String(cfg.clientName);
|
||||||
topicRoot = String(cfg.topicRoot);
|
topicRoot = String(cfg.topicRoot);
|
||||||
|
user = String(cfg.user);
|
||||||
|
pass = String(cfg.pass);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MqttPlugin::applyConfigFromFile(const char* fileName) {
|
void MqttPlugin::applyConfigFromFile(const char* fileName) {
|
||||||
@@ -51,7 +53,13 @@ void MqttPlugin::connect()
|
|||||||
if (!client->connected())
|
if (!client->connected())
|
||||||
{
|
{
|
||||||
PRINT_MSG(Serial, "MQTT", "try connect");
|
PRINT_MSG(Serial, "MQTT", "try connect");
|
||||||
if (client->connect(clientName.c_str()))
|
int connected = 0;
|
||||||
|
if(user.length() > 0 && pass.length() > 0){
|
||||||
|
connected = client->connect(clientName.c_str(), user.c_str(), pass.c_str());
|
||||||
|
} else {
|
||||||
|
client->connect(clientName.c_str());
|
||||||
|
}
|
||||||
|
if (connected)
|
||||||
{
|
{
|
||||||
// bind handlers to all local subscriptions
|
// bind handlers to all local subscriptions
|
||||||
if (!subscribed)
|
if (!subscribed)
|
||||||
|
|||||||
2
src/MqttPlugin.h
Normal file → Executable file
2
src/MqttPlugin.h
Normal file → Executable file
@@ -37,6 +37,8 @@ private:
|
|||||||
int brokerPort;
|
int brokerPort;
|
||||||
String clientName;
|
String clientName;
|
||||||
String topicRoot;
|
String topicRoot;
|
||||||
|
String user;
|
||||||
|
String pass;
|
||||||
int connectTries = 0;
|
int connectTries = 0;
|
||||||
int maxConnectTries = 5; // TODO add to config
|
int maxConnectTries = 5; // TODO add to config
|
||||||
|
|
||||||
|
|||||||
0
src/examples/basic/config.h
Normal file → Executable file
0
src/examples/basic/config.h
Normal file → Executable file
2
src/examples/basic/main.cpp
Normal file → Executable file
2
src/examples/basic/main.cpp
Normal file → Executable file
@@ -26,7 +26,7 @@ void setup()
|
|||||||
});
|
});
|
||||||
sprocket->addTask(publishHeap);
|
sprocket->addTask(publishHeap);
|
||||||
sprocket->addPlugin(
|
sprocket->addPlugin(
|
||||||
new MqttPlugin({"mqttSprocket", "192.168.1.2", 1883, "wirelos/mqttSprocket/"}));
|
new MqttPlugin({"clientId", "192.168.1.2", 1883, "some/topic", "myuser", "mypass"}));
|
||||||
|
|
||||||
network = new WiFiNet(
|
network = new WiFiNet(
|
||||||
SPROCKET_MODE,
|
SPROCKET_MODE,
|
||||||
|
|||||||
0
src/examples/chat/config.h
Normal file → Executable file
0
src/examples/chat/config.h
Normal file → Executable file
0
src/examples/chat/main.cpp
Normal file → Executable file
0
src/examples/chat/main.cpp
Normal file → Executable file
Reference in New Issue
Block a user