Skip to content

Instantly share code, notes, and snippets.

@random-robbie
Created February 12, 2023 13:29
Show Gist options
  • Save random-robbie/b0563d040f8c9032d599a0a547391369 to your computer and use it in GitHub Desktop.
Save random-robbie/b0563d040f8c9032d599a0a547391369 to your computer and use it in GitHub Desktop.
#include <WiFi.h>
#include <WiFiClient.h>
#include <WebServer.h>
#include <RCSwitch.h>
const char* ssid = "Wifi";
const char* password = "password";
RCSwitch mySwitch = RCSwitch();
WebServer server(80); // Initialize the WebServer object on port 80
void setup() {
Serial.begin(9600);
mySwitch.enableTransmit(23);
mySwitch.setPulseLength(320);
mySwitch.setRepeatTransmit(15);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
// Set up the HTTP server
server.on("/", []() {
server.send(200, "text/html", "Turn on or off lights");
});
server.on("/on", []() {
mySwitch.send(3114117, 28);
server.send(200, "text/plain", "On");
Serial.println("On");
});
server.on("/off", []() {
mySwitch.send(3114021, 28);
server.send(200, "text/plain", "Off");
Serial.println("Off");
});
server.begin();
Serial.println("HTTP server started");
}
void loop() {
server.handleClient();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment