18 * You should have received a copy of the GNU General Public License |
18 * You should have received a copy of the GNU General Public License |
19 * along with EC-65K; see the file COPYING. If not, write to the Free |
19 * along with EC-65K; see the file COPYING. If not, write to the Free |
20 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
20 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
21 *****************************************************************************/ |
21 *****************************************************************************/ |
22 |
22 |
23 |
|
24 #include "../lib/mbselib.h" |
|
25 #include "server.h" |
|
26 #include "thermferm.h" |
23 #include "thermferm.h" |
27 |
24 |
28 extern bool my_shutdown; |
25 extern bool my_shutdown; |
29 extern bool debug; |
26 extern bool debug; |
30 extern int lcdHandle; |
27 extern int lcdHandle; |
136 hostname = inet_ntoa(peeraddr_in.sin_addr); |
133 hostname = inet_ntoa(peeraddr_in.sin_addr); |
137 } else { |
134 } else { |
138 hostname = hp->h_name; |
135 hostname = hp->h_name; |
139 } |
136 } |
140 |
137 |
141 if (debug) { |
138 // if (debug) { |
142 syslog(LOG_NOTICE, "Start new client connection from %s port %u", hostname, ntohs(peeraddr_in.sin_port)); |
139 // syslog(LOG_NOTICE, "Start new client connection from %s port %u", hostname, ntohs(peeraddr_in.sin_port)); |
143 fprintf(stdout, "Start new client connection from %s port %u\n", hostname, ntohs(peeraddr_in.sin_port)); |
140 // fprintf(stdout, "Start new client connection from %s port %u\n", hostname, ntohs(peeraddr_in.sin_port)); |
144 } |
141 // } |
145 |
142 |
146 memset((char *)&buf, 0, SS_BUFSIZE); |
143 memset((char *)&buf, 0, SS_BUFSIZE); |
147 fromlen = sizeof(peeraddr_in); |
144 fromlen = sizeof(peeraddr_in); |
148 rlen = recvfrom(s, buf, sizeof(buf) -1, 0, (struct sockaddr *)&peeraddr_in, &fromlen); |
145 rlen = recvfrom(s, buf, sizeof(buf) -1, 0, (struct sockaddr *)&peeraddr_in, &fromlen); |
149 if (rlen == -1) { |
146 if (rlen == -1) { |
199 inp = xstrcpy(buf+8); |
196 inp = xstrcpy(buf+8); |
200 rc = sscanf(inp, "%f", &newtemp); |
197 rc = sscanf(inp, "%f", &newtemp); |
201 if (debug) |
198 if (debug) |
202 fprintf(stdout, "new temp from %s, %.1f, rc=%d\n", inp, newtemp, rc); |
199 fprintf(stdout, "new temp from %s, %.1f, rc=%d\n", inp, newtemp, rc); |
203 if (rc == 1) { |
200 if (rc == 1) { |
204 srv_send("ack"); |
201 if ((cc_tempSetMin <= newtemp) && (newtemp <= cc_tempSetMax)) { |
205 cs_mode = 'b'; |
202 syslog(LOG_NOTICE, "Beer temperature set to %.1f degrees in web interface", newtemp); |
206 cs_beerSet = newtemp; |
203 srv_send("ack"); |
|
204 cs_mode = 'b'; |
|
205 cs_beerSet = newtemp; |
|
206 } else { |
|
207 syslog(LOG_NOTICE, "Beer temperature setting %.1f is outside of allowed range %.1f - %.1f", newtemp, cc_tempSetMin, cc_tempSetMax); |
|
208 srv_send("err"); |
|
209 } |
207 } else { |
210 } else { |
|
211 syslog(LOG_NOTICE, "Cannot convert temperature '%s' to float", inp); |
208 srv_send("err"); |
212 srv_send("err"); |
209 } |
213 } |
210 free(inp); |
214 free(inp); |
211 } else if (strncmp(buf, "setFridge=", 10) == 0) { |
215 } else if (strncmp(buf, "setFridge=", 10) == 0) { |
212 inp = xstrcpy(buf+10); |
216 inp = xstrcpy(buf+10); |
213 rc = sscanf(inp, "%f", &newtemp); |
217 rc = sscanf(inp, "%f", &newtemp); |
214 if (debug) |
218 if (debug) |
215 fprintf(stdout, "new temp from %s, %.1f, rc=%d\n", inp, newtemp, rc); |
219 fprintf(stdout, "new temp from %s, %.1f, rc=%d\n", inp, newtemp, rc); |
216 if (rc == 1) { |
220 if (rc == 1) { |
217 srv_send("ack"); |
221 if ((cc_tempSetMin <= newtemp) && (newtemp <= cc_tempSetMax)) { |
218 cs_mode = 'f'; |
222 syslog(LOG_NOTICE, "Fridge temperature set to %.1f degrees in web interface", newtemp); |
219 cs_fridgeSet = newtemp; |
223 srv_send("ack"); |
|
224 cs_mode = 'f'; |
|
225 cs_fridgeSet = newtemp; |
|
226 } else { |
|
227 syslog(LOG_NOTICE, "Fridge temperature setting %.1f is outside of allowed range %.1f - %.1f", newtemp, cc_tempSetMin, cc_tempSetMax); |
|
228 srv_send("err"); |
|
229 } |
220 } else { |
230 } else { |
|
231 syslog(LOG_NOTICE, "Cannot convert temperature '%s' to float", inp); |
221 srv_send("err"); |
232 srv_send("err"); |
222 } |
233 } |
223 free(inp); |
234 free(inp); |
224 } else if (strncmp(buf, "setOff", 6) == 0) { |
235 } else if (strncmp(buf, "setOff", 6) == 0) { |
225 if (debug) |
236 if (debug) |
226 fprintf(stdout, "temperature control disabled\n"); |
237 fprintf(stdout, "temperature control disabled\n"); |
|
238 syslog(LOG_NOTICE, "Notification: Temperature control disabled"); |
227 cs_mode = 'o'; |
239 cs_mode = 'o'; |
228 srv_send("ack"); |
240 srv_send("ack"); |
|
241 } else if (strncmp(buf, "setParameters", 13) == 0) { |
|
242 if (debug) |
|
243 fprintf(stdout, "FIXME:\n"); |
|
244 srv_send("ack"); |
|
245 // stopScript |
|
246 // quit |
|
247 // eraseLogs |
|
248 // interval |
|
249 // startNewBrew |
|
250 // pauseLogging |
|
251 // stopLogging |
|
252 // resumeLogging |
|
253 // dateTimeFormatDisplay |
|
254 } else if (strncmp(buf, "setActiveProfile", 16) == 0) { |
|
255 syslog(LOG_NOTICE, "Setting profile '%s' as active profile", "undefined"); |
|
256 // programArduino |
|
257 // refreshDeviceList |
|
258 // getDeviceList |
|
259 // applyDevice |
229 } else { |
260 } else { |
230 if (debug) |
261 if (debug) |
231 fprintf(stdout, "unknown command \"%s\"\n", buf); |
262 fprintf(stdout, "unknown command \"%s\"\n", buf); |
232 srv_send((char *)"ERR"); |
263 srv_send((char *)"ERR"); |
233 } |
264 } |
234 } |
265 } |
235 } |
266 } |
236 |
267 |
237 if (debug) { |
268 // if (debug) { |
238 syslog(LOG_NOTICE, "End connection from %s port %u", hostname, ntohs(peeraddr_in.sin_port)); |
269 // syslog(LOG_NOTICE, "End connection from %s port %u", hostname, ntohs(peeraddr_in.sin_port)); |
239 fprintf(stdout, "End connection from %s port %u\n", hostname, ntohs(peeraddr_in.sin_port)); |
270 // fprintf(stdout, "End connection from %s port %u\n", hostname, ntohs(peeraddr_in.sin_port)); |
240 } |
271 // } |
241 |
272 |
242 close(s); |
273 close(s); |
243 } |
274 } |
244 |
275 |
245 |
276 |