Afstandbediening > IR > Raspberry Pi > WiFi > Sonos

Pagina: 1
Acties:

Onderwerpen


  • RobbieT
  • Registratie: Augustus 2007
  • Laatst online: 00:39
Ik heb ooit wat geknutseld met een Wemos D1 mini en een TSOP38238.
En dan een oude afstandsbediening van een CD-speler ofzo.

Of een universele remote die je instelt voor een CD-speler.
Commando’s uitluisteren en dan de IP commando’s via Wifi verzenden naar in mijn geval de Bluesound Node toen.

Ik zal straks de code even zoeken.

https://www.kiwi-electronics.com/nl/ir-sensor-tsop38238-552

https://www.hobbyelectronica.nl/product/wemos-d1-mini-v2/

https://www.hobbyelectron.../d1-mini-behuizing-blauw/

Afbeeldingslocatie: https://tweakers.net/i/AL8ROxLBNl1lW1PVh6OPaU5bCZc=/800x/filters:strip_exif()/f/image/J70EN6CPi27mbzSFB7RFOiBc.png?f=fotoalbum_large


Dit is met code voor een Bluesound Node, maar principe is hetzelfde.
Deze code gewoon in de Arduino IDE en dan in een Wemos D1 Mini met een TSOP er aan.

Signalen van de remote luister ik uit via de debug van de Arduino IDE en plak ik daarna in de code.

code:
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
// This code listens for IR signals and creates the IP commands for a Bluesound Node N100 (first gen)
// This way you can control your BlueSound using an IR remote control.
// For this I use a WEMOS D1 Mini with a IR sensor - TSOP38238 on a breadboard.
// The IR sensor - TSOP38238 is connected to 3.3V, GND and pin D2

#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <IRremoteESP8266.h>
#include <IRrecv.h>
#include <IRutils.h>

//Wifi settings, enter the SSID and PASSWORD of your wifi network here
const char* ssid = "wifi";
const char* password = "Password";

// Ir commands, These are from a NAD M50, I just chose that because the Logitech Harmony Hub knows that one, you can pick any cd-player remote.
// You can simply read the desired commands from the serial monitor, add 0x to indicate it is a hex value.
// And enter them here.
const double IrPlayCmd = 0xE13E9867;
const double IrPauseCmd = 0xE13E52AD;
const double IrSkipFwdCmd = 0xE13E609F;
const double IrSkipRevCmd = 0xE13EA05F;

// BlueSound IP address, fill in the address of your own Bluesound here:
char  bluesound[] = "192.168.1.102";

String StrBluesound(bluesound);
String IpPlayCmd = "/Play";
String IpPauseCmd = "/Pause";
String IpSkipFwdCmd = "/Skip";
String IpSkipRevCmd = "/Back";

int RECV_PIN = D2; //an IR detector connected to D2
bool NewIrCmdReceived;
String NewIpCmd;

IRrecv irrecv(RECV_PIN);

decode_results results;

WiFiClient client;

// Disable the wifi status LED, don't like flashing blue lights in the living room
void wifi_status_led_uninstall();

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver


  // Connect to WiFi network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");

  Serial.println("Server started");

  // Print the IP address
  Serial.print("Use this URL : ");
  Serial.print("http://");
  Serial.print(WiFi.localIP());
  Serial.println("/");
}

void loop() {

  NewIrCmdReceived = false;

  if (irrecv.decode(&results)) {
    // print() & println() can't handle printing long longs. (uint64_t)
    serialPrintUint64(results.value, HEX);
    Serial.println();
    irrecv.resume(); // Receive the next value

    if (results.value == IrPlayCmd) {
      NewIrCmdReceived = true;
      NewIpCmd = IpPlayCmd;
      Serial.println("http://" + StrBluesound + ":11000" + NewIpCmd);
    }
    else if (results.value == IrPauseCmd) {
      NewIrCmdReceived = true;
      NewIpCmd = IpPauseCmd;
      Serial.println("http://" + StrBluesound + ":11000" + NewIpCmd);
    }
    else if (results.value == IrSkipFwdCmd) {
      NewIrCmdReceived = true;
      NewIpCmd = IpSkipFwdCmd;
      Serial.println("http://" + StrBluesound + ":11000" + NewIpCmd);
    }
    else if (results.value == IrSkipRevCmd) {
      NewIrCmdReceived = true;
      NewIpCmd = IpSkipRevCmd;
      Serial.println("http://" + StrBluesound + ":11000" + NewIpCmd);
    }
    if (NewIrCmdReceived == true) {
      if (client.connect(bluesound, 11000)) {
        Serial.println("connected to server");
        // Make a HTTP request:
        client.println("GET http://" + StrBluesound + ":11000" + NewIpCmd + " HTTP/1.1");
        client.println("Host: " + StrBluesound);
        client.println("Connection: close");
        client.println();
      }
    }

  }
  delay(100);

}

[ Voor 93% gewijzigd door RobbieT op 22-01-2024 18:34 ]