20 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
20 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
21 *****************************************************************************/ |
21 *****************************************************************************/ |
22 |
22 |
23 #include "thermferm.h" |
23 #include "thermferm.h" |
24 #include "rdconfig.h" |
24 #include "rdconfig.h" |
25 #include "logger.h" |
|
26 #include "devices.h" |
25 #include "devices.h" |
27 #include "xutil.h" |
26 #include "xutil.h" |
28 #include "mqtt.h" |
27 #include "mqtt.h" |
29 |
28 |
30 extern sys_config Config; |
29 extern sys_config Config; |
151 |
150 |
152 |
151 |
153 |
152 |
154 void my_log_callback(struct mosquitto *my_mosq, void *obj, int level, const char *str) |
153 void my_log_callback(struct mosquitto *my_mosq, void *obj, int level, const char *str) |
155 { |
154 { |
156 // syslog(LOG_NOTICE, "MQTT: %s", str); |
155 // if (debug) |
157 if (debug) |
156 // fprintf(stdout, "MQTT: %s\n", str); |
158 fprintf(stdout, "MQTT: %s\n", str); |
|
159 } |
157 } |
160 |
158 |
161 |
159 |
162 |
160 |
163 void my_message_callback(struct mosquitto *my_mosq, void *userdata, const struct mosquitto_message *message) |
161 void my_message_callback(struct mosquitto *my_mosq, void *userdata, const struct mosquitto_message *message) |
236 if (strcmp((char *)json_object_get_string(val), UNITMODE[i]) == 0) { |
234 if (strcmp((char *)json_object_get_string(val), UNITMODE[i]) == 0) { |
237 if (unit->mode != i) { |
235 if (unit->mode != i) { |
238 unit->mqtt_flag |= MQTT_FLAG_DATA; |
236 unit->mqtt_flag |= MQTT_FLAG_DATA; |
239 /* Initialize log if the unit is turned on */ |
237 /* Initialize log if the unit is turned on */ |
240 if ((unit->mode == UNITMODE_OFF) && (i != UNITMODE_OFF)) { |
238 if ((unit->mode == UNITMODE_OFF) && (i != UNITMODE_OFF)) { |
241 initlog(unit->product_code, unit->product_name); |
|
242 unit->mqtt_flag |= MQTT_FLAG_BIRTH; |
239 unit->mqtt_flag |= MQTT_FLAG_BIRTH; |
243 } else if ((unit->mode != UNITMODE_OFF) && (i == UNITMODE_OFF)) { |
240 } else if ((unit->mode != UNITMODE_OFF) && (i == UNITMODE_OFF)) { |
244 unit->mqtt_flag |= MQTT_FLAG_DEATH; |
241 unit->mqtt_flag |= MQTT_FLAG_DEATH; |
245 } |
242 } |
246 if (i == UNITMODE_PROFILE) { |
243 if (i == UNITMODE_PROFILE) { |
440 } |
437 } |
441 free(cmd); |
438 free(cmd); |
442 cmd = NULL; |
439 cmd = NULL; |
443 } |
440 } |
444 } else if (json_object_object_get_ex(profile, "uuid", &profile1)) { |
441 } else if (json_object_object_get_ex(profile, "uuid", &profile1)) { |
445 // syslog(LOG_NOTICE, "profile new profile"); |
|
446 if ((unit->prof_state == PROFILE_OFF) || (unit->prof_state == PROFILE_DONE) || (unit->prof_state == PROFILE_ABORT)) { |
442 if ((unit->prof_state == PROFILE_OFF) || (unit->prof_state == PROFILE_DONE) || (unit->prof_state == PROFILE_ABORT)) { |
447 if (unit->profile_uuid) |
443 if (unit->profile_uuid) |
448 free(unit->profile_uuid); |
444 free(unit->profile_uuid); |
449 if (unit->profile_name) |
445 if (unit->profile_name) |
450 free(unit->profile_name); |
446 free(unit->profile_name); |
456 free(step); |
452 free(step); |
457 } |
453 } |
458 } |
454 } |
459 unit->profile_steps = NULL; |
455 unit->profile_steps = NULL; |
460 unit->profile_duration = unit->profile_totalsteps = 0; |
456 unit->profile_duration = unit->profile_totalsteps = 0; |
461 // syslog(LOG_NOTICE, "profile new profile: old cleared"); |
|
462 |
|
463 unit->profile_uuid = xstrcpy((char *)json_object_get_string(profile1)); |
457 unit->profile_uuid = xstrcpy((char *)json_object_get_string(profile1)); |
464 if (json_object_object_get_ex(profile, "name", &val)) { |
458 if (json_object_object_get_ex(profile, "name", &val)) { |
465 unit->profile_name = xstrcpy((char *)json_object_get_string(val)); |
459 unit->profile_name = xstrcpy((char *)json_object_get_string(val)); |
466 } |
460 } |
467 if (json_object_object_get_ex(profile, "inittemp", &setpoint)) { |
461 if (json_object_object_get_ex(profile, "inittemp", &setpoint)) { |