thermferm/server.c

changeset 533
49580ca85ab7
parent 529
00b45f2aaac3
child 534
92b546d4a839
equal deleted inserted replaced
532:34bf9f389749 533:49580ca85ab7
1 /***************************************************************************** 1 /*****************************************************************************
2 * Copyright (C) 2008-2017 2 * Copyright (C) 2008-2018
3 * 3 *
4 * Michiel Broek <mbroek at mbse dot eu> 4 * Michiel Broek <mbroek at mbse dot eu>
5 * 5 *
6 * This file is part of the mbsePi-apps 6 * This file is part of the mbsePi-apps
7 * 7 *
2097 if (strcmp(param, unit->uuid) == 0) { 2097 if (strcmp(param, unit->uuid) == 0) {
2098 srv_send((char *)"213 Unit listing follows:"); 2098 srv_send((char *)"213 Unit listing follows:");
2099 srv_send((char *)"NAME,%s", unit->name); 2099 srv_send((char *)"NAME,%s", unit->name);
2100 srv_send((char *)"UUID,%s", unit->uuid); 2100 srv_send((char *)"UUID,%s", unit->uuid);
2101 srv_send((char *)"ALIAS,%s", unit->alias); 2101 srv_send((char *)"ALIAS,%s", unit->alias);
2102 srv_send((char *)"MODE,%s", UNITMODE[unit->mode]);
2102 srv_send((char *)"VOLUME,%2f", unit->volume); 2103 srv_send((char *)"VOLUME,%2f", unit->volume);
2103 srv_send((char *)"AIR_ADDRESS,%s", unit->air_address); 2104 srv_send((char *)"AIR_ADDRESS,%s", unit->air_address);
2104 srv_send((char *)"AIR_STATE,%s", TEMPSTATE[unit->air_state]); 2105 srv_send((char *)"AIR_STATE,%s", TEMPSTATE[unit->air_state]);
2105 srv_send((char *)"AIR_TEMPERATURE,%.3f", unit->air_temperature / 1000.0); 2106 srv_send((char *)"AIR_TEMPERATURE,%.3f", unit->air_temperature / 1000.0);
2106 srv_send((char *)"AIR_IDX,%d", unit->air_idx); 2107 srv_send((char *)"AIR_IDX,%d", unit->air_idx);
2152 srv_send((char *)"DOOR_STATE,%d", unit->door_state); 2153 srv_send((char *)"DOOR_STATE,%d", unit->door_state);
2153 srv_send((char *)"DOOR_IDX,%d", unit->door_idx); 2154 srv_send((char *)"DOOR_IDX,%d", unit->door_idx);
2154 srv_send((char *)"PSU_ADDRESS,%s", unit->psu_address); 2155 srv_send((char *)"PSU_ADDRESS,%s", unit->psu_address);
2155 srv_send((char *)"PSU_STATE,%d", unit->psu_state); 2156 srv_send((char *)"PSU_STATE,%d", unit->psu_state);
2156 srv_send((char *)"PSU_IDX,%d", unit->psu_idx); 2157 srv_send((char *)"PSU_IDX,%d", unit->psu_idx);
2157 srv_send((char *)"MODE,%s", UNITMODE[unit->mode]);
2158 srv_send((char *)"FRIDGE_SET,%.1f", unit->fridge_set); 2158 srv_send((char *)"FRIDGE_SET,%.1f", unit->fridge_set);
2159 srv_send((char *)"BEER_SET,%.1f", unit->beer_set); 2159 srv_send((char *)"BEER_SET,%.1f", unit->beer_set);
2160 srv_send((char *)"PROFILE,%s", unit->profile); 2160 srv_send((char *)"PROFILE,%s", unit->profile);
2161 srv_send((char *)"PROF_STARTED,%d", (int)unit->prof_started); 2161 srv_send((char *)"PROF_STARTED,%d", (int)unit->prof_started);
2162 if (unit->prof_state == PROFILE_RUN) { 2162 if (unit->prof_state == PROFILE_RUN) {
2482 } 2482 }
2483 2483
2484 } else if (val && (strcmp(kwd, (char *)"MODE") == 0)) { 2484 } else if (val && (strcmp(kwd, (char *)"MODE") == 0)) {
2485 for (i = 0; i < 5; i++) { 2485 for (i = 0; i < 5; i++) {
2486 if (strcmp(val, UNITMODE[i]) == 0) { 2486 if (strcmp(val, UNITMODE[i]) == 0) {
2487 unit->mqtt_flag |= MQTT_FLAG_DATA;
2487 /* Initialize log if the unit is turned on */ 2488 /* Initialize log if the unit is turned on */
2488 if ((unit->mode == UNITMODE_OFF) && (i != UNITMODE_OFF)) 2489 if ((unit->mode == UNITMODE_OFF) && (i != UNITMODE_OFF)) {
2489 initlog(unit->name); 2490 initlog(unit->name);
2491 unit->mqtt_flag |= MQTT_FLAG_BIRTH;
2492 } else if ((unit->mode != UNITMODE_OFF) && (i == UNITMODE_OFF)) {
2493 unit->mqtt_flag |= MQTT_FLAG_DEATH;
2494 }
2490 syslog(LOG_NOTICE, "Fermenter unit %s mode %s to %s", unit->uuid, UNITMODE[unit->mode], UNITMODE[i]); 2495 syslog(LOG_NOTICE, "Fermenter unit %s mode %s to %s", unit->uuid, UNITMODE[unit->mode], UNITMODE[i]);
2491 unit->mode = i; 2496 unit->mode = i;
2492 unit->mqtt_flag |= MQTT_FLAG_DATA;
2493 /* Allways turn everything off after a mode change */ 2497 /* Allways turn everything off after a mode change */
2494 unit->PID_cool->OutP = unit->PID_heat->OutP = 0.0; 2498 unit->PID_cool->OutP = unit->PID_heat->OutP = 0.0;
2495 unit->PID_cool->Mode = unit->PID_heat->Mode = PID_MODE_NONE; 2499 unit->PID_cool->Mode = unit->PID_heat->Mode = PID_MODE_NONE;
2496 unit->heater_state = unit->cooler_state = unit->fan_state = unit->light_state = 0; 2500 unit->heater_state = unit->cooler_state = unit->fan_state = unit->light_state = 0;
2497 unit->heater_wait = unit->cooler_wait = unit->fan_wait = unit->light_wait = 0; 2501 unit->heater_wait = unit->cooler_wait = unit->fan_wait = unit->light_wait = 0;
2679 syslog(LOG_NOTICE, "Fermenter unit %s temperature set maximum %.1f to %.1f", unit->uuid, unit->temp_set_max, fval); 2683 syslog(LOG_NOTICE, "Fermenter unit %s temperature set maximum %.1f to %.1f", unit->uuid, unit->temp_set_max, fval);
2680 unit->temp_set_max = fval; 2684 unit->temp_set_max = fval;
2681 } 2685 }
2682 2686
2683 } 2687 }
2684 if (unit->mqtt_flag) 2688 if (unit->mqtt_flag) {
2685 publishDData(unit); 2689 if (debug)
2690 fprintf(stdout, "flag value %d\n", unit->mqtt_flag);
2691 if (unit->mqtt_flag & MQTT_FLAG_BIRTH) {
2692 publishDBirth(unit);
2693 } else {
2694 publishDData(unit);
2695 }
2696 if (unit->mqtt_flag & MQTT_FLAG_DEATH) {
2697 publishDDeath(unit);
2698 }
2699 }
2686 } 2700 }
2687 } 2701 }
2688 } 2702 }
2689 } 2703 }
2690 } 2704 }

mercurial