how to set brightness on Dlink 930 through curl

Posted on
Thu Aug 29, 2013 7:49 am
kw123 offline
User avatar
Posts: 8366
Joined: May 12, 2013
Location: Dallas, TX

how to set brightness on Dlink 930 through curl

I have some dlink 930. They do not adapt their brightness settings properly. the goal is to increase brightness at night and turn back lower in the morning.
A solution in applescript with keystrokes works, but that requires safari to open / close, and sometimes userid and password has to be entered etc..

Here my question: is there a way to use curl to change brightness. I have attached the response from the Dlink930 to the curl command that shows the page where brightness is changed, its ~ 60% down the code:
>>>> <SELECT id="BrightnessControlSel" size="1" onchange="document.forms[0].BrightnessControl.value = this.value"> <<<

Any help is appreciated.

Thanks

Karl




Code: Select all
curl -u userid:password http://192.168.1.77/image.htm
<html>
<head>
<link rel="stylesheet" rev="stylesheet" href="dlink.css?cidx=1.062012-08-15" type="text/css">
<title>D-Link Corporation. | WIRELESS INTERNET CAMERA | SETUP | IMAGE SETUP</title>
<META content="text/html; charset=windows-1252" http-equiv=Content-Type>
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">
<script language="Javascript" SRC="function.js?cidx=1.062012-08-15"></script>
<script language="Javascript">
function InitAUTO()
{
  frm = document.forms[0];
  frm.BrightnessControlSel.value = frm.BrightnessControl.value;
  frm.ContrastControlSel.value = frm.ContrastControl.value;
  frm.SaturationControlSel.value = frm.SaturationControl.value;
  if (frm.AntiFlickerEnable.value == 1)
     frm.TmpAntiFlicker.checked = true;
  else
     frm.TmpAntiFlicker.checked = false;
  if ((frm.Mirror.value & 0x01) == 0x01)
     frm.TmpMirror1.checked = true;
  else
     frm.TmpMirror1.checked = false;
  if ((frm.Mirror.value & 0x02) == 0x02)
     frm.TmpMirror2.checked = true;
  else
     frm.TmpMirror2.checked = false;
}

function ClickAntiFlicker()
{
  frm = document.forms[0];
  if (frm.TmpAntiFlicker.checked)
     frm.AntiFlickerEnable.value = 1;
  else
     frm.AntiFlickerEnable.value = 0;
}

function ClickMirror()
{
  frm = document.forms[0];

  frm.Mirror.value = 0;
  if (frm.TmpMirror1.checked)
     frm.Mirror.value |= 0x01;
  if (frm.TmpMirror2.checked)
     frm.Mirror.value |= 0x02;
}

function ClickCancel()
{
  Browser = CheckBrower();
  if ((Browser == "Opera") || (Browser == "Safari") || (Browser == "Chrome") || (Browser == "Firefox"))
     location.href="image.htm";
  else {
     javascript:document.forms[0].reset();
     InitAUTO();
  }
}
</script>
</head>
<body topmargin="1" leftmargin="0" rightmargin="0" bgcolor="#757575">
<table id="header_container" border="0" cellpadding="5" cellspacing="0" width="838" align="center">
<tr>
<td width="100%">Product: <a href="http://support.dlink.com/" target="_blank">DCS-930L</a></td>
  <td align="right" nowrap></td>
  <td align="right" nowrap>Firmware version: 1.06 &nbsp;</td>
</tr>
</table>
<table id="topnav_container" border="0" cellpadding="0" cellspacing="0" width="838" align="center">
<tr><td align="center" valign="middle"><img src="title.gif"></td></tr>
</table>
<table border="0" cellpadding="2" cellspacing="1" width="838" align="center" bgcolor="#FFFFFF">
<tr id="topnav_container">
  <td><img src="devmodel.jpg?cidx=DCS-930L"></td>
  <td id="topnavoff"><a href="home.htm">Live Video</a></td>
  <td id="topnavon"><a href="wizard.htm">Setup</a></td>
  <td id="topnavoff"><a href="advanced.htm">Maintenance</a></td>
  <td id="topnavoff"><a href="stsdev.htm">Status</a></td>
  <td id="topnavoff"><a href="support.htm">Help</a></td>
