35 static int last_mid = -1; |
35 static int last_mid = -1; |
36 static int last_mid_sent = -1; |
36 static int last_mid_sent = -1; |
37 static bool connected = true; |
37 static bool connected = true; |
38 static bool disconnect_sent = false; |
38 static bool disconnect_sent = false; |
39 static bool connect_lost = false; |
39 static bool connect_lost = false; |
40 static bool shutdown = false; |
40 static bool my_shutdown = false; |
41 static pid_t pgrp, mypid; |
41 static pid_t pgrp, mypid; |
42 |
42 |
43 extern bool debug; |
43 extern bool debug; |
44 extern sys_config Config; |
44 extern sys_config Config; |
45 #ifdef HAVE_WIRINGPI_H |
45 #ifdef HAVE_WIRINGPI_H |
71 case SIGTERM: syslog(LOG_NOTICE, "Got SIGTERM, shutting down"); |
71 case SIGTERM: syslog(LOG_NOTICE, "Got SIGTERM, shutting down"); |
72 break; |
72 break; |
73 default: syslog(LOG_NOTICE, "die() on signal %d", onsig); |
73 default: syslog(LOG_NOTICE, "die() on signal %d", onsig); |
74 } |
74 } |
75 |
75 |
76 shutdown = true; |
76 my_shutdown = true; |
77 } |
77 } |
78 |
78 |
79 |
79 |
80 |
80 |
81 void my_connect_callback(struct mosquitto *mosq, void *obj, int result) |
81 void my_connect_callback(struct mosquitto *mosq, void *obj, int result) |
94 |
94 |
95 |
95 |
96 |
96 |
97 void my_disconnect_callback(struct mosquitto *mosq, void *obj, int rc) |
97 void my_disconnect_callback(struct mosquitto *mosq, void *obj, int rc) |
98 { |
98 { |
99 if (shutdown) { |
99 if (my_shutdown) { |
100 syslog(LOG_NOTICE, "Acknowledged DISCONNECT from %s", Config.mosq_host); |
100 syslog(LOG_NOTICE, "Acknowledged DISCONNECT from %s", Config.mosq_host); |
101 connected = false; |
101 connected = false; |
102 } else { |
102 } else { |
103 /* |
103 /* |
104 * The remove server was brought down. We must keep running |
104 * The remove server was brought down. We must keep running |
506 snprintf(buf, 16, "%5.1f %cC %s ", tmp1->lastval / 1000.0, 0xdf, tmp1->alias); |
506 snprintf(buf, 16, "%5.1f %cC %s ", tmp1->lastval / 1000.0, 0xdf, tmp1->alias); |
507 lcdPuts(lcdHandle, buf); |
507 lcdPuts(lcdHandle, buf); |
508 } |
508 } |
509 #endif |
509 #endif |
510 |
510 |
511 if (shutdown) { |
511 if (my_shutdown) { |
512 /* |
512 /* |
513 * Final publish 0 to clients/<hostname>/thermometers/state |
513 * Final publish 0 to clients/<hostname>/thermometers/state |
514 */ |
514 */ |
515 sprintf(buf, "0"); |
515 sprintf(buf, "0"); |
516 mosquitto_publish(mosq, &mid_sent, state, strlen(buf), buf, qos, true); |
516 mosquitto_publish(mosq, &mid_sent, state, strlen(buf), buf, qos, true); |