-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTasmotaRF433Bridge.ino
84 lines (71 loc) · 2.09 KB
/
TasmotaRF433Bridge.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
#include <RCSwitch.h>
#include <ArduinoJson.h>
RCSwitch mySwitch = RCSwitch();
void setup() {
Serial.begin(115200);
mySwitch.enableReceive(1); // Receiver on inerrupt 1 => that is pin #3
mySwitch.enableTransmit(10); //Transmitter on pin #10
mySwitch.setProtocol(2, 450);
mySwitch.setRepeatTransmit(15);
}
void loop() {
if (mySwitch.available()) {
unsigned int* raw = mySwitch.getReceivedRawdata();
unsigned int length = mySwitch.getReceivedBitlength();
StaticJsonBuffer<200> jsonBuffer;
JsonObject& root = jsonBuffer.createObject();
root["Value"] = mySwitch.getReceivedValue();
root["Length"] = length;
root["Delay"] = mySwitch.getReceivedDelay();
root["Protocol"] = mySwitch.getReceivedProtocol();
mySwitch.resetAvailable();
/*String rawStrHex = "";
for (int i=0; i<= length; i++) {
rawStrHex += String(raw[i], HEX);
}
root["Data"] = rawStrHex;*/
root.printTo(Serial);
Serial.println();
} /*else {
unsigned int* raw = mySwitch.getReceivedRawdata();
int siz = sizeof(&raw);
if(siz > 2)
{
Serial.println(siz);
}
}*/
if(Serial.available())
{
String inData = Serial.readStringUntil('\n');
StaticJsonBuffer<200> jsonBuffer;
//char json[] =
// "{\"Protocol\":2,\"Value\":39933942,\"Length\":28,\"Delay\":450}";
JsonObject& root = jsonBuffer.parseObject(inData);
// Test if parsing succeeds.
if (!root.success()) {
Serial.println("parseObject() failed");
return;
}
int protocol = root["Protocol"];
long value = root["Value"];
int length = root["Length"];
int pulse = root["Delay"];
// Print values.
//Serial.println(protocol);
//Serial.println(value);
//Serial.println(length);
//Serial.println(pulse);
mySwitch.setProtocol(protocol, pulse);
char target[length];
int a = length;
for(int i = 0; i < length; i++) {
int bit = (value >> i) & 1U;
if(bit) {
target[--a] = '1';
} else {
target[--a] = '0';
}
}
mySwitch.send(target);
}
}