|
|
@@ -1,89 +1,81 @@
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
WiFi Web Server LED Blink
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
A simple web server that lets you blink an LED via the web.
|
|
|
|
WebServer to use as replacement for Sony RM-D27M to control Sony MiniDisc decks.
|
|
|
|
This sketch will print the IP address of your WiFi Shield (once connected)
|
|
|
|
|
|
|
|
to the Serial monitor. From there, you can open that address in a web browser
|
|
|
|
Based on the the following sketches:
|
|
|
|
to turn on and off the LED on pin 5.
|
|
|
|
- SimpleWifiServer example
|
|
|
|
|
|
|
|
- SD_Test
|
|
|
|
|
|
|
|
- IRremote/SendDemo
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
If the IP address of your shield is yourAddress:
|
|
|
|
If the IP address of your shield is yourAddress:
|
|
|
|
http://yourAddress/H turns the LED on
|
|
|
|
http://yourAddress/H turns the LED on
|
|
|
|
http://yourAddress/L turns it off
|
|
|
|
http://yourAddress/L turns it off
|
|
|
|
|
|
|
|
|
|
|
|
This example is written for a network using WPA2 encryption. For insecure
|
|
|
|
|
|
|
|
WEP or WPA, change the Wifi.begin() call and use Wifi.setMinSecurity() accordingly.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Circuit:
|
|
|
|
Circuit:
|
|
|
|
* LED attached to pin 13
|
|
|
|
* LED attached to pin 13 (optional)
|
|
|
|
* IR Transmitter attached to pin 4
|
|
|
|
* IR Transmitter attached to pin 4
|
|
|
|
|
|
|
|
* SD-Module to load HTML and CSS from SD-card
|
|
|
|
|
|
|
|
|
|
|
|
created for arduino 25 Nov 2012
|
|
|
|
developed for the ESP32vn IoT Uni board 2024
|
|
|
|
by Tom Igoe
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ported for sparkfun esp32
|
|
|
|
|
|
|
|
31.01.2017 by Jan Hendrik Berlin
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <WiFi.h>
|
|
|
|
#include <WiFi.h>
|
|
|
|
#include <IRremote.hpp>
|
|
|
|
#include <IRremote.hpp>
|
|
|
|
|
|
|
|
#include "secrets.h"
|
|
|
|
const char* ssid = "FritzBox-7590-NB";
|
|
|
|
#include "defines.h"
|
|
|
|
const char* password = "60762265561727730801";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
WiFiServer server(80);
|
|
|
|
WiFiServer server(80);
|
|
|
|
|
|
|
|
|
|
|
|
void setup()
|
|
|
|
void setup() {
|
|
|
|
{
|
|
|
|
Serial.begin(115200);
|
|
|
|
Serial.begin(115200);
|
|
|
|
pinMode(LED_PIN, OUTPUT); // set the LED pin mode
|
|
|
|
pinMode(13, OUTPUT); // set the LED pin mode
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
delay(10);
|
|
|
|
delay(10);
|
|
|
|
|
|
|
|
|
|
|
|
// We start by connecting to a WiFi network
|
|
|
|
// We start by connecting to a WiFi network
|
|
|
|
|
|
|
|
|
|
|
|
Serial.println();
|
|
|
|
Serial.println();
|
|
|
|
Serial.println();
|
|
|
|
Serial.println();
|
|
|
|
Serial.print("Connecting to ");
|
|
|
|
Serial.print("Connecting to ");
|
|
|
|
Serial.println(ssid);
|
|
|
|
Serial.println(SSID);
|
|
|
|
|
|
|
|
|
|
|
|
WiFi.begin(ssid, password);
|
|
|
|
WiFi.begin(SSID, PASSWORD);
|
|
|
|
|
|
|
|
|
|
|
|
while (WiFi.status() != WL_CONNECTED) {
|
|
|
|
while (WiFi.status() != WL_CONNECTED) {
|
|
|
|
delay(500);
|
|
|
|
delay(500);
|
|
|
|
Serial.print(".");
|
|
|
|
Serial.print(".");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Here the macro IR_SEND_PIN is not defined or undefined above with #undef IR_SEND_PIN
|
|
|
|
IrSender.begin(IR_SEND_PIN, ENABLE_LED_FEEDBACK, USE_DEFAULT_FEEDBACK_LED_PIN); // Specify send pin and enable feedback LED at default feedback LED pin
|
|
|
|
uint8_t tSendPin = 4;
|
|
|
|
Serial.println();
|
|
|
|
IrSender.begin(tSendPin, ENABLE_LED_FEEDBACK, USE_DEFAULT_FEEDBACK_LED_PIN); // Specify send pin and enable feedback LED at default feedback LED pin
|
|
|
|
Serial.print(F("Send IR signals at pin "));
|
|
|
|
// You can change send pin later with IrSender.setSendPin();
|
|
|
|
Serial.println(IR_SEND_PIN);
|
|
|
|
Serial.println();
|
|
|
|
|
|
|
|
Serial.print(F("Send IR signals at pin "));
|
|
|
|
|
|
|
|
Serial.println(tSendPin);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Serial.println();
|
|
|
|
Serial.println();
|
|
|
|
Serial.println("WiFi connected.");
|
|
|
|
Serial.println("WiFi connected.");
|
|
|
|
Serial.println("IP address: ");
|
|
|
|
Serial.println("IP address: ");
|
|
|
|
Serial.println(WiFi.localIP());
|
|
|
|
Serial.println(WiFi.localIP());
|
|
|
|
|
|
|
|
|
|
|
|
server.begin();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
server.begin();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void loop(){
|
|
|
|
void loop() {
|
|
|
|
WiFiClient client = server.available(); // listen for incoming clients
|
|
|
|
WiFiClient client = server.available(); // listen for incoming clients
|
|
|
|
|
|
|
|
|
|
|
|
if (client) { // if you get a client,
|
|
|
|
if (client) { // if you get a client,
|
|
|
|
Serial.println("New Client."); // print a message out the serial port
|
|
|
|
Serial.println("New Client."); // print a message out the serial port
|
|
|
|
String currentLine = ""; // make a String to hold incoming data from the client
|
|
|
|
String currentLine = ""; // make a String to hold incoming data from the client
|
|
|
|
while (client.connected()) { // loop while the client's connected
|
|
|
|
while (client.connected()) { // loop while the client's connected
|
|
|
|
if (client.available()) { // if there's bytes to read from the client,
|
|
|
|
if (client.available()) { // if there's bytes to read from the client,
|
|
|
|
char c = client.read(); // read a byte, then
|
|
|
|
char c = client.read(); // read a byte, then
|
|
|
|
Serial.write(c); // print it out the serial monitor
|
|
|
|
Serial.write(c); // print it out the serial monitor
|
|
|
|
if (c == '\n') { // if the byte is a newline character
|
|
|
|
if (c == '\n') { // if the byte is a newline character
|
|
|
|
|
|
|
|
|
|
|
|
// if the current line is blank, you got two newline characters in a row.
|
|
|
|
// if the current line is blank, you got two newline characters in a row.
|
|
|
|
// that's the end of the client HTTP request, so send a response:
|
|
|
|
// that's the end of the client HTTP request, so send a response:
|
|
|
@@ -99,13 +91,13 @@ void loop(){
|
|
|
|
client.print("Click <a href=\"/L\">here</a> to turn the LED on pin 13 off.<br>");
|
|
|
|
client.print("Click <a href=\"/L\">here</a> to turn the LED on pin 13 off.<br>");
|
|
|
|
client.print("<a href=\"/play\">play</a><br>");
|
|
|
|
client.print("<a href=\"/play\">play</a><br>");
|
|
|
|
client.print("<form action=\"/api/control-deck\" method=\"post\"><button name=\"control\" type=\"submit\" value=\"play\">play</button></form><br>");
|
|
|
|
client.print("<form action=\"/api/control-deck\" method=\"post\"><button name=\"control\" type=\"submit\" value=\"play\">play</button></form><br>");
|
|
|
|
client.print("<form action=\"/api/control-deck\" method=\"get\"><input name=\"textinput\" type=\"text\" /></form><br>");
|
|
|
|
client.print("<form action=\"/api/control-deck\" method=\"get\"><input name=\"textinput\" type=\"text\" /><button type=\"submit\">send</button></form><br>");
|
|
|
|
|
|
|
|
|
|
|
|
// The HTTP response ends with another blank line:
|
|
|
|
// The HTTP response ends with another blank line:
|
|
|
|
client.println();
|
|
|
|
client.println();
|
|
|
|
// break out of the while loop:
|
|
|
|
// break out of the while loop:
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
} else { // if you got a newline, then clear currentLine:
|
|
|
|
} else { // if you got a newline, then clear currentLine:
|
|
|
|
currentLine = "";
|
|
|
|
currentLine = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (c != '\r') { // if you got anything else but a carriage return character,
|
|
|
|
} else if (c != '\r') { // if you got anything else but a carriage return character,
|
|
|
@@ -114,15 +106,16 @@ void loop(){
|
|
|
|
|
|
|
|
|
|
|
|
// Check to see if the client request was "GET /H" or "GET /L":
|
|
|
|
// Check to see if the client request was "GET /H" or "GET /L":
|
|
|
|
if (currentLine.endsWith("GET /H")) {
|
|
|
|
if (currentLine.endsWith("GET /H")) {
|
|
|
|
digitalWrite(13, HIGH); // GET /H turns the LED on
|
|
|
|
digitalWrite(LED_PIN, HIGH); // GET /H turns the LED on
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (currentLine.endsWith("GET /L")) {
|
|
|
|
if (currentLine.endsWith("GET /L")) {
|
|
|
|
digitalWrite(13, LOW); // GET /L turns the LED off
|
|
|
|
digitalWrite(LED_PIN, LOW); // GET /L turns the LED off
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (currentLine.endsWith("GET /play")) {
|
|
|
|
if (currentLine.endsWith("GET /play")) {
|
|
|
|
Serial.println("MD play");
|
|
|
|
//Serial.println("MD play");
|
|
|
|
Serial.flush();
|
|
|
|
//Serial.flush();
|
|
|
|
IrSender.sendSony(0xF, 0x2A, 2, 12);
|
|
|
|
//IrSender.sendSony(0xF, PLAY, 2, 12);
|
|
|
|
|
|
|
|
sendButton(PLAY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (currentLine.endsWith("POST /api/control-deck")) {
|
|
|
|
if (currentLine.endsWith("POST /api/control-deck")) {
|
|
|
|
|
|
|
|
|
|
|
@@ -137,3 +130,10 @@ void loop(){
|
|
|
|
Serial.println("Client Disconnected.");
|
|
|
|
Serial.println("Client Disconnected.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void sendButton(int command)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Serial.println(command);
|
|
|
|
|
|
|
|
Serial.flush();
|
|
|
|
|
|
|
|
IrSender.sendSony(0xF, command, 2, 12);
|
|
|
|
|
|
|
|
}
|
|
|
|