AWS + Filesystem + Ftp

Hi,in an new application it should be possible for costumers, to upload dynamic webpages into the device (ns7520) with tags in html code. The tags are placeholder for variables in user application. The page should not be precompiled with pbuilder or any other tool! On an exebition Netsilicon told us, that such an application is possible with AWS combined with filesystem and Ftp, when the first page, named index1.html, is compiled into application and links to the empty link index2.html. The index2.html must be uploaded by the user via ftp into the filesystem. Now my question: Is there any documentation about this kind of using AWS, I can not find it in the normal AWS documentation? Kind regards Michael Sonst

Is ther noone who can help me? It es really neccessary that this basic problem will be solved! What’s about the developers itselve? Is there noone who has enough knowledge to answer my question? Michael Sonst

Hi Michael I have implemented this in our product, but there are many details about this. I don’t have much time to write right now, but here’s some info to get you started. First of all we have used pbuilder to make the default page with only a redirect. The page is dynamic and the redirect target is dynamic either our default (pbuilder) homepage or can be modified by configuration to a customer specific page. We use a tag to implement this. One problem with the web server is rights management for the pages. Maybe you need different access rights for different pages. Using FTP you cannot specify rights for a file, we have solved this by using a number of predefined and created directories with specific rights. The the user can place the files in the appropriate directory. Now for the file system, there used to be a number of bugs related to rights (and AWS) in the file system, I’m not aware if all is fixed in latest version of NET+OS but we have implemented a number of workaround to make everything work.

Hi,
I have got the same problem :
I need to manage dynamic web pages, created by the customers, which will get some data from my running application by using tags in the html code and cgi scripts. (These page musn’t be precompilated)

Today i am trying to find information on how to do that by using cgi scripts, but i didn’t find any usefull information. Can you help me please.

Regards
Paul

If you are looking for an html file to be loaded into the file system, containing AWS comment tags, NOT be precompiled by the pbuilder utility AND have access to device data as though it had been precompiled by the pbuilder utility, that can not be done. Part of the pbuilder utility process is to add hooks to the application so that AWS can call callback (stub) functions for accessing device data.

What you can do is when a web page is processed by the AWS and it has a stub function associated with that page, there are methods for redirecting to a page on the file system. BUT, that web page has NO hooks for acquiring device data. The only way to access device data is through C code and that C code is generated via the pbuilder utility.

Hi,
We have developped an application that treats data on the module. Our goal is to provide to our customer the possibility to upload dynamic web page on the module via FTP to monitor some of these data. The customers create is own web page with some tags in it to link with the treated data he wants to monitor. Then by uploading the page on the file system, they will be accessible via the web server, and the treated data could be monitored.
We are looking for doing that by using CGI.

Thank you
Best regards,
Paul

I do not agree that there is no way to do it. There might not be a ready made method in AWS, but it is possible in several ways.

I will try to explain.

First there are two kinds of pages; simple static pages that do not need dynamic data, and pages that require some kind of dynamic data available in the device.

I have a pbuilder compiled page with a simple redirect as the default page. The page redirects to a variable page so that the end user can control the default page by a configuration parameter.
( I also have a bunch of other pbuilder pages for configuration)

This is enough for static pages.

For pages with dynamic data there are some different approaches. There are many ways to implement this, I will mention two. But simply you can make the static HTML page request the data using java script, or you can hook into the AWS file handler and implement processing of the page before delivered to the HTML client. With the second approach you can make some kind of tags that the end user inserts and search for these while processing the page. I have used the first method so some more details on this.

Since data is dynamic anyway I have implemented CGI handler in the AWS that can deliver back different dynamic data. The CGI handler have code where you simple specifying the request data, single value or list, as CGI parameters and then returning the data in XML format, then the script on the HTML page process the data, and updates the page. An alternative could be to return JSON format that is easy to process on the HTML page.

So for example the CGI handler would catch:

http://192.168.1.100/SystemGetTemperature?id=4
http://192.168.1.100/SystemGetTemperature?id=all

and return the request temperature data.

