Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get CpDevice ip and other information.
17-09-2013, 03:04 PM
Post: #1
Get CpDevice ip and other information.
Hello,

I'm using CpDeviceListUpnpServiceType to scan a network for a device list with a requested service.

I have a question about how to get CpDevice's ip address and other information (manufacturer, model, etc) ?

Thanks in advance.
Find all posts by this user
17-09-2013, 06:41 PM (This post was last modified: 17-09-2013 06:42 PM by BitGriff.)
Post: #2
RE: Get CpDevice ip and other information.
I tried the following code for deviceAdded method of ICpDeviceListListener:

Code:
String location = getDeviceAttribute(aDevice, "Upnp.Location");
String deviceType = getDeviceAttribute(aDevice, "Upnp.Type");
String sDeviceTypeVersion = getDeviceAttribute(aDevice, "Upnp.Version");
String deviceName = getDeviceAttribute(aDevice, "Upnp.FriendlyName");
String manufacturer = getDeviceAttribute(aDevice, "Upnp.Manufacturer");
String model = getDeviceAttribute(aDevice, "Upnp.ModelName");

... skip ...

private String getDeviceAttribute(CpDevice device, String attrName) {
    CpAttribute attribute = device.getAttribute(attrName);
    if (attribute == null)
        return null;
    return attribute.getValue();
}

But, got nulls for Upnp.Manufacturer and Upnp.ModelName.

Device, that was found is registered as follows:
Code:
DpDevice device = new DvDeviceStandard(deviceInfo.getUuid());
device.setAttribute("Upnp.Domain", "upnp.org");
device.setAttribute("Upnp.Type", "MediaServer");
device.setAttribute("Upnp.Version", "1");
device.setAttribute("Upnp.FriendlyName", "Test name");
device.setAttribute("Upnp.Manufacturer", "Test");
device.setAttribute("Upnp.ModelName", "Test model");
        
device.setEnabled();

When i try to get device xml ("Upnp.DeviceXml") getAttribute returns valid value.

What can be wrong?

Do i need additional calls to parse manufacturer, model and etc attributes?
Find all posts by this user
23-09-2013, 10:39 AM
Post: #3
RE: Get CpDevice ip and other information.
I've checked, and it doesn't look like ohNet provides a quick way to access these properties. You will need to use an XML parser to parse the DeviceXml. I agree that it's confusing that there is this asymmetry between the UPNP attributes recognized by setAttribute and getAttribute. simonc will be back tomorrow: he might be able to give you more information.
Visit this user's website Find all posts by this user
24-09-2013, 10:22 AM
Post: #4
RE: Get CpDevice ip and other information.
The intended way to read these attributes is to call getAttribute("Upnp.DeviceXml") then parse the resulting xml in application code. The reasoning behind this is that ohNet uses a very basic xml parser and doesn't have easy access to anything better while application code usually has easy access to better/faster parsers.
Find all posts by this user
28-09-2013, 07:28 AM
Post: #5
RE: Get CpDevice ip and other information.
Thanks for your answers.

Is it possible to use ohNet's xml parser to parse the DeviceXml, or it's needed to write our own parser?
Find all posts by this user
28-09-2013, 08:09 PM (This post was last modified: 28-09-2013 08:09 PM by simonc.)
Post: #6
RE: Get CpDevice ip and other information.
(28-09-2013 07:28 AM)BitGriff Wrote:  Thanks for your answers.

Is it possible to use ohNet's xml parser to parse the DeviceXml, or it's needed to write our own parser?

You're welcome to try using ohNet's parser. See XmlParserBasic in Build/Include/OpenHome/Net/Private/XmlParser.h.

I think you mentioned in an earlier post that you were using ohNet as part of a .NET application. If you're still doing this, .NET has a variety of parsers that'll be as efficient or better and are easy to use. I'd recommend trying e.g. System.Xml or System.Linq.Xml before XmlParserBasic.

If you're writing C++ code that'll be deployed to multiple platforms, ignore all this and give XmlParserBasic a go Smile
Find all posts by this user
29-09-2013, 09:02 AM (This post was last modified: 29-09-2013 09:04 AM by BitGriff.)
Post: #7
RE: Get CpDevice ip and other information.
Thanks for your answer.

We are using .Net and Java (Android and j2se).

Of course, i know, that those frameworks have a good xml parsers, this question was because, if ohNet has already made xml parsing code, there is no need to reinvent the wheel.

Best regards.
Find all posts by this user


Forum Jump: