thermferm/server.c

changeset 510
2da3d3340403
parent 506
cdcd07bbee30
child 513
a2732027afb3
equal deleted inserted replaced
509:b5ae9017194f 510:2da3d3340403
2193 syslog(LOG_NOTICE, "Fermenter unit %s name `%s' to `%s'", unit->uuid, unit->name, val); 2193 syslog(LOG_NOTICE, "Fermenter unit %s name `%s' to `%s'", unit->uuid, unit->name, val);
2194 } 2194 }
2195 free(unit->name); 2195 free(unit->name);
2196 } 2196 }
2197 unit->name = xstrcpy(val); 2197 unit->name = xstrcpy(val);
2198 unit->mqtt_flag |= (MQTT_FLAG_MODE); 2198 unit->mqtt_flag |= MQTT_FLAG_DATA;
2199 2199
2200 } else if (val && (strcmp(kwd, (char *)"VOLUME") == 0)) { 2200 } else if (val && (strcmp(kwd, (char *)"VOLUME") == 0)) {
2201 if (sscanf(val, "%f", &fval) == 1) { 2201 if (sscanf(val, "%f", &fval) == 1) {
2202 if (unit->volume != fval) 2202 if (unit->volume != fval)
2203 syslog(LOG_NOTICE, "Fermenter unit %s volume %.3f to %.3f", unit->uuid, unit->volume, fval); 2203 syslog(LOG_NOTICE, "Fermenter unit %s volume %.3f to %.3f", unit->uuid, unit->volume, fval);
2214 if (val) { 2214 if (val) {
2215 unit->air_address = xstrcpy(val); 2215 unit->air_address = xstrcpy(val);
2216 device_count(TRUE, unit->air_address); 2216 device_count(TRUE, unit->air_address);
2217 } else 2217 } else
2218 unit->air_address = NULL; 2218 unit->air_address = NULL;
2219 unit->mqtt_flag |= MQTT_FLAG_AIR; 2219 unit->mqtt_flag |= MQTT_FLAG_DATA;
2220 2220
2221 } else if (strcmp(kwd, (char *)"BEER_ADDRESS") == 0) { 2221 } else if (strcmp(kwd, (char *)"BEER_ADDRESS") == 0) {
2222 if (val && unit->beer_address && (strcmp(val, unit->beer_address))) 2222 if (val && unit->beer_address && (strcmp(val, unit->beer_address)))
2223 syslog(LOG_NOTICE, "Fermenter unit %s beer address `%s' to `%s'", unit->uuid, unit->beer_address, val); 2223 syslog(LOG_NOTICE, "Fermenter unit %s beer address `%s' to `%s'", unit->uuid, unit->beer_address, val);
2224 if (unit->beer_address) { 2224 if (unit->beer_address) {
2228 if (val) { 2228 if (val) {
2229 unit->beer_address = xstrcpy(val); 2229 unit->beer_address = xstrcpy(val);
2230 device_count(TRUE, unit->beer_address); 2230 device_count(TRUE, unit->beer_address);
2231 } else 2231 } else
2232 unit->beer_address = NULL; 2232 unit->beer_address = NULL;
2233 unit->mqtt_flag |= MQTT_FLAG_BEER; 2233 unit->mqtt_flag |= MQTT_FLAG_DATA;
2234 2234
2235 } else if (strcmp(kwd, (char *)"HEATER_ADDRESS") == 0) { 2235 } else if (strcmp(kwd, (char *)"HEATER_ADDRESS") == 0) {
2236 if (val && unit->heater_address && (strcmp(val, unit->heater_address))) 2236 if (val && unit->heater_address && (strcmp(val, unit->heater_address)))
2237 syslog(LOG_NOTICE, "Fermenter unit %s heater address `%s' to `%s'", unit->uuid, unit->heater_address, val); 2237 syslog(LOG_NOTICE, "Fermenter unit %s heater address `%s' to `%s'", unit->uuid, unit->heater_address, val);
2238 if (unit->heater_address) { 2238 if (unit->heater_address) {
2242 if (val) { 2242 if (val) {
2243 unit->heater_address = xstrcpy(val); 2243 unit->heater_address = xstrcpy(val);
2244 device_count(TRUE, unit->heater_address); 2244 device_count(TRUE, unit->heater_address);
2245 } else 2245 } else
2246 unit->heater_address = NULL; 2246 unit->heater_address = NULL;
2247 unit->mqtt_flag |= MQTT_FLAG_HEATER; 2247 unit->mqtt_flag |= MQTT_FLAG_DATA;
2248 2248
2249 } else if (val && (strcmp(kwd, (char *)"HEATER_STATE") == 0)) { 2249 } else if (val && (strcmp(kwd, (char *)"HEATER_STATE") == 0)) {
2250 if ((sscanf(val, "%d", &ival) == 1) && ((ival == 0) || (ival == 100))) { 2250 if ((sscanf(val, "%d", &ival) == 1) && ((ival == 0) || (ival == 100))) {
2251 if (unit->heater_state != ival) 2251 if (unit->heater_state != ival)
2252 syslog(LOG_NOTICE, "Fermenter unit %s heater state %d to %d", unit->uuid, unit->heater_state, ival); 2252 syslog(LOG_NOTICE, "Fermenter unit %s heater state %d to %d", unit->uuid, unit->heater_state, ival);
2253 unit->heater_state = ival; 2253 unit->heater_state = ival;
2254 unit->mqtt_flag |= MQTT_FLAG_HEATER; 2254 unit->mqtt_flag |= MQTT_FLAG_DATA;
2255 } 2255 }
2256 2256
2257 } else if (val && (strcmp(kwd, (char *)"HEATER_DELAY") == 0)) { 2257 } else if (val && (strcmp(kwd, (char *)"HEATER_DELAY") == 0)) {
2258 if (sscanf(val, "%d", &ival) == 1) { 2258 if (sscanf(val, "%d", &ival) == 1) {
2259 if (unit->heater_delay != ival) 2259 if (unit->heater_delay != ival)
2271 if (val) { 2271 if (val) {
2272 unit->cooler_address = xstrcpy(val); 2272 unit->cooler_address = xstrcpy(val);
2273 device_count(TRUE, unit->cooler_address); 2273 device_count(TRUE, unit->cooler_address);
2274 } else 2274 } else
2275 unit->cooler_address = NULL; 2275 unit->cooler_address = NULL;
2276 unit->mqtt_flag |= MQTT_FLAG_COOLER; 2276 unit->mqtt_flag |= MQTT_FLAG_DATA;
2277 2277
2278 } else if (val && (strcmp(kwd, (char *)"COOLER_STATE") == 0)) { 2278 } else if (val && (strcmp(kwd, (char *)"COOLER_STATE") == 0)) {
2279 if ((sscanf(val, "%d", &ival) == 1) && ((ival == 0) || (ival == 100))) { 2279 if ((sscanf(val, "%d", &ival) == 1) && ((ival == 0) || (ival == 100))) {
2280 if (unit->cooler_state != ival) 2280 if (unit->cooler_state != ival)
2281 syslog(LOG_NOTICE, "Fermenter unit %s cooler state %d to %d", unit->uuid, unit->cooler_state, ival); 2281 syslog(LOG_NOTICE, "Fermenter unit %s cooler state %d to %d", unit->uuid, unit->cooler_state, ival);
2282 unit->cooler_state = ival; 2282 unit->cooler_state = ival;
2283 unit->mqtt_flag |= MQTT_FLAG_COOLER; 2283 unit->mqtt_flag |= MQTT_FLAG_DATA;
2284 } 2284 }
2285 2285
2286 } else if (val && (strcmp(kwd, (char *)"COOLER_DELAY") == 0)) { 2286 } else if (val && (strcmp(kwd, (char *)"COOLER_DELAY") == 0)) {
2287 if (sscanf(val, "%d", &ival) == 1) { 2287 if (sscanf(val, "%d", &ival) == 1) {
2288 if (unit->cooler_delay != ival) 2288 if (unit->cooler_delay != ival)
2300 if (val) { 2300 if (val) {
2301 unit->fan_address = xstrcpy(val); 2301 unit->fan_address = xstrcpy(val);
2302 device_count(TRUE, unit->fan_address); 2302 device_count(TRUE, unit->fan_address);
2303 } else 2303 } else
2304 unit->fan_address = NULL; 2304 unit->fan_address = NULL;
2305 unit->mqtt_flag |= MQTT_FLAG_FAN; 2305 unit->mqtt_flag |= MQTT_FLAG_DATA;
2306 2306
2307 } else if (val && (strcmp(kwd, (char *)"FAN_STATE") == 0)) { 2307 } else if (val && (strcmp(kwd, (char *)"FAN_STATE") == 0)) {
2308 if ((sscanf(val, "%d", &ival) == 1) && ((ival == 0) || (ival == 100))) { 2308 if ((sscanf(val, "%d", &ival) == 1) && ((ival == 0) || (ival == 100))) {
2309 if (unit->fan_state != ival) 2309 if (unit->fan_state != ival)
2310 syslog(LOG_NOTICE, "Fermenter unit %s fan state %d to %d", unit->uuid, unit->fan_state, ival); 2310 syslog(LOG_NOTICE, "Fermenter unit %s fan state %d to %d", unit->uuid, unit->fan_state, ival);
2311 unit->fan_state = ival; 2311 unit->fan_state = ival;
2312 unit->mqtt_flag |= MQTT_FLAG_FAN; 2312 unit->mqtt_flag |= MQTT_FLAG_DATA;
2313 } 2313 }
2314 2314
2315 } else if (val && (strcmp(kwd, (char *)"FAN_DELAY") == 0)) { 2315 } else if (val && (strcmp(kwd, (char *)"FAN_DELAY") == 0)) {
2316 if (sscanf(val, "%d", &ival) == 1) { 2316 if (sscanf(val, "%d", &ival) == 1) {
2317 if (unit->fan_delay != ival) 2317 if (unit->fan_delay != ival)
2329 if (val) { 2329 if (val) {
2330 unit->light_address = xstrcpy(val); 2330 unit->light_address = xstrcpy(val);
2331 device_count(TRUE, unit->light_address); 2331 device_count(TRUE, unit->light_address);
2332 } else 2332 } else
2333 unit->light_address = NULL; 2333 unit->light_address = NULL;
2334 unit->mqtt_flag |= MQTT_FLAG_LIGHT; 2334 unit->mqtt_flag |= MQTT_FLAG_DATA;
2335 2335
2336 } else if (val && (strcmp(kwd, (char *)"LIGHT_STATE") == 0)) { 2336 } else if (val && (strcmp(kwd, (char *)"LIGHT_STATE") == 0)) {
2337 if ((sscanf(val, "%d", &ival) == 1) && ((ival == 0) || (ival == 100))) { 2337 if ((sscanf(val, "%d", &ival) == 1) && ((ival == 0) || (ival == 100))) {
2338 if (unit->light_state != ival) 2338 if (unit->light_state != ival)
2339 syslog(LOG_NOTICE, "Fermenter unit %s light state %d to %d", unit->uuid, unit->light_state, ival); 2339 syslog(LOG_NOTICE, "Fermenter unit %s light state %d to %d", unit->uuid, unit->light_state, ival);
2340 unit->light_state = ival; 2340 unit->light_state = ival;
2341 unit->mqtt_flag |= MQTT_FLAG_LIGHT; 2341 unit->mqtt_flag |= MQTT_FLAG_DATA;
2342 } 2342 }
2343 2343
2344 } else if (val && (strcmp(kwd, (char *)"LIGHT_DELAY") == 0)) { 2344 } else if (val && (strcmp(kwd, (char *)"LIGHT_DELAY") == 0)) {
2345 if (sscanf(val, "%d", &ival) == 1) { 2345 if (sscanf(val, "%d", &ival) == 1) {
2346 if (unit->light_delay != ival) 2346 if (unit->light_delay != ival)
2371 if (val) { 2371 if (val) {
2372 unit->psu_address = xstrcpy(val); 2372 unit->psu_address = xstrcpy(val);
2373 device_count(TRUE, unit->psu_address); 2373 device_count(TRUE, unit->psu_address);
2374 } else 2374 } else
2375 unit->psu_address = NULL; 2375 unit->psu_address = NULL;
2376 unit->mqtt_flag |= MQTT_FLAG_PSU; 2376 unit->mqtt_flag |= MQTT_FLAG_DATA;
2377 2377
2378 } else if (val && (strcmp(kwd, (char *)"MODE") == 0)) { 2378 } else if (val && (strcmp(kwd, (char *)"MODE") == 0)) {
2379 for (i = 0; i < 5; i++) { 2379 for (i = 0; i < 5; i++) {
2380 if (strcmp(val, UNITMODE[i]) == 0) { 2380 if (strcmp(val, UNITMODE[i]) == 0) {
2381 /* Initialize log if the unit is turned on */ 2381 /* Initialize log if the unit is turned on */
2382 if ((unit->mode == UNITMODE_OFF) && (i != UNITMODE_OFF)) 2382 if ((unit->mode == UNITMODE_OFF) && (i != UNITMODE_OFF))
2383 initlog(unit->name); 2383 initlog(unit->name);
2384 syslog(LOG_NOTICE, "Fermenter unit %s mode %s to %s", unit->uuid, UNITMODE[unit->mode], UNITMODE[i]); 2384 syslog(LOG_NOTICE, "Fermenter unit %s mode %s to %s", unit->uuid, UNITMODE[unit->mode], UNITMODE[i]);
2385 unit->mode = i; 2385 unit->mode = i;
2386 unit->mqtt_flag |= (MQTT_FLAG_MODE | MQTT_FLAG_SP); 2386 unit->mqtt_flag |= MQTT_FLAG_DATA;
2387 /* Allways turn everything off after a mode change */ 2387 /* Allways turn everything off after a mode change */
2388 unit->PID_cool->OutP = unit->PID_heat->OutP = 0.0; 2388 unit->PID_cool->OutP = unit->PID_heat->OutP = 0.0;
2389 unit->PID_cool->Mode = unit->PID_heat->Mode = PID_MODE_NONE; 2389 unit->PID_cool->Mode = unit->PID_heat->Mode = PID_MODE_NONE;
2390 unit->heater_state = unit->cooler_state = unit->fan_state = unit->light_state = 0; 2390 unit->heater_state = unit->cooler_state = unit->fan_state = unit->light_state = 0;
2391 unit->heater_wait = unit->cooler_wait = unit->fan_wait = unit->light_wait = 0; 2391 unit->heater_wait = unit->cooler_wait = unit->fan_wait = unit->light_wait = 0;
2399 * main processing loop. 2399 * main processing loop.
2400 */ 2400 */
2401 unit->prof_target_lo = unit->prof_target_hi = 20.0; 2401 unit->prof_target_lo = unit->prof_target_hi = 20.0;
2402 unit->prof_fridge_mode = 0; 2402 unit->prof_fridge_mode = 0;
2403 if (unit->profile) { 2403 if (unit->profile) {
2404 unit->mqtt_flag |= MQTT_FLAG_PROFILE; 2404 unit->mqtt_flag |= MQTT_FLAG_DATA;
2405 unit->mqtt_flag |= MQTT_FLAG_SP;
2406 } 2405 }
2407 } 2406 }
2408 break; 2407 break;
2409 } 2408 }
2410 } 2409 }
2412 } else if (val && (strcmp(kwd, (char *)"FRIDGE_SET") == 0)) { 2411 } else if (val && (strcmp(kwd, (char *)"FRIDGE_SET") == 0)) {
2413 if ((sscanf(val, "%f", &fval) == 1) && (fval >= unit->temp_set_min) && (fval <= unit->temp_set_max)) { 2412 if ((sscanf(val, "%f", &fval) == 1) && (fval >= unit->temp_set_min) && (fval <= unit->temp_set_max)) {
2414 if (unit->fridge_set != fval) 2413 if (unit->fridge_set != fval)
2415 syslog(LOG_NOTICE, "Fermenter unit %s fridge temperature %.1f to %.1f", unit->uuid, unit->fridge_set, fval); 2414 syslog(LOG_NOTICE, "Fermenter unit %s fridge temperature %.1f to %.1f", unit->uuid, unit->fridge_set, fval);
2416 unit->fridge_set = fval; 2415 unit->fridge_set = fval;
2417 unit->mqtt_flag |= MQTT_FLAG_SP; 2416 unit->mqtt_flag |= MQTT_FLAG_DATA;
2418 } 2417 }
2419 2418
2420 } else if (val && (strcmp(kwd, (char *)"BEER_SET") == 0)) { 2419 } else if (val && (strcmp(kwd, (char *)"BEER_SET") == 0)) {
2421 if ((sscanf(val, "%f", &fval) == 1) && (fval >= unit->temp_set_min) && (fval <= unit->temp_set_max)) { 2420 if ((sscanf(val, "%f", &fval) == 1) && (fval >= unit->temp_set_min) && (fval <= unit->temp_set_max)) {
2422 if (unit->beer_set != fval) 2421 if (unit->beer_set != fval)
2423 syslog(LOG_NOTICE, "Fermenter unit %s beer temperature %.1f to %.1f", unit->uuid, unit->beer_set, fval); 2422 syslog(LOG_NOTICE, "Fermenter unit %s beer temperature %.1f to %.1f", unit->uuid, unit->beer_set, fval);
2424 unit->beer_set = fval; 2423 unit->beer_set = fval;
2425 unit->mqtt_flag |= MQTT_FLAG_SP; 2424 unit->mqtt_flag |= MQTT_FLAG_DATA;
2426 } 2425 }
2427 2426
2428 } else if (val && (strcmp(kwd, (char *)"PIDC_IMAX") == 0)) { 2427 } else if (val && (strcmp(kwd, (char *)"PIDC_IMAX") == 0)) {
2429 if ((sscanf(val, "%f", &fval) == 1) && (fval >= 0.0)) { 2428 if ((sscanf(val, "%f", &fval) == 1) && (fval >= 0.0)) {
2430 if (unit->PID_cool->iMax != fval) 2429 if (unit->PID_cool->iMax != fval)
2518 unit->heater_wait = unit->cooler_wait = unit->fan_wait = unit->light_wait = 0; 2517 unit->heater_wait = unit->cooler_wait = unit->fan_wait = unit->light_wait = 0;
2519 device_out(unit->heater_address, unit->heater_state); 2518 device_out(unit->heater_address, unit->heater_state);
2520 device_out(unit->cooler_address, unit->cooler_state); 2519 device_out(unit->cooler_address, unit->cooler_state);
2521 device_out(unit->fan_address, unit->fan_state); 2520 device_out(unit->fan_address, unit->fan_state);
2522 device_out(unit->light_address, unit->light_state); 2521 device_out(unit->light_address, unit->light_state);
2523 unit->mqtt_flag |= (MQTT_FLAG_PROFILE | MQTT_FLAG_SP | MQTT_FLAG_HEATER | MQTT_FLAG_COOLER | MQTT_FLAG_FAN); 2522 unit->mqtt_flag |= MQTT_FLAG_DATA;
2524 } 2523 }
2525 2524
2526 } else if (val && (strcmp(kwd, (char *)"PROF_STATE") == 0)) { 2525 } else if (val && (strcmp(kwd, (char *)"PROF_STATE") == 0)) {
2527 for (i = 0; i < 5; i++) { 2526 for (i = 0; i < 5; i++) {
2528 if (strcmp(val, PROFSTATE[i]) == 0) { 2527 if (strcmp(val, PROFSTATE[i]) == 0) {
2554 unit->prof_started = 0; 2553 unit->prof_started = 0;
2555 syslog(LOG_NOTICE, "Fermenter unit %s profile ABORT", unit->uuid); 2554 syslog(LOG_NOTICE, "Fermenter unit %s profile ABORT", unit->uuid);
2556 } 2555 }
2557 break; 2556 break;
2558 } 2557 }
2559 unit->mqtt_flag |= (MQTT_FLAG_SP | MQTT_FLAG_PROFILE | MQTT_FLAG_PERCENT); 2558 unit->mqtt_flag |= MQTT_FLAG_DATA;
2560 break; 2559 break;
2561 } 2560 }
2562 } 2561 }
2563 2562
2564 } else if (val && (strcmp(kwd, (char *)"TEMP_SET_MIN") == 0)) { 2563 } else if (val && (strcmp(kwd, (char *)"TEMP_SET_MIN") == 0)) {

mercurial