I'm trying to put together a project that on certain events will hit a URL with some parameters that will set various commands on a WebCam.
A made up example would be something like: http:///camera_control.cgi?user=user&password=password&command=
This works fine in a browser, but I'm having a little trouble getting this to work with the ethernet shield.
The program connects fine and the following is output:
HTTP/1.1 401 Unauthorized
Server: Netwave IP Camera
Date: Wed, 01 Feb 2012 21:37:37 GMT
WWW-Authenticate: Basic realm="ipcamera_000DC5D34ADE"
Content-Type: text/html
Content-Length: 140
Connection: close
401 Unauthorized
401 Unauthorized
Authorization required.
after which the connection is closed (from the WebCam side I'd imagine), which means I'm unable to do the next step and execute the actual command.
Note that I'm able to connect to google etc just fine and execute commands.
I guess the WebCam is prevent the type of connection that the Arduino board is attempting (its not an HTTPS connection) - is there an alternative way to hit arbitrary URLs without first making a connection?
As a temporary workaround I'm going to setup a script on a server that the Ethernet board can connect to, which will in turn trigger the webcam command.
Looks like the web server is expecting a username and password. I'm guessing that you entered that data in your browser the first time you connected to the camera and your browser remembers your login information. The URL syntax is:
The camera does indeed require basic authentication, which I can workaround via the browser as you say, but the problem I have is that I cant get that far as the process fails shortly after the following code:
if(client.connect(camera, 80)>0) {
It connects, but then outputs the 401 error above. I agree that it expects authentication, I'm just at a loss on how to provide it via Arduino !
The problem I was actually having was that the connection would be made using
client.connect(camera, 80)
but when I attempted to control the camera (using the various authentication methods mentioned - the base64 method was something I'd tried in java and PHP, but not here - very useful, thanks!) it failed as the connection had already been closed.
The posts above however inspired me to try a different approach: instead of opening the connection and keeping it open, I've tried opening the connection on a given event, controlling the camera and then stopping the connection, as follows:
This works a treat - I guess due to either the cameras implemenation or Arduinos connections are terminated if not authenticated in a reasonable time window.