Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
// 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