forked from letscontrolit/ESPEasyPluginPlayground
-
Notifications
You must be signed in to change notification settings - Fork 1
/
_P111_RF.ino
150 lines (131 loc) · 4.82 KB
/
_P111_RF.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
//#######################################################################################################
//#################################### Plugin 111: Input RF #############################################
//#######################################################################################################
/*
Version: 1.1
Description: use this script to recieve RF with a cheap MX-05V alike reciever
Author: S4nder
Copyright: (c) 2015-2016 Sander Pleijers (s4nder)
License: MIT
License URI: http://en.wikipedia.org/wiki/MIT_License
Status : "Proof of concept"
This program was developed independently and it is not supported in any way.
*/
#include <RCSwitch.h>
RCSwitch *rfReceiver;
#define PLUGIN_111
#define PLUGIN_ID_111 111
#define PLUGIN_NAME_111 "RF Recieve - MX-05V alike reciever"
#define PLUGIN_ValueNAME1_111 "RF"
boolean Plugin_111(byte function, struct EventStruct *event, String& string)
{
boolean success = false;
switch (function)
{
case PLUGIN_DEVICE_ADD:
{
Device[++deviceCount].Number = PLUGIN_ID_111;
Device[deviceCount].Type = DEVICE_TYPE_SINGLE;
Device[deviceCount].VType = SENSOR_TYPE_LONG;
Device[deviceCount].Ports = 0;
Device[deviceCount].InverseLogicOption = false;
Device[deviceCount].FormulaOption = false;
Device[deviceCount].ValueCount = 1;
Device[deviceCount].SendDataOption = true;
Device[deviceCount].TimerOption = false;
Device[deviceCount].GlobalSyncOption = true;
break;
}
case PLUGIN_GET_DEVICENAME:
{
string = F(PLUGIN_NAME_111);
break;
}
case PLUGIN_GET_DEVICEVALUENAMES:
{
strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[0], PSTR(PLUGIN_ValueNAME1_111));
break;
}
case PLUGIN_INIT:
{
int rfPin = Settings.TaskDevicePin1[event->TaskIndex];
//Serial.println(String(rfPin));
if (irReceiver != 0) {
String log = F("BUG: Cannot use IR reciever and RF reciever at the same time!");
Serial.print(log);
addLog(LOG_LEVEL_INFO, log);
delete rfReceiver;
rfReceiver = 0;
} else {
if (rfPin != -1)
{
Serial.println("INIT: RF433 RX created!");
rfReceiver = new RCSwitch();
rfReceiver->enableReceive(rfPin);
}
if (rfReceiver != 0 && rfPin == -1)
{
Serial.println("INIT: RF433 RX removed!");
rfReceiver->resetAvailable();
delete rfReceiver;
rfReceiver = 0;
}
}
success = true;
break;
}
case PLUGIN_ONCE_A_SECOND:
{
if (irReceiver != 0) break;
if (rfReceiver->available())
{
Serial.print("RF recieved");
int valuerf = rfReceiver->getReceivedValue();
if (valuerf == 0) {
Serial.print("Unknown encoding");
String log = F("RF Code Recieved: ");
log += String(valuerf);
log += " =Unknown encoding";
addLog(LOG_LEVEL_INFO, log);
} else {
Serial.print("Received ");
Serial.print( rfReceiver->getReceivedValue() );
Serial.print(" / ");
Serial.print( rfReceiver->getReceivedBitlength() );
Serial.print("bit ");
Serial.print("Protocol: ");
Serial.println( rfReceiver->getReceivedProtocol() );
UserVar[event->BaseVarIndex] = (valuerf & 0xFFFF);
UserVar[event->BaseVarIndex + 1] = ((valuerf >> 16) & 0xFFFF);
String log = F("RF Code Recieved: ");
log += String(valuerf);
addLog(LOG_LEVEL_INFO, log);
/*
Usage:
1=RFSEND
2=commando
3=repeat (if not set will use default settings)
4=bits (if not set will use default settings)
1 2 3 4
http://<ESP IP address>/control?cmd=RFSEND,blablacommando,10,24
Output this in logging:
*/
String url = String(Settings.Name) + "/control?cmd=RFSEND," + String(rfReceiver->getReceivedValue()) + ",1," + String(rfReceiver->getReceivedBitlength()) ;
String printString = F("For sending this command,");
addLog(LOG_LEVEL_INFO, printString);
printString = F("use URL: <a href=\"http://");
printString += url;
printString += F("\">http://");
printString += url;
printString += F("</a>");
addLog(LOG_LEVEL_INFO, printString);
sendData(event);
}
rfReceiver->resetAvailable();
}
success = true;
break;
}
}
return success;
}