77#define MI_USE_SYSTEMTIME
88#define DEBUG_PRINT_TIMES
99// #define DEBUG_PRINT_SETTINGSYNC
10+ // #define MIMQTT_USE_JSON
1011
1112#ifdef _WIN32
1213 // MS compiler does not like PJON_MAX_PACKETS=0 in PJON
@@ -24,7 +25,7 @@ PJONModuleInterface interface("LightCon", // Module name
2425 bus, // PJON bus
2526 " Target:f4" , // Settings
2627 " ETemp:f4" , // Inputs
27- " Temp:f4 TTarg:f4 UTC:u4" ); // Outputs (measurements)
28+ " Temp:f4 TTarg:f4 UTC:u4 ETempOut:f4 " ); // Outputs (measurements)
2829
2930// Settings
3031#define s_target_ix 0
@@ -36,6 +37,7 @@ PJONModuleInterface interface("LightCon", // Module name
3637#define o_temp_ix 0
3738#define o_target_ix 1
3839#define o_utc_ix 2
40+ #define o_externaltemp_ix 3
3941
4042uint32_t last_out_event_time = 0 , last_setting_event_time = 0 , last_control_time = 0 ;
4143
@@ -63,10 +65,12 @@ void lightcontrol() {
6365 }
6466*/
6567 // Step controller towards target temp every second
66- if (mi_interval_elapsed (last_control_time, 1000 )) {
67- temp += (target - temp) / 50.0 ;
68- interface.outputs .set_value (o_temp_ix, temp);
69- interface.outputs .set_event (o_temp_ix);
68+ if (mi_interval_elapsed (last_control_time, 1000 )) {
69+ if (abs (target - temp) > 0 .001f ) {
70+ temp += (target - temp) / 50 .0f ;
71+ interface.outputs .set_value (o_temp_ix, temp);
72+ interface.outputs .set_event (o_temp_ix);
73+ }
7074 }
7175 }
7276}
@@ -77,6 +81,7 @@ void notification_function(NotificationType notification_type, const ModuleInter
7781 interface.outputs .set_value (o_temp_ix, temp);
7882 interface.outputs .set_value (o_target_ix, target);
7983 interface.outputs .set_value (o_utc_ix, interface.get_time_utc_s ());
84+ interface.outputs .set_value (o_externaltemp_ix, interface.inputs .get_float (i_externaltemp_ix));
8085 interface.outputs .set_updated ();
8186 }
8287 else if (notification_type == ntNewInputs) {
0 commit comments