Created
January 8, 2017 22:08
-
-
Save gbaeke/9c185e82e7f23c0c4c9d803990d3660f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Code requires a Sonos control API from https://github.com/jishi/node-sonos-http-api at | |
// SonosController IP address and port defined in request.port | |
// include HttpClient library in your Build project | |
#include "application.h" | |
#include "HttpClient/HttpClient.h" | |
int LED=D1; | |
int BUTTON = D0; | |
bool pressed; | |
bool ledon; | |
HttpClient http; | |
http_request_t request; | |
http_response_t response; | |
IPAddress SonosController(192,168,0,203); | |
void setup() { | |
pinMode(BUTTON, INPUT); | |
pinMode(LED, OUTPUT); | |
digitalWrite(LED, LOW); | |
ledon=false; | |
if(digitalRead(BUTTON)==HIGH) pressed=false; | |
else pressed=true; | |
// setup request | |
request.port=5005; | |
request.ip=SonosController; | |
} | |
void loop() { | |
if(digitalRead(BUTTON)==HIGH && !pressed) { | |
pressed=true; | |
if(ledon) { | |
digitalWrite(LED, LOW); | |
ledon=false; | |
// ask Sonos to resume playing | |
request.path="/living%20room/pause"; | |
http.get(request, response); | |
} else { | |
digitalWrite(LED, HIGH); | |
ledon=true; | |
// ask Sonos to resume playing | |
request.path="/living%20room/playlist/car"; | |
http.get(request, response); | |
} | |
} else if(digitalRead(BUTTON)==LOW && pressed) { | |
pressed=false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment