Closed rafek00 closed 5 years ago
Yes , it is possible. I did it yesterday. I can paste the code snipplet if you like .
`settings.h
...
/****** MQTT Settings ********************************************************/
const char* mqtt_server = "192.168.4.21"; // MQTT Server (broker) address
const char* mqtt_user = "iobroker"; // MQTT Server (broker) userid
const char* mqtt_pass = "iobroker"; // MQTT Server (broker) password
...
`
und
solar-wifi .. .ino
...
void connect_to_MQTT() {
Serial.print("---> Connecting to MQTT, ");
client.setServer(mqtt_server, 1883);
while (!client.connected()) {
Serial.println("reconnecting MQTT...");
reconnect();
}
Serial.println("MQTT connected ok.");
} //end connect_to_MQTT
void reconnect() {
// Loop until we're reconnected
while (!client.connected()) {
Serial.print("Attempting MQTT connection with ");
// Create a random client ID
String clientId = "ESP8266Client-";
clientId += String(random(0xffff), HEX);
Serial.print(clientId.c_str());
// Attempt to connect
if (client.connect(clientId.c_str(), mqtt_user, mqtt_pass )) {
Serial.println("connected");
// Once connected, publish an announcement...
client.publish("solarweatherstation/debug", "SolarWeatherstation: client started...");
delay(50);
} else {
Serial.print(" ...failed, rc=");
Serial.print(client.state());
Serial.println(" try again in 5 seconds");
// Wait 5 seconds before retrying
delay(5000);
}
}
} //end void reconnect*/
...
Thank you Frank.
3KUdelta - Tkanks a lot for sharing the code. I added a DHT22 Sensor and would like to transfer data to an INFLUX DB. This will be my next step. I am waiting for my UV sensor, which I would like to integrate. Maybe I can share this with you. Greeting from Germany
Hi Frank. The easiest way to do this if you just fork my work and put your solution there. I am happy to do a comment on the main page to describe your add-ons.
Solar-WiFi-Weather-Station-V2.3MQTT-FU.zip
Hi 3KUdelta, thank you very much for your offer to fork your briliant solution. In the moment we are going to vacation. When I am back I have to learn how to do it and whcih tool I should use to access gitub for forking. I guess there is a way to sync the code from my laptop.
Hello, would it be possible to expand MQTT version, with user support and password ?