-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdesired_speed_MQTT_DS18B20.h
41 lines (34 loc) · 1.2 KB
/
desired_speed_MQTT_DS18B20.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// uint8_t throttleFanspeed=PWM_THROTTLE; // ca 20 % speed
void publishDesSpeed(uint8_t speed){
PWM_THROTTLE = speed;
// todo for test pupose - to write here ist not necessarily correct if standalone ESP866 code control loop of fan speed,
// and MQTT server is only responsible for desired values, limits etc
//analogWrite(pwmGpio, speed);
if (mqttClient.connected()){
mqttClient.publish((MQTT_PUB_DES_PREFIX + MQTT_PUB_FANTHROTTLE_SUFFIX).c_str(), 0, true, String(speed, DEC).c_str());
delay(10);
#if SERIAL_TRACE
Serial.print("desired speed published: ");
Serial.println(PWM_THROTTLE, HEX);
#endif
} else {
Serial.print("MQTT not up - desired speed not published: ");
Serial.println(PWM_THROTTLE, HEX);
}
}
void testDesiredFanspeed(char* payload, char* topic)
{
String strComp((MQTT_PUB_DES_PREFIX + MQTT_PUB_FANTHROTTLE_SUFFIX).c_str());
if (strComp.compareTo(topic)!=0)
{
#if SERIAL_TRACE
Serial.print (topic);
Serial.print(" - testDesiredFanspeed - not mine expected:");
Serial.println(MQTT_PUB_DES_PREFIX + MQTT_PUB_FANTHROTTLE_SUFFIX);
#endif
return;
}
unsigned long lRes = (unsigned)atol(payload);
publishDesSpeed(lRes & 0xFF);
delay(10);
}