FOSCAM IP CameraAs you’ve seen in other articles on my website I am really big into computer vision and securing my house. Today, I added a new toy to my home security arsenal and I wanted to share my thoughts about it. First off, the new device I have added to my home security is the Foscam FI8910W Wireless N IP Camera. The Foscam is a really cool IP Camera that supports both wired and wireless access. Some of its features include pan & tilt, motion detection with alarms, and even infrared (IR) for night vision. Another really cool feature about this IP camera is that it also has apps for Android, iPhone, and Blackberry which allow you to view and control the camera as long as your mobile device is connected to the same network as the Foscam. With a little bit of tweaking to your network router / firewall, the instructions show you how to access the camera over the internet from any location and even shows you how to use sites like No-IP in case your  external IP address is dynamic. The camera is accessible via one of the mobile apps or via a standard web browser. However, I didn’t like using the browser, so I wrote my own application using C#. More on that in a minute.

Even though I really like this camera, there are still a few things I don’t like. First off, the only way you can configure the camera is to first plug it directly into your network switch using the provided ethernet cable. Once it is plugged into your network, you can use the IPCamSetup tool that comes on a CD in the box. The laptop I used to setup the camera didn’t have an optical drive. I replaced the optical drive with a second SSD and drive-bay. Luckily though, the manufacturer’s website has a link to download the setup application. I mention this because there have been several products I have purchased that only provide installers on a CD and not as a download. If you prefer the download installer, head over to the Foscam.US support page. Once you have the IPCamSetup tool installed, you can run the tool which will detect & identify the camera on your network. Once it has been identified, you can double-click on the camera from the list which opens your web browser and takes you to the camera control page. So, basically, you’ll be doing everything through your browser anyways. Once you have established a connection to your camera, you can set it up for wireless connectivity using the admin tool. After it has been configured for wireless, you can disconnect the ethernet cable and move the camera anywhere within range of your wireless access point.

Now for the fun stuff. As I mentioned earlier, I’m not a big fan of having to use the web browser as my only interface to the camera. Lucky for me, I’m a geek that knows how to get around this. Plus, the manufacturer has made it extremely easy to write your own apps if you know what you’re doing. After a quick browse of the Foscam website, I couldn’t find any SDK’s. But, since I could access the camera from the web browser, I decided to launch the control page in Firefox and used Firebug to watch the network traffic. Sure I could’ve used Wireshark or some other network monitoring tool, but Firebug worked just fine. With Firebug running, I clicked through all of the camera controls and recorded the URLs that were attached to each button. From there, I wrote a small Windows Forms application using Visual Studio and C# where I basically recreated the browser functionality in C#. Here is a screenshot of the application at work.

FOSCAM IP Camera C#

It’s not pretty, but it works. Below is the complete code that made this all possible. You can download the entire Visual Studio project from here. Overall, I really like this camera and believe that it will be a good addition to my home security. Plus, having apps for most of the mobile devices and works over the internet, this camera could also make a good baby monitor. If you’re interested in getting one for yourself, Amazon has it for $77 right now. Click here to get yours now.

Update: I have updated the example application download below to include controls for brightness and contrast.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using System.Windows.Forms;

namespace FOSCAMViewer
{
    public partial class Form1 : Form
    {
        private Thread _cameraThread;
        private Thread _commandThread;
        private WebClient wc;
        private HttpWebRequest req;
        private WebResponse res;
        private Stream stream;
        private string cameraUrl = "http://{0}/snapshot.cgi?user={1}&pwd={2}";
        private string commandUrl = "http://{0}/decoder_control.cgi?user={1}&pwd={2}&command={3}";

        public Form1()
        {
            InitializeComponent();

            Control.CheckForIllegalCrossThreadCalls = false;
        }

        #region Button Handlers
        private void btnRun_Click(object sender, EventArgs e)
        {
            if (btnRun.Text.Equals("Start"))
            {
                if (_cameraThread == null)
                    _cameraThread = new Thread(new ThreadStart(Run));

                _cameraThread.Start();
                btnRun.Text = "Stop";
            }
            else
            {
                btnRun.Text = "Start";
                _cameraThread.Abort();
                _cameraThread = null;
            }
        }

        private void btnUp_Click(object sender, EventArgs e)
        {
            SendCommand("0");
            Thread.Sleep(250);
            SendCommand("1");
        }

        private void btnLeft_Click(object sender, EventArgs e)
        {
            SendCommand("6");
            Thread.Sleep(250);
            SendCommand("1");
        }

        private void btnRight_Click(object sender, EventArgs e)
        {
            SendCommand("4");
            Thread.Sleep(250);
            SendCommand("1");
        }

        private void btnDown_Click(object sender, EventArgs e)
        {
            SendCommand("2");
            Thread.Sleep(250);
            SendCommand("1");
        }

        private void btnUpDown_Click(object sender, EventArgs e)
        {
            if (btnUpDown.Text.Equals("Up / Down"))
            {
                btnUpDown.Text = "Stop";
                SendCommand("26");
            }
            else
            {
                btnUpDown.Text = "Up / Down";
                SendCommand("27");
            }
        }

