Skip to content

Commit c1c89fb

Browse files
committed
fixed typos in mqtt ldr v2
1 parent 58b51e3 commit c1c89fb

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

usermods/photoresistor_sensor_mqtt_v2/photoresistor_sensor_mqtt_v2.cpp

+15-11
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
class photoresistor_sensor_mqtt_v2 : public Usermod
44
{
55
private:
6-
long update_interval = 3000;
7-
float change_threshould = 1;
6+
unsigned long update_interval = 3000;
7+
float change_threshold = 1;
88
const char *MQTT_TOPIC = "/ldr";
99
int ldrPin = A0;
10-
long lastTime = 0;
11-
int lightValue = 0;
10+
unsigned long lastTime = 0;
11+
unsigned int lightValue = 0;
1212
float lightPercentage = 0;
1313
float lastPercentage = 0;
1414
bool hassDiscoverySent = false;
@@ -54,9 +54,9 @@ class photoresistor_sensor_mqtt_v2 : public Usermod
5454
{
5555
if (initDone && ldrEnabled && WLED_MQTT_CONNECTED)
5656
{
57-
bool force_upadate = (millis() - lastTime) > (update_interval * 100); // to keep the mqtt alive if the light is not changing
57+
bool force_update = (millis() - lastTime) > (update_interval * 100); // to keep the mqtt alive if the light is not changing
5858
bool regular_update = (millis() - lastTime) > update_interval;
59-
if (regular_update || force_upadate)
59+
if (regular_update || force_update)
6060
{
6161
lightValue = analogRead(ldrPin);
6262
#ifdef ESP32
@@ -73,7 +73,7 @@ class photoresistor_sensor_mqtt_v2 : public Usermod
7373
lightPercentage = ((float)lightValue * -1 + mapping) / (float)mapping * 100;
7474
}
7575

76-
if (abs(lightPercentage - lastPercentage) > change_threshould || force_upadate)
76+
if (abs(lightPercentage - lastPercentage) > change_threshold || force_update)
7777
{
7878
if (WLED_MQTT_CONNECTED)
7979
{
@@ -97,7 +97,7 @@ class photoresistor_sensor_mqtt_v2 : public Usermod
9797
top["LDR Pin"] = ldrPin;
9898
top["LDR update interval"] = update_interval;
9999
top["LDR inverted"] = inverted;
100-
top["change threshould"] = change_threshould;
100+
top["change threshould"] = change_threshold;
101101
}
102102

103103
bool readFromConfig(JsonObject &root)
@@ -109,7 +109,7 @@ class photoresistor_sensor_mqtt_v2 : public Usermod
109109
configComplete &= getJsonValue(top["LDR Pin"], ldrPin);
110110
configComplete &= getJsonValue(top["LDR update interval"], update_interval);
111111
configComplete &= getJsonValue(top["LDR inverted"], inverted);
112-
configComplete &= getJsonValue(top["change threshould"], change_threshould);
112+
configComplete &= getJsonValue(top["change threshould"], change_threshold);
113113
// pin changed - un-register previous pin, register new pin
114114
PinManager::deallocatePin(oldLdrPin, PinOwner::UM_PHOTO_RESISTOR_MQTT);
115115
if (ldrEnabled && ldrPin > 0)
@@ -137,8 +137,8 @@ class photoresistor_sensor_mqtt_v2 : public Usermod
137137
JsonArray LDR_interval = user.createNestedArray("LDR interval");
138138
LDR_interval.add(update_interval);
139139

140-
JsonArray LDR_change_threshould = user.createNestedArray("change threshould");
141-
LDR_change_threshould.add(change_threshould);
140+
JsonArray LDR_change_threshold = user.createNestedArray("change threshould");
141+
LDR_change_threshold.add(change_threshold);
142142
}
143143

144144
uint16_t getId()
@@ -183,7 +183,11 @@ class photoresistor_sensor_mqtt_v2 : public Usermod
183183
device[F("mf")] = F(WLED_BRAND);
184184
device[F("mdl")] = F(WLED_PRODUCT_NAME);
185185
device[F("sw")] = versionString;
186+
#ifdef ESP32
186187
device[F("hw_version")] = F("esp32");
188+
#else
189+
device[F("hw_version")] = F("esp8266");
190+
#endif
187191
JsonArray connections = device[F("connections")].createNestedArray();
188192
connections.add(F("mac"));
189193
connections.add(WiFi.macAddress());

0 commit comments

Comments
 (0)