37 struct hostent *hp; |
37 struct hostent *hp; |
38 |
38 |
39 #define SS_BUFSIZE 1024 |
39 #define SS_BUFSIZE 1024 |
40 #define SS_TIMEOUT 300 |
40 #define SS_TIMEOUT 300 |
41 |
41 |
42 unsigned char cs_mode = 'o'; /* o = Off, f = fridge, b = beer, p = profile-run */ |
|
43 float cs_beerSet = 20.0; |
|
44 float cs_fridgeSet = 20.0; |
|
45 float cs_heatEstimator = 0.2; |
|
46 float cs_coolEstimator = 5; |
|
47 |
|
48 unsigned char cc_tempFormat = 'C'; |
42 unsigned char cc_tempFormat = 'C'; |
49 float cc_tempSetMin = 1.0; |
43 float cc_tempSetMin = 1.0; |
50 float cc_tempSetMax = 30.0; |
44 float cc_tempSetMax = 30.0; |
51 float cc_idleRangeH = 1.000; |
45 float cc_idleRangeH = 1.000; |
52 float cc_idleRangeL = -1.000; |
46 float cc_idleRangeL = -1.000; |
165 obuf[i+50] = lcdbuf[lcdHandle][i][2]; |
159 obuf[i+50] = lcdbuf[lcdHandle][i][2]; |
166 obuf[i+74] = lcdbuf[lcdHandle][i][3]; |
160 obuf[i+74] = lcdbuf[lcdHandle][i][3]; |
167 } |
161 } |
168 srv_send(obuf); |
162 srv_send(obuf); |
169 } else if (strncmp(buf, "getMode", 7) == 0) { |
163 } else if (strncmp(buf, "getMode", 7) == 0) { |
170 srv_send("%c", cs_mode); |
164 srv_send("%c", Config.cs_mode); |
171 } else if (strncmp(buf, "getFridge", 9) == 0) { |
165 } else if (strncmp(buf, "getFridge", 9) == 0) { |
172 srv_send("%.1f", cs_fridgeSet); |
166 srv_send("%.1f", Config.cs_fridgeSet); |
173 } else if (strncmp(buf, "getBeer", 7) == 0) { |
167 } else if (strncmp(buf, "getBeer", 7) == 0) { |
174 srv_send("%.1f", cs_beerSet); |
168 srv_send("%.1f", Config.cs_beerSet); |
175 } else if (strncmp(buf, "getControlConstants", 19) == 0) { |
169 } else if (strncmp(buf, "getControlConstants", 19) == 0) { |
176 srv_send("{ \"tempFormat\":\"%c\", \"tempSetMin\":%.1f, \"tempSetMax\":%.1f, \"idleRangeH\":%.3f, \"idleRangeL\":%.3f }", |
170 srv_send("{ \"tempFormat\":\"%c\", \"tempSetMin\":%.1f, \"tempSetMax\":%.1f, \"idleRangeH\":%.3f, \"idleRangeL\":%.3f }", |
177 cc_tempFormat, cc_tempSetMin, cc_tempSetMax, cc_idleRangeH, cc_idleRangeL ); |
171 cc_tempFormat, cc_tempSetMin, cc_tempSetMax, cc_idleRangeH, cc_idleRangeL ); |
178 } else if (strncmp(buf, "getControlSettings", 18) == 0) { |
172 } else if (strncmp(buf, "getControlSettings", 18) == 0) { |
179 srv_send("{ \"mode\":\"%c\", \"beerSet\":%.1f, \"fridgeSet\":%.1f, \"heatEstimator\":%.1f, \"coolEstimator\":%.1f }", |
173 srv_send("{ \"mode\":\"%c\", \"beerSet\":%.1f, \"fridgeSet\":%.1f, \"heatEstimator\":%.1f, \"coolEstimator\":%.1f }", |
180 cs_mode, cs_beerSet, cs_fridgeSet, cs_heatEstimator, cs_coolEstimator); |
174 Config.cs_mode, Config.cs_beerSet, Config.cs_fridgeSet, Config.cs_heatEstimator, Config.cs_coolEstimator); |
181 } else if (strncmp(buf, "getControlVariables", 19) == 0) { |
175 } else if (strncmp(buf, "getControlVariables", 19) == 0) { |
182 srv_send("{ \"beerDiff\":%.2f }", cv_beerDiff); |
176 srv_send("{ \"beerDiff\":%.2f }", cv_beerDiff); |
183 } else if (strncmp(buf, "loadDefaultControlSettings", 26) == 0) { |
177 } else if (strncmp(buf, "loadDefaultControlSettings", 26) == 0) { |
184 defaultControlSettings(); |
178 defaultControlSettings(); |
185 srv_send("ack"); |
179 srv_send("ack"); |
193 fprintf(stdout, "new temp from %s, %.1f, rc=%d\n", inp, newtemp, rc); |
187 fprintf(stdout, "new temp from %s, %.1f, rc=%d\n", inp, newtemp, rc); |
194 if (rc == 1) { |
188 if (rc == 1) { |
195 if ((cc_tempSetMin <= newtemp) && (newtemp <= cc_tempSetMax)) { |
189 if ((cc_tempSetMin <= newtemp) && (newtemp <= cc_tempSetMax)) { |
196 syslog(LOG_NOTICE, "Beer temperature set to %.1f degrees in web interface", newtemp); |
190 syslog(LOG_NOTICE, "Beer temperature set to %.1f degrees in web interface", newtemp); |
197 srv_send("ack"); |
191 srv_send("ack"); |
198 cs_mode = 'b'; |
192 Config.cs_mode = 'b'; |
199 cs_beerSet = newtemp; |
193 Config.cs_beerSet = newtemp; |
200 } else { |
194 } else { |
201 syslog(LOG_NOTICE, "Beer temperature setting %.1f is outside of allowed range %.1f - %.1f", newtemp, cc_tempSetMin, cc_tempSetMax); |
195 syslog(LOG_NOTICE, "Beer temperature setting %.1f is outside of allowed range %.1f - %.1f", newtemp, cc_tempSetMin, cc_tempSetMax); |
202 srv_send("err"); |
196 srv_send("err"); |
203 } |
197 } |
204 } else { |
198 } else { |
213 fprintf(stdout, "new temp from %s, %.1f, rc=%d\n", inp, newtemp, rc); |
207 fprintf(stdout, "new temp from %s, %.1f, rc=%d\n", inp, newtemp, rc); |
214 if (rc == 1) { |
208 if (rc == 1) { |
215 if ((cc_tempSetMin <= newtemp) && (newtemp <= cc_tempSetMax)) { |
209 if ((cc_tempSetMin <= newtemp) && (newtemp <= cc_tempSetMax)) { |
216 syslog(LOG_NOTICE, "Fridge temperature set to %.1f degrees in web interface", newtemp); |
210 syslog(LOG_NOTICE, "Fridge temperature set to %.1f degrees in web interface", newtemp); |
217 srv_send("ack"); |
211 srv_send("ack"); |
218 cs_mode = 'f'; |
212 Config.cs_mode = 'f'; |
219 cs_fridgeSet = newtemp; |
213 Config.cs_fridgeSet = newtemp; |
220 } else { |
214 } else { |
221 syslog(LOG_NOTICE, "Fridge temperature setting %.1f is outside of allowed range %.1f - %.1f", newtemp, cc_tempSetMin, cc_tempSetMax); |
215 syslog(LOG_NOTICE, "Fridge temperature setting %.1f is outside of allowed range %.1f - %.1f", newtemp, cc_tempSetMin, cc_tempSetMax); |
222 srv_send("err"); |
216 srv_send("err"); |
223 } |
217 } |
224 } else { |
218 } else { |
228 free(inp); |
222 free(inp); |
229 } else if (strncmp(buf, "setOff", 6) == 0) { |
223 } else if (strncmp(buf, "setOff", 6) == 0) { |
230 if (debug) |
224 if (debug) |
231 fprintf(stdout, "temperature control disabled\n"); |
225 fprintf(stdout, "temperature control disabled\n"); |
232 syslog(LOG_NOTICE, "Notification: Temperature control disabled"); |
226 syslog(LOG_NOTICE, "Notification: Temperature control disabled"); |
233 cs_mode = 'o'; |
227 Config.cs_mode = 'o'; |
234 srv_send("ack"); |
228 srv_send("ack"); |
235 } else if (strncmp(buf, "setParameters", 13) == 0) { |
229 } else if (strncmp(buf, "setParameters", 13) == 0) { |
236 if (debug) |
230 if (debug) |
237 fprintf(stdout, "FIXME:\n"); |
231 fprintf(stdout, "FIXME:\n"); |
238 srv_send("ack"); |
232 srv_send("ack"); |