</tr>
<tr><td colspan=6 height=1 bgcolor="#ffffff"></td></tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="838" align="center" bgcolor="#FFFFFF" bordercolordark="#FFFFFF">
<tr><td height=1 bgcolor="#000000"></td></tr>
<tr><td>
<table border="0" cellpadding="0" cellspacing="0" width="838" align="center" bgcolor="#FFFFFF" bordercolordark="#FFFFFF">
<tr>
  <td valign="top" width="131" height="100%" align="right">
    <!-- === BEGIN SIDENAV === -->
    <table border="0" cellpadding="1" cellspacing="1" height=100% bgcolor="#FFFFFF">
    <tr id="sidenav_container"><td id="sidenavoff"><a href="wizard.htm">Wizard</a></td></tr>
    <tr id="sidenav_container"><td id="sidenavoff"><a href="network.htm">Network Setup</a></td></tr>
    <tr id="sidenav_container"><td id="sidenavoff"><a href="wireless.htm">Wireless Setup</a></td></tr>
    <tr id="sidenav_container"><td id="sidenavoff"><a href="ddns.htm">Dynamic DNS</a></td></tr>
    <tr id="sidenav_container"><td id="sidenavon"><a href="image.htm">Image Setup</a></td></tr>
    <tr id="sidenav_container"><td id="sidenavoff"><a href="video.htm">Video</a></td></tr>
    <tr id="sidenav_container"><td id="sidenavoff"><a href="audio.htm">Audio</a></td></tr>
    <tr id="sidenav_container"><td id="sidenavoff"><a href="motion.htm">Motion Detection</a></td></tr>
    <tr id="sidenav_container"><td id="sidenavoff"><a href="email.htm">Mail</a></td></tr>
    <tr id="sidenav_container"><td id="sidenavoff"><a href="upload.htm">FTP</a></td></tr>
    <tr id="sidenav_container"><td id="sidenavoff"><a href="time.htm">Time and Date</a></td></tr>
    <tr id="sidenav_container"><td id="sidenavoff"><a href="logout.htm">Logout</a></td></tr>
    <tr id="sidenav_container" height=100%><td id="sidenavoff" align="center" valign="top">&nbsp;</td></tr>
    </table>
    <!-- === END SIDENAV === -->
  </td>
  <td valign="top" id="maincontent_container" height="420">
    <table height="420" width=100% border="0" cellpadding="0" cellspacing="0" bgcolor="white">
    <tr><td>
    <div id="maincontent">
      <!-- === BEGIN MAINCONTENT === -->
      <div id="box_header">
      <h1>Image Setup</h1>
      In this section, you can configure the image settings for your camera.
