Browse Source

Send Thingspeak API key to web UI

i18n
Xose Pérez 6 years ago
parent
commit
e0723f6998
2 changed files with 26 additions and 19 deletions
  1. +4
    -4
      code/espurna/mqtt.ino
  2. +22
    -15
      code/espurna/thinkspeak.ino

+ 4
- 4
code/espurna/mqtt.ino View File

@ -549,8 +549,10 @@ void mqttSetBrokerIfNone(IPAddress ip, unsigned int port) {
void mqttSetup() { void mqttSetup() {
DEBUG_MSG_P(PSTR("[MQTT] MQTT_USE_ASYNC = %d\n"), MQTT_USE_ASYNC);
DEBUG_MSG_P(PSTR("[MQTT] MQTT_AUTOCONNECT = %d\n"), MQTT_AUTOCONNECT);
DEBUG_MSG_P(PSTR("[MQTT] Async %s, Autoconnect %s\n"),
MQTT_USE_ASYNC ? "ENABLED" : "DISABLED",
MQTT_AUTOCONNECT ? "ENABLED" : "DISABLED"
);
#if MQTT_USE_ASYNC #if MQTT_USE_ASYNC
@ -592,8 +594,6 @@ void mqttSetup() {
#else // not MQTT_USE_ASYNC #else // not MQTT_USE_ASYNC
DEBUG_MSG_P(PSTR("[MQTT] Using SYNC MQTT library\n"));
_mqtt.setCallback([](char* topic, byte* payload, unsigned int length) { _mqtt.setCallback([](char* topic, byte* payload, unsigned int length) {
_mqttOnMessage(topic, (char *) payload, length); _mqttOnMessage(topic, (char *) payload, length);
}); });


+ 22
- 15
code/espurna/thinkspeak.ino View File

@ -9,15 +9,15 @@ Copyright (C) 2018 by Xose Pérez <xose dot perez at gmail dot com>
#if THINGSPEAK_SUPPORT #if THINGSPEAK_SUPPORT
#if THINGSPEAK_USE_ASYNC #if THINGSPEAK_USE_ASYNC
#include <ESPAsyncTCP.h>
AsyncClient _tspk_client;
#include <ESPAsyncTCP.h>
AsyncClient _tspk_client;
#else #else
#include <ESP8266WiFi.h>
#if THINGSPEAK_USE_SSL
WiFiClientSecure _tspk_client;
#else
WiFiClient _tspk_client;
#endif
#include <ESP8266WiFi.h>
#if THINGSPEAK_USE_SSL
WiFiClientSecure _tspk_client;
#else
WiFiClient _tspk_client;
#endif
#endif #endif
const char THINGSPEAK_REQUEST_TEMPLATE[] PROGMEM = const char THINGSPEAK_REQUEST_TEMPLATE[] PROGMEM =
@ -41,6 +41,7 @@ void _tspkWebSocketOnSend(JsonObject& root) {
root["tspkVisible"] = 1; root["tspkVisible"] = 1;
root["tspkEnabled"] = getSetting("tspkEnabled", THINGSPEAK_ENABLED).toInt() == 1; root["tspkEnabled"] = getSetting("tspkEnabled", THINGSPEAK_ENABLED).toInt() == 1;
root["tspkKey"] = getSetting("tspkKey");
JsonArray& relays = root.createNestedArray("tspkRelays"); JsonArray& relays = root.createNestedArray("tspkRelays");
for (byte i=0; i<relayCount(); i++) { for (byte i=0; i<relayCount(); i++) {
@ -103,16 +104,18 @@ void _tspkPost(String data) {
}, NULL); }, NULL);
#if ASYNC_TCP_SSL_ENABLED #if ASYNC_TCP_SSL_ENABLED
if (!_tspk_client.connect(THINGSPEAK_HOST, THINGSPEAK_PORT, THINGSPEAK_USE_SSL)) {
#else
if (!_tspk_client.connect(THINGSPEAK_HOST, THINGSPEAK_PORT)) {
#endif
DEBUG_MSG_P(PSTR("[THINGSPEAK] Connection failed\n"));
}
if (!_tspk_client.connect(THINGSPEAK_HOST, THINGSPEAK_PORT, THINGSPEAK_USE_SSL)) {
DEBUG_MSG_P(PSTR("[THINGSPEAK] Connection failed\n"));
}
#else // ASYNC_TCP_SSL_ENABLED
if (!_tspk_client.connect(THINGSPEAK_HOST, THINGSPEAK_PORT)) {
DEBUG_MSG_P(PSTR("[THINGSPEAK] Connection failed\n"));
}
#endif // ASYNC_TCP_SSL_ENABLED
} }
#else // not THINGSPEAK_USE_ASYNC
#else // THINGSPEAK_USE_ASYNC
void _tspkPost(String data) { void _tspkPost(String data) {
@ -210,6 +213,10 @@ void tspkSetup() {
wsOnSendRegister(_tspkWebSocketOnSend); wsOnSendRegister(_tspkWebSocketOnSend);
wsOnAfterParseRegister(_tspkConfigure); wsOnAfterParseRegister(_tspkConfigure);
#endif #endif
DEBUG_MSG_P(PSTR("[THINGSPEAK] Async %s, SSL %s\n"),
THINGSPEAK_USE_ASYNC ? "ENABLED" : "DISABLED",
THINGSPEAK_USE_SSL ? "ENABLED" : "DISABLED"
);
} }
void tspkLoop() { void tspkLoop() {


Loading…
Cancel
Save