        private void btnLeftRight_Click(object sender, EventArgs e)
        {
            if (btnLeftRight.Text.Equals("Left / Right"))
            {
                btnLeftRight.Text = "Stop";
                SendCommand("28");
            }
            else
            {
                btnLeftRight.Text = "Left / Right";
                SendCommand("29");
            }
        }

        private void btnIR_Click(object sender, EventArgs e)
        {
            if (btnIR.Text.Equals("IR On"))
            {
                btnIR.Text = "IR Off";
                SendCommand("95");
            }
            else
            {
                btnIR.Text = "IR On";
                SendCommand("94");
            }
        }
        #endregion

        #region Private Methods
        private void Run()
        {
            while (btnRun.Text.Equals("Stop"))
            {
                try
                {
                    cameraUrl = String.Format(cameraUrl, txtHost.Text, txtUsername.Text, txtPassword.Text);
                    req = (HttpWebRequest)HttpWebRequest.Create(cameraUrl);

                    req.AllowWriteStreamBuffering = true;
                    req.Timeout = 20000;

                    res = req.GetResponse();
                    stream = res.GetResponseStream();
                    pctViewer.Image = Image.FromStream(stream);
                    res.Close();
                }
                catch (Exception e)
                {
                    Console.WriteLine("Exception: {0}", e.ToString());
                }
            }
        }

        private void SendCommand(string command)
        {
            string url = String.Format(commandUrl, txtHost.Text, txtUsername.Text, txtPassword.Text, command);
            WebClient wc = new WebClient();
            wc.DownloadString(url);
        }
        #endregion

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (_cameraThread != null)
            {
                _cameraThread.Abort();
                _cameraThread = null;
            }
        }
    }
}

Download: FOSCAMViewer.zip (23KB)

Update: I have updated the example application download above to include controls for brightness and contrast.

Update: I have now added the ability to utilize the video streaming capabilities using “videostream.cgi”. You can get the updated app here.

Thank you for your interest in my site. If you find the information provided on this site useful, please consider making a donation to help continue development!

PayPal will open in a new tab.
$2.00
$5.00
Other

Related Posts

Tagged with:  

