3
3
class photoresistor_sensor_mqtt_v2 : public Usermod
4
4
{
5
5
private:
6
- long update_interval = 3000 ;
7
- float change_threshould = 1 ;
6
+ unsigned long update_interval = 3000 ;
7
+ float change_threshold = 1 ;
8
8
const char *MQTT_TOPIC = " /ldr" ;
9
9
int ldrPin = A0;
10
- long lastTime = 0 ;
11
- int lightValue = 0 ;
10
+ unsigned long lastTime = 0 ;
11
+ unsigned int lightValue = 0 ;
12
12
float lightPercentage = 0 ;
13
13
float lastPercentage = 0 ;
14
14
bool hassDiscoverySent = false ;
@@ -54,9 +54,9 @@ class photoresistor_sensor_mqtt_v2 : public Usermod
54
54
{
55
55
if (initDone && ldrEnabled && WLED_MQTT_CONNECTED)
56
56
{
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
58
58
bool regular_update = (millis () - lastTime) > update_interval;
59
- if (regular_update || force_upadate )
59
+ if (regular_update || force_update )
60
60
{
61
61
lightValue = analogRead (ldrPin);
62
62
#ifdef ESP32
@@ -73,7 +73,7 @@ class photoresistor_sensor_mqtt_v2 : public Usermod
73
73
lightPercentage = ((float )lightValue * -1 + mapping) / (float )mapping * 100 ;
74
74
}
75
75
76
- if (abs (lightPercentage - lastPercentage) > change_threshould || force_upadate )
76
+ if (abs (lightPercentage - lastPercentage) > change_threshold || force_update )
77
77
{
78
78
if (WLED_MQTT_CONNECTED)
79
79
{
@@ -97,7 +97,7 @@ class photoresistor_sensor_mqtt_v2 : public Usermod
97
97
top[" LDR Pin" ] = ldrPin;
98
98
top[" LDR update interval" ] = update_interval;
99
99
top[" LDR inverted" ] = inverted;
100
- top[" change threshould" ] = change_threshould ;
100
+ top[" change threshould" ] = change_threshold ;
101
101
}
102
102
103
103
bool readFromConfig (JsonObject &root)
@@ -109,7 +109,7 @@ class photoresistor_sensor_mqtt_v2 : public Usermod
109
109
configComplete &= getJsonValue (top[" LDR Pin" ], ldrPin);
110
110
configComplete &= getJsonValue (top[" LDR update interval" ], update_interval);
111
111
configComplete &= getJsonValue (top[" LDR inverted" ], inverted);
112
- configComplete &= getJsonValue (top[" change threshould" ], change_threshould );
112
+ configComplete &= getJsonValue (top[" change threshould" ], change_threshold );
113
113
// pin changed - un-register previous pin, register new pin
114
114
PinManager::deallocatePin (oldLdrPin, PinOwner::UM_PHOTO_RESISTOR_MQTT);
115
115
if (ldrEnabled && ldrPin > 0 )
@@ -137,8 +137,8 @@ class photoresistor_sensor_mqtt_v2 : public Usermod
137
137
JsonArray LDR_interval = user.createNestedArray (" LDR interval" );
138
138
LDR_interval.add (update_interval);
139
139
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 );
142
142
}
143
143
144
144
uint16_t getId ()
@@ -183,7 +183,11 @@ class photoresistor_sensor_mqtt_v2 : public Usermod
183
183
device[F (" mf" )] = F (WLED_BRAND);
184
184
device[F (" mdl" )] = F (WLED_PRODUCT_NAME);
185
185
device[F (" sw" )] = versionString;
186
+ #ifdef ESP32
186
187
device[F (" hw_version" )] = F (" esp32" );
188
+ #else
189
+ device[F (" hw_version" )] = F (" esp8266" );
190
+ #endif
187
191
JsonArray connections = device[F (" connections" )].createNestedArray ();
188
192
connections.add (F (" mac" ));
189
193
connections.add (WiFi.macAddress ());
0 commit comments