kopia lustrzana https://github.com/dl9rdz/rdz_ttgo_sonde
finalize
rodzic
2a43004b71
commit
b268754b66
|
@ -478,7 +478,7 @@ struct st_configitems config_list[] = {
|
|||
/* MQTT */
|
||||
{"mqtt.active", "MQTT Active (needs reboot)", 0, &sonde.config.mqtt.active},
|
||||
{"mqtt.id", "MQTT client ID", 63, &sonde.config.mqtt.id},
|
||||
{"mqtt.host", "MQTT server IP address", 63, &sonde.config.mqtt.host},
|
||||
{"mqtt.host", "MQTT server hostname", 63, &sonde.config.mqtt.host},
|
||||
{"mqtt.port", "MQTT Port", 0, &sonde.config.mqtt.port},
|
||||
{"mqtt.username", "MQTT Username", 63, &sonde.config.mqtt.username},
|
||||
{"mqtt.password", "MQTT Password", 63, &sonde.config.mqtt.password},
|
||||
|
|
|
@ -101,10 +101,10 @@ tcp.idformat=0
|
|||
# data not sanitized / quality checked, outliers not filtered out
|
||||
mqtt.active=0
|
||||
mqtt.id=rdz_sonde_server
|
||||
mqtt.ip=/0
|
||||
mqtt.ip=
|
||||
mqtt.port=1883
|
||||
mqtt.username=/0
|
||||
mqtt.password=/0
|
||||
mqtt.username=
|
||||
mqtt.password=
|
||||
mqtt.prefix=rdz_sonde_server/
|
||||
#-------------------------------#
|
||||
# EOF
|
||||
|
|
|
@ -2,6 +2,9 @@
|
|||
#include "mqtt.h"
|
||||
#include <WiFi.h>
|
||||
#include <AsyncMqttClient.h>
|
||||
#include <ESPmDNS.h>
|
||||
|
||||
TimerHandle_t mqttReconnectTimer;
|
||||
|
||||
void mqttCallback(char* topic, byte* payload, unsigned int length) {
|
||||
Serial.print("Message arrived [");
|
||||
|
@ -13,10 +16,9 @@ void mqttCallback(char* topic, byte* payload, unsigned int length) {
|
|||
Serial.println();
|
||||
}
|
||||
|
||||
|
||||
void MQTT::init(const char* ip, uint16_t port, const char* id, const char *username, const char *password, const char *prefix)
|
||||
void MQTT::init(const char* host, uint16_t port, const char* id, const char *username, const char *password, const char *prefix)
|
||||
{
|
||||
this->ip = this->ip.fromString(ip);
|
||||
WiFi.hostByName(host, this->ip);
|
||||
this->port = port;
|
||||
this->username = username;
|
||||
this->password = password;
|
||||
|
@ -32,9 +34,6 @@ void MQTT::init(const char* ip, uint16_t port, const char* id, const char *usern
|
|||
if (strlen(password) > 0) {
|
||||
mqttClient.setCredentials(username, password);
|
||||
}
|
||||
mqttClient.connect();
|
||||
|
||||
//mqttReconnectTimer = xTimerCreate("mqttTimer", pdMS_TO_TICKS(2000), pdFALSE, (void*)0, connectToMqtt);
|
||||
}
|
||||
|
||||
void MQTT::connectToMqtt() {
|
||||
|
@ -44,6 +43,8 @@ void MQTT::connectToMqtt() {
|
|||
|
||||
void MQTT::publishUptime()
|
||||
{
|
||||
mqttClient.connect(); // ensure we've got connection
|
||||
|
||||
Serial.println("[MQTT] writing");
|
||||
char payload[12];
|
||||
snprintf(payload, 12, "%lu", millis());
|
||||
|
@ -54,6 +55,8 @@ void MQTT::publishUptime()
|
|||
|
||||
void MQTT::publishPacket(SondeInfo *s)
|
||||
{
|
||||
mqttClient.connect(); // ensure we've got connection
|
||||
|
||||
char payload[1024];
|
||||
snprintf(payload, 1024, "{"
|
||||
"\"active\": %d,"
|
||||
|
|
|
@ -18,7 +18,7 @@ public:
|
|||
const char *password;
|
||||
const char *prefix;
|
||||
|
||||
void init(const char *ip, uint16_t port, const char *id, const char *username, const char *password, const char *prefix);
|
||||
void init(const char *host, uint16_t port, const char *id, const char *username, const char *password, const char *prefix);
|
||||
void publishPacket(SondeInfo *s);
|
||||
void publishUptime();
|
||||
private:
|
||||
|
|
Ładowanie…
Reference in New Issue