Added ota hostname

This commit is contained in:
Nis Wechselberg 2017-09-26 00:11:17 +02:00
parent b32b5dbdee
commit 001219c80e
11 changed files with 329 additions and 16 deletions

View file

@ -2,14 +2,21 @@
const char* ssid = "http://kiel.freifunk.net/";
const char* password = "";
// OTA Hostname
const char* ota_hostname = "RGBControl";
// MQTT Broker
const char* mqtt_server = "broker.mqtt-dashboard.com";
// Device identification
const char* mqtt_device = "esp8266client"
const char* mqtt_device = "esp8266RGBControl"
// MQTT topics
const char* mqtt_topic_power = "esp8266client/power";
const char* mqtt_topic_color = "esp8266client/color";
const char* mqtt_topic_breathe = "esp8266client/breathe";
const char* mqtt_topic_cycle = "esp8266client/cycle";
const char* mqtt_topic_power = "RGBControl/power";
const char* mqtt_topic_powerState = "RGBControl/powerState";
const char* mqtt_topic_color = "RGBControl/color";
const char* mqtt_topic_colorState = "RGBControl/colorState";
const char* mqtt_topic_breathe = "RGBControl/breathe";
const char* mqtt_topic_breatheState = "RGBControl/breatheState";
const char* mqtt_topic_cycle = "RGBControl/cycle";
const char* mqtt_topic_cycleState = "RGBControl/cycleState";

View file

@ -78,6 +78,13 @@ unsigned char decColor = 0;
// Timestamp for last color update
unsigned long lastColorUpdate = 0;
// Timestamp for last publish
unsigned long lastMsg = 0;
unsigned long publishInterval = 5000;
// Message buffer
char msg[50];
/*
* Initial setup for arduino
*/
@ -117,7 +124,7 @@ void setup_wifi() {
Serial.print("My IP address: ");
Serial.println(WiFi.localIP());
ArduinoOTA.setHostname("esp8266-Lighting2");
ArduinoOTA.setHostname(ota_hostname);
ArduinoOTA.begin();
}
@ -293,6 +300,20 @@ void setColor() {
}
}
void publishState() {
snprintf(msg, 49, "%d", powerFactor);
client.publish(mqtt_topic_powerState, msg);
snprintf(msg, 49, "#%02X%02X%02X", rgbColor[0], rgbColor[1], rgbColor[2]);
client.publish(mqtt_topic_colorState, msg);
snprintf(msg, 49, "%d", doBreathe);
client.publish(mqtt_topic_breatheState, msg);
snprintf(msg, 49, "%d", doColorCycle);
client.publish(mqtt_topic_cycleState, msg);
}
void loop() {
// Check OTA update
ArduinoOTA.handle();
@ -302,11 +323,16 @@ void loop() {
}
client.loop();
unsigned long now = millis();
if (isPowerSet & isColorSet & isCycleSet & isBreatheSet) {
unsigned long now = millis();
if (now - lastColorUpdate > 30) {
lastColorUpdate = now;
updateLight();
}
}
if (now - lastMsg > publishInterval) {
lastMsg = now;
publishState();
}
}