ACAP SERVICE SETTINGS

An ACAP service needs to have configuration settings. Axis cameras provides the param.conf service to store settings in the cameras parameter management. The param.conf has limitations and is not always the best solution.

There are some cases where param.conf should be used:

  • The service settings consists of a limited static number of parameters.
  • The ACAP service does not need a config user interface. Parameter settings can be made visible and updated under [ Setup | Application | Your service ]
  • Some 3:rd party client may integrate configuration of your ACAP service using the cameras param.cgi. Note: not very likely that a 3:rd party client integrates configuration settings.
  • It is important that the ACAP server settings will be included in the cameras server report

Param.conf is not designed for dynamic parameters or large and complex data structures. You will end up shooting yourself in the foot if you try to stretch param.conf capabilities.

A better solution to manage large and complex data structures is to store them in your own files under /localdata. You can create, open read, write these files using fopen(), fclose(), fread() etc. The full path is /usr/local/packages/yourservice/localdata/yourfile.xxx.

This means that your service must provide some CGI to get, update and delete settings. As the primary user interface is a web interface I can recommend to use JSON data representation instead of XML (or worse – plain text). Using JSON will simplify your HTML/JavaScript development. Add jQuery library to that equation and you will save yourself hours of WEB-coding. On the embedded side there is a very good JSON parser called cJSON (http://sourceforge.net/projects/cjson/). I can recommend to use JSON data representation throughout the whole application service. This adds bit of typing using the cJSON parser but you will gain when replying JSON data on your CGI. I think cJSON structure is easier to use than e.g. GLIB containers. cJSON is not as effective as GLIB containers but it does not really impact the service performance.  ACAP is not the best platform for managing large database with thousands of records.

In most cases you can use HTTP GET when adding or updating settings – as long as the amount of data is limited. If you need to send more data to the service you need to use HTTP POST. However, the Axis cameras has some quirks and does not manage HTTP POST well. The POST data ends up on the query string which means that you need uri-encode that data before it is sent. Then, in order to get hold of the data in the CGI callback function, you need to add some attribute name to the posted data.

Example how to POST a JSON data object to an embedded ACAP service CGI and parsing it on the other side. The example includes no exception/error management nor clean up.

HTML Page

<script>
function foobar() {
  var someObjectToSend = {
    property1: 10,
    property2: “some string”
  };
  var cgiURL = “mycgi?update=settingX”;
  var postData = "&postdata=" + JSON.stringify(someObjectToSend);
  postData = encodeURI( postData );
  $.ajax({ type: "POST", url: cgiURL, data: postData});
  //A simple jQuery HTTP POST that ignores response and errors
}
</script>

Embedded CGI

static void
http_main_callback(const gchar *path,const gchar *method, const gchar *query,GHashTable *params, OutputStream *output_stream, gpointer user_data){
  char *thePostData;
  cJSON *object = 0;
  int property1;
  const char *property2;

  if( g_hash_table_lookup_extended( params, “postData, NULL, (gpointer*)&thePostData)){
    //thePostData points to the JSON data string.
    //This data can now be saved to a file in localdata
    object = cJSON_Parse( thePostData );
    property1 = cJSON_GetObjectItem( object, “property1”)->valueint;
    property2 = cJSON_GetObjectItem( object, “property2”)->valuestring;
  }
}

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s