forked from letscontrolit/ESPEasyPluginPlayground
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_P112_RFTX.ino
433 lines (379 loc) · 20.5 KB
/
_P112_RFTX.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
//#######################################################################################################
//########################### Plugin 112: Output 433 MHZ - RF ###########################
//#######################################################################################################
/*
Version: 2.0
Description: use this script to send RF with a cheap FS1000A alike sender
Example of usage:
Learn codes via _P111_RF.ino plugin!
Needs: RCSwitch library
Tested on GPIO:14
Author: S4nder
Copyright: (c) 2015-2016 Sander Pleijers (s4nder)
License: MIT
License URI: http://en.wikipedia.org/wiki/MIT_License
Status : "Proof of concept"
Usage:
1=RFSEND or RFSWITCH or RFTRISTATE Or RFSWITCHTYPEA/B/C/D
2=commando (1=on 0=off for DIP switches, otherwise use code)
3=repeat (if not set will use default settings)
4=bits (if not set will use default settings)
5=group (for DIP switches only)
6=device (for DIP switches only)
7=family (for DIP switches only)
1 2 3 4
http://<ESP IP address>/control?cmd=RFSEND,blablacommando,10,24
DIP switches A+B+D:
1 2 5 6 3
http://<ESP IP address>/control?cmd=RFSWITCHTYPEA,1,11001,01000,10
DIP switches C (intertechno):
1 2 5 6 7 3
http://<ESP IP address>/control?cmd=RFSWITCHTYPEC,1,1,2,a,10
TriState switches:
1 2 3
http://<ESP IP address>/control?cmd=RFTRISTATE,blablacommando,10
This program was developed independently and it is not supported in any way.
*/
#ifdef PLUGIN_BUILD_TESTING
#include <RCSwitch.h>
RCSwitch *rcswitchSender;
#define PLUGIN_112
#define PLUGIN_ID_112 112
#define PLUGIN_NAME_112 "RF Transmit - FS1000A alike sender"
unsigned int Plugin_112_iCode;
unsigned int Plugin_112_Repeat;
unsigned int Plugin_112_Bits;
unsigned int Plugin_112_Pulse;
unsigned int Plugin_112_nGroup;
unsigned int Plugin_112_nDevice;
unsigned int Plugin_112_nAddressCode;
unsigned int Plugin_112_nChannelCode;
char* Plugin_112_sCodeWord;
char* Plugin_112_sGroup;
char* Plugin_112_sDevice;
char Plugin_112_csGroup;
char Plugin_112_sFamily;
boolean Plugin_112(byte function, struct EventStruct *event, String& string)
{
boolean success = false;
switch (function)
{
case PLUGIN_DEVICE_ADD:
{
Device[++deviceCount].Number = PLUGIN_ID_112;
Device[deviceCount].Type = DEVICE_TYPE_SINGLE;
Device[deviceCount].SendDataOption = false;
Device[deviceCount].Ports = 0;
Device[deviceCount].VType = SENSOR_TYPE_SWITCH;
Device[deviceCount].PullUpOption = false;
Device[deviceCount].InverseLogicOption = false;
Device[deviceCount].FormulaOption = false;
Device[deviceCount].ValueCount = 0;
Device[deviceCount].TimerOption = false;
Device[deviceCount].TimerOptional = false;
break;
}
case PLUGIN_GET_DEVICENAME:
{
string = F(PLUGIN_NAME_112);
break;
}
case PLUGIN_GET_DEVICEVALUENAMES:
{
break;
}
case PLUGIN_WEBFORM_LOAD:
{
char tmpString[140];
Plugin_112_Bits = ExtraTaskSettings.TaskDevicePluginConfigLong[0];
Plugin_112_Pulse = ExtraTaskSettings.TaskDevicePluginConfigLong[1];
Plugin_112_Repeat = ExtraTaskSettings.TaskDevicePluginConfigLong[2];
addFormNumericBox(F("Bits (default=24)"), F("plugin_112_bits"), Plugin_112_Bits, 1, 100);
addFormNumericBox(F("Pulselength (default=165)"), F("plugin_112_pulse"), Plugin_112_Pulse, 1, 1000);
addFormNumericBox(F("Repeat (default=1)"), F("plugin_112_repeat"), Plugin_112_Repeat, 1, 20);
success = true;
break;
}
case PLUGIN_WEBFORM_SAVE:
{
Plugin_112_Bits = getFormItemInt(F("plugin_112_bits"));
Plugin_112_Pulse = getFormItemInt(F("plugin_112_pulse"));
Plugin_112_Repeat = getFormItemInt(F("plugin_112_repeat"));
if (Plugin_112_Bits > 100) Plugin_112_Bits = 24;
if (Plugin_112_Pulse > 1000) Plugin_112_Pulse = 165;
if (Plugin_112_Repeat > 20) Plugin_112_Repeat = 1;
ExtraTaskSettings.TaskDevicePluginConfigLong[0] = Plugin_112_Bits;
ExtraTaskSettings.TaskDevicePluginConfigLong[1] = Plugin_112_Pulse;
ExtraTaskSettings.TaskDevicePluginConfigLong[2] = Plugin_112_Repeat;
SaveTaskSettings(event->TaskIndex);
success = true;
break;
}
case PLUGIN_WEBFORM_SHOW_CONFIG:
{
string += String(ExtraTaskSettings.TaskDevicePluginConfigLong[0]);
string += String(ExtraTaskSettings.TaskDevicePluginConfigLong[1]);
string += String(ExtraTaskSettings.TaskDevicePluginConfigLong[2]);
success = true;
break;
}
case PLUGIN_INIT:
{
LoadTaskSettings(event->TaskIndex);
Plugin_112_Bits = ExtraTaskSettings.TaskDevicePluginConfigLong[0];
Plugin_112_Pulse = ExtraTaskSettings.TaskDevicePluginConfigLong[1];
Plugin_112_Repeat = ExtraTaskSettings.TaskDevicePluginConfigLong[2];
int txPin = Settings.TaskDevicePin1[event->TaskIndex];
if (rcswitchSender == 0 && txPin != -1)
{
addLog(LOG_LEVEL_INFO, "INIT: RF433 TX created!");
//rcswitchSender = new RCSwitch(txPin);
rcswitchSender = new RCSwitch();
rcswitchSender->enableTransmit(txPin);
rcswitchSender->setPulseLength(Plugin_112_Pulse);
// Set TX Repeat xx times
rcswitchSender->setRepeatTransmit(Plugin_112_Repeat);
// RepeatTransmit * PulseLength = TX time total
// Ex. RepeatTransmit = 3 & PulseLength = 330ms
// 3 * 330ms = 990ms or 0,990 Sec. for TX time total
}
if (rcswitchSender != 0 && txPin == -1)
{
addLog(LOG_LEVEL_INFO, "INIT: RF433 TX REMOVED!");
delete rcswitchSender;
rcswitchSender = 0;
}
success = true;
break;
}
case PLUGIN_WRITE:
{
//reset
unsigned int Plugin_112_iCode = 0;
unsigned int Plugin_112_nGroup = 0;
unsigned int Plugin_112_nDevice = 0;
unsigned int Plugin_112_nAddressCode = 0;
unsigned int Plugin_112_nChannelCode = 0;
char * Plugin_112_sCodeWord;
char* Plugin_112_sGroup;
char* Plugin_112_sDevice;
char Plugin_112_csGroup = '\0';
char Plugin_112_sFamily = '\0';
char command[80]; command[0] = 0;
char TmpStr1[80]; TmpStr1[0] = 0;
char TmpStr2[80]; TmpStr2[0] = 0;
char TmpStr3[80]; TmpStr3[0] = 0;
char TmpStr4[80]; TmpStr4[0] = 0;
string.toCharArray(command, 80);
String tmpString = string;
int argIndex = tmpString.indexOf(',');
if (argIndex) tmpString = tmpString.substring(0, argIndex);
if (tmpString.equalsIgnoreCase("RFSWITCHTYPEA") && rcswitchSender != 0)
{
/* For DIP switches type A */
Serial.println("RFSWITCHTYPEA");
if (GetArgv(command, TmpStr1, 2)) Plugin_112_iCode = str2int(TmpStr1);
if (GetArgv(command, TmpStr2, 3)) Plugin_112_sGroup = TmpStr2;
if (GetArgv(command, TmpStr3, 4)) Plugin_112_sDevice = TmpStr3;
if (GetArgv(command, TmpStr4, 5)) Plugin_112_Repeat = str2int(TmpStr4);
/* checks */
if (Plugin_112_iCode == 0) break;
//if (Plugin_112_sGroup == '\0') break;
//if (Plugin_112_sDevice == '\0') break;
if (Plugin_112_Repeat > 20) { break; }
rcswitchSender->setRepeatTransmit(Plugin_112_Repeat);
/**
* Switch a remote switch on (Type A with 10 pole DIP switches)
*
* @param sGroup Code of the switch group (refers to DIP switches 1..5 where "1" = on and "0" = off, if all DIP switches are on it's "11111")
* @param sDevice Code of the switch device (refers to DIP switches 6..10 (A..E) where "1" = on and "0" = off, if all DIP switches are on it's "11111")
*
* void RCSwitch::switchOn(const char* sGroup, const char* sDevice) {
*/
if (Plugin_112_iCode == 1) {
rcswitchSender->switchOn(Plugin_112_sGroup, Plugin_112_sDevice);
} else {
rcswitchSender->switchOff(Plugin_112_sGroup, Plugin_112_sDevice);
}
success = true;
}
else if (tmpString.equalsIgnoreCase("RFSWITCHTYPEB") && rcswitchSender != 0)
{
/* For DIP switches type B */
Serial.println("RFSWITCHTYPEB");
if (GetArgv(command, TmpStr1, 2)) Plugin_112_iCode = str2int(TmpStr1);
if (GetArgv(command, TmpStr1, 3)) Plugin_112_nAddressCode = str2int(TmpStr1);
if (GetArgv(command, TmpStr1, 4)) Plugin_112_nChannelCode = str2int(TmpStr1);
if (GetArgv(command, TmpStr1, 5)) Plugin_112_Repeat = str2int(TmpStr1);
/* checks */
if (Plugin_112_iCode == 0) break;
if (Plugin_112_nAddressCode == 0) break;
if (Plugin_112_nChannelCode == 0) break;
if (Plugin_112_Repeat > 20) break;
rcswitchSender->setRepeatTransmit(Plugin_112_Repeat);
/**
* Switch a remote switch on (Type B with two rotary/sliding switches)
*
* @param nAddressCode Number of the switch group (1..4)
* @param nChannelCode Number of the switch itself (1..4)
*
* void RCSwitch::switchOn(int nAddressCode, int nChannelCode) {
*/
if (Plugin_112_iCode == 1) {
rcswitchSender->switchOn((int)Plugin_112_nAddressCode, (int)Plugin_112_nChannelCode);
} else {
rcswitchSender->switchOff((int)Plugin_112_nAddressCode, (int)Plugin_112_nChannelCode);
}
success = true;
}
else if (tmpString.equalsIgnoreCase("RFSWITCHTYPEC") && rcswitchSender != 0)
{
/* For DIP switches type C */
Serial.println("RFSWITCHTYPEC");
if (GetArgv(command, TmpStr1, 2)) Plugin_112_iCode = str2int(TmpStr1);
if (GetArgv(command, TmpStr1, 3)) Plugin_112_nDevice = str2int(TmpStr1);
if (GetArgv(command, TmpStr1, 4)) Plugin_112_nGroup = str2int(TmpStr1);
if (GetArgv(command, TmpStr2, 5)) Plugin_112_sFamily = TmpStr2[0]; //only first char from string
if (GetArgv(command, TmpStr1, 6)) Plugin_112_Repeat = str2int(TmpStr1);
/* checks */
if (Plugin_112_iCode == 0) break;
if (Plugin_112_nDevice == 0) break;
if (Plugin_112_nGroup == 0) break;
if (Plugin_112_sFamily == '\0') break;
if (Plugin_112_Repeat > 20) break;
rcswitchSender->setRepeatTransmit(Plugin_112_Repeat);
/**
* Switch a remote switch on (Type C Intertechno)
*
* @param sFamily Familycode (a..f)
* @param nGroup Number of group (1..4)
* @param nDevice Number of device (1..4)
*
* void RCSwitch::switchOn(char sFamily, int nGroup, int nDevice) {
*/
if (Plugin_112_iCode == 1) {
rcswitchSender->switchOn(Plugin_112_sFamily, Plugin_112_nGroup, Plugin_112_nDevice);
} else {
rcswitchSender->switchOff(Plugin_112_sFamily, Plugin_112_nGroup, Plugin_112_nDevice);
}
success = true;
}
else if (tmpString.equalsIgnoreCase("RFSWITCHTYPED") && rcswitchSender != 0)
{
/* For DIP switches type D */
Serial.println("RFSWITCHTYPED");
/**
* Switch a remote switch on (Type D REV)
*
* @param sGroup Code of the switch group (A,B,C,D)
* @param nDevice Number of the switch itself (1..3)
*
* void RCSwitch::switchOn(char sGroup, int nDevice) {
*/
if (GetArgv(command, TmpStr1, 2)) Plugin_112_iCode = str2int(TmpStr1);
if (GetArgv(command, TmpStr1, 3)) Plugin_112_nDevice = str2int(TmpStr1);
if (GetArgv(command, TmpStr2, 4)) Plugin_112_csGroup = TmpStr2[0];
if (GetArgv(command, TmpStr1, 5)) Plugin_112_Repeat = str2int(TmpStr1);
/* checks */
if (Plugin_112_iCode == 0) break;
if (Plugin_112_nDevice == 0) break;
//if (Plugin_112_csGroup == '\0') break;
if (Plugin_112_Repeat > 20) break;
rcswitchSender->setRepeatTransmit(Plugin_112_Repeat);
if (Plugin_112_iCode == 1) {
rcswitchSender->switchOn(Plugin_112_csGroup, Plugin_112_nDevice);
} else {
rcswitchSender->switchOff(Plugin_112_csGroup, Plugin_112_nDevice);
}
success = true;
}
else if (tmpString.equalsIgnoreCase("RFTRISTATE") && rcswitchSender != 0)
{
/* For RFTRISTATE commands */
Serial.println("RFTRISTATE");
if (GetArgv(command, TmpStr1, 2)) Plugin_112_sCodeWord = TmpStr1;
if (GetArgv(command, TmpStr2, 3)) Plugin_112_Repeat = str2int(TmpStr2);
/* checks */
//if (strcmp(Plugin_112_sCodeWord, "") == 0) break;
if (Plugin_112_Repeat > 20) break;
rcswitchSender->setRepeatTransmit(Plugin_112_Repeat);
/**
* @param sCodeWord a tristate code word consisting of the letter 0, 1, F
*
* void RCSwitch::sendTriState(const char* sCodeWord) {
*/
rcswitchSender->sendTriState(Plugin_112_sCodeWord);
success = true;
}
else if (tmpString.equalsIgnoreCase("RFSEND") && rcswitchSender != 0 && Plugin_112_Bits != 0)
{
/* For general commands */
Serial.println("RFSEND");
if (GetArgv(command, TmpStr1, 2)) Plugin_112_iCode = str2int(TmpStr1);
if (GetArgv(command, TmpStr1, 3)) Plugin_112_Repeat = str2int(TmpStr1);
if (GetArgv(command, TmpStr1, 4)) Plugin_112_Bits = str2int(TmpStr1);
/* checks */
if (Plugin_112_iCode == 0) break;
if (Plugin_112_Bits > 100) break;
if (Plugin_112_Repeat > 20) break;
rcswitchSender->setRepeatTransmit(Plugin_112_Repeat);
/**
* Transmit the first 'length' bits of the integer 'code'. The
* bits are sent from MSB to LSB, i.e., first the bit at position length-1,
* then the bit at position length-2, and so on, till finally the bit at position 0.
*
* void RCSwitch::send(unsigned long code, unsigned int length) {
*/
rcswitchSender->send(Plugin_112_iCode, Plugin_112_Bits);
success = true;
}
if (success)
{
String url = String(Settings.Name) + "/control?cmd=" + string;
addLog(LOG_LEVEL_INFO, "RF Code Sent: " + String(Plugin_112_iCode) + Plugin_112_sCodeWord);
addLog(LOG_LEVEL_INFO, "To send this command again, ");
addLog(LOG_LEVEL_INFO, "use this: <a href=\"http://" + url + "\">URL</a>");
if (printToWeb)
{
printWebString += F("RCSwitch Code Sent!");
printWebString += F("<BR>Value: ");
printWebString += Plugin_112_iCode;
printWebString += F("<BR>Tristate: ");
printWebString += String(Plugin_112_sCodeWord);
printWebString += F("<BR>Family: ");
printWebString += String(Plugin_112_sFamily);
printWebString += F("<BR>sFamily: ");
printWebString += String(Plugin_112_sFamily);
printWebString += F("<BR>nGroup: ");
printWebString += String(Plugin_112_nGroup);
printWebString += F("<BR>sGroup: ");
printWebString += String(Plugin_112_sGroup);
printWebString += String(Plugin_112_csGroup);
printWebString += F("<BR>nDevice: ");
printWebString += String(Plugin_112_nDevice);
printWebString += F("<BR>sDevice: ");
printWebString += String(Plugin_112_sDevice);
printWebString += F("<BR>nAddressCode: ");
printWebString += String(Plugin_112_nAddressCode);
printWebString += F("<BR>nChannelCode: ");
printWebString += String(Plugin_112_nChannelCode);
printWebString += F("<BR>Repeats: ");
printWebString += String(Plugin_112_Repeat);
printWebString += F("<BR>Bits: ");
printWebString += String(Plugin_112_Bits);
printWebString += F("<BR>Pulselength: ");
printWebString += String(Plugin_112_Pulse);
printWebString += F("<BR><BR>");
printWebString += F("<BR>Use URL: <a href=\"http://");
printWebString += url;
printWebString += F("\">http://");
printWebString += url;
printWebString += F("</a>");
}
}
}
break;
}
return success;
}
#endif