Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Questions about ControlPoint Stack in C#
26-09-2014, 08:49 AM
Post: #1
Questions about ControlPoint Stack in C#
Hi,

I want to integrate Sonos modules with the help of the ControlPoint stack but I encounter some issues.

It takes forever for the stack to detect the module on my network. Is there some mean I can use to directly have my devices in the stack without waiting for automatic detection ?

My second issue is that when the device is finally detected, the callback method is correctly called but I can't get any information, except the name, out of it.

Here my prototype code :

Code:
class Program
    {
        static List<CpDevice> devices = new List<CpDevice>();

        static void Added(CpDeviceList list, CpDevice device)
        {
            Console.WriteLine("Added!");

            string alive;
            string UDN;
            string serialNumber;
            string friendlyName;
            string modelName;
            string modelNumber;
            string manufacturer;
            string description;
            string presentationURL;
            string modelURL;
            string manufacturerURL;
            string iconFileName;
            string deviceSendWakeSupported;
            string deviceCompatFlags;
            string functionalDMR;
            string isControlPoint;

            device.GetAttribute("Upnp.Alive", out alive);
            device.GetAttribute("Upnp.UDN", out UDN);
            device.GetAttribute("Upnp.SerialNumber", out serialNumber);
            device.GetAttribute("Upnp.FriendlyName", out friendlyName);
            device.GetAttribute("Upnp.ModelName", out modelName);
            device.GetAttribute("Upnp.Manufacturer", out manufacturer);
            device.GetAttribute("Upnp.Description", out description);
            device.GetAttribute("Upnp.PresentationURL", out presentationURL);
            device.GetAttribute("Upnp.ModelURL", out modelURL);
            device.GetAttribute("Upnp.ManufacturerURL", out manufacturerURL);
            device.GetAttribute("Upnp.IconeFileName", out iconFileName);
            device.GetAttribute("Upnp.DeviceSendWakeSupported", out deviceSendWakeSupported);
            device.GetAttribute("Upnp.DeviceCompatFlags", out deviceCompatFlags);
            device.GetAttribute("Upnp.FunctionalDMR", out functionalDMR);
            device.GetAttribute("Upnp.IsControlPoint", out isControlPoint);
            
            Console.WriteLine("Upnp.Alive : {0}", alive);
            Console.WriteLine("Upnp.UDN : {0}", UDN);
            Console.WriteLine("Upnp.SerialNumber : {0}", serialNumber);
            Console.WriteLine("Upnp.FriendlyName : {0}", friendlyName);
            Console.WriteLine("Upnp.ModelName : {0}", modelName);
            Console.WriteLine("Upnp.Manufacturer : {0}", manufacturer);
            Console.WriteLine("Upnp.Description : {0}", description);
            Console.WriteLine("Upnp.PresentationURL : {0}", presentationURL);
            Console.WriteLine("Upnp.ModelURL : {0}", modelURL);
            Console.WriteLine("Upnp.ManufacturerURL : {0}", manufacturerURL);
            Console.WriteLine("Upnp.IconeFileName : {0}", iconFileName);
            Console.WriteLine("Upnp.DeviceSendWakeSupported : {0}", deviceSendWakeSupported);
            Console.WriteLine("Upnp.DeviceCompatFlags : {0}", deviceCompatFlags);
            Console.WriteLine("Upnp.FunctionalDMR : {0}", functionalDMR);
            Console.WriteLine("Upnp.IsControlPoint : {0}", isControlPoint);

            if(!devices.Contains(device){
                devices.Add(device);
            }
        }

        static void Removed(CpDeviceList list, CpDevice device)
        {
            Console.WriteLine("Removed!");
            devices.Remove(device);
        }

        static uint GetSubnet()
        {
            SubnetList subnetList = new SubnetList();
            NetworkAdapter nif = subnetList.SubnetAt(0);
            uint subnet = nif.Subnet();
            Console.WriteLine("Using adapter: {0} on subnet {1}", nif.Name(), subnet);
            subnetList.Dispose();

            return subnet;
        }

        static void Main(string[] args)
        {
            Console.WriteLine("Creating library");
            InitParams p = new InitParams() { MsearchTimeSecs = 1 };
            
            using (Library library = Library.Create(p))
            {
                Console.WriteLine("Starting stack");
                uint subnet = GetSubnet();
                Console.WriteLine("Subnet = {0}", subnet);
                library.StartCp(subnet);

                CpDeviceList.ChangeHandler added = new CpDeviceList.ChangeHandler(Added);
                CpDeviceList.ChangeHandler removed = new CpDeviceList.ChangeHandler(Removed);
                CpDeviceListUpnpAll dv = new CpDeviceListUpnpAll(added, removed);

                Console.WriteLine("Now waiting for something to happen...");
                Console.ReadKey();

                dv.Dispose();
                foreach(CpDevice d in devices){
                    d.RemoveRef();
                }
            }
        }
    }

Maybe am I doing something wrong. Any hint will be appreciated Big Grin
Find all posts by this user
26-09-2014, 04:30 PM (This post was last modified: 29-09-2014 07:53 AM by simonc.)
Post: #2
RE: Questions about ControlPoint Stack in C#
(26-09-2014 08:49 AM)Yann Wrote:  It takes forever for the stack to detect the module on my network. Is there some mean I can use to directly have my devices in the stack without waiting for automatic detection ?

Creating a device list should automatically issue a MSEARCH, quickly running your Added callback for each device that responds. After this, the device list listens for periodic ALIVE or BYEBYE messages that devices send out, calling Added or Removed when it receives them.

If you only see devices slowly trickling into your list, I'd guess your problem is one of
  • The devices on your network don't support UPnP discovery property and don't respond to MSEARCH messages. This seems unlikely for most modern devices but is possible if you are testing against a small set of devices which are running very old software.
  • Your network or firewall is mis-configured, preventing MSEARCH requests being sent or responses received. MSEARCH requires that the control point can send multicast UDP and receive unicast UDP responses. In contrast, the later ALIVE messages (which it sounds like you are receiving) require that the control point is able to receive multicast.
    To investigate this, you'll need to check settings on your Firewall and router.

(26-09-2014 08:49 AM)Yann Wrote:  My second issue is that when the device is finally detected, the callback method is correctly called but I can't get any information, except the name, out of it.

ohNet has a rather rudimentary XML parser so leaves most parsing of device xml to clients.
Code:
string xml;
device.GetAttribute("Upnp.DeviceXml", out xml);
will return you the full device xml. You can then parse it to read most of the values you want. If you are left with some attributes you can't read after this, can you explain more about their meaning please? Some of the attributes in your sample code don't sound like they might be specific to use cases of yours.
Find all posts by this user
29-09-2014, 07:24 AM (This post was last modified: 30-09-2014 07:17 AM by Yann.)
Post: #3
RE: Questions about ControlPoint Stack in C#
Thx for the answer, I'll try this out today !

edit: Admins had the broadcasting shut down on switchs, now it appears nearly instantaneously Smile Thx man !
Find all posts by this user


Forum Jump: