166 srv_send("%.1f", Config.cs_fridgeSet); |
161 srv_send("%.1f", Config.cs_fridgeSet); |
167 } else if (strncmp(buf, "getBeer", 7) == 0) { |
162 } else if (strncmp(buf, "getBeer", 7) == 0) { |
168 srv_send("%.1f", Config.cs_beerSet); |
163 srv_send("%.1f", Config.cs_beerSet); |
169 } else if (strncmp(buf, "getControlConstants", 19) == 0) { |
164 } else if (strncmp(buf, "getControlConstants", 19) == 0) { |
170 srv_send("{ \"tempFormat\":\"%c\", \"tempSetMin\":%.1f, \"tempSetMax\":%.1f, \"idleRangeH\":%.3f, \"idleRangeL\":%.3f }", |
165 srv_send("{ \"tempFormat\":\"%c\", \"tempSetMin\":%.1f, \"tempSetMax\":%.1f, \"idleRangeH\":%.3f, \"idleRangeL\":%.3f }", |
171 cc_tempFormat, cc_tempSetMin, cc_tempSetMax, cc_idleRangeH, cc_idleRangeL ); |
166 Config.cc_tempFormat, Config.cc_tempSetMin, Config.cc_tempSetMax, Config.cc_idleRangeH, Config.cc_idleRangeL ); |
172 } else if (strncmp(buf, "getControlSettings", 18) == 0) { |
167 } else if (strncmp(buf, "getControlSettings", 18) == 0) { |
173 srv_send("{ \"mode\":\"%c\", \"beerSet\":%.1f, \"fridgeSet\":%.1f, \"heatEstimator\":%.1f, \"coolEstimator\":%.1f }", |
168 srv_send("{ \"mode\":\"%c\", \"beerSet\":%.1f, \"fridgeSet\":%.1f, \"heatEstimator\":%.1f, \"coolEstimator\":%.1f }", |
174 Config.cs_mode, Config.cs_beerSet, Config.cs_fridgeSet, Config.cs_heatEstimator, Config.cs_coolEstimator); |
169 Config.cs_mode, Config.cs_beerSet, Config.cs_fridgeSet, Config.cs_heatEstimator, Config.cs_coolEstimator); |
175 } else if (strncmp(buf, "getControlVariables", 19) == 0) { |
170 } else if (strncmp(buf, "getControlVariables", 19) == 0) { |
176 srv_send("{ \"beerDiff\":%.2f }", cv_beerDiff); |
171 srv_send("{ \"beerDiff\":%.2f }", cv_beerDiff); |
184 inp = xstrcpy(buf+8); |
179 inp = xstrcpy(buf+8); |
185 rc = sscanf(inp, "%f", &newtemp); |
180 rc = sscanf(inp, "%f", &newtemp); |
186 if (debug) |
181 if (debug) |
187 fprintf(stdout, "new temp from %s, %.1f, rc=%d\n", inp, newtemp, rc); |
182 fprintf(stdout, "new temp from %s, %.1f, rc=%d\n", inp, newtemp, rc); |
188 if (rc == 1) { |
183 if (rc == 1) { |
189 if ((cc_tempSetMin <= newtemp) && (newtemp <= cc_tempSetMax)) { |
184 if ((Config.cc_tempSetMin <= newtemp) && (newtemp <= Config.cc_tempSetMax)) { |
190 syslog(LOG_NOTICE, "Beer temperature set to %.1f degrees in web interface", newtemp); |
185 syslog(LOG_NOTICE, "Beer temperature set to %.1f degrees in web interface", newtemp); |
191 srv_send("ack"); |
186 srv_send("ack"); |
192 Config.cs_mode = 'b'; |
187 Config.cs_mode = 'b'; |
193 Config.cs_beerSet = newtemp; |
188 Config.cs_beerSet = newtemp; |
194 } else { |
189 } else { |
195 syslog(LOG_NOTICE, "Beer temperature setting %.1f is outside of allowed range %.1f - %.1f", newtemp, cc_tempSetMin, cc_tempSetMax); |
190 syslog(LOG_NOTICE, "Beer temperature setting %.1f is outside of allowed range %.1f - %.1f", newtemp, Config.cc_tempSetMin, Config.cc_tempSetMax); |
196 srv_send("err"); |
191 srv_send("err"); |
197 } |
192 } |
198 } else { |
193 } else { |
199 syslog(LOG_NOTICE, "Cannot convert temperature '%s' to float", inp); |
194 syslog(LOG_NOTICE, "Cannot convert temperature '%s' to float", inp); |
200 srv_send("err"); |
195 srv_send("err"); |
204 inp = xstrcpy(buf+10); |
199 inp = xstrcpy(buf+10); |
205 rc = sscanf(inp, "%f", &newtemp); |
200 rc = sscanf(inp, "%f", &newtemp); |
206 if (debug) |
201 if (debug) |
207 fprintf(stdout, "new temp from %s, %.1f, rc=%d\n", inp, newtemp, rc); |
202 fprintf(stdout, "new temp from %s, %.1f, rc=%d\n", inp, newtemp, rc); |
208 if (rc == 1) { |
203 if (rc == 1) { |
209 if ((cc_tempSetMin <= newtemp) && (newtemp <= cc_tempSetMax)) { |
204 if ((Config.cc_tempSetMin <= newtemp) && (newtemp <= Config.cc_tempSetMax)) { |
210 syslog(LOG_NOTICE, "Fridge temperature set to %.1f degrees in web interface", newtemp); |
205 syslog(LOG_NOTICE, "Fridge temperature set to %.1f degrees in web interface", newtemp); |
211 srv_send("ack"); |
206 srv_send("ack"); |
212 Config.cs_mode = 'f'; |
207 Config.cs_mode = 'f'; |
213 Config.cs_fridgeSet = newtemp; |
208 Config.cs_fridgeSet = newtemp; |
214 } else { |
209 } else { |
215 syslog(LOG_NOTICE, "Fridge temperature setting %.1f is outside of allowed range %.1f - %.1f", newtemp, cc_tempSetMin, cc_tempSetMax); |
210 syslog(LOG_NOTICE, "Fridge temperature setting %.1f is outside of allowed range %.1f - %.1f", newtemp, Config.cc_tempSetMin, Config.cc_tempSetMax); |
216 srv_send("err"); |
211 srv_send("err"); |
217 } |
212 } |
218 } else { |
213 } else { |
219 syslog(LOG_NOTICE, "Cannot convert temperature '%s' to float", inp); |
214 syslog(LOG_NOTICE, "Cannot convert temperature '%s' to float", inp); |
220 srv_send("err"); |
215 srv_send("err"); |
224 if (debug) |
219 if (debug) |
225 fprintf(stdout, "temperature control disabled\n"); |
220 fprintf(stdout, "temperature control disabled\n"); |
226 syslog(LOG_NOTICE, "Notification: Temperature control disabled"); |
221 syslog(LOG_NOTICE, "Notification: Temperature control disabled"); |
227 Config.cs_mode = 'o'; |
222 Config.cs_mode = 'o'; |
228 srv_send("ack"); |
223 srv_send("ack"); |
229 } else if (strncmp(buf, "setParameters", 13) == 0) { |
224 } else if (strncmp(buf, "setParameters=", 14) == 0) { |
230 if (debug) |
225 inp = xstrcpy(buf+14); /* {"tempSetMax":30.5} */ |
231 fprintf(stdout, "FIXME:\n"); |
226 if (debug) |
232 srv_send("ack"); |
227 fprintf(stdout, "setParameters: %s\n", inp); |
|
228 strtok(inp, (char *)"\""); |
|
229 p = strtok(NULL, (char *)"\""); |
|
230 q = strtok(NULL, (char *)":,}"); |
|
231 if (strcmp(p, (char *)"tempSetMin") == 0) { |
|
232 rc = sscanf(q, "%f", &newtemp); |
|
233 if (rc == 1) { |
|
234 syslog(LOG_NOTICE, "cc_tempSetMin = %1.f", newtemp); |
|
235 Config.cc_tempSetMin = newtemp; |
|
236 srv_send("ack"); |
|
237 } else { |
|
238 srv_send("ERR"); |
|
239 } |
|
240 } else if (strcmp(p, (char *)"tempSetMax") == 0) { |
|
241 rc = sscanf(q, "%f", &newtemp); |
|
242 if (rc == 1) { |
|
243 syslog(LOG_NOTICE, "cc_tempSetMax = %1.f", newtemp); |
|
244 Config.cc_tempSetMax = newtemp; |
|
245 srv_send("ack"); |
|
246 } else { |
|
247 srv_send("ERR"); |
|
248 } |
|
249 } else { |
|
250 fprintf(stdout, "p='%s' q='%s' inp='%s'\n", p, q, inp); |
|
251 srv_send("ERR"); |
|
252 } |
233 // stopScript |
253 // stopScript |
234 // quit |
254 // quit |
235 // eraseLogs |
255 // eraseLogs |
236 // interval |
256 // interval |
237 // startNewBrew |
257 // startNewBrew |