<FORM ACTION="/setSystemStream" METHOD="POST">
        <input type="hidden" name="ReplySuccessPage" value="image.htm">
        <input type="hidden" name="ReplyErrorPage" value="errrimg.htm">
        <input type="hidden" name="BrightnessControl" value="103">
        <input type="hidden" name="ContrastControl" value="64">
        <input type="hidden" name="SaturationControl" value="64">
        <input type="hidden" name="AntiFlickerEnable" value="1">
        <input type="hidden" name="Mirror" value="0">
        <div align=center>
        &nbsp;<INPUT type="button" width="80" value=" Save Settings " onclick="javascript:document.forms[0].submit()">
        &nbsp;&nbsp;<INPUT type="button" width="80" value=" Don't Save Settings " onclick="ClickCancel()">
        </div>
      </div>
      <div class="box">
        <h2>image settings</h2>
        <table cellpadding="2" cellspacing="1" border="0" bgcolor="white" bordercolor="#FFFFFF">
        <TR>
          <TD width="137">Enable Anti Flicker</TD>
          <TD><input type="checkbox" id="TmpAntiFlicker" onclick="ClickAntiFlicker()"></TD>
        </TR>
        <TR>
          <TD>Flip Image</TD>
          <TD><input type="checkbox" id="TmpMirror2" onclick="ClickMirror()"></TD>
        </TR>
        <TR>
          <TD>Mirror</TD>
          <TD><input type="checkbox" id="TmpMirror1" onclick="ClickMirror()"></TD>
        </TR>
        <TR>
          <TD>Brightness Control</TD>
          <TD>
            <SELECT id="BrightnessControlSel" size="1" onchange="document.forms[0].BrightnessControl.value = this.value">
            <OPTION value=128>+5</OPTION>
            <OPTION value=115>+4</OPTION>
            <OPTION value=103>+3</OPTION>
            <OPTION value=90 >+2</OPTION>
            <OPTION value=77 >+1</OPTION>
            <OPTION value=64 >+0</OPTION>
            <OPTION value=51 >-1</OPTION>
            <OPTION value=39 >-2</OPTION>
            <OPTION value=26 >-3</OPTION>
            <OPTION value=14 >-4</OPTION>
            <OPTION value=1  >-5</OPTION>
            </SELECT>
          </TD>
        </TR>
        <TR>
          <TD>Contrast Control</TD>
          <TD>
            <SELECT id="ContrastControlSel" size="1" onchange="document.forms[0].ContrastControl.value = this.value">
            <OPTION value=128>+5</OPTION>
            <OPTION value=115>+4</OPTION>
            <OPTION value=103>+3</OPTION>
            <OPTION value=90 >+2</OPTION>
            <OPTION value=77 >+1</OPTION>
            <OPTION value=64 >+0</OPTION>
            <OPTION value=51 >-1</OPTION>
            <OPTION value=39 >-2</OPTION>
            <OPTION value=26 >-3</OPTION>
            <OPTION value=14 >-4</OPTION>
            <OPTION value=1  >-5</OPTION>
            </SELECT>
          </TD>
        </TR>
        <TR>
          <TD>Saturation Control</TD>
          <TD>
            <SELECT id="SaturationControlSel" size="1" onchange="document.forms[0].SaturationControl.value = this.value">
            <OPTION value=128>+5</OPTION>
            <OPTION value=115>+4</OPTION>
            <OPTION value=103>+3</OPTION>
            <OPTION value=90 >+2</OPTION>
            <OPTION value=77 >+1</OPTION>
            <OPTION value=64 >+0</OPTION>
            <OPTION value=51 >-1</OPTION>
            <OPTION value=39 >-2</OPTION>
            <OPTION value=26 >-3</OPTION>
            <OPTION value=14 >-4</OPTION>
            <OPTION value=1  >-5</OPTION>
            </SELECT>
          </TD>
        </TR>
        </table>
      </div>
      <p align=center>
        <input type="hidden" name="ConfigSystemStream" value="Save">
        &nbsp;<INPUT type="button" width="80" value=" Save Settings " onclick="javascript:document.forms[0].submit()">
        &nbsp;&nbsp;<INPUT type="button" width="80" value=" Don't Save Settings " onclick="ClickCancel()">
      </p>
</FORM>
      <!-- === END MAINCONTENT === -->
    </div>
    </td></tr>
    <tr height=100%><td></td></tr>
    </table>
  </td>
  <td valign="top" width="150" id="sidehelp_container" align="left">
    <table cellpadding="2" cellspacing="0" border="0" bgcolor="#FFFFFF" bordercolor="#FFFFFF" bordercolordark="#FFFFFF" bordercolorlight="#FFFFFF">
    <tr>
      <td id="help_text">
        <b>Helpful Hints..</b>
        <br><br><b>Anti Flicker</b> - This feature will help to offset the
        interference of the lighting system and avoid the image flicker
        issue. ONLY use this option when it is necessary.
        <br><br><b>Flip Image</b> - Flip the image vertically.
        <br><br><b>Mirror</b> - Flip the image horizontally.
        <br><br><b>Brightness, Contrast, or Saturation</b> Control - There
        are 11 settings (-5 to 5).
        <br><br><b>Note</b>: Please wait a few seconds for the camera to
        adjust the image after the setting has been selected.
      </td>
    </tr>
    </table>
  </td>
