Author Topic: Question regarding Luup Requests: request_image  (Read 395 times)

Offline floyderman3d

  • Jr. Member
  • **
  • Posts: 56
  • Karma: +0/-0
Question regarding Luup Requests: request_image
« on: April 18, 2018, 11:13:41 am »
Hi,

In the documentation (Luup Requests section in Wiki) I could see the following for Luup Request: request_image

Quote
Returns an image from a camera. This fetches the image from the camera using the URL variable for the device. Pass arguments:

cam = the device id of the camera.  This is the only mandatory argument.
res = optional: a resolution, which gets appended to the variable.  So passing "low" means the image from the URL_low variable will be returned.  If it doesn't exist it reverts to the standard URL or DirectStreamingURL
timeout = optional: how long to wait for the image to be retrieved, or how long to retrieve video.  defaults to 10 seconds.
url = optional: override the camera's default URL
ip = optional: override the camera's default ip
user or pass = optional: override the camera's default username/password

According to that, the parameter "cam" is supposed to be the only mandatory argument. The other ones are optional and defaults will be taken if not present. Hence, I could just send, for example,

Code: [Select]
http://ip_address:3480/data_request?id=request_image&cam=4
But I must be doing something wrong since, if I dont specify also IP and URL in the request, then it won't work for me.

This, in fact, works for me:

Code: [Select]
http://ip_address:3480/data_request?id=request_image&ip=192.168.1.137&url=/Jpeg/CamImg0000.jpg
(whether or not I specify CAM parameter)

But when I eliminate either IP or URL to let defaults apply it will not succeed (no matter if cam is specified or not). The error is always the same: Camera URL is invalid. Hence, my guess is that Vera does not see any default values for those two parameters: IP and URL.

However, my device has the IP filled in Advanced tab of my device, and it is actually used correctly as a variable through luup.devices[lul_device].ip in different parts of the implementation file.

Regarding the URL, I'm kind of confused. In the documentation says:

Quote
url = optional: override the camera's default URL

My question is: which is the default URL of my camera?

My device has two services: one of my own and I have included also this built-in one in order to have an URL camera parameter of that service, which I assumed it was the right one for the luup request:

Code: [Select]
urn:micasaverde-com:serviceId:Camera1
I have set that URL variable to the right value: /Jpeg/CamImg0000.jpg during startup to have it set by default and variable url appears correctly in advanced tab of my device, filled in.

Code: [Select]
function lug_startup(lul_device)
lug_Path = luup.variable_get("urn:micasaverde-com:serviceId:Camera1", "URL", lul_device)
if (lug_Path == nil or lug_Path == "" ) then
luup.variable_set("urn:micasaverde-com:serviceId:Camera1", "URL", "/Jpeg/CamImg0000.jpg", lul_device)
end
end

I guess I'm missing something obvious, maybe when MCV says default it means a different way to set them as default, like in the service file?

At least, I would expect the IP default value to work since IP was defined when the device was created in Vera.


Thanks a lot in advance for your help and best regards,
Best regards.











« Last Edit: April 19, 2018, 03:13:30 am by floyderman3d »

Offline floyderman3d

  • Jr. Member
  • **
  • Posts: 56
  • Karma: +0/-0
Re: Question regarding Luup Requests: request_image
« Reply #1 on: April 21, 2018, 09:17:46 pm »
Hi,

Anyone has a guess on this subject?

Basically, I need a way to set default values for IP address and URL for snapshots for an IP camera, so that I can launch an HTTP request based only on device number, like:

Code: [Select]
http://ip_address:3480/data_request?id=request_image&cam=4
Having the value set in the variable field (Advanced tab of the plugin) or setting them up during startup does not seem to help. The request only works when I specify IP and URL in the request.


If anyone could help, I would really appreciate it. I'm stuck there.

Thanks!
« Last Edit: April 21, 2018, 09:36:41 pm by floyderman3d »

Offline akbooer

  • Master Member
  • *******
  • Posts: 6152
  • Karma: +275/-69
  • "Less is more"
Re: Question regarding Luup Requests: request_image
« Reply #2 on: April 22, 2018, 01:28:24 am »
There's a number of things you're not telling us, which makes it very hard to respond usefully, and a bad guess is worse than no answer at all:

  • What is the make of the camera?
  • What device file have you set of the Vera device?
  • What implementation file?
  • Does it require username and password?
  • What attributes are set?
  • What is the current value of all the device variables?
  • In particular, what is the URL variable set to?
  • What is the ACTUAL HTTP request that you are trying to send?

Otherwise, I for one, am floundering about to understand what's really the problem.
3x Vera Lite-UI5/Edge-UI7, 25x Fibaro, 23x TKB, 9x MiniMote, 2x NorthQ Power, 2x Netatmo, 1x Foscam FI9831P, 9x Philips Hue,
Razberry, MySensors Arduino, HomeWave, AltUI, AltHue, DataYours, Grafana, openLuup, ZWay, ZeroBrane Studio.

Offline floyderman3d

  • Jr. Member
  • **
  • Posts: 56
  • Karma: +0/-0
Re: Question regarding Luup Requests: request_image
« Reply #3 on: April 22, 2018, 07:51:27 am »
Hi akbooer,

Thanks for your reply.

Sorry if I didn't provide you with all the relevant data.

Actually it's a very simple test.

The camera is not a standard one from a known maker. It's a camera integrated in a WiFi robot. You can get snapshots from that camera on the URL:

Code: [Select]
http://192.168.1.137/Jpeg/CamImg0000.jpg
where 192.168.1.137 is the IP address of the WiFi card of the robot.

No need for user password.

This works correctly. I only need snapshots from the camera, no more complex stuff.

The device in Vera is one of my own. Camera service will be only a part of the device. Hence, it will have other services of my own to allow other specific controls not related to the camera but, for this test, only Camera1 service is added, so:

Code: [Select]
<?xml version="1.0"?>
<root xmlns="urn:schemas-upnp-org:device-1-0">
  <specVersion>
    <major>1</major>
    <minor>0</minor>
  </specVersion>
  <device>
    <deviceType>urn:schemas-upnp-org:device:Test:1</deviceType>
<staticJson>D_Test.json</staticJson>
    <serviceList>
      <service>
<Optional/>
<serviceType>urn:schemas-micasaverde-com:service:Camera:1</serviceType>
<serviceId>urn:micasaverde-com:serviceId:Camera1</serviceId>
<SCPDURL>S_Camera1.xml</SCPDURL>
      </service>
    </serviceList>
  </device>
</root>

The implementation file only runs a startup function to set the value of the variable URL belonging to Camera1 service to: /Jpeg/CamImg0000.jpg

Code: [Select]
<?xml version="1.0"?>
<implementation>
  <functions>
function lug_startup(lul_device)
luup.variable_set("urn:micasaverde-com:serviceId:Camera1", "URL", "/Jpeg/CamImg0000.jpg", lul_device)
end
  </functions>
  <startup>lug_startup</startup>
  <actionList>
  </actionList>
</implementation>

There is also a basic json file to have the Advanced tab for the device.

Code: [Select]
{
    "flashicon": "icons\/generic_icon.swf",
    "inScene": "1",
    "DisplayStatus": {},
    "doc_url": {
        "doc_language": 1,
        "doc_manual": 1,
        "doc_version": 1,
        "doc_platform": 0,
        "doc_page": "devices"
    },
    "Tabs": [
       
{
            "Label": {
                "lang_tag": "advanced",
                "text": "Advanced"
            },
            "Position": "1",
            "TabType": "javascript",
            "ScriptName": "shared.js",
            "Function": "advanced_device"
        }
    ],
    "DeviceType": "urn:schemas-upnp-org:device:Test:1",
    "device_type": "urn:schemas-upnp-org:device:Test:1"
   }



And that's it.

URL variable is set to: /Jpeg/CamImg0000.jpg
IP = 192.168.1.137
device number = 6

Actual HTTP request trying to send is:
Code: [Select]
http://192.168.1.200:3480/data_request?id=request_image&cam=6
where 192.168.1.200 is IP address of Vera and the number of the created device is 6.

But I get the error: "Camera URL is invalid" when trying to browse that URL.

However, this actually works like a charm:

Code: [Select]
http://192.168.1.200:3480/data_request?id=request_image&cam=6&ip=192.168.1.137&url=/Jpeg/CamImg0000.jpg
What I need for my plugin is that the request works without specifying URL and IP address, just by specifying the device number.

According to documentation for HTTP request_image function, IP address and URL are optional, it should get defaults for the device, which I think are set. Am I missing something?

As it can be checked in the screenshot attached, variable_get request for the URL replies with the right value.

Any additional information, dont hesitate to ask.

Thanks in advance!













« Last Edit: April 22, 2018, 09:08:11 am by floyderman3d »

Offline akbooer

  • Master Member
  • *******
  • Posts: 6152
  • Karma: +275/-69
  • "Less is more"
Re: Question regarding Luup Requests: request_image
« Reply #4 on: April 22, 2018, 10:48:34 am »
Well, this changes everything...

...it's the first time that you mentioned you were not using a standard device file.

In yet another stunning example of Vera/MiOS implementation incompetency, it turns out, after a little experimentation, that whilst you might have hoped that /data_request?id=request_image&cam=xxx would work on any device with the urn:micasaverde-com:serviceId:Camera1 service, you would be wrong.

By trying things out on a dummy device file:

Code: [Select]
<?xml version="1.0"?>
<root xmlns="urn:schemas-upnp-org:device-1-0">
<specVersion>
<major>1</major>
<minor>0</minor>
</specVersion>
<device>
<deviceType>urn:akb-org:device:InSecurityCamera:1</deviceType>
<staticJson>D_DigitalSecurityCamera1.json</staticJson>
<friendlyName>IP Camera</friendlyName>
<serviceList>
<service>
<Optional/>
<serviceType>urn:schemas-micasaverde-com:service:Camera:1</serviceType>
<serviceId>urn:micasaverde-com:serviceId:Camera1</serviceId>
<SCPDURL>S_Camera1.xml</SCPDURL>
</service>
</serviceList>
</device>
</root>

...it turns out that the only way you can get this to work is if you set the category_num device attribute to be 6 (which is to say, a camera.)

I would suggest that you try that on your own device, but it also prompts the question WHY do you want this to work at all?  If you're writing your own device, you can presumably make action requests to that device do anything that you like, within reason.

« Last Edit: April 22, 2018, 10:50:40 am by akbooer »
3x Vera Lite-UI5/Edge-UI7, 25x Fibaro, 23x TKB, 9x MiniMote, 2x NorthQ Power, 2x Netatmo, 1x Foscam FI9831P, 9x Philips Hue,
Razberry, MySensors Arduino, HomeWave, AltUI, AltHue, DataYours, Grafana, openLuup, ZWay, ZeroBrane Studio.