ESP8266 Amazon Echo Sonos Controller (Wemo emulator library + Sonos Library)

December 12th, 2016

esp8266  sonos-logo

While it can only start and stop playback, I still felt it worthy of documenting. I was trying to find a way to control my speakers with my new Amazon Echo Dot.

The sketch can be found

on GitHub:, or

Downloaded(.ZIP), or

Copy and paste the below code:

#include <ESP8266WiFi.h>
#include <SonosUPnP.h>
#include <MicroXPath_P.h>

#include "WemoSwitch.h"
#include "WemoManager.h"
#include "CallbackFunction.h"

#define SERIAL_ERROR_TIMEOUT "E: Serial"

// prototypes
boolean connectWifi();

//on/off callbacks
void lightOn();
void lightOff();
void ethConnectError();

WiFiClient client;
SonosUPnP g_sonos = SonosUPnP(client, ethConnectError);
IPAddress g_JoeyIP(192, 168, 1, 250);
const char g_JoeyID[] = "949F3E0C46646";

//------- Replace the following! ------
char ssid[] = "ssid";       // your network SSID (name)
char password[] = "password";  // your network key

WemoManager wemoManager;
WemoSwitch *light = NULL;

void setup()

  // Set WiFi to station mode and disconnect from an AP if it was Previously
  // connected

  // Attempt to connect to Wifi network:
  Serial.print("Connecting Wifi: ");
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  IPAddress ip = WiFi.localIP();

  // Format: Alexa invocation name, local port no, on callback, off callback
  light = new WemoSwitch("Kitchen Speaker", 80, lightOn, lightOff);

void loop()

void lightOn() {
    Serial.print("Speaker turned on ...");;

void lightOff() {
    Serial.print("Speaker turned off ...");

void ethConnectError()
  Serial.println("Wifi died.");


Leave a Reply

Your email address will not be published. Required fields are marked *