-
Notifications
You must be signed in to change notification settings - Fork 0
/
rf.ino
86 lines (63 loc) · 1.86 KB
/
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
// RF
void setupRF()
{
Serial.println("-setup RF");
//setup Receiver
rfLib.enableReceive(RF_RECEIVE_PIN);
// setup Transmitter
rfLib.enableTransmit(RF_TRANSMIT_PIN);
// Optional set pulse length.
rfLib.setPulseLength(360);
// Optional set protocol (default is 1, will work for most outlets)
// rfLib.setProtocol(2);
// Optional set number of transmission repetitions.
// rfLib.setRepeatTransmit(15);
Serial.println("-setup RF - OK");
}
void rf_receive()
{
// RF Receive
if (rfLib.available())
{
//output(rfLib.getReceivedValue(), rfLib.getReceivedBitlength(), rfLib.getReceivedDelay(), rfLib.getReceivedRawdata(),rfLib.getReceivedProtocol());
lastcode = rfLib.getReceivedValue();
rfLib.resetAvailable();
Serial.println("RF received: ");
Serial.println(lastcode);
String msg = String(lastcode);
// send to mqtt
mqttPublish(topicOutRec, msg, false);
}
}
void rf_send(int code)
{
rfLib.send(code, 24);
Serial.print("RF send: ");
Serial.println(code);
// send to mqtt
mqttPublish(topicOutSend, String(code), false);
//TODO: check if code is from RF on or off code list - set fauxmo switchstate variable
/* See Example: TypeA_WithDIPSwitches */
// rfLib.switchOn("11111", "00010");
// delay(1000);
// rfLib.switchOff("11111", "00010");
// delay(1000);
/* Same switch as above, but using decimal code */
// rfLib.send(1394004, 24);
// delay(1000);
// rfLib.send(5396, 24);
// delay(1000);
//
// /* Same switch as above, but using binary code */
// rfLib.send("000000000001010100010001");
// delay(1000);
// rfLib.send("000000000001010100010100");
// delay(1000);
//
// /* Same switch as above, but tri-state code */
// rfLib.sendTriState("00000FFF0F0F");
// delay(1000);
// rfLib.sendTriState("00000FFF0FF0");
// delay(1000);
//delay(20000);
}