Initial Commit

This commit is contained in:
Tim Windelschmidt 2016-11-28 17:39:15 +01:00
commit b8d1373a22
1 changed files with 100 additions and 0 deletions

100
sketch_oct11a.ino Normal file
View File

@ -0,0 +1,100 @@
/*
* This sketch sends data via HTTP GET requests to data.sparkfun.com service.
*
* You need to get streamId and privateKey at data.sparkfun.com and paste them
* below. Or just customize this script to talk to other HTTP servers.
*
*/
#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);
// We start by connecting to a WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
/* Explicitly set the ESP8266 to be a WiFi-client, otherwise, it by default,
would try to act as both a client and an access-point and could cause
network-issues with your other WiFi-devices on your WiFi-network. */
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);
}
}