183 struct json_object *jobj, *pobj, *iobj, *val; |
183 struct json_object *jobj, *pobj, *iobj, *val; |
184 char *node = NULL, *alias = NULL, *beeruuid = NULL, *beercode = NULL, *beername = NULL; |
184 char *node = NULL, *alias = NULL, *beeruuid = NULL, *beercode = NULL, *beername = NULL; |
185 char *mode = NULL, *stage = NULL, *profile = NULL, *profile_uuid = NULL, *profile_name = NULL, *profile_steps = NULL; |
185 char *mode = NULL, *stage = NULL, *profile = NULL, *profile_uuid = NULL, *profile_name = NULL, *profile_steps = NULL; |
186 char *topic = NULL, *pay = NULL, buf[75], *profile_command = NULL; |
186 char *topic = NULL, *pay = NULL, buf[75], *profile_command = NULL; |
187 float setpoint_low = 0, setpoint_high = 0, yeast_lo = 0, yeast_hi = 0, inittemp_lo = 0, inittemp_hi = 0; |
187 float setpoint_low = 0, setpoint_high = 0, yeast_lo = 0, yeast_hi = 0, inittemp_lo = 0, inittemp_hi = 0; |
188 int heater_state = -1, cooler_state = -1, fan_state = -1, profile_fridgemode = -1; |
188 int heater_state = -1, cooler_state = -1, fan_state = -1, light_state = -1, profile_fridgemode = -1; |
189 |
189 |
190 syslog(LOG_NOTICE, "fermenter_ws_receive(%s)", payload); |
190 syslog(LOG_NOTICE, "fermenter_ws_receive(%s)", payload); |
191 |
191 |
192 /* |
192 /* |
193 * Process the JSON formatted payload. |
193 * Process the JSON formatted payload. |
219 heater_state = json_object_get_int(val); |
219 heater_state = json_object_get_int(val); |
220 if (json_object_object_get_ex(jobj, "cooler_state", &val)) |
220 if (json_object_object_get_ex(jobj, "cooler_state", &val)) |
221 cooler_state = json_object_get_int(val); |
221 cooler_state = json_object_get_int(val); |
222 if (json_object_object_get_ex(jobj, "fan_state", &val)) |
222 if (json_object_object_get_ex(jobj, "fan_state", &val)) |
223 fan_state = json_object_get_int(val); |
223 fan_state = json_object_get_int(val); |
|
224 if (json_object_object_get_ex(jobj, "light_state", &val)) |
|
225 light_state = json_object_get_int(val); |
224 if (json_object_object_get_ex(jobj, "profile", &pobj)) { |
226 if (json_object_object_get_ex(jobj, "profile", &pobj)) { |
225 profile = xstrcpy((char *)json_object_get_string(pobj)); |
227 profile = xstrcpy((char *)json_object_get_string(pobj)); |
226 if (profile == NULL) { // clear profile request |
228 if (profile == NULL) { // clear profile request |
227 profile = xstrcpy((char *)"null"); |
229 profile = xstrcpy((char *)"null"); |
228 } |
230 } |
329 pay = xstrcat(pay, (char *)"}}}"); |
331 pay = xstrcat(pay, (char *)"}}}"); |
330 mqtt_publish(topic, pay); |
332 mqtt_publish(topic, pay); |
331 free(pay); |
333 free(pay); |
332 pay = NULL; |
334 pay = NULL; |
333 } |
335 } |
|
336 |
|
337 if (light_state >= 0) { |
|
338 syslog(LOG_NOTICE, "Set fermenter %s/%s light %d", node, alias, light_state); |
|
339 pay = fermenter_paybase(); |
|
340 pay = xstrcat(pay, (char *)"{\"light\":{\"state\":"); |
|
341 snprintf(buf, 64, "%d", light_state); |
|
342 pay = xstrcat(pay, buf); |
|
343 pay = xstrcat(pay, (char *)"}}}"); |
|
344 mqtt_publish(topic, pay); |
|
345 free(pay); |
|
346 pay = NULL; |
|
347 } |
334 |
348 |
335 if (beeruuid && beercode && beername && (yeast_hi > yeast_lo) && (yeast_lo > 0)) { |
349 if (beeruuid && beercode && beername && (yeast_hi > yeast_lo) && (yeast_lo > 0)) { |
336 syslog(LOG_NOTICE, "Set fermenter %s/%s beer %s %s", node, alias, beercode, beername); |
350 syslog(LOG_NOTICE, "Set fermenter %s/%s beer %s %s", node, alias, beercode, beername); |
337 pay = fermenter_paybase(); |
351 pay = fermenter_paybase(); |
338 pay = xstrcat(pay, (char *)"{\"product\":{\"uuid\":\""); |
352 pay = xstrcat(pay, (char *)"{\"product\":{\"uuid\":\""); |