Project goals:
- Making it possible to both control and read the state of my home speaker system using UPnP.
- Keeping the binary size and RAM usage low enough for the library to run on Arduino boards using the ATmega328 chip.
- Learning more about writing parsers, using PROGMEM and the UPnP protocol.
Reverse engineering with Wireshark:
It isn't feasible to implement the entire UPnP protocol on a device like the Arduino, and reading protocol specifications can be tedious. Therefore, for small projects like Sonos speaker integration, it's sometimes faster to use a tool like Wireshark to get an understanding of and replicate some of the messages being sent over the wire.
![]() |
| To get started with Wireshark: download, install, select capture interface and click start. Tip: Use the filter function. |
Using PROGMEM (Flash) instead of RAM for storing strings:
The Arduino Uno and Duemilanove boards use the ATmega328 chip with only 2048 bytes of SRAM. Normally when you use strings (char arrays) in your code, all the strings will get copied to the heap on startup and waste your precious RAM.
The SonosUPnP library contains almost 4KB of string data and it would not be possible to run on the ATmega328 without using PROGMEM for strings. More information about using PROGMEM:
Sending UPnP messages seems simple enough, but what about receiving and parsing?
One of my goals when writing the SonosUPnP library was to support reading state in addition to controlling the Sonos speakers. This capability is also what sets my library apart from the other Sonos Arduino libraries I've seen so far.
Again the challenge is the limited amount of RAM: How do you parse and read the values you are interested in from an XML file while only using a few bytes of RAM? To accomplish this I decided to write a library for this particular purpose: MicroXPath
Downloads:
