add defines, create simple sendButton function

This commit is contained in:
Norman Bos
2024-07-20 10:22:12 +02:00
parent f48752f1c4
commit 6fdba62d0e
4 changed files with 90 additions and 68 deletions
+2
View File
@@ -30,3 +30,5 @@
*.exe
*.out
*.app
secrets.h
+7
View File
@@ -5,3 +5,10 @@ This is an arduino sketch to make an IR-remote control for easier title renaming
- Add webserver
- Add ir remote library
- Add SD-Card support to load html and css
Store WiFi secrets in a secrets.h like this:
```
#define SSID "your-ssid"
#define PASSWORD "your-password"
```
+61 -61
View File
@@ -1,89 +1,81 @@
/*
WiFi Web Server LED Blink
A simple web server that lets you blink an LED via the web.
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
to turn on and off the LED on pin 5.
WebServer to use as replacement for Sony RM-D27M to control Sony MiniDisc decks.
Based on the the following sketches:
- SimpleWifiServer example
- SD_Test
- IRremote/SendDemo
If the IP address of your shield is yourAddress:
http://yourAddress/H turns the LED on
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:
* LED attached to pin 13
* LED attached to pin 13 (optional)
* IR Transmitter attached to pin 4
* SD-Module to load HTML and CSS from SD-card
created for arduino 25 Nov 2012
by Tom Igoe
ported for sparkfun esp32
31.01.2017 by Jan Hendrik Berlin
developed for the ESP32vn IoT Uni board 2024
*/
#include <WiFi.h>
#include <IRremote.hpp>
const char* ssid = "FritzBox-7590-NB";
const char* password = "60762265561727730801";
#include "secrets.h"
#include "defines.h"
WiFiServer server(80);
void setup()
{
Serial.begin(115200);
pinMode(13, OUTPUT); // set the LED pin mode
void setup() {
Serial.begin(115200);
pinMode(LED_PIN, 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.print("Connecting to ");
Serial.println(ssid);
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(SSID);
WiFi.begin(ssid, password);
WiFi.begin(SSID, PASSWORD);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
// Here the macro IR_SEND_PIN is not defined or undefined above with #undef IR_SEND_PIN
uint8_t tSendPin = 4;
IrSender.begin(tSendPin, ENABLE_LED_FEEDBACK, USE_DEFAULT_FEEDBACK_LED_PIN); // Specify send pin and enable feedback LED at default feedback LED pin
// You can change send pin later with IrSender.setSendPin();
Serial.println();
Serial.print(F("Send IR signals at pin "));
Serial.println(tSendPin);
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
Serial.println();
Serial.print(F("Send IR signals at pin "));
Serial.println(IR_SEND_PIN);
Serial.println();
Serial.println("WiFi connected.");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
server.begin();
Serial.println();
Serial.println("WiFi connected.");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
server.begin();
}
void loop(){
WiFiClient client = server.available(); // listen for incoming clients
void loop() {
WiFiClient client = server.available(); // listen for incoming clients
if (client) { // if you get a client,
Serial.println("New Client."); // print a message out the serial port
String currentLine = ""; // make a String to hold incoming data from the client
while (client.connected()) { // loop while the client's connected
if (client.available()) { // if there's bytes to read from the client,
char c = client.read(); // read a byte, then
Serial.write(c); // print it out the serial monitor
if (c == '\n') { // if the byte is a newline character
if (client) { // if you get a client,
Serial.println("New Client."); // print a message out the serial port
String currentLine = ""; // make a String to hold incoming data from the client
while (client.connected()) { // loop while the client's connected
if (client.available()) { // if there's bytes to read from the client,
char c = client.read(); // read a byte, then
Serial.write(c); // print it out the serial monitor
if (c == '\n') { // if the byte is a newline character
// 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:
@@ -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("<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=\"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:
client.println();
// break out of the while loop:
break;
} else { // if you got a newline, then clear currentLine:
} else { // if you got a newline, then clear currentLine:
currentLine = "";
}
} 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":
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")) {
digitalWrite(13, LOW); // GET /L turns the LED off
digitalWrite(LED_PIN, LOW); // GET /L turns the LED off
}
if (currentLine.endsWith("GET /play")) {
Serial.println("MD play");
Serial.flush();
IrSender.sendSony(0xF, 0x2A, 2, 12);
//Serial.println("MD play");
//Serial.flush();
//IrSender.sendSony(0xF, PLAY, 2, 12);
sendButton(PLAY);
}
if (currentLine.endsWith("POST /api/control-deck")) {
@@ -137,3 +130,10 @@ void loop(){
Serial.println("Client Disconnected.");
}
}
void sendButton(int command)
{
Serial.println(command);
Serial.flush();
IrSender.sendSony(0xF, command, 2, 12);
}
+19 -6
View File
@@ -1,5 +1,18 @@
// Pin definitions
#define IR_SEND_PIN 4
#define LED_PIN 13
// IR commands (Sony 12bit)
#define POWER 0x15
#define PLAY 0x2A
#define PAUSE 0x29
#define STOP 0x28
#define PREV 0x20 //geraten
#define NEXT 0x21
//old commands
#define EJECT 0x69E
#define POWER 0xA9E
//#define POWER 0xA9E
#define DISPLAY 0x19E
#define SCROLL 0x99E
#define CONTINUE 0xB9E
@@ -41,11 +54,11 @@
#define CHAR 0x6DE
#define NUM 0xEDE
#define CLEAR 0xF1E
#define PLAY 0x55E
#define PAUSE 0x95E
#define STOP 0x15E
#define AMSPREV 0x05E
#define AMSNEXT 0x85E
// #define PLAY 0x55E
// #define PAUSE 0x95E
// #define STOP 0x15E
// #define AMSPREV 0x05E
// #define AMSNEXT 0x85E
#define RECORD 0xB5E
#define REWIND 0xD5E
#define FASTFORWARD 0x35E