Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
7c31b15de2 | |||
01575e2937 | |||
f9a92bceca |
@ -30,6 +30,7 @@ It is also possible to send the same json configuration on mqtt using topic *lig
|
|||||||
"mqttuser": "mymqtt_user",
|
"mqttuser": "mymqtt_user",
|
||||||
"mqttpass": "7j%!fs#",
|
"mqttpass": "7j%!fs#",
|
||||||
"mqttport": "1883",
|
"mqttport": "1883",
|
||||||
|
"guestureEnabled" : "true"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -61,6 +62,9 @@ Meant for debugging there is a topic ***light/bedlamp/debug***. This topic will
|
|||||||
* Uptime (s) is sent repeatedly at every *state* update (default each 120s)
|
* Uptime (s) is sent repeatedly at every *state* update (default each 120s)
|
||||||
* All incoming topics and payloads
|
* All incoming topics and payloads
|
||||||
|
|
||||||
|
### Guesture Enable topic
|
||||||
|
Topic to activate or deactivate guestures for controlling the lamp ***light/bedlamp/guestureenabled/set***. Payload **1** or **0**.
|
||||||
|
|
||||||
## Home Assistant
|
## Home Assistant
|
||||||
Adjust the name and topics to suite your configuration
|
Adjust the name and topics to suite your configuration
|
||||||
```
|
```
|
||||||
|
@ -13,6 +13,7 @@ public:
|
|||||||
char mqttUser[10];
|
char mqttUser[10];
|
||||||
char mqttPass[20];
|
char mqttPass[20];
|
||||||
int mqttPort;
|
int mqttPort;
|
||||||
|
bool gestureEnabled;
|
||||||
uint8_t brightness;
|
uint8_t brightness;
|
||||||
std::array<uint8_t, 3> color;
|
std::array<uint8_t, 3> color;
|
||||||
} Data;
|
} Data;
|
||||||
@ -23,6 +24,8 @@ public:
|
|||||||
ConfigTopic,
|
ConfigTopic,
|
||||||
AvailabilityTopic,
|
AvailabilityTopic,
|
||||||
DebugTopic,
|
DebugTopic,
|
||||||
|
InGuestureEnabled,
|
||||||
|
OutGuestureEnabled,
|
||||||
};
|
};
|
||||||
|
|
||||||
static Config& Instance();
|
static Config& Instance();
|
||||||
|
@ -72,6 +72,14 @@ String Config::getMqttTopic(MqttTopic topic)
|
|||||||
break;
|
break;
|
||||||
case (MqttTopic::DebugTopic):
|
case (MqttTopic::DebugTopic):
|
||||||
return String("light/" + String(data.hostname) + "/debug");
|
return String("light/" + String(data.hostname) + "/debug");
|
||||||
|
break;
|
||||||
|
case (MqttTopic::InGuestureEnabled):
|
||||||
|
return String("light/" + String(data.hostname) +
|
||||||
|
"/guestureenabled/set");
|
||||||
|
break;
|
||||||
|
case (MqttTopic::OutGuestureEnabled):
|
||||||
|
return String("light/" + String(data.hostname) + "/guestureenabled");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
25
src/main.cpp
25
src/main.cpp
@ -55,6 +55,7 @@ void setConfig(String jsonConfig)
|
|||||||
String mqttUser = obj["mqttuser"];
|
String mqttUser = obj["mqttuser"];
|
||||||
String mqttPass = obj["mqttpass"];
|
String mqttPass = obj["mqttpass"];
|
||||||
int mqttPort = obj["mqttport"];
|
int mqttPort = obj["mqttport"];
|
||||||
|
bool gestureEnabled = obj["gestureEnabled"];
|
||||||
Serial.printf("Parsed hostname: %s, ssid: %s, pass: %s\n",
|
Serial.printf("Parsed hostname: %s, ssid: %s, pass: %s\n",
|
||||||
hostname.c_str(),
|
hostname.c_str(),
|
||||||
ssid.c_str(),
|
ssid.c_str(),
|
||||||
@ -74,6 +75,8 @@ void setConfig(String jsonConfig)
|
|||||||
sizeof(config.data.mqttPass));
|
sizeof(config.data.mqttPass));
|
||||||
config.data.mqttPort = mqttPort;
|
config.data.mqttPort = mqttPort;
|
||||||
|
|
||||||
|
config.data.gestureEnabled = gestureEnabled;
|
||||||
|
|
||||||
config.write();
|
config.write();
|
||||||
|
|
||||||
Serial.println("rebooting...");
|
Serial.println("rebooting...");
|
||||||
@ -92,6 +95,7 @@ String configToString()
|
|||||||
jsonConfig["mqttuser"] = config.data.mqttUser;
|
jsonConfig["mqttuser"] = config.data.mqttUser;
|
||||||
jsonConfig["mqttpass"] = config.data.mqttPass;
|
jsonConfig["mqttpass"] = config.data.mqttPass;
|
||||||
jsonConfig["mqttport"] = config.data.mqttPort;
|
jsonConfig["mqttport"] = config.data.mqttPort;
|
||||||
|
jsonConfig["guestureenabled"] = config.data.gestureEnabled;
|
||||||
jsonConfig["brightness"] = config.data.brightness;
|
jsonConfig["brightness"] = config.data.brightness;
|
||||||
JsonArray color = jsonConfig.createNestedArray("color");
|
JsonArray color = jsonConfig.createNestedArray("color");
|
||||||
color.add(config.data.color.at(0));
|
color.add(config.data.color.at(0));
|
||||||
@ -141,6 +145,9 @@ void mqttPublishState()
|
|||||||
mqttClient.publish(
|
mqttClient.publish(
|
||||||
config.getMqttTopic(Config::MqttTopic::AvailabilityTopic).c_str(),
|
config.getMqttTopic(Config::MqttTopic::AvailabilityTopic).c_str(),
|
||||||
"1");
|
"1");
|
||||||
|
mqttClient.publish(
|
||||||
|
config.getMqttTopic(Config::MqttTopic::OutGuestureEnabled).c_str(),
|
||||||
|
String(config.data.gestureEnabled).c_str());
|
||||||
|
|
||||||
auto uptime = millis() / 1000;
|
auto uptime = millis() / 1000;
|
||||||
mqttClient.publish(
|
mqttClient.publish(
|
||||||
@ -164,6 +171,9 @@ void mqttConnect()
|
|||||||
config.getMqttTopic(Config::MqttTopic::InTopic).c_str());
|
config.getMqttTopic(Config::MqttTopic::InTopic).c_str());
|
||||||
mqttClient.subscribe(
|
mqttClient.subscribe(
|
||||||
config.getMqttTopic(Config::MqttTopic::ConfigTopic).c_str());
|
config.getMqttTopic(Config::MqttTopic::ConfigTopic).c_str());
|
||||||
|
mqttClient.subscribe(
|
||||||
|
config.getMqttTopic(Config::MqttTopic::InGuestureEnabled)
|
||||||
|
.c_str());
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
Serial.printf("failed, rc=%d\n", mqttClient.state());
|
Serial.printf("failed, rc=%d\n", mqttClient.state());
|
||||||
@ -186,6 +196,13 @@ void mqttCallback(char* topic, byte* payload, unsigned int length)
|
|||||||
} else if (sTopic == config.getMqttTopic(Config::ConfigTopic))
|
} else if (sTopic == config.getMqttTopic(Config::ConfigTopic))
|
||||||
{
|
{
|
||||||
setConfig(msg);
|
setConfig(msg);
|
||||||
|
} else if (sTopic == config.getMqttTopic(Config::InGuestureEnabled))
|
||||||
|
{
|
||||||
|
config.data.gestureEnabled = (msg == "1");
|
||||||
|
config.write();
|
||||||
|
mqttClient.publish(
|
||||||
|
config.getMqttTopic(Config::MqttTopic::OutGuestureEnabled).c_str(),
|
||||||
|
String(config.data.gestureEnabled).c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
mqttClient.publish(
|
mqttClient.publish(
|
||||||
@ -364,9 +381,11 @@ void evalDist(SensorData data)
|
|||||||
|
|
||||||
void slowLoop()
|
void slowLoop()
|
||||||
{
|
{
|
||||||
SensorData data = getDist();
|
if (config.data.gestureEnabled)
|
||||||
|
{
|
||||||
evalDist(data);
|
SensorData data = getDist();
|
||||||
|
evalDist(data);
|
||||||
|
}
|
||||||
|
|
||||||
myLed.run();
|
myLed.run();
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
const float minBrightness = 0.1;
|
const float minBrightness = 0.05;
|
||||||
}
|
}
|
||||||
|
|
||||||
MyLed::MyLed(int ledPin, int ledCount, bool effects)
|
MyLed::MyLed(int ledPin, int ledCount, bool effects)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user