2173 * but may also sent everything. Simply ignore things we |
2174 * but may also sent everything. Simply ignore things we |
2174 * don't understand. |
2175 * don't understand. |
2175 */ |
2176 */ |
2176 if (val && (strcmp(kwd, (char *)"NAME") == 0)) { |
2177 if (val && (strcmp(kwd, (char *)"NAME") == 0)) { |
2177 if (unit->name) { |
2178 if (unit->name) { |
2178 if (strcmp(unit->name, val)) |
2179 if (strcmp(unit->name, val)) { |
2179 syslog(LOG_NOTICE, "Fermenter unit %s name `%s' to `%s'", unit->uuid, unit->name, val); |
2180 syslog(LOG_NOTICE, "Fermenter unit %s name `%s' to `%s'", unit->uuid, unit->name, val); |
|
2181 mqtt_publish_str(unit->uuid, (char *)"name", val); |
|
2182 } |
2180 free(unit->name); |
2183 free(unit->name); |
2181 } |
2184 } |
2182 unit->name = xstrcpy(val); |
2185 unit->name = xstrcpy(val); |
2183 |
2186 |
2184 } else if (val && (strcmp(kwd, (char *)"VOLUME") == 0)) { |
2187 } else if (val && (strcmp(kwd, (char *)"VOLUME") == 0)) { |
2354 /* Initialize log if the unit is turned on */ |
2357 /* Initialize log if the unit is turned on */ |
2355 if ((unit->mode == UNITMODE_OFF) && (i != UNITMODE_OFF)) |
2358 if ((unit->mode == UNITMODE_OFF) && (i != UNITMODE_OFF)) |
2356 initlog(unit->name); |
2359 initlog(unit->name); |
2357 syslog(LOG_NOTICE, "Fermenter unit %s mode %s to %s", unit->uuid, UNITMODE[unit->mode], UNITMODE[i]); |
2360 syslog(LOG_NOTICE, "Fermenter unit %s mode %s to %s", unit->uuid, UNITMODE[unit->mode], UNITMODE[i]); |
2358 unit->mode = i; |
2361 unit->mode = i; |
|
2362 unit->mqtt_flag |= (MQTT_FLAG_MODE | MQTT_FLAG_SP); |
2359 /* Allways turn everything off after a mode change */ |
2363 /* Allways turn everything off after a mode change */ |
2360 unit->PID_cool->OutP = unit->PID_heat->OutP = 0.0; |
2364 unit->PID_cool->OutP = unit->PID_heat->OutP = 0.0; |
2361 unit->PID_cool->Mode = unit->PID_heat->Mode = PID_MODE_NONE; |
2365 unit->PID_cool->Mode = unit->PID_heat->Mode = PID_MODE_NONE; |
2362 unit->heater_state = unit->cooler_state = unit->fan_state = unit->light_state = 0; |
2366 unit->heater_state = unit->cooler_state = unit->fan_state = unit->light_state = 0; |
2363 unit->heater_wait = unit->cooler_wait = unit->fan_wait = unit->light_wait = 0; |
2367 unit->heater_wait = unit->cooler_wait = unit->fan_wait = unit->light_wait = 0; |
2370 * Set a sane default until it will be overruled by the |
2374 * Set a sane default until it will be overruled by the |
2371 * main processing loop. |
2375 * main processing loop. |
2372 */ |
2376 */ |
2373 unit->prof_target_lo = unit->prof_target_hi = 20.0; |
2377 unit->prof_target_lo = unit->prof_target_hi = 20.0; |
2374 unit->prof_fridge_mode = 0; |
2378 unit->prof_fridge_mode = 0; |
|
2379 if (unit->profile) { |
|
2380 unit->mqtt_flag |= MQTT_FLAG_PROFILE; |
|
2381 unit->mqtt_flag |= MQTT_FLAG_SP; |
|
2382 } |
2375 } |
2383 } |
|
2384 if (unit->heater_address) |
|
2385 mqtt_publish_int(unit->uuid, (char *)"heater", 0); |
|
2386 if (unit->cooler_address) |
|
2387 mqtt_publish_int(unit->uuid, (char *)"cooler", 0); |
|
2388 if (unit->fan_address) |
|
2389 mqtt_publish_int(unit->uuid, (char *)"fan", 0); |
2376 break; |
2390 break; |
2377 } |
2391 } |
2378 } |
2392 } |
2379 |
2393 |
2380 } else if (val && (strcmp(kwd, (char *)"FRIDGE_SET") == 0)) { |
2394 } else if (val && (strcmp(kwd, (char *)"FRIDGE_SET") == 0)) { |
2381 if ((sscanf(val, "%f", &fval) == 1) && (fval >= unit->temp_set_min) && (fval <= unit->temp_set_max)) { |
2395 if ((sscanf(val, "%f", &fval) == 1) && (fval >= unit->temp_set_min) && (fval <= unit->temp_set_max)) { |
2382 if (unit->fridge_set != fval) |
2396 if (unit->fridge_set != fval) |
2383 syslog(LOG_NOTICE, "Fermenter unit %s fridge temperature %.1f to %.1f", unit->uuid, unit->fridge_set, fval); |
2397 syslog(LOG_NOTICE, "Fermenter unit %s fridge temperature %.1f to %.1f", unit->uuid, unit->fridge_set, fval); |
2384 unit->fridge_set = fval; |
2398 unit->fridge_set = fval; |
|
2399 unit->mqtt_flag |= MQTT_FLAG_SP; |
2385 } |
2400 } |
2386 |
2401 |
2387 } else if (val && (strcmp(kwd, (char *)"BEER_SET") == 0)) { |
2402 } else if (val && (strcmp(kwd, (char *)"BEER_SET") == 0)) { |
2388 if ((sscanf(val, "%f", &fval) == 1) && (fval >= unit->temp_set_min) && (fval <= unit->temp_set_max)) { |
2403 if ((sscanf(val, "%f", &fval) == 1) && (fval >= unit->temp_set_min) && (fval <= unit->temp_set_max)) { |
2389 if (unit->beer_set != fval) |
2404 if (unit->beer_set != fval) |
2390 syslog(LOG_NOTICE, "Fermenter unit %s beer temperature %.1f to %.1f", unit->uuid, unit->beer_set, fval); |
2405 syslog(LOG_NOTICE, "Fermenter unit %s beer temperature %.1f to %.1f", unit->uuid, unit->beer_set, fval); |
2391 unit->beer_set = fval; |
2406 unit->beer_set = fval; |
|
2407 unit->mqtt_flag |= MQTT_FLAG_SP; |
2392 } |
2408 } |
2393 |
2409 |
2394 } else if (val && (strcmp(kwd, (char *)"PIDC_IMAX") == 0)) { |
2410 } else if (val && (strcmp(kwd, (char *)"PIDC_IMAX") == 0)) { |
2395 if ((sscanf(val, "%f", &fval) == 1) && (fval >= 0.0)) { |
2411 if ((sscanf(val, "%f", &fval) == 1) && (fval >= 0.0)) { |
2396 if (unit->PID_cool->iMax != fval) |
2412 if (unit->PID_cool->iMax != fval) |
2484 unit->heater_wait = unit->cooler_wait = unit->fan_wait = unit->light_wait = 0; |
2500 unit->heater_wait = unit->cooler_wait = unit->fan_wait = unit->light_wait = 0; |
2485 device_out(unit->heater_address, unit->heater_state); |
2501 device_out(unit->heater_address, unit->heater_state); |
2486 device_out(unit->cooler_address, unit->cooler_state); |
2502 device_out(unit->cooler_address, unit->cooler_state); |
2487 device_out(unit->fan_address, unit->fan_state); |
2503 device_out(unit->fan_address, unit->fan_state); |
2488 device_out(unit->light_address, unit->light_state); |
2504 device_out(unit->light_address, unit->light_state); |
|
2505 if (unit->heater_address) |
|
2506 mqtt_publish_int(unit->uuid, (char *)"heater", 0); |
|
2507 if (unit->cooler_address) |
|
2508 mqtt_publish_int(unit->uuid, (char *)"cooler", 0); |
|
2509 if (unit->fan_address) |
|
2510 mqtt_publish_int(unit->uuid, (char *)"fan", 0); |
|
2511 unit->mqtt_flag |= (MQTT_FLAG_PROFILE | MQTT_FLAG_SP); |
2489 } |
2512 } |
2490 |
2513 |
2491 } else if (val && (strcmp(kwd, (char *)"PROF_STATE") == 0)) { |
2514 } else if (val && (strcmp(kwd, (char *)"PROF_STATE") == 0)) { |
2492 for (i = 0; i < 5; i++) { |
2515 for (i = 0; i < 5; i++) { |
2493 if (strcmp(val, PROFSTATE[i]) == 0) { |
2516 if (strcmp(val, PROFSTATE[i]) == 0) { |
2494 switch (i) { |
2517 switch (i) { |
2495 case PROFILE_OFF: if (unit->prof_state == PROFILE_DONE) { |
2518 case PROFILE_OFF: if (unit->prof_state == PROFILE_DONE) { |
2496 unit->prof_state = PROFILE_OFF; |
2519 unit->prof_state = PROFILE_OFF; |
2497 syslog(LOG_NOTICE, "Fermenter unit %s profile to OFF", unit->uuid); |
2520 syslog(LOG_NOTICE, "Fermenter unit %s profile to OFF", unit->uuid); |
|
2521 mqtt_publish_str(unit->uuid, (char *)"profile/state", (char *)PROFSTATE[i]); |
2498 } |
2522 } |
2499 break; |
2523 break; |
2500 case PROFILE_PAUSE: if (unit->prof_state == PROFILE_RUN) { |
2524 case PROFILE_PAUSE: if (unit->prof_state == PROFILE_RUN) { |
2501 unit->prof_state = PROFILE_PAUSE; |
2525 unit->prof_state = PROFILE_PAUSE; |
2502 syslog(LOG_NOTICE, "Fermenter unit %s profile PAUSE", unit->uuid); |
2526 syslog(LOG_NOTICE, "Fermenter unit %s profile PAUSE", unit->uuid); |
|
2527 mqtt_publish_str(unit->uuid, (char *)"profile/state", (char *)PROFSTATE[i]); |
2503 } else if (unit->prof_state == PROFILE_PAUSE) { |
2528 } else if (unit->prof_state == PROFILE_PAUSE) { |
2504 unit->prof_state = PROFILE_RUN; |
2529 unit->prof_state = PROFILE_RUN; |
2505 syslog(LOG_NOTICE, "Fermenter unit %s profile RESUME", unit->uuid); |
2530 syslog(LOG_NOTICE, "Fermenter unit %s profile RESUME", unit->uuid); |
|
2531 mqtt_publish_str(unit->uuid, (char *)"profile/state", (char *)PROFSTATE[PROFILE_RUN]); |
2506 } |
2532 } |
2507 break; |
2533 break; |
2508 case PROFILE_RUN: if (unit->prof_state == PROFILE_OFF) { |
2534 case PROFILE_RUN: if (unit->prof_state == PROFILE_OFF) { |
2509 unit->prof_state = PROFILE_RUN; |
2535 unit->prof_state = PROFILE_RUN; |
2510 unit->prof_started = time(NULL); |
2536 unit->prof_started = time(NULL); |
2511 unit->prof_paused = unit->prof_primary_done = 0; |
2537 unit->prof_paused = unit->prof_primary_done = 0; |
2512 unit->prof_peak_abs = unit->prof_peak_rel = 0.0; |
2538 unit->prof_peak_abs = unit->prof_peak_rel = 0.0; |
2513 syslog(LOG_NOTICE, "Fermenter unit %s profile to RUN", unit->uuid); |
2539 syslog(LOG_NOTICE, "Fermenter unit %s profile to RUN", unit->uuid); |
|
2540 mqtt_publish_str(unit->uuid, (char *)"profile/state", (char *)PROFSTATE[i]); |
2514 } |
2541 } |
2515 break; |
2542 break; |
2516 case PROFILE_DONE: break; /* Command is illegal */ |
2543 case PROFILE_DONE: break; /* Command is illegal */ |
2517 case PROFILE_ABORT: if ((unit->prof_state == PROFILE_RUN) || (unit->prof_state == PROFILE_PAUSE)) { |
2544 case PROFILE_ABORT: if ((unit->prof_state == PROFILE_RUN) || (unit->prof_state == PROFILE_PAUSE)) { |
2518 unit->prof_state = PROFILE_OFF; |
2545 unit->prof_state = PROFILE_OFF; |
2519 unit->prof_started = 0; |
2546 unit->prof_started = 0; |
2520 syslog(LOG_NOTICE, "Fermenter unit %s profile ABORT", unit->uuid); |
2547 syslog(LOG_NOTICE, "Fermenter unit %s profile ABORT", unit->uuid); |
|
2548 mqtt_publish_str(unit->uuid, (char *)"profile/state", (char *)PROFSTATE[i]); |
2521 } |
2549 } |
2522 break; |
2550 break; |
2523 } |
2551 } |
|
2552 unit->mqtt_flag |= (MQTT_FLAG_SP | MQTT_FLAG_PROFILE | MQTT_FLAG_PERCENT); |
2524 break; |
2553 break; |
2525 } |
2554 } |
2526 } |
2555 } |
2527 |
2556 |
2528 } else if (val && (strcmp(kwd, (char *)"TEMP_SET_MIN") == 0)) { |
2557 } else if (val && (strcmp(kwd, (char *)"TEMP_SET_MIN") == 0)) { |