mqtt clientid done right
This commit is contained in:
parent
23fa620aa6
commit
1d4f406dbb
|
|
@ -16,6 +16,7 @@ void mqttCallback(char* topic, byte* payload, unsigned int length) {
|
||||||
Serial.println();
|
Serial.println();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char buffer[21];
|
||||||
void MQTT::init(const char* host, 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)
|
||||||
{
|
{
|
||||||
WiFi.hostByName(host, this->ip);
|
WiFi.hostByName(host, this->ip);
|
||||||
|
|
@ -26,8 +27,8 @@ void MQTT::init(const char* host, uint16_t port, const char* id, const char *use
|
||||||
|
|
||||||
Serial.println("[MQTT] pubsub client");
|
Serial.println("[MQTT] pubsub client");
|
||||||
mqttClient.setServer(ip, port);
|
mqttClient.setServer(ip, port);
|
||||||
char buffer[20];
|
|
||||||
snprintf(buffer, 20, "%s%6ld", id, random(0, 1000));
|
snprintf(buffer, 20, "%s%6ld", id, random(0, 1000));
|
||||||
|
buffer[20] = 0;
|
||||||
mqttClient.setClientId(buffer);
|
mqttClient.setClientId(buffer);
|
||||||
if (strlen(password) > 0) {
|
if (strlen(password) > 0) {
|
||||||
mqttClient.setCredentials(username, password);
|
mqttClient.setCredentials(username, password);
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
const char *version_name = "rdzTTGOsonde";
|
const char *version_name = "rdzTTGOsonde";
|
||||||
const char *version_id = "devel20211002";
|
const char *version_id = "devel20211003";
|
||||||
const int SPIFFS_MAJOR=2;
|
const int SPIFFS_MAJOR=2;
|
||||||
const int SPIFFS_MINOR=16;
|
const int SPIFFS_MINOR=16;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue