1
1
#define INPUT_COMMAND_SIZE 80
2
- void ExecuteCommand (const char *Line)
2
+ void ExecuteCommand (byte source, const char *Line)
3
3
{
4
+ String status = " " ;
5
+ boolean success = false ;
4
6
char TmpStr1[80 ];
5
7
TmpStr1[0 ] = 0 ;
6
8
char Command[80 ];
@@ -20,22 +22,24 @@ void ExecuteCommand(const char *Line)
20
22
21
23
if (strcasecmp_P (Command, PSTR (" pinstates" )) == 0 )
22
24
{
25
+ success = true ;
23
26
for (byte x = 0 ; x < PINSTATE_TABLE_MAX; x++)
24
27
if (pinStates[x].plugin != 0 )
25
28
{
26
- Serial. print ( F (" Plugin : " ) );
27
- Serial. print ( pinStates[x].plugin ) ;
28
- Serial. print ( F (" index: " ) );
29
- Serial. print ( pinStates[x].index ) ;
30
- Serial. print ( F (" mode: " ) );
31
- Serial. print ( pinStates[x].mode ) ;
32
- Serial. print ( F (" value: " ) );
33
- Serial. println ( pinStates[x].value ) ;
29
+ status += F (" \n Plugin : " );
30
+ status += pinStates[x].plugin ;
31
+ status += F (" index: " );
32
+ status += pinStates[x].index ;
33
+ status += F (" mode: " );
34
+ status += pinStates[x].mode ;
35
+ status += F (" value: " );
36
+ status += pinStates[x].value ;
34
37
}
35
38
}
36
39
37
40
if (strcasecmp_P (Command, PSTR (" timer" )) == 0 )
38
41
{
42
+ success = true ;
39
43
if (GetArgv (Line, TmpStr1, 3 ))
40
44
{
41
45
setSystemTimer (Par1 * 1000 , Par2, Par3, 0 , 0 );
@@ -44,6 +48,7 @@ void ExecuteCommand(const char *Line)
44
48
45
49
if (strcasecmp_P (Command, PSTR (" cmdtimer" )) == 0 )
46
50
{
51
+ success = true ;
47
52
if (GetArgv (Line, TmpStr1, 3 ))
48
53
{
49
54
String demo = TmpStr1;
@@ -53,11 +58,23 @@ void ExecuteCommand(const char *Line)
53
58
54
59
if (strcasecmp_P (Command, PSTR (" TaskClear" )) == 0 )
55
60
{
61
+ success = true ;
56
62
taskClear (Par1 - 1 , true );
57
63
}
58
64
65
+ if (strcasecmp_P (Command, PSTR (" TaskGlobalSync" )) == 0 )
66
+ {
67
+ success = true ;
68
+ if (Par2 == 1 )
69
+ Settings.TaskDeviceGlobalSync [Par1 -1 ] = true ;
70
+ else
71
+ Settings.TaskDeviceGlobalSync [Par1 -1 ] = false ;
72
+ }
73
+
74
+
59
75
if (strcasecmp_P (Command, PSTR (" wdconfig" )) == 0 )
60
76
{
77
+ success = true ;
61
78
Wire.beginTransmission (Par1); // address
62
79
Wire.write (Par2); // command
63
80
Wire.write (Par3); // data
@@ -66,6 +83,7 @@ void ExecuteCommand(const char *Line)
66
83
67
84
if (strcasecmp_P (Command, PSTR (" wdread" )) == 0 )
68
85
{
86
+ success = true ;
69
87
Wire.beginTransmission (Par1); // address
70
88
Wire.write (0x83 ); // command to set pointer
71
89
Wire.write (Par2); // pointer value
@@ -74,30 +92,28 @@ void ExecuteCommand(const char *Line)
74
92
if (Wire.available ())
75
93
{
76
94
byte value = Wire.read ();
77
- if (printToWeb)
78
- {
79
- printWebString += F (" Reg value: " );
80
- printWebString += value;
81
- }
82
- Serial.print (F (" Reg value: " ));
83
- Serial.println (value);
95
+ status = F (" Reg value: " );
96
+ status += value;
84
97
}
85
98
}
86
99
87
100
if (strcasecmp_P (Command, PSTR (" VariableSet" )) == 0 )
88
101
{
102
+ success = true ;
89
103
if (GetArgv (Line, TmpStr1, 3 ))
90
104
UserVar[Par1 - 1 ] = atof (TmpStr1);
91
105
}
92
106
93
107
if (strcasecmp_P (Command, PSTR (" build" )) == 0 )
94
108
{
109
+ success = true ;
95
110
Settings.Build = Par1;
96
111
SaveSettings ();
97
112
}
98
113
99
114
if (strcasecmp_P (Command, PSTR (" NoSleep" )) == 0 )
100
115
{
116
+ success = true ;
101
117
Settings.deepSleep = 0 ;
102
118
}
103
119
@@ -108,16 +124,19 @@ void ExecuteCommand(const char *Line)
108
124
109
125
if (strcasecmp_P (Command, PSTR (" TimerSet" )) == 0 )
110
126
{
127
+ success = true ;
111
128
RulesTimer[Par1 - 1 ] = millis () + (1000 * Par2);
112
129
}
113
130
114
131
if (strcasecmp_P (Command, PSTR (" Delay" )) == 0 )
115
132
{
133
+ success = true ;
116
134
delayMillis (Par1);
117
135
}
118
136
119
137
if (strcasecmp_P (Command, PSTR (" Rules" )) == 0 )
120
138
{
139
+ success = true ;
121
140
if (Par1 == 1 )
122
141
Settings.UseRules = true ;
123
142
else
@@ -126,6 +145,7 @@ void ExecuteCommand(const char *Line)
126
145
127
146
if (strcasecmp_P (Command, PSTR (" Event" )) == 0 )
128
147
{
148
+ success = true ;
129
149
String event = Line;
130
150
event = event.substring (6 );
131
151
event.replace (" $" , " #" );
@@ -139,6 +159,7 @@ void ExecuteCommand(const char *Line)
139
159
140
160
if (strcasecmp_P (Command, PSTR (" DomoticzSend" )) == 0 )
141
161
{
162
+ success = true ;
142
163
if (GetArgv (Line, TmpStr1, 4 ))
143
164
{
144
165
struct EventStruct TempEvent;
@@ -153,47 +174,67 @@ void ExecuteCommand(const char *Line)
153
174
154
175
if (strcasecmp (Command, " DomoticzGet" ) == 0 )
155
176
{
177
+ success = true ;
156
178
float value = 0 ;
157
179
if (Domoticz_getData (Par2, &value))
158
180
{
159
- Serial. print ( F (" DomoticzGet " ) );
160
- Serial. println ( value) ;
181
+ status = F (" DomoticzGet " );
182
+ status += value;
161
183
}
162
184
else
163
- Serial. println ( F (" Error getting data" ) );
185
+ status = F (" Error getting data" );
164
186
}
165
187
166
188
// ****************************************
167
189
// configure settings commands
168
190
// ****************************************
169
191
if (strcasecmp_P (Command, PSTR (" WifiSSID" )) == 0 )
192
+ {
193
+ success = true ;
170
194
strcpy (SecuritySettings.WifiSSID , Line + 9 );
195
+ }
171
196
172
197
if (strcasecmp_P (Command, PSTR (" WifiKey" )) == 0 )
198
+ {
199
+ success = true ;
173
200
strcpy (SecuritySettings.WifiKey , Line + 8 );
201
+ }
174
202
175
203
if (strcasecmp_P (Command, PSTR (" WifiScan" )) == 0 )
204
+ {
205
+ success = true ;
176
206
WifiScan ();
177
-
207
+ }
208
+
178
209
if (strcasecmp_P (Command, PSTR (" WifiConnect" )) == 0 )
210
+ {
211
+ success = true ;
179
212
WifiConnect ();
180
-
213
+ }
214
+
181
215
if (strcasecmp_P (Command, PSTR (" WifiDisconnect" )) == 0 )
216
+ {
217
+ success = true ;
182
218
WifiDisconnect ();
183
-
219
+ }
220
+
184
221
if (strcasecmp_P (Command, PSTR (" Reboot" )) == 0 )
185
222
{
223
+ success = true ;
186
224
pinMode (0 , INPUT);
187
225
pinMode (2 , INPUT);
188
226
pinMode (15 , INPUT);
189
227
ESP.reset ();
190
228
}
191
229
192
230
if (strcasecmp_P (Command, PSTR (" Restart" )) == 0 )
231
+ {
232
+ success = true ;
193
233
ESP.restart ();
194
-
234
+ }
195
235
if (strcasecmp_P (Command, PSTR (" Erase" )) == 0 )
196
236
{
237
+ success = true ;
197
238
EraseFlash ();
198
239
ZeroFillFlash ();
199
240
saveToRTC (0 );
@@ -203,16 +244,26 @@ void ExecuteCommand(const char *Line)
203
244
}
204
245
205
246
if (strcasecmp_P (Command, PSTR (" Reset" )) == 0 )
247
+ {
248
+ success = true ;
206
249
ResetFactory ();
250
+ }
207
251
208
252
if (strcasecmp_P (Command, PSTR (" Save" )) == 0 )
253
+ {
254
+ success = true ;
209
255
SaveSettings ();
256
+ }
210
257
211
258
if (strcasecmp_P (Command, PSTR (" Load" )) == 0 )
259
+ {
260
+ success = true ;
212
261
LoadSettings ();
262
+ }
213
263
214
264
if (strcasecmp_P (Command, PSTR (" FlashDump" )) == 0 )
215
265
{
266
+ success = true ;
216
267
uint32_t _sectorStart = ((uint32_t )&_SPIFFS_start - 0x40200000 ) / SPI_FLASH_SEC_SIZE;
217
268
uint32_t _sectorEnd = ((uint32_t )&_SPIFFS_end - 0x40200000 ) / SPI_FLASH_SEC_SIZE;
218
269
@@ -240,21 +291,27 @@ void ExecuteCommand(const char *Line)
240
291
241
292
if (strcasecmp_P (Command, PSTR (" flashcheck" )) == 0 )
242
293
{
294
+ success = true ;
243
295
CheckFlash (Par1, Par2);
244
296
}
245
297
246
298
if (strcasecmp_P (Command, PSTR (" Debug" )) == 0 )
299
+ {
300
+ success = true ;
247
301
Settings.SerialLogLevel = Par1;
302
+ }
248
303
249
304
if (strcasecmp_P (Command, PSTR (" IP" )) == 0 )
250
305
{
306
+ success = true ;
251
307
if (GetArgv (Line, TmpStr1, 2 ))
252
308
if (!str2ip (TmpStr1, Settings.IP ))
253
309
Serial.println (" ?" );
254
310
}
255
311
256
312
if (strcasecmp_P (Command, PSTR (" Settings" )) == 0 )
257
313
{
314
+ success = true ;
258
315
char str[20 ];
259
316
Serial.println ();
260
317
@@ -268,5 +325,11 @@ void ExecuteCommand(const char *Line)
268
325
Serial.print (F (" WifiKey : " )); Serial.println (SecuritySettings.WifiKey );
269
326
Serial.print (F (" Free mem : " )); Serial.println (FreeMem ());
270
327
}
328
+
329
+ if (success)
330
+ status += F (" \n Ok" );
331
+ else
332
+ status += F (" \n Unknown command!" );
333
+ SendStatus (source,status);
271
334
}
272
335
0 commit comments