</tr>
</table>
</td></tr></table>
<table id="footer_container" border="0" cellpadding="0" cellspacing="0" width="838" align="center">
<tr>
  <td width="125" align="center">&nbsp;&nbsp;<img src="security.gif" width="114" height="35"></td>
  <td width="10">&nbsp;</td>
  <td>&nbsp;</td>
</tr>
</table><br>
<div align="center"><FONT color=#ffffff>Copyright 2010 - 2012, D-Link Corporation / D-Link Systems, Inc. All rights reserved.</font></div>
<br>
</body>
<script language="Javascript">
InitAUTO();
</script>
</html>

Posted on
Thu Aug 29, 2013 12:24 pm
RogueProeliator offline
User avatar
Posts: 2501
Joined: Nov 13, 2012
Location: Baton Rouge, LA

Re: how to set brightness on Dlink 930 through curl

I assume that you are aware just, by the fact that you posed your question, but curl can indeed do a POST operation to what effectively simulates a form post by the user. The command line is fairly straight forward, but usually the difficulty is in determining what exactly the receiving server expects.

I find the easiest way to debug/test that kind of thing is to actually just watch the HTTP traffic going back and forth. This can be done in many ways - packet sniffers, proxy servers, etc. However, there is an extremely easy one to use for simple tasks -- use the Tamper Data extension with Firefox. When activated you can see the traffic (both ways), including the exact body of the POST.

Once you have that, if you can determine the meaning of the values, you can use it to modify your curl POST with the data. Often this is very straight forward for simple tasks (though not always, just have to look at the data sent... post it here if you need help decoding it).

Adam

Posted on
Thu Aug 29, 2013 2:58 pm
kw123 offline
User avatar
Posts: 8366
Joined: May 12, 2013
Location: Dallas, TX

Re: how to set brightness on Dlink 930 through curl

firefox data tamper gives:

POSTDATA=ReplySuccessPage=image.htm&ReplyErrorPage=errrimg.htm&BrightnessControl=64&ContrastControl=64&SaturationControl=64&AntiFlickerEnable=1&Mirror=0&ConfigSystemStream=Save



curl -u userid:password -d "ReplySuccessPage=image.htm&ReplyErrorPage=errrimg.htm&BrightnessControl=64&ContrastControl=64&SaturationControl=64&AntiFlickerEnable=1&Mirror=0&ConfigSystemStream=Save" http://192.168.1.77/image.htm

seems not to do anything same response as without -d.

Also tried

-X POST -d "...
--Data..

just one more helping hand and I have it (I hope so)

(do i need to handle cookies?)

thx so much

KArl

Posted on
Thu Aug 29, 2013 9:40 pm
RogueProeliator offline
User avatar
Posts: 2501
Joined: Nov 13, 2012
Location: Baton Rouge, LA

Re: how to set brightness on Dlink 930 through curl

You actually need to send that curl request to the action of the form - in this case "/setSystemStream" - as opposed to the image.html page... give that a try as the target and see if it gets you anywhere.

It is possible you have to handle cookies, but if it is supporting basic authentication, the username/password *should* be enough. Will cross our fingers because, though not terribly difficult, that would definitely make it more troublesome.

Posted on
Thu Aug 29, 2013 10:00 pm
kw123 offline
User avatar
Posts: 8366
Joined: May 12, 2013
Location: Dallas, TX

Re: how to set brightness on Dlink 930 through curl

that url (192.168.1.77/setSystemStream) does not exit (with and without htm(l))

