In my last blogs, I was showing how to create DLNA devices. In my final blog about this topic I will demonstrate how to create a DLNA Control Point (=Client) which uses the functionality of these devices.

I will demo a simple Control Point for a Media Renderer which will start playing some music:

The Arduino Sketch

First we define the relevant objects:

#include "WiFi.h"
#include "dlna.h"

// Replace these with your WiFi credentials
const char* ssid = "YOUR_SSID";
const char* password = "YOUR_PASSWORD";

DLNAControlPoint cp; // w/o Notifications
HttpRequest<WiFiClient> http;
UDPService<WiFiUDP> udp;
DLNAControlPointMediaRenderer renderer(cp, http, udp);
Code language: PHP (php)

In the Arduino setup() we start the processing:

void setup() {
  Serial.begin(115200);
  DlnaLogger.begin(Serial, DlnaLogLevel::Info);

  setupWifi();

  // Start control point to discover devices: min 1 sec - max 10 min
  if (!renderer.begin(1000, 10 * 60 * 1000)) {
    Serial.println("No devices found");
    return;
  }

  // Print number of discovered renderers
  Serial.print("Renderer count: ");
  Serial.println(renderer.getDeviceCount());

  // Use first discovered renderer device
  renderer.setDeviceIndex(0);

  // Starting playback
  Serial.println("Starting playback...");
  if (!renderer.play("http://stream.srg-ssr.ch/m/rsj/mp3_128")) {
    Serial.println("Play failed");
  } else {
    Serial.println("Play command sent");
  }
}
Code language: PHP (php)

We just start the control point by calling begin. When begin returns we select one of the provided devices: in ths example we just use the first device and we are ready to call the available methods (e.g. play in the example above)

The loop processing is like in all other examples also pretty simple: we just call the loop processing logic of the control point:

void loop() { cp.loop(); }
Code language: JavaScript (javascript)

Dependencies

Further Examples

Further examples can be found in the examples of the project:

Conclusion

With this simple yet powerful DLNA Control Point, we’ve unlocked the ability to command media renderers from an Arduino. This final piece completes the DLNA trilogy, allowing you to create a self-contained ecosystem where your Arduino projects can act as both servers and commanders of media. The play() function shown here is just the beginning; the same principles can be used to implement pause, stop, volume control, and playlist management. I encourage you to use this foundation to innovate and build seamless, voice-controlled, or automated media experiences for your home.

Categories: ArduinoMachine Sound

0 Comments

Leave a Reply

Avatar placeholder

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