thermferm/server.c

changeset 502
0e2c58f8eb78
parent 500
5aa914eb644e
child 504
862de87f9f89
equal deleted inserted replaced
501:52bb55ba0b01 502:0e2c58f8eb78
2187 */ 2187 */
2188 if (val && (strcmp(kwd, (char *)"NAME") == 0)) { 2188 if (val && (strcmp(kwd, (char *)"NAME") == 0)) {
2189 if (unit->name) { 2189 if (unit->name) {
2190 if (strcmp(unit->name, val)) { 2190 if (strcmp(unit->name, val)) {
2191 syslog(LOG_NOTICE, "Fermenter unit %s name `%s' to `%s'", unit->uuid, unit->name, val); 2191 syslog(LOG_NOTICE, "Fermenter unit %s name `%s' to `%s'", unit->uuid, unit->name, val);
2192 mqtt_publish_str(unit->uuid, (char *)"name", val); 2192 mqtt_publish_str(unit->alias, (char *)"name", val);
2193 } 2193 }
2194 free(unit->name); 2194 free(unit->name);
2195 } 2195 }
2196 unit->name = xstrcpy(val); 2196 unit->name = xstrcpy(val);
2197 2197
2391 unit->mqtt_flag |= MQTT_FLAG_PROFILE; 2391 unit->mqtt_flag |= MQTT_FLAG_PROFILE;
2392 unit->mqtt_flag |= MQTT_FLAG_SP; 2392 unit->mqtt_flag |= MQTT_FLAG_SP;
2393 } 2393 }
2394 } 2394 }
2395 if (unit->heater_address) 2395 if (unit->heater_address)
2396 mqtt_publish_int(unit->uuid, (char *)"heater", 0); 2396 mqtt_publish_int(unit->alias, (char *)"heater", 0);
2397 if (unit->cooler_address) 2397 if (unit->cooler_address)
2398 mqtt_publish_int(unit->uuid, (char *)"cooler", 0); 2398 mqtt_publish_int(unit->alias, (char *)"cooler", 0);
2399 if (unit->fan_address) 2399 if (unit->fan_address)
2400 mqtt_publish_int(unit->uuid, (char *)"fan", 0); 2400 mqtt_publish_int(unit->alias, (char *)"fan", 0);
2401 break; 2401 break;
2402 } 2402 }
2403 } 2403 }
2404 2404
2405 } else if (val && (strcmp(kwd, (char *)"FRIDGE_SET") == 0)) { 2405 } else if (val && (strcmp(kwd, (char *)"FRIDGE_SET") == 0)) {
2512 device_out(unit->heater_address, unit->heater_state); 2512 device_out(unit->heater_address, unit->heater_state);
2513 device_out(unit->cooler_address, unit->cooler_state); 2513 device_out(unit->cooler_address, unit->cooler_state);
2514 device_out(unit->fan_address, unit->fan_state); 2514 device_out(unit->fan_address, unit->fan_state);
2515 device_out(unit->light_address, unit->light_state); 2515 device_out(unit->light_address, unit->light_state);
2516 if (unit->heater_address) 2516 if (unit->heater_address)
2517 mqtt_publish_int(unit->uuid, (char *)"heater", 0); 2517 mqtt_publish_int(unit->alias, (char *)"heater", 0);
2518 if (unit->cooler_address) 2518 if (unit->cooler_address)
2519 mqtt_publish_int(unit->uuid, (char *)"cooler", 0); 2519 mqtt_publish_int(unit->alias, (char *)"cooler", 0);
2520 if (unit->fan_address) 2520 if (unit->fan_address)
2521 mqtt_publish_int(unit->uuid, (char *)"fan", 0); 2521 mqtt_publish_int(unit->alias, (char *)"fan", 0);
2522 unit->mqtt_flag |= (MQTT_FLAG_PROFILE | MQTT_FLAG_SP); 2522 unit->mqtt_flag |= (MQTT_FLAG_PROFILE | MQTT_FLAG_SP);
2523 } 2523 }
2524 2524
2525 } else if (val && (strcmp(kwd, (char *)"PROF_STATE") == 0)) { 2525 } else if (val && (strcmp(kwd, (char *)"PROF_STATE") == 0)) {
2526 for (i = 0; i < 5; i++) { 2526 for (i = 0; i < 5; i++) {
2527 if (strcmp(val, PROFSTATE[i]) == 0) { 2527 if (strcmp(val, PROFSTATE[i]) == 0) {
2528 switch (i) { 2528 switch (i) {
2529 case PROFILE_OFF: if (unit->prof_state == PROFILE_DONE) { 2529 case PROFILE_OFF: if (unit->prof_state == PROFILE_DONE) {
2530 unit->prof_state = PROFILE_OFF; 2530 unit->prof_state = PROFILE_OFF;
2531 syslog(LOG_NOTICE, "Fermenter unit %s profile to OFF", unit->uuid); 2531 syslog(LOG_NOTICE, "Fermenter unit %s profile to OFF", unit->uuid);
2532 mqtt_publish_str(unit->uuid, (char *)"profile/state", (char *)PROFSTATE[i]); 2532 mqtt_publish_str(unit->alias, (char *)"profile/state", (char *)PROFSTATE[i]);
2533 } 2533 }
2534 break; 2534 break;
2535 case PROFILE_PAUSE: if (unit->prof_state == PROFILE_RUN) { 2535 case PROFILE_PAUSE: if (unit->prof_state == PROFILE_RUN) {
2536 unit->prof_state = PROFILE_PAUSE; 2536 unit->prof_state = PROFILE_PAUSE;
2537 syslog(LOG_NOTICE, "Fermenter unit %s profile PAUSE", unit->uuid); 2537 syslog(LOG_NOTICE, "Fermenter unit %s profile PAUSE", unit->uuid);
2538 mqtt_publish_str(unit->uuid, (char *)"profile/state", (char *)PROFSTATE[i]); 2538 mqtt_publish_str(unit->alias, (char *)"profile/state", (char *)PROFSTATE[i]);
2539 } else if (unit->prof_state == PROFILE_PAUSE) { 2539 } else if (unit->prof_state == PROFILE_PAUSE) {
2540 unit->prof_state = PROFILE_RUN; 2540 unit->prof_state = PROFILE_RUN;
2541 syslog(LOG_NOTICE, "Fermenter unit %s profile RESUME", unit->uuid); 2541 syslog(LOG_NOTICE, "Fermenter unit %s profile RESUME", unit->uuid);
2542 mqtt_publish_str(unit->uuid, (char *)"profile/state", (char *)PROFSTATE[PROFILE_RUN]); 2542 mqtt_publish_str(unit->alias, (char *)"profile/state", (char *)PROFSTATE[PROFILE_RUN]);
2543 } 2543 }
2544 break; 2544 break;
2545 case PROFILE_RUN: if (unit->prof_state == PROFILE_OFF) { 2545 case PROFILE_RUN: if (unit->prof_state == PROFILE_OFF) {
2546 unit->prof_state = PROFILE_RUN; 2546 unit->prof_state = PROFILE_RUN;
2547 unit->prof_started = time(NULL); 2547 unit->prof_started = time(NULL);
2548 unit->prof_paused = unit->prof_primary_done = 0; 2548 unit->prof_paused = unit->prof_primary_done = 0;
2549 unit->prof_peak_abs = unit->prof_peak_rel = 0.0; 2549 unit->prof_peak_abs = unit->prof_peak_rel = 0.0;
2550 syslog(LOG_NOTICE, "Fermenter unit %s profile to RUN", unit->uuid); 2550 syslog(LOG_NOTICE, "Fermenter unit %s profile to RUN", unit->uuid);
2551 mqtt_publish_str(unit->uuid, (char *)"profile/state", (char *)PROFSTATE[i]); 2551 mqtt_publish_str(unit->alias, (char *)"profile/state", (char *)PROFSTATE[i]);
2552 } 2552 }
2553 break; 2553 break;
2554 case PROFILE_DONE: break; /* Command is illegal */ 2554 case PROFILE_DONE: break; /* Command is illegal */
2555 case PROFILE_ABORT: if ((unit->prof_state == PROFILE_RUN) || (unit->prof_state == PROFILE_PAUSE)) { 2555 case PROFILE_ABORT: if ((unit->prof_state == PROFILE_RUN) || (unit->prof_state == PROFILE_PAUSE)) {
2556 unit->prof_state = PROFILE_OFF; 2556 unit->prof_state = PROFILE_OFF;
2557 unit->prof_started = 0; 2557 unit->prof_started = 0;
2558 syslog(LOG_NOTICE, "Fermenter unit %s profile ABORT", unit->uuid); 2558 syslog(LOG_NOTICE, "Fermenter unit %s profile ABORT", unit->uuid);
2559 mqtt_publish_str(unit->uuid, (char *)"profile/state", (char *)PROFSTATE[i]); 2559 mqtt_publish_str(unit->alias, (char *)"profile/state", (char *)PROFSTATE[i]);
2560 } 2560 }
2561 break; 2561 break;
2562 } 2562 }
2563 unit->mqtt_flag |= (MQTT_FLAG_SP | MQTT_FLAG_PROFILE | MQTT_FLAG_PERCENT); 2563 unit->mqtt_flag |= (MQTT_FLAG_SP | MQTT_FLAG_PROFILE | MQTT_FLAG_PERCENT);
2564 break; 2564 break;

mercurial