-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path433MHz.ino
136 lines (105 loc) · 3.55 KB
/
433MHz.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
/*
mySwitch.switchOn("11111", "00010");
mySwitch.switchOff("11111", "00010");
Same switch as above, but using decimal code // decimal + bits (standart: 24bit)
mySwitch.send(5393, 24);
mySwitch.send(5396, 24);
mySwitch.send("000000000001010100010001"); // 24bit
mySwitch.send("000000000001010100010100");
// Хуй знает
mySwitch.sendTriState("00000FFF0F0F");
mySwitch.sendTriState("00000FFF0FF0");
*/
#include <ESP8266WiFi.h>
#include <ESPAsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include <RCSwitch.h>
#ifndef APSSID
#define APSSID "iPhone"
#define APPSK "12345678"
#endif
/* Set these to your desired credentials. */
const char *ssid = APSSID;
const char *password = APPSK;
// Initialize RCSwitch objects for transmitting and receiving data on 433MHz
RCSwitch mySwitchTx;
RCSwitch mySwitchRx;
// Variable to store the received data
String receivedData;
// Initialize the AsyncWebServer object
AsyncWebServer server(80);
// Handler for the root URL
void handleRoot(AsyncWebServerRequest* request) {
String html = "<html><body>";
html += "<h2>Enter Data: </h2>";
html += "<form action=\"/submit\" method=\"get\">";
html += "<input type=\"text\" name=\"data\">";
html += "<br>";
html += "<p>Choise Type: </p>";
html += "<input type='radio' name='option' value='1'>Binary (000000000001010100010001)<br>";
html += "<input type='radio' name='option' value='2'>TriState (00000FFF0F0F)<br>";
html += "<input type=\"submit\" value=\"Send\">";
html += "</form>";
html += "<h2>Received Data: </h2>";
html += "<ul>";
html += receivedData;
html += "</ul>";
html += "</body></html>";
request->send(200, "text/html", html);
}
// Handler for submitting data
void handleSubmit(AsyncWebServerRequest* request) {
String data = request->arg("data");
String option = request->arg("option");
String type;
if (option == "1")
{
Serial.println("1");
type = "Binary";
mySwitchTx.send(data.c_str());
} else if (option == "2")
{
Serial.println("2");
type = "TriState";
mySwitchTx.sendTriState(data.c_str());
} else
{
type = "Error";
Serial.println("Choise error");
}
Serial.println("Received Data: " + data);
// Update the received data
receivedData += "<li>SENDED: " + data + " Type: " + type + "</li>";
request->redirect("/");
}
void setup() {
Serial.begin(115200);
Serial.println();
Serial.print("Configuring access point...");
WiFi.softAP(ssid, password);
IPAddress myIP = WiFi.softAPIP();
Serial.print("AP IP address: ");
Serial.println(myIP);
// Enable transmitting and receiving on the respective pins
mySwitchTx.enableTransmit(D8);
mySwitchRx.enableReceive(D2);
// Set the default received data
receivedData = "";
// Route handlers
server.on("/", HTTP_GET, handleRoot);
server.on("/submit", HTTP_GET, handleSubmit);
// Start the web server
server.begin();
Serial.println("Web server started!");
}
void loop() {
// Check for new data on the receiver
if (mySwitchRx.available()) {
String result1, result2, result3, result4, result5, result6;
output(mySwitchRx.getReceivedValue(), mySwitchRx.getReceivedBitlength(), mySwitchRx.getReceivedDelay(), mySwitchRx.getReceivedRawdata(), mySwitchRx.getReceivedProtocol(), &result1, &result2, &result3, &result4, &result5, &result6);
mySwitchRx.resetAvailable();
// Update the received data
receivedData += "<li>RECIVED: Decimal: " + result1 + " Binary: " + result2 + " Tri-State: " + result3 + " Protocol: " + result4 + " Delay: " + result5 + " Lenght: " + result6 + "-bits </li>";
}
delay(100);
}