Skip to content

REMOTE control "Spotify Connect Web" by ESP8266 (ESP 01)

rojait00 edited this page Dec 27, 2016 · 16 revisions

Coming soon!!

As soon as I tested it I will share more information and the commented Sketch!

Prototype

Current Sketch: ESP01Display.ino

Code-Snippets:

Set Volume

`WiFiClient client;`
`String msg = "";`

`if (client.connect(host, 4000))`
`{`
	`Serial.println("Connected to server");`
	`int outval = map(volume, 0, 100, 2, 65532);`
	`outval = outval > 65534 ? 65534 : outval;`
	`outval = outval < 0 ? 1 : outval;`
	`String PostData = "value=" + String(outval)+ "&";`
	`Sprintln(PostData);`
	`client.println("POST /api/playback/volume HTTP/1.1");`
	`client.println("Connection: close");`
	`client.println("Content-Type: application/x-www-form-urlencoded; charset=UTF-8");`
	`client.println(String("Host: ") + host);`
	`client.println("Accept-Encoding: gzip");`
	`client.println(String("Content-Length: ") + String(PostData.length()));`
	`client.println();`
	`client.println(PostData);`

	`long interval = 2000;`
	`unsigned long currentMillis = millis(), previousMillis = millis();`

	`while (!client.available()) {`

		`if ((currentMillis - previousMillis) > interval) {`

			`client.stop();`
			`return;`
		`}`
		`currentMillis = millis();`
	`}`

	`while (client.connected())`
	`{`
		`if (client.available())`
		`{`
			`char str = client.read();`
			`Sprint(str);`
		`}`
	`}`
	`client.stop();`
`}`

Next -Perv - Play - Pause...

String httpRequestGET(String url) { Sprintln("GET" + url); WiFiClient client; String msg = ""; if (!client.connect(host, port)) { return ""; } // This will send the request to the server client.println(String("GET ") + url + " HTTP/1.1"); client.println(String("Host: ") + host); client.println(String("Connection: close")); client.println(); unsigned long timeout = millis(); while (client.available() == 0 && millis() - timeout < 5000) {} while (client.available() != 0) { msg += client.readString(); delay(2); } client.stop(); Sprintln(msg); return msg; }

Based on libraries: Display: https://github.com/squix78/esp8266-oled-ssd1306

Keypad: https://www.youtube.com/watch?v=HE-PFaakFEE -> http://jlaservideo.com/project-downloads/