basser/sketch_oct11a.ino

86 lines
1.8 KiB
C++

#include <ESP8266WiFi.h>
const char* ssid = "CTDO-g";
const char* password = "ctdo2342";
const char* host = "rpi3.raum.ctdo.de";
const int httpPort = 6600;
const int buttonPin = 5;
int buttonState;
bool previousState;
int previousMillis;
int currentMillis;
void setup() {
Serial.begin(115200);
delay(10);
pinMode(buttonPin, INPUT);
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("IP address: ");
Serial.println(WiFi.localIP());
}
void loop() {
currentMillis = millis();
buttonState = digitalRead(buttonPin);
if (currentMillis - previousMillis > 500) {
if (buttonState == HIGH && previousState == false) {
mpdbass(true);
previousState = true;
} else if (buttonState == LOW && previousState == true) {
mpdbass(false);
previousState = false;
}
}
}
void mpdbass(bool start) {
WiFiClient client;
if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
return;
}
unsigned long timeout = millis();
while (client.available() == 0) {
if (millis() - timeout > 5000) {
Serial.println(">>> Client Timeout !");
client.stop();
return;
}
}
while(client.available()){
String line = client.readStringUntil('\r');
Serial.print(line);
}
if (start == true){
Serial.println("Play");
client.println("addid \"users/lucas/Alben/Function/Incubation/01 Voiceprint.flac\" 0");
client.println("play 0");
} else if (start == false) {
Serial.println("Remove");
client.println("delete 0");
}
while(client.available()){
String line = client.readStringUntil('\r');
Serial.print(line);
}
}