237 int server(void) |
237 int server(void) |
238 { |
238 { |
239 char buf[1024]; |
239 char buf[1024]; |
240 w1_therm *tmp1, *old1; |
240 w1_therm *tmp1, *old1; |
241 rc_switch *tmp2, *old2; |
241 rc_switch *tmp2, *old2; |
242 int rc, run = 0; |
242 int rc, run = 0, temp; |
243 |
243 |
244 my_mosquitto_init(); |
244 my_mosquitto_init(); |
245 |
245 |
246 rc = piThreadCreate(my_sensors_loop); |
246 rc = piThreadCreate(my_sensors_loop); |
247 if (rc) { |
247 if (rc) { |
248 fprintf(stderr, "my_sensors_loop thread didn't start rc=%d\n", rc); |
248 fprintf(stderr, "my_sensors_loop thread didn't start rc=%d\n", rc); |
249 syslog(LOG_NOTICE, "my_sensors_loop thread didn't start rc=%d", rc); |
249 syslog(LOG_NOTICE, "my_sensors_loop thread didn't start rc=%d", rc); |
250 } |
250 } |
|
251 |
|
252 snprintf(buf, 1023, "tempA,coolerA,tempB,coolerB"); |
|
253 logger((char *)"coolers.log", (char *)"coolers", buf); |
251 |
254 |
252 do { |
255 do { |
253 lcdupdate = FALSE; |
256 lcdupdate = FALSE; |
254 |
257 |
255 run = my_mosquitto_loop(); |
258 run = my_mosquitto_loop(); |
258 tmp2 = Config.rcswitch; |
261 tmp2 = Config.rcswitch; |
259 if (((tmp1->lastval / 100) < (tempA - 5)) && (coolerA == 1)) { |
262 if (((tmp1->lastval / 100) < (tempA - 5)) && (coolerA == 1)) { |
260 my_mosquitto_switch(tmp2->address, 0); |
263 my_mosquitto_switch(tmp2->address, 0); |
261 coolerA = 0; |
264 coolerA = 0; |
262 syslog(LOG_NOTICE, "Temperature A is %.1f, switched cooler off", (tmp1->lastval / 1000.0)); |
265 syslog(LOG_NOTICE, "Temperature A is %.1f, switched cooler off", (tmp1->lastval / 1000.0)); |
|
266 lcdupdate = TRUE; |
263 } |
267 } |
264 if (((tmp1->lastval / 100) > (tempA + 5)) && (coolerA == 0)) { |
268 if (((tmp1->lastval / 100) > (tempA + 5)) && (coolerA == 0)) { |
265 my_mosquitto_switch(tmp2->address, 1); |
269 my_mosquitto_switch(tmp2->address, 1); |
266 coolerA = 1; |
270 coolerA = 1; |
267 syslog(LOG_NOTICE, "Temperature A is %.1f, switched cooler on", (tmp1->lastval / 1000.0)); |
271 syslog(LOG_NOTICE, "Temperature A is %.1f, switched cooler on", (tmp1->lastval / 1000.0)); |
|
272 lcdupdate = TRUE; |
268 } |
273 } |
269 old1 = tmp1->next; |
274 old1 = tmp1->next; |
270 tmp1 = old1; |
275 tmp1 = old1; |
271 old2 = tmp2->next; |
276 old2 = tmp2->next; |
272 tmp2 = old2; |
277 tmp2 = old2; |
273 if (((tmp1->lastval / 100) < (tempB - 5)) && (coolerB == 1)) { |
278 if (((tmp1->lastval / 100) < (tempB - 5)) && (coolerB == 1)) { |
274 my_mosquitto_switch(tmp2->address, 0); |
279 my_mosquitto_switch(tmp2->address, 0); |
275 coolerB = 0; |
280 coolerB = 0; |
276 syslog(LOG_NOTICE, "Temperature B is %.1f, switched cooler off", (tmp1->lastval / 1000.0)); |
281 syslog(LOG_NOTICE, "Temperature B is %.1f, switched cooler off", (tmp1->lastval / 1000.0)); |
|
282 lcdupdate = TRUE; |
277 } |
283 } |
278 if (((tmp1->lastval / 100) > (tempB + 5)) && (coolerB == 0)) { |
284 if (((tmp1->lastval / 100) > (tempB + 5)) && (coolerB == 0)) { |
279 my_mosquitto_switch(tmp2->address, 1); |
285 my_mosquitto_switch(tmp2->address, 1); |
280 coolerB = 1; |
286 coolerB = 1; |
281 syslog(LOG_NOTICE, "Temperature B is %.1f, switched cooler on", (tmp1->lastval / 1000.0)); |
287 syslog(LOG_NOTICE, "Temperature B is %.1f, switched cooler on", (tmp1->lastval / 1000.0)); |
|
288 lcdupdate = TRUE; |
282 } |
289 } |
283 |
290 |
284 if (run && lcdupdate) { |
291 if (run && lcdupdate) { |
285 lcdPosition(lcdHandle, 0, 0); |
292 lcdPosition(lcdHandle, 0, 0); |
286 tmp1 = Config.w1therms; |
293 tmp1 = Config.w1therms; |
287 snprintf(buf, 16, "%4.1f %cC %c %s ", tmp1->lastval / 1000.0, 0xdf, coolerA ? '+' : ' ', tmp1->alias); |
294 snprintf(buf, 16, "%4.1f %cC %c %s ", tmp1->lastval / 1000.0, 0xdf, coolerA ? '+' : ' ', tmp1->alias); |
288 lcdPuts(lcdHandle, buf); |
295 lcdPuts(lcdHandle, buf); |
|
296 temp = tmp1->lastval; |
289 old1 = tmp1->next; |
297 old1 = tmp1->next; |
290 tmp1 = old1; |
298 tmp1 = old1; |
291 lcdPosition(lcdHandle, 0, 1); |
299 lcdPosition(lcdHandle, 0, 1); |
292 snprintf(buf, 16, "%4.1f %cC %c %s ", tmp1->lastval / 1000.0, 0xdf, coolerB ? '+' : ' ', tmp1->alias); |
300 snprintf(buf, 16, "%4.1f %cC %c %s ", tmp1->lastval / 1000.0, 0xdf, coolerB ? '+' : ' ', tmp1->alias); |
293 lcdPuts(lcdHandle, buf); |
301 lcdPuts(lcdHandle, buf); |
|
302 snprintf(buf, 1023, "%.1f,%s,%.1f,%s", temp / 1000.0, coolerA ? (char *)"on" : (char *)"off", |
|
303 tmp1->lastval / 1000.0, coolerB ? (char *)"on" : (char *)"off"); |
|
304 logger((char *)"coolers.log", (char *)"coolers", buf); |
294 } |
305 } |
295 usleep(100000); |
306 usleep(100000); |
296 |
307 |
297 } while (run); |
308 } while (run); |
298 |
309 |