27 Responses to FOSCAM Wireless IP Camera Review and C# Controller App

  1. Nutcha_K says:

    Thank you very much for good article. Can you suggest me how to find Microsoft.CSharp.I use visual studio and C# 2008 and .Net framwork 4.0

    • LuCuS says:

      Thanks. You don’t need the Microsoft.CSharp namespace for this application. But, for apps that do need it, on your Solution Explorer panel, right-click on References and select Add Reference. Then, click on the .NET tab and you’ll find it in there.

      • Nutcha_K says:

        Thank you for your suggestion.I find Microsoft.Csharp from add reference tab already but I can’t find it.What reference i can use instead Microsoft.Csharp? Thank you very much.

        * I can’t debug FOSCAMviewer,after i press F5 it show message box following url http://www.uppicthai.com/image/NL5

        • LuCuS says:

          That’s probably because I wrote the app using Visual Studio C# 2010 Ultimate and you’re using 2008. To fix that, close Visual Studio and open FOSCAMViewer.sln with a text editor (Notepad is fine). Then, replace the top 2 lines:

          Microsoft Visual Studio Solution File, Format Version 11.00
          # Visual Studio 2010

          with these:

          Microsoft Visual Studio Solution File, Format Version 10.00
          # Visual Studio 2008

          Notice the changes in bold. After that, close the text editor and open reopen the project using Visual Studio.

          • Nutcha_K says:

            Thank you for your suggestion.I try to replace the top 2 lines following your suggestion but it can’t debug like before replace the top 2 lines.

            Now I’m using visual studio 2010 instead visual studio 2008.

            I want to develop your project.I want to add button for adjust contrast and brightness.Could you answer me what command you use to control contrast and brightness in FOSCAM? Thank you very much.

          • LuCuS says:

            I don’t have my FOSCam with me at the moment. So, I can’t check it for the proper commands. Hopefully, I will have time this weekend to work with it and will send you the commands once I have them.

          • LuCuS says:

            I finally got a chance to look into the brightness and contrast commands.

            For contrast: http://{0}/camera_control.cgi?param=2&value={1} (where {0} is your IP address and {1} is the contrast value between 0 and 6)

            For brightness: http://{0}/camera_control.cgi?param=1&value={1} (where {0} is your IP address and {1} is the brightness value between 0 and 15). When passing the value for brightness, you will need to multiple the number times 16. Example: For brightness 5, I would pass 80 which is 5 x 16. For brightness level 7, I would pass 112 which is 7 x 16.

          • LuCuS says:

            I have updated the example download above to include brightness and contrast.

  2. juribe says:

    Hi, It’s a great article. I’ve been testing it on Windows7+VS2010+.NetFramework4.0, however i get one error : Remote server error: (404) Not Found. My camera is plugged to switch, the ping response good. In VS2010, I can see that the url is correct, IP, user, pass, command, but the error remains.

    Some one know how solve this error.
    bye.

  3. Nutcha_K says:

    Thank you very much for your updated code.Now I’m trying to record video file from my ip-cam.

  4. babos says:

    Can you suggest a method in c # to take a snapshot and save the image?
    Very Thx !!!

    • LuCuS says:

      Yep. I wrote an article a while back that does that (http://www.prodigyproductionsllc.com/articles/programming/screen-capture-with-c/). In that article, I continuously update a picturebox using a timer object. If you just want to take a snapshot by clicking a button, here is an extremely simple example:

      using System;
      using System.Drawing;
      using System.Windows.Forms;

      namespace ScreenCapture
      {
      public partial class Form1 : Form
      {
      public Form1()
      {
      InitializeComponent();
      }

      private void button1_Click(object sender, EventArgs e)
      {
      Rectangle screen = Screen.PrimaryScreen.Bounds;
      Bitmap bm = new Bitmap(screen.Width, screen.Height);
      Graphics g = Graphics.FromImage(bm);
      g.CopyFromScreen(0, 0, 0, 0, new Size(screen.Width, screen.Height));
      bm.Save("c:\\new_image.jpg");
      }
      }
      }

    • LuCuS says:

      Sorry, I didn’t notice which article you posted this comment on. My last response was for doing screen capturing. If you want to take a snapshot from the FOSCAM, you can call the following code to save an image directly from the window:

      pctViewer.Image.Save("C:\\new_image.jpg");

      Just put that in a button click handler and change the location and name of the image you want to save.

  5. henrikl says:

    Hi LuCus,
    Thank you for sharing. I have translated your code to VB.NET and it works well. Though I have a little issue.
    You are grabbing pictures from the camera through snapshot.cgi which results in picture freezes up for a short time. Would it be possible to grab through videostream.cgi instead to give non freezing live stream ?
    Thank you in advance,
    Henrik

    • LuCuS says:

      Sorry for the late reply. I’ve been all kinds of busy lately.

      It is possible to grab video from videostream.cgi instead of from snapshot.cgi. At one point I had created a C# app that does exactly that, but now I can’t seem to find it. I’ll try going thru my backups and see if I can find it somewhere. If I still have it, I’ll post it on here. I did it by adding a reference to wmp.dll (Windows Media Player) and using that to display the video coming back from the IP cam.

  6. henrikl says:

    Hi LuCus,
    Thank you for your reply. I hope it is not to much that I have asked for.
    Best regards
    Henrik

  7. ngoisao_bang1016 says:

    Hello! With this lineup needs SDK library not you? If so, get in where? Thank you very much!

    • LuCuS says:

      As far as I know, there’s not an SDK for this. Instead, you’ll need to use the REST API as demonstrated above. Also, in case you missed it at the end of the article, I now have an updated version of the app which uses “videostream.cgi” for live streaming instead of individual snapshots like in this demo. You can find the updated code at http://www.prodigyproductionsllc.com/articles/automation/insteon-wireless-security-ip-camera-c-controller/.

      • ngoisao_bang1016 says:

        I have read your post but have not understood a number of libraries that you use! Hope you help me explain. Thank you very much!

        • LuCuS says:

          I’m not using any special libraries. I’m just using the REST API that is provided by the camera itself.

          As an example, point your web browser to “http://[YOUR_CAMERA_IP_ADDRESS]/snapshot.cgi?user=[YOUR_USRENAME]&pwd=[YOUR_PASSWORD]” making sure that you swap out the corresponding pieces with the IP address & port of your camera, your username, and your password for the camera. When you do that, you should see a single image from your camera being displayed in your browser. Hit the refresh button (or press F5) to get an updated image from your camera. The code above does the same exact thing your browser is doing, but does it much faster than you having to manually refresh the page.

          The code from the other article I linked to does pretty much the same thing. However, the images coming from the videostream.cgi link sends the messages encoded and in chunks. All I do is parse the encoded messages and put the chunks back together to form the images.

          • ngoisao_bang1016 says:

            Hello Luca! I have a small wonder the place settings at VGA resolution and frequency of your transmission set this place? Or does it automatically by default! I want to increase the resolution and image frequencies up to not being paved! Help yourself with! Thank you Luca!

          • LuCuS says:

            The resolution is whatever the camera provides. In the case of the FOSCAM cameras mentioned in this article, the resolution only goes up to 640×480. You can zoom in on areas using the API or you can zoom in on the image in your client app. But, you won’t get better resolution than that. The frequency is also provided by the camera. In this case, it’s 50 or 60 Hz.

  8. ngoisao_bang1016 says:

    I want to use this code get Foscam FI8918W not? Waiting for your reply! Thank you!

  9. ngoisao_bang1016 says:

    Your project just download and open up normal half plus what library you huh? do not understand this issue wish you help!

Leave a Reply