thermferm/websocket.c

changeset 683
d48733bf1529
parent 682
f82be2bd472f
child 684
b2265c7e5707
equal deleted inserted replaced
682:f82be2bd472f 683:d48733bf1529
107 } else { 107 } else {
108 unit->beer_set_lo = unit->PID_heat->SetP; 108 unit->beer_set_lo = unit->PID_heat->SetP;
109 unit->beer_set_hi = unit->PID_cool->SetP; 109 unit->beer_set_hi = unit->PID_cool->SetP;
110 } 110 }
111 unit->mqtt_flag |= MQTT_FLAG_DATA; 111 unit->mqtt_flag |= MQTT_FLAG_DATA;
112 break; 112 return;
113 } 113 }
114 } 114 }
115 115
116 /* 116 /*
117 * Unit mode 117 * Unit mode
157 unit->prof_state = PROFILE_OFF; 157 unit->prof_state = PROFILE_OFF;
158 unit->prof_started = unit->prof_paused = unit->prof_primary_done = 0; 158 unit->prof_started = unit->prof_paused = unit->prof_primary_done = 0;
159 unit->prof_peak_abs = unit->prof_peak_rel = 0.0; 159 unit->prof_peak_abs = unit->prof_peak_rel = 0.0;
160 } 160 }
161 } 161 }
162 break; 162 return;
163 } 163 }
164 } 164 }
165 } 165 }
166 166
167 /* 167 /*
170 */ 170 */
171 if (json_object_object_get_ex(jobj, "stage", &val)) { 171 if (json_object_object_get_ex(jobj, "stage", &val)) {
172 for (int i = 0; i < 4; i++) { 172 for (int i = 0; i < 4; i++) {
173 if (strcmp((char *)json_object_get_string(val), UNITSTAGE[i]) == 0) { 173 if (strcmp((char *)json_object_get_string(val), UNITSTAGE[i]) == 0) {
174 if (unit->stage != i) { 174 if (unit->stage != i) {
175 syslog(LOG_NOTICE, "DCMD change fermenter %s: stage to %s", unit->alias, UNITSTAGE[i]); 175 syslog(LOG_NOTICE, "ws: unit %s: stage to %s", unit->alias, UNITSTAGE[i]);
176 unit->mqtt_flag |= MQTT_FLAG_DATA; 176 unit->mqtt_flag |= MQTT_FLAG_DATA;
177 unit->stage = i; 177 unit->stage = i;
178 if ((unit->mode != UNITMODE_OFF) && ! unit->event_msg) 178 if ((unit->mode != UNITMODE_OFF) && ! unit->event_msg)
179 unit->event_msg = xstrcpy((char *)UNITSTAGE[i]); 179 unit->event_msg = xstrcpy((char *)UNITSTAGE[i]);
180 } 180 }
181 break; 181 return;
182 } 182 }
183 } 183 }
184 } 184 }
185 185
186 /* 186 /*
192 (unit->mode == UNITMODE_NONE)) { 192 (unit->mode == UNITMODE_NONE)) {
193 if (json_object_get_int(val) != unit->heater_state) 193 if (json_object_get_int(val) != unit->heater_state)
194 unit->heater_state = json_object_get_int(val); 194 unit->heater_state = json_object_get_int(val);
195 if (json_object_get_int(val2) != unit->cooler_state) 195 if (json_object_get_int(val2) != unit->cooler_state)
196 unit->cooler_state = json_object_get_int(val2); 196 unit->cooler_state = json_object_get_int(val2);
197 if (unit->heater_state || unit->cooler_state) 197 if (unit->heater_state && unit->cooler_state)
198 unit->heater_state = unit->cooler_state = 0; // Safety 198 unit->heater_state = unit->cooler_state = 0; // Safety
199 unit->mqtt_flag |= MQTT_FLAG_DATA; 199 unit->mqtt_flag |= MQTT_FLAG_DATA;
200 syslog(LOG_NOTICE, "ws: unit %s heater_state to %d, cooler_state to %d", unit->alias, unit->heater_state, unit->cooler_state); 200 syslog(LOG_NOTICE, "ws: unit %s heater_state to %d, cooler_state to %d", unit->alias, unit->heater_state, unit->cooler_state);
201 break; 201 return;
202 } 202 }
203 203
204 /* 204 /*
205 * Unit fan switch 205 * Unit fan switch
206 * {"type":"fermenter","unit":"unit0","fan_state":0} 206 * {"type":"fermenter","unit":"unit0","fan_state":0}
208 if ((json_object_object_get_ex(jobj, "fan_state", &val)) && (unit->mode == UNITMODE_NONE)) { 208 if ((json_object_object_get_ex(jobj, "fan_state", &val)) && (unit->mode == UNITMODE_NONE)) {
209 if (json_object_get_int(val) != unit->fan_state) 209 if (json_object_get_int(val) != unit->fan_state)
210 unit->fan_state = json_object_get_int(val); 210 unit->fan_state = json_object_get_int(val);
211 unit->mqtt_flag |= MQTT_FLAG_DATA; 211 unit->mqtt_flag |= MQTT_FLAG_DATA;
212 syslog(LOG_NOTICE, "ws: unit %s fan_state to %d", unit->alias, unit->fan_state); 212 syslog(LOG_NOTICE, "ws: unit %s fan_state to %d", unit->alias, unit->fan_state);
213 break; 213 return;
214 } 214 }
215 215
216 /* 216 /*
217 * We don't implement "light", "product", "profile" download here. 217 * We don't implement "light", "product", "profile" download here.
218 * But "profile" commands are implemented. That means a profile 218 * But "profile" commands are implemented. That means a profile
269 } 269 }
270 } 270 }
271 free(cmd); 271 free(cmd);
272 cmd = NULL; 272 cmd = NULL;
273 } 273 }
274 break; 274 return;
275 } 275 }
276 276
277 return; 277 return;
278 } 278 }
279 } 279 }
345 345
346 case LWS_CALLBACK_RECEIVE: 346 case LWS_CALLBACK_RECEIVE:
347 347
348 memcpy(buf, in, len); 348 memcpy(buf, in, len);
349 buf[len] = '\0'; 349 buf[len] = '\0';
350 syslog(LOG_NOTICE, "ws: reveived %ld bytes %s", len, buf); 350 syslog(LOG_NOTICE, "ws: received %ld bytes %s", len, buf);
351 /* 351 /*
352 * These are send by bmsapp to bmsd. Then bmsd resends these via MQTT. 352 * These are send by bmsapp to bmsd. Then bmsd resends these via MQTT.
353 * Do we want to change that? Or use it for the new web pages. 353 * Do we want to change that? Or use it for the new web pages.
354 * {"node":"rpi01","group_id":"fermenters","control":"reboot"} 354 * {"node":"rpi01","group_id":"fermenters","control":"reboot"}
355 * {"node":"rpi01","group_id":"fermenters","control":"rebirth"} 355 * {"node":"rpi01","group_id":"fermenters","control":"rebirth"}

mercurial