Browse Source

Change MQTT retain flag, QoS and keep alive time from web UI (#321)

fastled
Xose Pérez 6 years ago
parent
commit
ae979bc7b3
5 changed files with 2921 additions and 2886 deletions
  1. BIN
      code/espurna/data/index.html.gz
  2. +23
    -12
      code/espurna/mqtt.ino
  3. +2874
    -2870
      code/espurna/static/index.html.gz.h
  4. +2
    -2
      code/html/checkboxes.css
  5. +22
    -2
      code/html/index.html

BIN
code/espurna/data/index.html.gz View File


+ 23
- 12
code/espurna/mqtt.ino View File

@ -35,6 +35,9 @@ WiFiClientSecure _mqtt_client_secure;
bool _mqtt_enabled = MQTT_ENABLED;
bool _mqtt_use_json = false;
unsigned long _mqtt_reconnect_delay = MQTT_RECONNECT_DELAY_MIN;
unsigned char _mqtt_qos = MQTT_QOS;
bool _mqtt_retain = MQTT_RETAIN;
unsigned char _mqtt_keepalive = MQTT_KEEPALIVE;
String _mqtt_topic;
String _mqtt_setter;
String _mqtt_getter;
@ -86,10 +89,10 @@ String mqttSubtopic(char * topic) {
void mqttSendRaw(const char * topic, const char * message) {
if (_mqtt.connected()) {
#if MQTT_USE_ASYNC
unsigned int packetId = _mqtt.publish(topic, MQTT_QOS, MQTT_RETAIN, message);
unsigned int packetId = _mqtt.publish(topic, _mqtt_qos, _mqtt_retain, message);
DEBUG_MSG_P(PSTR("[MQTT] Sending %s => %s (PID %d)\n"), topic, message, packetId);
#else
_mqtt.publish(topic, message, MQTT_RETAIN);
_mqtt.publish(topic, message, _mqtt_retain);
DEBUG_MSG_P(PSTR("[MQTT] Sending %s => %s\n"), topic, message);
#endif
}
@ -172,10 +175,10 @@ void mqttSend(const char * topic, unsigned int index, const char * message) {
void mqttSubscribeRaw(const char * topic) {
if (_mqtt.connected() && (strlen(topic) > 0)) {
#if MQTT_USE_ASYNC
unsigned int packetId = _mqtt.subscribe(topic, MQTT_QOS);
unsigned int packetId = _mqtt.subscribe(topic, _mqtt_qos);
DEBUG_MSG_P(PSTR("[MQTT] Subscribing to %s (PID %d)\n"), topic, packetId);
#else
_mqtt.subscribe(topic, MQTT_QOS);
_mqtt.subscribe(topic, _mqtt_qos);
DEBUG_MSG_P(PSTR("[MQTT] Subscribing to %s\n"), topic);
#endif
}
@ -214,6 +217,9 @@ void _mqttWebSocketOnSend(JsonObject& root) {
root["mqttPort"] = getSetting("mqttPort", MQTT_PORT);
root["mqttUser"] = getSetting("mqttUser");
root["mqttPassword"] = getSetting("mqttPassword");
root["mqttKeep"] = _mqtt_keepalive;
root["mqttRetain"] = _mqtt_retain;
root["mqttQOS"] = _mqtt_qos;
#if ASYNC_TCP_SSL_ENABLED
root["mqttsslVisible"] = 1;
root["mqttUseSSL"] = getSetting("mqttUseSSL", 0).toInt() == 1;
@ -385,8 +391,8 @@ void mqttConnect() {
#if MQTT_USE_ASYNC
_mqtt.setServer(host, port);
_mqtt.setKeepAlive(MQTT_KEEPALIVE).setCleanSession(false);
_mqtt.setWill(_mqtt_will, MQTT_QOS, MQTT_RETAIN, "0");
_mqtt.setKeepAlive(_mqtt_keepalive).setCleanSession(false);
_mqtt.setWill(_mqtt_will, _mqtt_qos, _mqtt_retain, "0");
if ((strlen(_mqtt_user) > 0) && (strlen(_mqtt_pass) > 0)) {
DEBUG_MSG_P(PSTR("[MQTT] Connecting as user %s\n"), _mqtt_user);
_mqtt.setCredentials(_mqtt_user, _mqtt_pass);
@ -409,8 +415,8 @@ void mqttConnect() {
#endif // ASYNC_TCP_SSL_ENABLED
DEBUG_MSG_P(PSTR("[MQTT] Will topic: %s\n"), _mqtt_will);
DEBUG_MSG_P(PSTR("[MQTT] QoS: %d\n"), MQTT_QOS);
DEBUG_MSG_P(PSTR("[MQTT] Retain flag: %d\n"), MQTT_RETAIN);
DEBUG_MSG_P(PSTR("[MQTT] QoS: %d\n"), _mqtt_qos);
DEBUG_MSG_P(PSTR("[MQTT] Retain flag: %d\n"), _mqtt_retain ? 1 : 0);
_mqtt.connect();
@ -459,14 +465,14 @@ void mqttConnect() {
if ((strlen(_mqtt_user) > 0) && (strlen(_mqtt_pass) > 0)) {
DEBUG_MSG_P(PSTR("[MQTT] Connecting as user %s\n"), _mqtt_user);
response = _mqtt.connect(getIdentifier().c_str(), _mqtt_user, _mqtt_pass, _mqtt_will, MQTT_QOS, MQTT_RETAIN, "0");
response = _mqtt.connect(getIdentifier().c_str(), _mqtt_user, _mqtt_pass, _mqtt_will, _mqtt_qos, _mqtt_retain, "0");
} else {
response = _mqtt.connect(getIdentifier().c_str(), _mqtt_will, MQTT_QOS, MQTT_RETAIN, "0");
response = _mqtt.connect(getIdentifier().c_str(), _mqtt_will, _mqtt_qos, _mqtt_retain, "0");
}
DEBUG_MSG_P(PSTR("[MQTT] Will topic: %s\n"), _mqtt_will);
DEBUG_MSG_P(PSTR("[MQTT] QoS: %d\n"), MQTT_QOS);
DEBUG_MSG_P(PSTR("[MQTT] Retain flag: %d\n"), MQTT_RETAIN);
DEBUG_MSG_P(PSTR("[MQTT] QoS: %d\n"), _mqtt_qos);
DEBUG_MSG_P(PSTR("[MQTT] Retain flag: %d\n"), _mqtt_retain ? 1 : 0);
}
@ -494,6 +500,11 @@ void mqttConfigure() {
_mqtt_getter = getSetting("mqttGetter", MQTT_USE_GETTER);
_mqtt_forward = !_mqtt_getter.equals(_mqtt_setter);
// MQTT options
_mqtt_qos = getSetting("mqttQOS", MQTT_QOS).toInt();
_mqtt_retain = getSetting("mqttRetain", MQTT_RETAIN).toInt() == 1;
_mqtt_keepalive = getSetting("mqttKeep", MQTT_KEEPALIVE).toInt();
// Enable
if (getSetting("mqttServer", MQTT_SERVER).length() == 0) {
mqttEnabled(false);


+ 2874
- 2870
code/espurna/static/index.html.gz.h
File diff suppressed because it is too large
View File


+ 2
- 2
code/html/checkboxes.css View File

@ -1,10 +1,10 @@
.iPhoneCheckContainer {
-webkit-transform:translate3d(0,0,0);
position: relative;
height: 27px;
height: 30px;
cursor: pointer;
overflow: hidden;
margin-bottom: 10px;
margin: 5px 0 10px 0;
}
.iPhoneCheckContainer input {


+ 22
- 2
code/html/index.html View File

@ -561,9 +561,29 @@
<input class="pure-u-1 pure-u-lg-1-4" name="mqttPassword" type="password" size="20" tabindex="24" placeholder="Leave blank if no pass" autocomplete="false" />
</div>
<div class="pure-g">
<label class="pure-u-1 pure-u-lg-1-4">MQTT QOS</label>
<select class="pure-u-1 pure-u-lg-1-4" name="mqttQOS">
<option value="0">0: At most once</option>
<option value="1">1: At least once</option>
<option value="2">2: Exactly once</option>
</select>
</div>
<div class="pure-g">
<label class="pure-u-1 pure-u-lg-1-4">MQTT Retain</label>
<div class="pure-u-1 pure-u-lg-1-4"><input type="checkbox" name="mqttRetain" tabindex="25" /></div>
</div>
<div class="pure-g">
<label class="pure-u-1 pure-u-lg-1-4">MQTT Keep Alive</label>
<div class="pure-u-1 pure-u-lg-1-4"><input type="number" name="mqttKeep" min="10" max="60" tabindex="25" /></div>
</div>
<div class="pure-g module module-mqttssl">
<div class="pure-u-1 pure-u-lg-1-4"><label>Use secure connection (SSL)</label></div>
<div class="pure-u-1 pure-u-lg-1-4"><input type="checkbox" name="mqttUseSSL" tabindex="25" /></div>
<label class="pure-u-1 pure-u-lg-1-4">Use secure connection (SSL)</label>
<div class="pure-u-1 pure-u-lg-1-4"><input type="checkbox" name="mqttUseSSL" tabindex="26" /></div>
</div>
<div class="pure-g module module-mqttssl">


Loading…
Cancel
Save