-
Notifications
You must be signed in to change notification settings - Fork 0
/
arduino-443mhz-web-ui.ino
62 lines (51 loc) · 1.9 KB
/
arduino-443mhz-web-ui.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
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <RCSwitch.h>
const char* ssid = "433";
const char* password = "";
const int receiverPin = D2; // D2 pin on NodeMCU
ESP8266WebServer server(80);
RCSwitch mySwitch = RCSwitch();
String messageLog;
void handleRoot() {
String html = "<html><head><title>433MHz Receiver Log</title>";
html += "<style>body{font-family: Arial, sans-serif;} pre {white-space: pre-wrap;}</style><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"></head><body>";
html += "<h1>433MHz Receiver Log</h1><hr>";
html += "<pre>" + messageLog + "</pre>";
html += "</body></html>";
server.send(200, "text/html", html);
}
void setup() {
Serial.begin(115200);
// Configure 433MHz receiver
mySwitch.enableReceive(receiverPin);
// Connect to Wi-Fi
WiFi.softAP(ssid, password);
IPAddress ip = WiFi.softAPIP();
Serial.print("Access Point IP address: ");
Serial.println(ip);
// Initialize web server routes
server.on("/", handleRoot);
server.begin();
Serial.println("Web server started");
}
void loop() {
server.handleClient();
if (mySwitch.available()) {
unsigned int value = mySwitch.getReceivedValue();
int bitLength = mySwitch.getReceivedBitlength();
int delay = mySwitch.getReceivedDelay();
unsigned long rawdata = (unsigned long)mySwitch.getReceivedRawdata();
int protocol = mySwitch.getReceivedProtocol();
if (value != 0) {
String binaryValue = String(value, BIN);
String receivedMessage = "Received: " + String(value) + " (" + binaryValue + ")" +
" | Bit Length: " + String(bitLength) +
" | Delay: " + String(delay) + " | Raw Data: " + String(rawdata) +
" | Protocol: " + String(protocol);
Serial.println(receivedMessage);
messageLog += receivedMessage + "\n";
}
mySwitch.resetAvailable();
}
}