This was made long ago, today it is common practice with AJAX to specify data as path (not as CGI parameters with ‘?’) which would be more like:

http://192.168.1.100/temperature/4
http://192.168.1.100/temperature

On the static page I have a script included that handle reading of parameters. It used HttpRequest object that is build in to modern browsers (or ActiveX as fallback).

This also gives the advantage of really nice dynamic updates of the page, since you only update the data fields not the whole page. You can make a interval update on the page using a timer.

You need to identify the elements on the page that needs updated values. If you do this smart with the id field of the page element matching the data identification, you will be able to make generic code that can update variable fields on the page.

I hope this can get you started, otherwise feel free to ask more details.

Hi,
This method using CGI is interresting me, i need more information to get started with a little application.
You mean that using

First, yes you use RpExternalCgi to catch the CGI call and generate a response.

Secondly on the static part of the page you need a script to handle background reading of dynamic values.

On the page make a script that is activated by the “onload” event. If you like start a timer that reads updated values with an interval.

You should use the HttpRequest object to read the data and the have a script parse the resonse and insert into the HTML.

Maybe you can also use the form method as you describe, but then your CGI handler needs to return HTML code. I would not implement it using form.

Yes, you are right, returning HTML code was problematic since the page was created by customers.

I understood that a script is started when the page is loaded, and it runs in loop due to the timer. This script is used to refresh dynamic value. But how is this script coded? with which langage?? What is the command to call my CGI with this script?

Then when my CGI is called, the RpExternalCgi function will be called. I will retrieve all environment variable in the CGI structure block. Then i’ll need to parse the URL given in the fPathPtr (Pointer to request URL path) to find the name of the variable. Now I need to return the value corresponding to the variable I found, but how do I answer, how can I send back the value to monitor it on the HTML page.

I will try to boil down some example code for you. I will take the important parts, not all error handling etc. removed.

First here is a CGI handler example:

void RpExternalCgi(void *theDataPtr, rpCgiPtr theCgiPtr)
{
   if (theCgiPtr->fHttpRequest == eRpCgiHttpGet || theCgiPtr->fHttpRequest == eRpCgiHttpPost)
   {
      if (strncmp(theCgiPtr->fPathPtr, "/SystemGetTemperature", 21) == 0)
      {
         static char buffer[1024]; // Watch out this is not OK, some better buffer management needed
         int size;
         // Here you also need to check if (theCgiPtr->fUserDataPtr = (void *) 0)
         // at least if you expect to return more than simple data. When zero this is first call from AWS you can then initialize fUserDataPtr and use it on subsequnt calls
         // If you need time to process you can release process and make the AWS call back again. (use fResponseState for this)

         // If you implement parameters like ?id=4 you then need to
         // process theCgiPtr->fArgumentBufferPtr

         // Response will be more complex than this but basically
         size = sprintf(buffer, "
");

         // Very simplified
         size += sprintf(buffer+size, "
");
         size += sprintf(buffer+size, "
");
         size += sprintf(buffer+size, "
");

         theCgiPtr->fHttpResponse = eRpCgiHttpOk;
         theCgiPtr->fResponseState = eRpCgiLastBuffer;
         theCgiPtr->fResponseBufferPtr = buffer;
         theCgiPtr->fResponseBufferLength = size;
      }
   }
}

I hope I got it right it is very simplified.

Now on you static web page you need something like this.

Again very simplified (cut and paste from js files):



AWS Dynamic demo





  
    Temp. 4
    
  


For the customer you probably would make a nice java script library that he can include to his HTML page and then tell him how to name the page elements so that it can be handled by you system. You can even make a naming scheme so that you can collect the data that is needed from element id of from custom namespace on the HTML page.

Hoe this helped you a little further.

Thanks for these example, for sure they will help me to understand what you have done.

Hi,

I have been working to find some solutions, and finally we assume that thhis one is the best for our need. If you can send me a more detailled javascript code, it could be nice, otherwize i’ll understand. Thanks for this greatfull help!

Best regards,
Paul