Flyport WEBCAM

From openPicus Wiki
Jump to: navigation, search

Project Summary

This document shows how to setup a webcam with a Flyport module and a serial camera (VC0706 based). This project makes use of the JPEG compressed picture that can be copied from the camera module to the flyport. As of memory limitations, single pictures are transferred in small blocks from the camera to the flyport memory and in a from there to the web page. The code has been tested in ad-hoc and infrastructure mode. With an appropriate setup of the router (DMZ), the webcam connected to a private network can be accessed from the public internet. In order to protect privacy, two web pages versions have been included in the project: –protected and -unprotected mode. The application also allows to control a RC-Servo able to rotate the camera module from the web interface. Push buttons on the embedded web page allow update of the picture and movements of the camera.

Device: OpenPicus Flyport + LSY201 or VC0706 camera with JPEG/UART interface

Tools/Code: OpenPicus Free IDE version: 2.2 External Libs: VC0706.c, base64.c Connections: serial link to camera (38kb or 112kb) + pwm signal to RC Servo.


How to Build the project

Initiating a picture transfer: A picture transfer will be initiated by pressing the update button on the web page or by a timer inside HTML. JavaScript will trigger a new picture every minute. The camera driver code vc0706.c is handling all camera commands. Basically, the camera is waiting for commands from the Flyport and it will answer either with status information or with picture data block.

Transfer process: The picture data is transferred in 64 or 128 byte blocks from the camera to the Flyport and from the Flyport to the web page using "TCPPutArray" call. Increasing the block size (set in vc0706.h) will reduce the transmission quality.

The transfer process works as follow:

  • freezing picture (JPEG will be compressed and buffered inside the camera chip)
  • asking the picture size (JPEG)
  • reading the picture blocks until the full picture is transferred
  • resume camera acquisition

As the Flyport has no bit RAM memory, each block of data will be immediately sent to the web page. This means no full picture is stored on the Flyport itself.

XML limitations: The learning during the development was that XML only handles ASCII data. In order to transfer the binary JPEG data, the information is encoded using base64 algorithm. The code is included in the ext lib under “base64.c”. Web browsers are able to interpret this data without special decode code inside the HTML code. IExplore and Chrome work fine, Firefox still blocks after a part of the picture. TCP limitations: in order to keep the web server running, "curHTTP.callbackPos" was used to repeat subroutine calls until all blocks are transferred. You can experiment different sizes up to use the full PIC RAM. Security: The app was designed with protected html code to prevent unwanted access to the camera. Use user name: guest, password: Flyport if requested and can be modified in HTTPApp.c Camera movement: One RC servo connected to a Flyport PWM output allows turning the camera. The PWM signal is controlled by two buttons located on the web interface, arrow left and right.

NOTE:. VC0706 is the name of the chip used on cameras that target security products. The camera is generating JPEG compressed pictures in 3 formats, from 640x480, 320x240 and 160x120 pixels. Transfer speed of the pictures is dependent on the resolution programmed and the UART speed configured. By default, the camera is setup at 640x480 pixels and a baud rate of 38400 baud. With this setup a picture of approx. 40kb is generated, transferred in around 30seconds. Reducing the resolution and increasing the speed allows a transfer of pictures within 1-2 seconds. The current implementation copies data with 115200baud in less than 10 seconds. The camera has also some magic features like detecting movements. Many parameters are possible but very badly documented. Please feel free to add functionality, and share your experience.

HARDWARE: The camera is connected with 4 wires to the Flyport UART 2 RX (D1IN) and TX (D1OUT), powered by 5v and ground. The datasheet mentioned that the camera may work at 3.3v, but some notes indicate that communication will work better powering the module at 5V. The RC Servo is connected to power, ground and PWM (D2out). Hardware initialization is done in “HWinit.c” and ”taskFlyport.c”.

FIRMWARE: The external library consists of 2 files, vc0706.c including the camera driver and base64.c including the encoding code + corresponding header files. A summary of the routines is shown below.

Camera (VC0706.c) routines:

  • cam_init(); //initiated the UART interface
  • cam_reset(); //puts the camera in initial state, UART baud rate is set back to 38400b.
  • cam_init_115k(); // set the camera UART to 115200baud
  • cam_takepicture(); //picture is frozen inside the camera module, ready for getting copied
  • cam_resume(); //camera is again running (video output in motion)
  • cam_frameLength(); // returns the size of the JPEG (each picture is different)
  • cam_readPicture(n); // read n bytes from the picture buffer
  • cam_setPictureSize(b); // set the picture resolution of the camera
  • cam_setMotionDetect(BOOL f); // switches motion detection ON/OFF
  • cam_getMotionDetect(); // returns TRUE/FALSE depending on motion detected
  • ... and some more not used in our project.

This code was partially migrated from Arduino and MBED code available on internet.

Base64 encoding (base64.c) routine:

                void base64 (char *orig, char *dest, int nbcar, char end); // orig, pointer to input buffer
  • *dest, pointer to output buffer
  • nbcar, bytes in input buffer
  • end, indicates to flush the buffer

HTML code (in WebPages_login and WebPages_nologin)

  • index.htm // main page requesting login for secured camera access
  • status.xml // storage file to exchange data
  • protect/index.htm // user interface code and java script sending requests to Flyport
  • ... standard java script and style code to format the web page similar to other projects.

taskFlyport. functions:

  • initialize baud rate
  • camera initialization
  • set transfer speed (115200 baud), sometimes fails when reset is pressed
  • change picture size on the fly, not fully tested yet.

HTTPApp.c modified functions:

  • HTTPCheckAuth to change login names and passwords
  • HTTPExecuteGet and button.cgi to get camera movements
  • HTTPPrint_pot to send picture number to web page, progress bar did not work
  • HTTPPrint_cgi just toggles LED if button is pressed
  • HTTPPrint_cam includes the code to read and transfer pictures from camera to web

User interface: The user interface currently consists of 3 buttons <LEFT><UPDATE><RIGHT>. The direction buttons change the PWM signal on the servo allowing to rotate the camera in 5 positions. The update button initiates a new transfer from camera to the web page.

Z-cam1webpage.jpg Z-cam1webpage2.jpg 14:01, 30 September 2012 (CDT)

Project Open Issues

Possible improvement: remember, no picture is stored on the Flyport, so HTTPPrint_cam is called many times until a full picture is copied. This also means that it will take 10seconds before the 1st picture appears on the client web page. Please share your experience if you have any improvements for speed and functionality. I will be glad to update the documentation accordingly.

Personal tools