:(

Posted on
Thu Aug 29, 2013 10:33 pm
RogueProeliator offline
User avatar
Posts: 2501
Joined: Nov 13, 2012
Location: Baton Rouge, LA

Re: how to set brightness on Dlink 930 through curl

On the Tamper Data request where you found the POSTDATA example, what is the URL shown in the grid? (Note you may have to look in the grid itself, not the details... at least, my version of Tamper Data doesn't show the URL in the details for some unexplained reason.)

When you use curl to POST to that "http://192.168.1.77/setSystemStream" URL, is the returned status 404 or just no response at all?

Posted on
Thu Aug 29, 2013 10:37 pm
kw123 offline
User avatar
Posts: 8366
Joined: May 12, 2013
Location: Dallas, TX

Re: how to set brightness on Dlink 930 through curl

this is the command and the reply

curl -u userid:password -X POST -d \"ReplySuccessPage=image.htm%26ReplyErrorPage=errrimg.htm%26BrightnessControl=1%26ContrastControl=2%26SaturationControl=1%26AntiFlickerEnable=0%26Mirror=0%26ConfigSystemStream=Save\" http://192.168.1.77/setSystemStream"
--> "<html><body><h2>Error: File Not Found</h2>
<p>getfile: Cannot open URL(/etc_ro/web/image.htm&ReplyErrorPage=errrimg.htm&BrightnessControl=1&ContrastControl=2&SaturationControl=1&AntiFlickerEnable=0&Mirror=0&ConfigSystemStream=Save,No such file or directory)</p></body></html>
"

Posted on
Thu Aug 29, 2013 11:49 pm
RogueProeliator offline
User avatar
Posts: 2501
Joined: Nov 13, 2012
Location: Baton Rouge, LA

Re: how to set brightness on Dlink 930 through curl

I can't say that I've ever used the -X option with a POST, but I can't imagine that would make any difference since you are using the correct method. I kind of feel like it is something obvious that we are both just missing, but don't know why.

Did you check the URL in TamperData's grid? Possible that javascript file is mucking with the form before it is sent, but I highly doubt it because they aren't using event handlers to attach any of those other events (other than the onclick/onchange method). Could also double check that Tamper Data is now showing any cookies being sent when submitted via web page, just in case.

Posted on
Thu Aug 29, 2013 11:58 pm
kw123 offline
User avatar
Posts: 8366
Joined: May 12, 2013
Location: Dallas, TX

Re: how to set brightness on Dlink 930 through curl

This works:

set theIPNumber to "192.168.1.71"
set theUserID to "xxx"
set thePassword to "yyy"
set brightnessLevel to 64 -- 1...128 1=-5, 14 =-4, 26 = -3, 39 = -2, 51=-1, 64 = 0, 77=+1, 90=+2, 103=3, 115=+4, 128=5

set cmd to " curl -u " & theUserID & ":" & thePassword & " -d \"" & "ReplySuccessPage=image.htm&ReplyErrorPage=errrimg.htm&BrightnessControl="

set cmd to cmd & brightnessLevel

set cmd to cmd & "&ContrastControl=64&SaturationControl=64&AntiFlickerEnable=1&Mirror=0&ConfigSystemStream=Save\""
set cmd to cmd & " http://" & theIPNumber & "/setSystemStream"
do shell script cmd

likely the & were bad..

thanks .. learned
- fiddler
- chrome tools
- firefox tamper

on the way..

Karl

Posted on
Fri Aug 30, 2013 6:59 am
RogueProeliator offline
User avatar
Posts: 2501
Joined: Nov 13, 2012
Location: Baton Rouge, LA

Re: how to set brightness on Dlink 930 through curl

Awesome, glad you got it working! Fiddler is indeed another excellent tool - I use it all the time at work... Tamper Data is sometimes a bit more convenient since it is build in the browser and thus easier to intercept/modify things. The tools built into Chrome are incredible, especially at debugging web and display (CSS/HTML) issues.

Posted on
Fri Aug 30, 2013 12:16 pm
kw123 offline
User avatar
Posts: 8366
Joined: May 12, 2013
Location: Dallas, TX

Re: how to set brightness on Dlink 930 through curl

just in case someone would like to go the applescript+safari route to do this , heres the code:


Karl

Code: Select all
set theUserID to "xxxxxxx"   --- yours go here
set thePassword to "xxxxxxxxxxxxx"


   tell application "IndigoServer"  -- get requested brightness level and ip number of camera  you might have more than one
      set ipNumber to (get value of variable "cameraBrightnessLevelPNumber")
      set brightnessLevel to (get value of variable "cameraBrightnessLevel")
   end tell

-- first login if needed
tell application "Safari"
   activate
   delay 0.5
   make new document
   set URL of document 1 to "http://" & ipNumber & "/image.htm"
end tell

set returnValue to SafariWindowIsLoading("Password")

if returnValue = "false" or returnValue = "true" then  -- we are at the login screen
   delay 4
   tell application "System Events"
      tell process "Safari"
         delay 0.1
         keystroke theUserID
         key code 48
         keystroke thePassword
         delay 0.1
         keystroke return
         delay 0.1
      end tell
   end tell
   -- close window
   tell application "Safari" to close every window
   delay 0.1
end if



--now start without/after login:
if returnValue is not equal to "skip" then -- is safari already on right page? if yes skip
   tell application "Safari"
      activate
      make new document
      set URL of document 1 to "http://" & ipNumber & "/image.htm"
   end tell
   SafariWindowIsLoading("Brightness") -- wait for "brighness" in on the page
   delay 4
end if


tell application "System Events"  -- we are on the right screen, move cursor to the right place
   tell process "Safari"
      
      key code 48 -- tab to brightness selection
      key code 48
      key code 48
      key code 48
      key code 48
      key code 48
      
      -- set brightness to top level no matter what .. move up
      set ii to 0
      repeat until ii = 10
         delay 0.1
         key code 126
         set ii to ii + 1
      end repeat
      
      
      -- we are now at brightness +5,  decrement to right value
      set ii to 0
      repeat until ii = 5 - brightnessLevel
         delay 0.1
         key code 125
         set ii to ii + 1
      end repeat
      
      -- now save settings
      delay 0.1
      keystroke return -- select value
      key code 48  -- tab to save button
      key code 48
      key code 48
      keystroke return -- click save button
      delay 3
      
   end tell
end tell

tell application "Safari" to close every window



tell application "IndigoServer"   -- try to avoid having 2 codes running at the same time,  will confuse safari, set variable and check in triggers if this pgm should be called
   set value of variable "cameraBrightnessLevelRunning" to "false"
end tell



-----------------

on SafariWindowIsLoading(theText)  -- check if page loaded and if  theText is on the page
   
   delay 0.2
   repeat with i from 1 to 15
      tell application "Safari"
         if name of current tab of window 1 is not "Loading" then exit repeat
      end tell
      delay 1
   end repeat
   if i is 15 then return false
   tell application "Safari"
      repeat until (do JavaScript "document.readyState" in document 1) is "complete"
         delay 0.5
      end repeat
   end tell
   tell application "Safari" to set PageText to the text of document 1
   
   if PageText contains "Brightness" then return "skip"
   if PageText contains "theText" then return "true"
   return "false"
   
end SafariWindowIsLoading


Posted on
Mon Sep 02, 2013 12:53 am
berkinet offline
User avatar
Posts: 3290
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: how to set brightness on Dlink 930 through curl

kw123 wrote:
this is the command and the reply

    curl -u userid:password -X POST -d \"ReplySuccessPage=image.htm%26ReplyErrorPage=errrimg.htm%26BrightnessControl=1%26ContrastControl=2%26SaturationControl=1%26AntiFlickerEnable=0%26Mirror=0%26ConfigSystemStream=Save\" http://192.168.1.77/setSystemStream"
--> "<html><body><h2>Error: File Not Found</h2>


I realize you've gotten this to work. But, I had been meaning (and forgot) to comment that I think the problem with the command above is that the quotation marks around the POST args were escaped (preceeded by \). In the shell, this would cause the "s to be passed to curl as part of its args rather than being used to delimit the args and capture any enclosed spaces.

BTW, since the POST args were URL encoded anyway - with no embedded spaces or other special characters - the quotation marks were probably net necessary at all.

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 11 guests