Wed, 02 Jul 2014 22:09:35 +0200
Added SET commands
42
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
1 | /***************************************************************************** |
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
2 | * Copyright (C) 2008-2014 |
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
3 | * |
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
4 | * Michiel Broek <mbroek at mbse dot eu> |
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
5 | * |
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
6 | * This file is part of the mbsePi-apps |
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
7 | * |
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
8 | * This is free software; you can redistribute it and/or modify it |
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
9 | * under the terms of the GNU General Public License as published by the |
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
10 | * Free Software Foundation; either version 2, or (at your option) any |
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
11 | * later version. |
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
12 | * |
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
13 | * mbsePi-apps is distributed in the hope that it will be useful, but |
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
16 | * General Public License for more details. |
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
17 | * |
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
18 | * You should have received a copy of the GNU General Public License |
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
19 | * along with EC-65K; see the file COPYING. If not, write to the Free |
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
20 | * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
21 | *****************************************************************************/ |
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
22 | |
46
000399c64d3f
More client/server communications
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
23 | #include "thermferm.h" |
42
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
24 | |
58
e8e7b46b705b
Fixed compilation without wiringpi
Michiel Broek <mbroek@mbse.eu>
parents:
54
diff
changeset
|
25 | |
75
4b976601737d
Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents:
74
diff
changeset
|
26 | extern int my_shutdown; |
4b976601737d
Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents:
74
diff
changeset
|
27 | extern int debug; |
71 | 28 | extern int current_unit; |
66
805f1d285acd
Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents:
62
diff
changeset
|
29 | #ifdef HAVE_WIRINGPI_H |
42
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
30 | extern int lcdHandle; |
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
31 | extern unsigned char lcdbuf[MAX_LCDS][20][4]; |
66
805f1d285acd
Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents:
62
diff
changeset
|
32 | #endif |
43 | 33 | extern sys_config Config; |
81 | 34 | extern const char UNITMODE[5][8]; |
42
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
35 | |
43 | 36 | int s; /* connected socket */ |
37 | int ls; /* listen socket */ | |
42
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
38 | |
43 | 39 | struct sockaddr_in myaddr_in; /* for local socket address */ |
40 | struct sockaddr_in peeraddr_in; /* for peer socket address */ | |
41 | ||
42 | struct hostent *hp; | |
43 | ||
44 | #define SS_BUFSIZE 1024 | |
45 | #define SS_TIMEOUT 300 | |
42
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
46 | |
48 | 47 | |
48 | float cv_beerDiff = 0.0; | |
49 | ||
42
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
50 | |
46
000399c64d3f
More client/server communications
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
51 | |
49
92a9ca143677
Fixed temperature logging, added some commands
Michiel Broek <mbroek@mbse.eu>
parents:
48
diff
changeset
|
52 | void defaultControlSettings(void) |
46
000399c64d3f
More client/server communications
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
53 | { |
53 | 54 | Config.cs_mode = 'o'; /* o = Off, f = fridge, b = beer, p = profile-run */ |
55 | Config.cs_beerSet = 20.0; | |
56 | Config.cs_fridgeSet = 20.0; | |
57 | Config.cs_heatEstimator = 0.2; | |
58 | Config.cs_coolEstimator = 5; | |
46
000399c64d3f
More client/server communications
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
59 | } |
000399c64d3f
More client/server communications
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
60 | |
000399c64d3f
More client/server communications
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
61 | |
000399c64d3f
More client/server communications
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
62 | |
000399c64d3f
More client/server communications
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
63 | void defaultControlConstants(void) |
000399c64d3f
More client/server communications
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
64 | { |
77
143077e54255
Added old configuration to write xml config
Michiel Broek <mbroek@mbse.eu>
parents:
75
diff
changeset
|
65 | Config.tempFormat = 'C'; |
54
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
66 | Config.cc_tempSetMin = 1.0; |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
67 | Config.cc_tempSetMax = 30.0; |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
68 | Config.cc_idleRangeH = 1.000; |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
69 | Config.cc_idleRangeL = -1.000; |
46
000399c64d3f
More client/server communications
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
70 | } |
000399c64d3f
More client/server communications
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
71 | |
000399c64d3f
More client/server communications
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
72 | |
000399c64d3f
More client/server communications
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
73 | |
43 | 74 | /* |
75 | * Send message to client | |
76 | */ | |
77 | int srv_send(const char *format, ...) | |
78 | { | |
79 | char out[SS_BUFSIZE]; | |
80 | va_list va_ptr; | |
81 | ||
82 | if (s == -1) | |
83 | return -1; | |
42
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
84 | |
43 | 85 | va_start(va_ptr, format); |
86 | vsnprintf(out, SS_BUFSIZE-1, format, va_ptr); | |
87 | va_end(va_ptr); | |
88 | ||
48 | 89 | if (debug) { |
80
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
90 | syslog(LOG_NOTICE, "send: \"%s\"", out); |
45
053c4657105f
Mirror LCD display on the webpage works
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
91 | fprintf(stdout, "send: \"%s\"\n", out); |
48 | 92 | } |
44 | 93 | |
43 | 94 | if (send(s, out, strlen(out), 0) != strlen(out)) { |
95 | syslog(LOG_NOTICE, "srv_send failed"); | |
96 | return -1; | |
97 | } | |
80
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
98 | |
43 | 99 | if (send(s, (char *)"\r\n", 2, 0) != 2) { |
100 | syslog(LOG_NOTICE, "srv_send failed"); | |
101 | return -1; | |
102 | } | |
103 | ||
104 | return 0; | |
105 | } | |
106 | ||
107 | ||
42
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
108 | |
88 | 109 | /* |
110 | * ADD name | |
111 | */ | |
80
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
112 | int unit_add(char *buf) |
43 | 113 | { |
80
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
114 | units_list *unit, *tmp; |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
115 | uuid_t uu; |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
116 | char *cmd, *opt; |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
117 | int id = 1; |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
118 | |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
119 | cmd = strtok(buf, " \0"); |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
120 | opt = strtok(NULL, "\0"); |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
121 | if (opt == NULL) { |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
122 | srv_send((char *)"501 Parameter missing"); |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
123 | return 1; |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
124 | } |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
125 | |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
126 | if (debug) |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
127 | fprintf(stdout, "cmd: '%s' opt: '%s'\n", MBSE_SS(cmd), MBSE_SS(opt)); |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
128 | |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
129 | unit = (units_list *)malloc(sizeof(units_list)); |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
130 | unit->next = NULL; |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
131 | unit->uuid = malloc(37); |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
132 | uuid_generate(uu); |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
133 | uuid_unparse(uu, unit->uuid); |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
134 | unit->name = xstrcpy(opt); |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
135 | unit->air_address = unit->beer_address = unit->io1_address = unit->io2_address = unit->profile = NULL; |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
136 | unit->volume = 0.0; |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
137 | unit->heater_available = unit->cooler_available = unit->fan_available = FALSE; |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
138 | unit->air_temp = unit->beer_temp = unit->beer_set = unit->fridge_set = 20.0; |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
139 | unit->heater_state = unit->cooler_state = unit->fan_state = unit->door_state = unit->mode = 0; |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
140 | unit->temp_set_min = 1.0; |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
141 | unit->temp_set_max = 30.0; |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
142 | unit->idle_rangeH = 1.0; |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
143 | unit->idle_rangeL = -1.0; |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
144 | unit->prof_started = (time_t)0; |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
145 | |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
146 | if (Config.units == NULL) { |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
147 | Config.units = unit; |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
148 | } else { |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
149 | for (tmp = Config.units; tmp; tmp = tmp->next) { |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
150 | id++; |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
151 | if (tmp->next == NULL) { |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
152 | tmp->next = unit; |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
153 | break; |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
154 | } |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
155 | } |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
156 | } |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
157 | |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
158 | syslog(LOG_NOTICE, "Unit %d with uuid %s added", id, unit->uuid); |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
159 | srv_send((char *)"211 Unit %d with uuid %s added", id, unit->uuid); |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
160 | current_unit = id; |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
161 | return 0; |
43 | 162 | } |
163 | ||
164 | ||
165 | ||
81 | 166 | /* |
167 | * LIST | |
84 | 168 | * LIST BUS |
169 | * LIST PROFILES | |
170 | * LIST UNIT | |
81 | 171 | */ |
172 | int cmd_list(char *buf) | |
173 | { | |
87
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
174 | char *opt, *mypath; |
84 | 175 | units_list *unit; |
176 | int i; | |
177 | DIR *fd; | |
178 | struct dirent *de; | |
81 | 179 | |
87
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
180 | opt = strtok(buf, " \0"); |
81 | 181 | opt = strtok(NULL, " \0"); |
84 | 182 | |
81 | 183 | if (opt == NULL) { |
184 | srv_send((char *)"212 Fermenter list follows:"); | |
185 | i = 0; | |
186 | for (unit = Config.units; unit; unit = unit->next) { | |
187 | i++; | |
188 | srv_send((char *)"%02d %s %-20s %-7s", i, unit->uuid, unit->name, UNITMODE[unit->mode]); | |
189 | } | |
190 | srv_send((char *)"."); | |
84 | 191 | } else if (strcmp(opt, (char *)"BUS") == 0) { |
86
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
192 | /* |
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
193 | * 1-wire bus |
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
194 | */ |
84 | 195 | if ((fd = opendir((char *)"/sys/bus/w1/devices"))) { |
86
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
196 | srv_send((char *)"212 1-wire bus devices:"); |
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
197 | while ((de = readdir(fd))) { |
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
198 | if (de->d_name[0] != '.') { |
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
199 | if (strncmp(de->d_name, (char *)"w1", 2) == 0) { |
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
200 | srv_send((char *)"%-15s system device", de->d_name); |
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
201 | } else if (strncmp(de->d_name, (char *)"10", 2) == 0) { |
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
202 | srv_send((char *)"%-15s 18S20 digital thermometer", de->d_name); |
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
203 | } else if (strncmp(de->d_name, (char *)"28", 2) == 0) { |
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
204 | srv_send((char *)"%-15s 18B20 digital thermometer", de->d_name); |
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
205 | } else if (strncmp(de->d_name, (char *)"29", 2) == 0) { |
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
206 | srv_send((char *)"%-15s 2408 8-channel addressable switch/LCD", de->d_name); |
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
207 | } else if (strncmp(de->d_name, (char *)"3a", 2) == 0) { |
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
208 | srv_send((char *)"%-15s 2413 dual channel addressable switchs", de->d_name); |
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
209 | } else { |
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
210 | srv_send((char *)"%-15s unknown device", de->d_name); |
84 | 211 | } |
212 | } | |
86
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
213 | } |
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
214 | srv_send((char *)"."); |
84 | 215 | closedir(fd); |
216 | } else { | |
217 | srv_send((char *)"503 directory /sys/bus/w1/devices: %s", strerror(errno)); | |
218 | } | |
219 | } else if (strcmp(opt, (char *)"PROFILES") == 0) { | |
86
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
220 | /* |
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
221 | * User profiles directory |
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
222 | */ |
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
223 | if (getenv((char *)"USER") == NULL) { |
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
224 | mypath = xstrcpy((char *)"/root"); |
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
225 | } else { |
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
226 | mypath = xstrcpy(getenv((char *)"HOME")); |
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
227 | } |
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
228 | mypath = xstrcat(mypath, (char *)"/.thermferm/profiles/"); |
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
229 | mkdirs(mypath, 0755); |
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
230 | if ((fd = opendir(mypath))) { |
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
231 | srv_send((char *)"212 profiles:"); |
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
232 | while ((de = readdir(fd))) { |
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
233 | if (de->d_name[0] != '.') { |
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
234 | srv_send((char *)"%s", de->d_name); |
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
235 | } |
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
236 | } |
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
237 | srv_send((char *)"."); |
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
238 | closedir(fd); |
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
239 | } else { |
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
240 | srv_send((char *)"503 directory %s: %s", mypath, strerror(errno)); |
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
241 | } |
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
242 | free(mypath); |
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
243 | mypath = NULL; |
84 | 244 | } else if (strcmp(opt, (char *)"UNIT") == 0) { |
86
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
245 | /* |
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
246 | * List configured and selected fermenter unit |
3d7a241329e2
Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
247 | */ |
84 | 248 | if (current_unit == -1) { |
249 | srv_send((char *)"401 No fermenter unit selected"); | |
250 | } else { | |
87
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
251 | srv_send((char *)"213 Unit %d listing follows:", current_unit); |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
252 | i = 0; |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
253 | for (unit = Config.units; unit; unit = unit->next) { |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
254 | i++; |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
255 | if (i == current_unit) { |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
256 | srv_send((char *)"Name of the unit/beer %s", unit->name); |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
257 | srv_send((char *)"UUID of this unit %s", unit->uuid); |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
258 | if (unit->air_address) { |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
259 | srv_send((char *)"1-wire address air sensor %s", unit->air_address); |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
260 | srv_send((char *)"Air temperature %.1f", unit->air_temp); |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
261 | } |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
262 | if (unit->beer_address) { |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
263 | srv_send((char *)"1-wire address beer sensor %s", unit->air_address); |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
264 | srv_send((char *)"Beer temperature %.1f", unit->air_temp); |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
265 | } |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
266 | if (unit->io1_address) { |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
267 | srv_send((char *)"1-wire address cool/heat %s", unit->io1_address); |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
268 | } |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
269 | if (unit->io2_address) { |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
270 | srv_send((char *)"1-wire address fan/door %s", unit->io2_address); |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
271 | } |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
272 | if (unit->heater_available) { |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
273 | srv_send((char *)"Heater available %s", unit->heater_available); |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
274 | } |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
275 | if (unit->cooler_available) { |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
276 | srv_send((char *)"Cooler available %s", unit->cooler_available); |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
277 | } |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
278 | if (unit->fan_available) { |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
279 | srv_send((char *)"Fan available %s", unit->fan_available); |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
280 | } |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
281 | srv_send((char *)"Unit mode %s", UNITMODE[unit->mode]); |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
282 | srv_send((char *)"Fridge temperature set to %.1f", unit->fridge_set); |
88 | 283 | srv_send((char *)"Beer temperature set to %.1f", unit->beer_set); |
87
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
284 | if (unit->profile) { |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
285 | srv_send((char *)"Profile name %s", unit->profile); |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
286 | } |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
287 | srv_send((char *)"Temperature range %.1f .. %.1f", unit->temp_set_min, unit->temp_set_max); |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
288 | srv_send((char *)"Idle temperature range %.1f .. %.1f", unit->idle_rangeL, unit->idle_rangeH); |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
289 | } |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
290 | } |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
291 | srv_send((char *)"."); |
84 | 292 | } |
293 | } else { | |
294 | srv_send((char *)"502 Unknown command option"); | |
81 | 295 | } |
296 | ||
297 | return 0; | |
298 | } | |
299 | ||
300 | ||
301 | ||
87
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
302 | /* |
88 | 303 | * Set new operating mode |
304 | * MODE OFF|NONE|BEER|FRIDGE|PROFILE | |
305 | */ | |
306 | int cmd_mode(char *buf) | |
307 | { | |
308 | return 1; | |
309 | } | |
310 | ||
311 | ||
312 | ||
313 | /* | |
314 | * SET commands | |
315 | */ | |
316 | int cmd_set(char *buf) | |
317 | { | |
318 | char *opt, *param; | |
319 | units_list *unit; | |
320 | int i, rc; | |
321 | float fval; | |
322 | ||
323 | opt = strtok(buf, " \0"); | |
324 | opt = strtok(NULL, " \0"); | |
325 | if (opt == NULL) { | |
326 | srv_send((char *)"501 Subcommand missing"); | |
327 | return 1; | |
328 | } | |
329 | ||
330 | param = strtok(NULL, "\0"); | |
331 | if (param == NULL) { | |
332 | srv_send((char *)"501 Parameter missing"); | |
333 | return 1; | |
334 | } | |
335 | ||
336 | rc = sscanf(param, "%f", &fval); | |
337 | ||
338 | if (debug) | |
339 | fprintf(stdout, "opt='%s' param='%s' rc=%d fval=%.1f\n", opt, param, rc, fval); | |
340 | ||
341 | /* | |
342 | * Commands below need a selected unit | |
343 | */ | |
344 | if (current_unit == -1) { | |
345 | srv_send((char *)"401 No fermenter unit selected"); | |
346 | return 1; | |
347 | } | |
348 | ||
349 | i = 0; | |
350 | for (unit = Config.units; unit; unit = unit->next) { | |
351 | i++; | |
352 | if (i == current_unit) | |
353 | break; | |
354 | } | |
355 | ||
356 | /* | |
357 | * If a valid parameter float value | |
358 | */ | |
359 | if (rc == 1) { | |
360 | if (strcmp(opt, (char *)"BEER") == 0) { | |
361 | if ((fval >= unit->temp_set_min) && (fval <= unit->temp_set_max)) { | |
362 | unit->beer_set = fval; | |
363 | srv_send((char *)"214 Unit %d BEER set to %.1f", current_unit, fval); | |
364 | return 0; | |
365 | } else { | |
366 | srv_send((char *)"510 New temperature not between %.1f and %.1f", unit->temp_set_min, unit->temp_set_max); | |
367 | return 1; | |
368 | } | |
369 | } else if (strcmp(opt, (char *)"FRIDGE") == 0) { | |
370 | if ((fval >= unit->temp_set_min) && (fval <= unit->temp_set_max)) { | |
371 | unit->fridge_set = fval; | |
372 | srv_send((char *)"214 Unit %d BEER set to %.1f", current_unit, fval); | |
373 | return 0; | |
374 | } else { | |
375 | srv_send((char *)"510 New temperature not between %.1f and %.1f", unit->temp_set_min, unit->temp_set_max); | |
376 | return 1; | |
377 | } | |
378 | } else if (strcmp(opt, (char *)"VOLUME") == 0) { | |
379 | /* | |
380 | * Must fit in a 2 TEU container | |
381 | */ | |
382 | if ((fval >= 0.0) && (fval <= 77020.0)) { | |
383 | unit->volume = fval; | |
384 | srv_send((char *)"214 Unit %d VOLUME set to %.1f", current_unit, fval); | |
385 | return 0; | |
386 | } else { | |
387 | srv_send((char *)"510 New volume not between 0 and 77020"); | |
388 | return 1; | |
389 | } | |
390 | } else if (strcmp(opt, (char *)"IDLE_LOW") == 0) { | |
391 | if ((fval >= -5.0) && (fval <= -0.1)) { | |
392 | unit->idle_rangeL = fval; | |
393 | srv_send((char *)"214 Unit %d IDLE_LOW set to %.1f", current_unit, fval); | |
394 | return 0; | |
395 | } else { | |
396 | srv_send((char *)"510 New value not between -5.0 and -0.1"); | |
397 | return 1; | |
398 | } | |
399 | } else if (strcmp(opt, (char *)"IDLE_HIGH") == 0) { | |
400 | if ((fval >= 0.1) && (fval <= 5.0)) { | |
401 | unit->idle_rangeH = fval; | |
402 | srv_send((char *)"214 Unit %d IDLE_HIGH set to %.1f", current_unit, fval); | |
403 | return 0; | |
404 | } else { | |
405 | srv_send((char *)"510 New value not between -5.0 and -0.1"); | |
406 | return 1; | |
407 | } | |
408 | } else if (strcmp(opt, (char *)"TEMP_MIN") == 0) { | |
409 | if ((fval >= -2.0) && (fval <= 35.0) && (fval < unit->temp_set_max)) { | |
410 | unit->temp_set_min = fval; | |
411 | srv_send((char *)"214 Unit %d TEMP_MIN set to %.1f", current_unit, fval); | |
412 | return 0; | |
413 | } else { | |
414 | srv_send((char *)"510 New value not between -2.0 and 35.0 and lower then TEMP_MAX"); | |
415 | return 1; | |
416 | } | |
417 | } else if (strcmp(opt, (char *)"TEMP_MAX") == 0) { | |
418 | if ((fval >= -2.0) && (fval <= 35.0) && (fval > unit->temp_set_min)) { | |
419 | unit->temp_set_max = fval; | |
420 | srv_send((char *)"214 Unit %d TEMP_MAX set to %.1f", current_unit, fval); | |
421 | return 0; | |
422 | } else { | |
423 | srv_send((char *)"510 New value not between -2.0 and 35.0 and higher then TEMP_MIN"); | |
424 | return 1; | |
425 | } | |
426 | } | |
427 | } | |
428 | ||
429 | /* | |
430 | * Set new unit or beer name | |
431 | */ | |
432 | if (strcmp(opt, (char *)"NAME") == 0) { | |
433 | if (unit->name) | |
434 | free(unit->name); | |
435 | unit->name = xstrcpy(param); | |
436 | srv_send((char *)"214 Unit %d NAME set to '%s'", current_unit, param); | |
437 | // TODO: change logfile name | |
438 | return 0; | |
439 | } else if (strcmp(opt, (char *)"PROFILE") == 0) { | |
440 | // check profile file, excists, type, at least one profile item | |
441 | } | |
442 | ||
443 | srv_send((char *)"502 Unknown command option"); | |
444 | return 1; | |
445 | } | |
446 | ||
447 | ||
448 | ||
449 | /* | |
87
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
450 | * UNIT n |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
451 | * UNIT uuid |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
452 | */ |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
453 | int cmd_unit(char *buf) |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
454 | { |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
455 | char *opt; |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
456 | units_list *tmp; |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
457 | int i, unit_no; |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
458 | |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
459 | opt = strtok(buf, " \0"); |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
460 | opt = strtok(NULL, " \0"); |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
461 | |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
462 | if (opt == NULL) { |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
463 | srv_send((char *)"501 Parameter missing"); |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
464 | return 1; |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
465 | } |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
466 | |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
467 | i = 0; |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
468 | if (strlen(opt) == 36) { |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
469 | /* |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
470 | * Search using uuid |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
471 | */ |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
472 | for (tmp = Config.units; tmp; tmp = tmp->next) { |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
473 | i++; |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
474 | if (strcmp(opt, tmp->uuid) == 0) { |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
475 | srv_send((char *)"210 Unit %d selected", i); |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
476 | current_unit = i; |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
477 | return 0; |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
478 | } |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
479 | } |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
480 | srv_send((char *)"410 No such unit"); |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
481 | return 1; |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
482 | } |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
483 | |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
484 | if (sscanf(opt, "%d", &unit_no) == 1) { |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
485 | /* |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
486 | * We got a number, see if it is valid. |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
487 | */ |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
488 | for (tmp = Config.units; tmp; tmp = tmp->next) { |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
489 | i++; |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
490 | if (unit_no == i) { |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
491 | srv_send((char *)"210 Unit %d selected", i); |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
492 | current_unit = i; |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
493 | return 0; |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
494 | } |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
495 | } |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
496 | srv_send((char *)"410 No such unit"); |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
497 | return 1; |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
498 | } |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
499 | |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
500 | srv_send((char *)"502 Unknown command option"); |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
501 | return 1; |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
502 | } |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
503 | |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
504 | |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
505 | |
43 | 506 | void cmd_server(void) |
507 | { | |
54
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
508 | char *inp, *p, *q, buf[SS_BUFSIZE], obuf[SS_BUFSIZE]; |
48 | 509 | int i, rc, rlen; |
43 | 510 | socklen_t fromlen; |
46
000399c64d3f
More client/server communications
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
511 | float newtemp; |
68
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
512 | #ifdef HAVE_WIRINGPI_H |
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
513 | int j; |
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
514 | #endif |
42
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
515 | |
51
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
516 | // if (debug) { |
52 | 517 | // char *hostname = inet_ntoa(peeraddr_in.sin_addr); |
51
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
518 | // syslog(LOG_NOTICE, "Start new client connection from %s port %u", hostname, ntohs(peeraddr_in.sin_port)); |
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
519 | // fprintf(stdout, "Start new client connection from %s port %u\n", hostname, ntohs(peeraddr_in.sin_port)); |
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
520 | // } |
43 | 521 | |
48 | 522 | memset((char *)&buf, 0, SS_BUFSIZE); |
523 | fromlen = sizeof(peeraddr_in); | |
524 | rlen = recvfrom(s, buf, sizeof(buf) -1, 0, (struct sockaddr *)&peeraddr_in, &fromlen); | |
525 | if (rlen == -1) { | |
526 | syslog(LOG_NOTICE, "recvfrom(): %s", strerror(errno)); | |
527 | } else { | |
528 | for (i = 0; i < strlen(buf); i++) { | |
529 | if (buf[i] == '\n') | |
530 | buf[i] = '\0'; | |
531 | if (buf[i] == '\r') | |
532 | buf[i] = '\0'; | |
533 | } | |
80
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
534 | for (i = strlen(buf) -1; i > 0; i--) { |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
535 | if (buf[i] == ' ') |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
536 | buf[i] = '\0'; |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
537 | else |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
538 | break; |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
539 | } |
48 | 540 | if (strlen(buf)) { |
541 | if (debug) { | |
542 | syslog(LOG_NOTICE, "recv: \"%s\"", buf); | |
543 | fprintf(stdout, "recv: \"%s\"\n", buf); | |
43 | 544 | } |
545 | ||
546 | /* | |
48 | 547 | * Process commands from the client |
43 | 548 | */ |
80
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
549 | if (strncmp(buf, "ADD", 3) == 0) { |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
550 | unit_add(buf); |
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
551 | } else if (strncmp(buf, "HELP", 4) == 0) { |
68
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
552 | srv_send((char *)"100 Help text follows"); |
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
553 | srv_send((char *)"Recognized commands:"); |
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
554 | srv_send((char *)""); |
80
81bf78a7618e
Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents:
79
diff
changeset
|
555 | srv_send((char *)"ADD name Add a new unit with \"name\""); |
68
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
556 | srv_send((char *)"LCD Get LCD screen (allways 4 rows of 20 characters)"); |
81 | 557 | srv_send((char *)"LIST List all fermenter units"); |
84 | 558 | srv_send((char *)"LIST BUS List 1-wire bus"); |
87
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
559 | srv_send((char *)"LIST PROFILES List available profiles"); |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
560 | srv_send((char *)"LIST UNIT List fermenter unit"); |
88 | 561 | srv_send((char *)"MODE OFF|NONE|BEER|FRIDGE|PROFILE"); |
81 | 562 | // srv_send((char *)"PROFILE Profile status"); |
563 | // srv_send((char *)"PROFILE start|stop|pause Profile start, stop or pause"); | |
88 | 564 | srv_send((char *)"SET BEER val Set beer temperature"); |
565 | srv_send((char *)"SET FRIDGE val Set fridge temperature"); | |
566 | srv_send((char *)"SET IDLE_LOW val Set idle temperature low (-5.0 .. -0.1)"); | |
567 | srv_send((char *)"SET IDLE_HIGH val Set idle temperature high (0.1 .. 5.0)"); | |
568 | srv_send((char *)"SET NAME name Set name or beername for the unit"); | |
81 | 569 | // srv_send((char *)"SET PROFILE name Set named profile"); |
88 | 570 | srv_send((char *)"SET TEMP_MIN val Set unit minimum temperature"); |
571 | srv_send((char *)"SET TEMP_MAX val Set unit maximum temperature"); | |
572 | srv_send((char *)"SET VOLUME val Set unit volume"); | |
87
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
573 | srv_send((char *)"UNIT n|uuid Select unit by number or uuid"); |
68
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
574 | srv_send((char *)"."); |
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
575 | } else if (strncmp(buf, "LCD", 3) == 0) { |
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
576 | #ifdef HAVE_WIRINGPI_H |
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
577 | srv_send((char *)"201 information follows"); |
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
578 | for (j = 0; j < 4; j++) { |
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
579 | sprintf(obuf, " "); |
70 | 580 | obuf[20] = '\0'; |
68
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
581 | for (i = 0; i < 20; i++) |
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
582 | obuf[i] = lcdbuf[lcdHandle][i][j]; |
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
583 | srv_send(obuf); |
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
584 | } |
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
585 | srv_send((char *)"."); |
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
586 | #else |
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
587 | srv_send((char *)"403 LCD not available"); |
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
588 | #endif |
81 | 589 | } else if (strncmp(buf, "LIST", 4) == 0) { |
590 | cmd_list(buf); | |
88 | 591 | } else if (strncmp(buf, "MODE", 4) == 0) { |
592 | cmd_mode(buf); | |
593 | } else if (strncmp(buf, "SET", 3) == 0) { | |
594 | cmd_set(buf); | |
87
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
595 | } else if (strncmp(buf, "UNIT", 4) == 0) { |
55f1315c94f1
Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents:
86
diff
changeset
|
596 | cmd_unit(buf); |
68
6dba71439cd8
Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents:
66
diff
changeset
|
597 | } else if (strncmp(buf, "ack", 3) == 0) { |
48 | 598 | srv_send((char *)"ack"); |
599 | } else if (strncmp(buf, "lcd", 3) == 0) { | |
600 | sprintf(obuf, "[\" \", \" \", \" \", \" \"]"); | |
66
805f1d285acd
Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents:
62
diff
changeset
|
601 | #ifdef HAVE_WIRINGPI_H |
48 | 602 | for (i = 0; i < 20; i++) { |
603 | obuf[i+2] = lcdbuf[lcdHandle][i][0]; | |
604 | obuf[i+26] = lcdbuf[lcdHandle][i][1]; | |
605 | obuf[i+50] = lcdbuf[lcdHandle][i][2]; | |
606 | obuf[i+74] = lcdbuf[lcdHandle][i][3]; | |
607 | } | |
66
805f1d285acd
Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents:
62
diff
changeset
|
608 | #endif |
48 | 609 | srv_send(obuf); |
610 | } else if (strncmp(buf, "getMode", 7) == 0) { | |
53 | 611 | srv_send("%c", Config.cs_mode); |
48 | 612 | } else if (strncmp(buf, "getFridge", 9) == 0) { |
53 | 613 | srv_send("%.1f", Config.cs_fridgeSet); |
48 | 614 | } else if (strncmp(buf, "getBeer", 7) == 0) { |
53 | 615 | srv_send("%.1f", Config.cs_beerSet); |
48 | 616 | } else if (strncmp(buf, "getControlConstants", 19) == 0) { |
617 | srv_send("{ \"tempFormat\":\"%c\", \"tempSetMin\":%.1f, \"tempSetMax\":%.1f, \"idleRangeH\":%.3f, \"idleRangeL\":%.3f }", | |
77
143077e54255
Added old configuration to write xml config
Michiel Broek <mbroek@mbse.eu>
parents:
75
diff
changeset
|
618 | Config.tempFormat, Config.cc_tempSetMin, Config.cc_tempSetMax, Config.cc_idleRangeH, Config.cc_idleRangeL ); |
48 | 619 | } else if (strncmp(buf, "getControlSettings", 18) == 0) { |
620 | srv_send("{ \"mode\":\"%c\", \"beerSet\":%.1f, \"fridgeSet\":%.1f, \"heatEstimator\":%.1f, \"coolEstimator\":%.1f }", | |
53 | 621 | Config.cs_mode, Config.cs_beerSet, Config.cs_fridgeSet, Config.cs_heatEstimator, Config.cs_coolEstimator); |
48 | 622 | } else if (strncmp(buf, "getControlVariables", 19) == 0) { |
623 | srv_send("{ \"beerDiff\":%.2f }", cv_beerDiff); | |
49
92a9ca143677
Fixed temperature logging, added some commands
Michiel Broek <mbroek@mbse.eu>
parents:
48
diff
changeset
|
624 | } else if (strncmp(buf, "loadDefaultControlSettings", 26) == 0) { |
92a9ca143677
Fixed temperature logging, added some commands
Michiel Broek <mbroek@mbse.eu>
parents:
48
diff
changeset
|
625 | defaultControlSettings(); |
92a9ca143677
Fixed temperature logging, added some commands
Michiel Broek <mbroek@mbse.eu>
parents:
48
diff
changeset
|
626 | srv_send("ack"); |
92a9ca143677
Fixed temperature logging, added some commands
Michiel Broek <mbroek@mbse.eu>
parents:
48
diff
changeset
|
627 | } else if (strncmp(buf, "loadDefaultControlConstants", 27) == 0) { |
92a9ca143677
Fixed temperature logging, added some commands
Michiel Broek <mbroek@mbse.eu>
parents:
48
diff
changeset
|
628 | defaultControlConstants(); |
92a9ca143677
Fixed temperature logging, added some commands
Michiel Broek <mbroek@mbse.eu>
parents:
48
diff
changeset
|
629 | srv_send("ack"); |
48 | 630 | } else if (strncmp(buf, "setBeer=", 8) == 0) { |
631 | inp = xstrcpy(buf+8); | |
632 | rc = sscanf(inp, "%f", &newtemp); | |
633 | if (debug) | |
634 | fprintf(stdout, "new temp from %s, %.1f, rc=%d\n", inp, newtemp, rc); | |
635 | if (rc == 1) { | |
54
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
636 | if ((Config.cc_tempSetMin <= newtemp) && (newtemp <= Config.cc_tempSetMax)) { |
51
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
637 | syslog(LOG_NOTICE, "Beer temperature set to %.1f degrees in web interface", newtemp); |
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
638 | srv_send("ack"); |
53 | 639 | Config.cs_mode = 'b'; |
640 | Config.cs_beerSet = newtemp; | |
51
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
641 | } else { |
54
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
642 | syslog(LOG_NOTICE, "Beer temperature setting %.1f is outside of allowed range %.1f - %.1f", newtemp, Config.cc_tempSetMin, Config.cc_tempSetMax); |
51
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
643 | srv_send("err"); |
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
644 | } |
48 | 645 | } else { |
51
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
646 | syslog(LOG_NOTICE, "Cannot convert temperature '%s' to float", inp); |
48 | 647 | srv_send("err"); |
648 | } | |
649 | free(inp); | |
650 | } else if (strncmp(buf, "setFridge=", 10) == 0) { | |
651 | inp = xstrcpy(buf+10); | |
652 | rc = sscanf(inp, "%f", &newtemp); | |
653 | if (debug) | |
654 | fprintf(stdout, "new temp from %s, %.1f, rc=%d\n", inp, newtemp, rc); | |
655 | if (rc == 1) { | |
54
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
656 | if ((Config.cc_tempSetMin <= newtemp) && (newtemp <= Config.cc_tempSetMax)) { |
51
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
657 | syslog(LOG_NOTICE, "Fridge temperature set to %.1f degrees in web interface", newtemp); |
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
658 | srv_send("ack"); |
53 | 659 | Config.cs_mode = 'f'; |
660 | Config.cs_fridgeSet = newtemp; | |
51
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
661 | } else { |
54
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
662 | syslog(LOG_NOTICE, "Fridge temperature setting %.1f is outside of allowed range %.1f - %.1f", newtemp, Config.cc_tempSetMin, Config.cc_tempSetMax); |
51
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
663 | srv_send("err"); |
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
664 | } |
48 | 665 | } else { |
51
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
666 | syslog(LOG_NOTICE, "Cannot convert temperature '%s' to float", inp); |
48 | 667 | srv_send("err"); |
668 | } | |
669 | free(inp); | |
49
92a9ca143677
Fixed temperature logging, added some commands
Michiel Broek <mbroek@mbse.eu>
parents:
48
diff
changeset
|
670 | } else if (strncmp(buf, "setOff", 6) == 0) { |
92a9ca143677
Fixed temperature logging, added some commands
Michiel Broek <mbroek@mbse.eu>
parents:
48
diff
changeset
|
671 | if (debug) |
92a9ca143677
Fixed temperature logging, added some commands
Michiel Broek <mbroek@mbse.eu>
parents:
48
diff
changeset
|
672 | fprintf(stdout, "temperature control disabled\n"); |
51
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
673 | syslog(LOG_NOTICE, "Notification: Temperature control disabled"); |
53 | 674 | Config.cs_mode = 'o'; |
49
92a9ca143677
Fixed temperature logging, added some commands
Michiel Broek <mbroek@mbse.eu>
parents:
48
diff
changeset
|
675 | srv_send("ack"); |
54
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
676 | } else if (strncmp(buf, "setParameters=", 14) == 0) { |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
677 | inp = xstrcpy(buf+14); /* {"tempSetMax":30.5} */ |
51
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
678 | if (debug) |
54
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
679 | fprintf(stdout, "setParameters: %s\n", inp); |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
680 | strtok(inp, (char *)"\""); |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
681 | p = strtok(NULL, (char *)"\""); |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
682 | q = strtok(NULL, (char *)":,}"); |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
683 | if (strcmp(p, (char *)"tempSetMin") == 0) { |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
684 | rc = sscanf(q, "%f", &newtemp); |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
685 | if (rc == 1) { |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
686 | syslog(LOG_NOTICE, "cc_tempSetMin = %1.f", newtemp); |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
687 | Config.cc_tempSetMin = newtemp; |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
688 | srv_send("ack"); |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
689 | } else { |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
690 | srv_send("ERR"); |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
691 | } |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
692 | } else if (strcmp(p, (char *)"tempSetMax") == 0) { |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
693 | rc = sscanf(q, "%f", &newtemp); |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
694 | if (rc == 1) { |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
695 | syslog(LOG_NOTICE, "cc_tempSetMax = %1.f", newtemp); |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
696 | Config.cc_tempSetMax = newtemp; |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
697 | srv_send("ack"); |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
698 | } else { |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
699 | srv_send("ERR"); |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
700 | } |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
701 | } else { |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
702 | fprintf(stdout, "p='%s' q='%s' inp='%s'\n", p, q, inp); |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
703 | srv_send("ERR"); |
c06190a58f22
More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
53
diff
changeset
|
704 | } |
62 | 705 | free(inp); |
51
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
706 | // stopScript |
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
707 | // quit |
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
708 | // eraseLogs |
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
709 | // interval |
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
710 | // startNewBrew |
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
711 | // pauseLogging |
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
712 | // stopLogging |
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
713 | // resumeLogging |
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
714 | // dateTimeFormatDisplay |
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
715 | } else if (strncmp(buf, "setActiveProfile", 16) == 0) { |
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
716 | syslog(LOG_NOTICE, "Setting profile '%s' as active profile", "undefined"); |
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
717 | // programArduino |
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
718 | // refreshDeviceList |
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
719 | // getDeviceList |
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
720 | // applyDevice |
43 | 721 | } else { |
48 | 722 | if (debug) |
723 | fprintf(stdout, "unknown command \"%s\"\n", buf); | |
724 | srv_send((char *)"ERR"); | |
43 | 725 | } |
726 | } | |
42
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
727 | } |
44 | 728 | |
51
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
729 | // if (debug) { |
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
730 | // syslog(LOG_NOTICE, "End connection from %s port %u", hostname, ntohs(peeraddr_in.sin_port)); |
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
731 | // fprintf(stdout, "End connection from %s port %u\n", hostname, ntohs(peeraddr_in.sin_port)); |
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
49
diff
changeset
|
732 | // } |
48 | 733 | |
44 | 734 | close(s); |
42
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
735 | } |
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
736 | |
01b96a24ae7c
Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
737 | |
66
805f1d285acd
Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents:
62
diff
changeset
|
738 | #ifdef HAVE_WIRINGPI_H |
43 | 739 | PI_THREAD (my_server_loop) |
66
805f1d285acd
Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents:
62
diff
changeset
|
740 | #else |
74 | 741 | void *my_server_loop(void *threadid) |
66
805f1d285acd
Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents:
62
diff
changeset
|
742 | #endif |
43 | 743 | { |
744 | socklen_t addrlen; | |
44 | 745 | int optval = 1; |
43 | 746 | |
747 | syslog(LOG_NOTICE, "Thread my_server_loop started"); | |
748 | if (debug) | |
749 | fprintf(stdout, "Thread my_server_loop started\n"); | |
750 | ||
44 | 751 | memset((char *)&myaddr_in, 0, sizeof(struct sockaddr_in)); |
752 | memset((char *)&peeraddr_in, 0, sizeof(struct sockaddr_in)); | |
753 | myaddr_in.sin_family = AF_INET; | |
754 | myaddr_in.sin_addr.s_addr = INADDR_ANY; | |
755 | myaddr_in.sin_port = htons(Config.my_port); | |
756 | ||
757 | ls = socket(AF_INET, SOCK_STREAM, 0); | |
758 | if (ls == -1) { | |
759 | syslog(LOG_NOTICE, "Can't create listen socket: %s", strerror(errno)); | |
760 | fprintf(stderr, "Can't create listen socket: %s\n", strerror(errno)); | |
761 | return 0; | |
762 | } | |
763 | ||
764 | if (setsockopt(ls, SOL_SOCKET, SO_KEEPALIVE, &optval, sizeof(optval)) == -1) { | |
765 | syslog(LOG_NOTICE, "Can't setsockopt SO_KEEPALIVE socket: %s", strerror(errno)); | |
766 | close(ls); | |
767 | return 0; | |
768 | } | |
769 | ||
770 | if (setsockopt(ls, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)) == -1) { | |
771 | syslog(LOG_NOTICE, "Can't setsockopt SO_REUSEADDR socket: %s", strerror(errno)); | |
772 | close(ls); | |
66
805f1d285acd
Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents:
62
diff
changeset
|
773 | return 0; |
44 | 774 | } |
775 | ||
776 | if (bind(ls, (struct sockaddr *)&myaddr_in, sizeof(struct sockaddr_in)) == -1) { | |
777 | syslog(LOG_NOTICE, "Can't bind to listen socket: %s", strerror(errno)); | |
778 | close(ls); | |
66
805f1d285acd
Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents:
62
diff
changeset
|
779 | return 0; |
44 | 780 | } |
781 | ||
782 | if (listen(ls, 5) == -1) { | |
783 | syslog(LOG_NOTICE, "Can't listen on listen socket: %s", strerror(errno)); | |
784 | close(ls); | |
66
805f1d285acd
Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents:
62
diff
changeset
|
785 | return 0; |
44 | 786 | } |
787 | ||
788 | syslog(LOG_NOTICE, "listen socket created %d", ls); | |
789 | if (debug) | |
790 | fprintf(stdout, "listen socket created %d\n", ls); | |
791 | ||
792 | ||
43 | 793 | /* |
794 | * Loop forever until the external shutdown variable is set. | |
795 | */ | |
796 | for (;;) { | |
797 | ||
798 | addrlen = sizeof(struct sockaddr_in); | |
799 | /* | |
800 | * This call will block until a new connection | |
801 | * arrives. Then it will return the address of | |
802 | * the connecting peer, and a new socket | |
803 | * descriptor, s, for that connection. | |
804 | */ | |
805 | s = accept(ls, (struct sockaddr *)&peeraddr_in, &addrlen); | |
806 | if (s == -1) { | |
807 | syslog(LOG_NOTICE, "my_server_loop accept failed %s", strerror(errno)); | |
808 | if (debug) | |
809 | fprintf(stdout, "my_server_loop accept failed %s\n", strerror(errno)); | |
44 | 810 | return 0; |
43 | 811 | } |
812 | ||
48 | 813 | cmd_server(); |
43 | 814 | |
815 | if (my_shutdown) { | |
816 | syslog(LOG_NOTICE, "Thread my_server_loop stopped"); | |
817 | if (debug) | |
818 | fprintf(stdout, "Thread my_server_loop stopped\n"); | |
819 | return 0; | |
820 | } | |
821 | ||
822 | } | |
823 | } | |
824 | ||
825 |