Page 1 of 1

Writing value of application variable to a dynamic HTML form

Posted: Thu Jun 07, 2012 4:28 am
by sehsamudra
Hi, with reference to section 10.2.1 , Page 44, of the NetBurner Network Development Kit Programming Guide 350080-003 is there any updated application note on the method for displaying program variables (a string, a number, etc.) directly in a dynamic HTML page running on a netburner module?

I just recently tried (to no luck):

-- defined a local file "foobar.h"
/*
* foobar.h
*
* Created on: Jun 7, 2012
* Author: XXXX
*/

#ifndef FOOBAR_H_
#define FOOBAR_H_

char BUILD_APP_TASKMON[30];

#endif /* FOOBAR_H_ */
In my index.htm file:
<!--INCLUDE foobar.h -->
<p><b><!--VARIABLE BUILD_APP_TASKMON --></b>
What I want to display is contained as a static assignment in my main.cpp
#define BUILD_APP_TASKMON "Some String"
That is, I want the HTML code to be generated at run time that would display the contents of BUILD_ASK_TASKMON defined in main.cpp


I've gone through some of the earlier posts in this forum on the very same topic, and wonder if the functionality of the VARIABLE is still supported?

The resultant HTML code generated is shown below - What am I missing here? I have included in main.cpp:
/*include for HTML variable calls? 6/7/12*/
#include <htmlfiles.h>
After compilation, download and execution, the generated HTML code (from, View Source, on GOOGLE CHROME)
<P><B></B>

Re: Writing value of application variable to a dynamic HTML

Posted: Thu Jun 07, 2012 9:58 am
by dciliske
From what I gather, you want to define what version of the App you are building and embed that into the webpage that gets sent out. Having recently done some redesign work on the comphtml utility and htmldecomp for the device, variables still do indeed work. However, they must be variables.

To do what you are looking for you must use

Code: Select all

/*
* foobar.h
*
* Created on: Jun 7, 2012
* Author: XXXX
*/

#ifndef FOOBAR_H_
#define FOOBAR_H_

char *BUILD_APP_TASKMON = "This is my taskmon";

#endif /* FOOBAR_H_ */
And then call it in the html file like this

Code: Select all

<p><b><!--VARIABLE BUILD_APP_TASKMON --></b>
What you were doing with the define does not set a value for the actual variable, but simply defining a macro to replace the name. The reason you get nothing out is that BUILD_APP_TASKMON is a char*, but has not been given a value. In the boot process of Netburner modules all of memory is zeroed out. So when you go to dereference the pointer to walk the string, the first byte is a null char and it stops.

Re: Writing value of application variable to a dynamic HTML

Posted: Mon Jun 11, 2012 7:16 pm
by sehsamudra
Okay, that looks promising indeed. May I ask if the reference *BUILD_APP_TASKMON can point to an existing variable somewhere else in the *.h or *.c codebase, or is it limited to only the local scope of the foobar.h file? I'm unable to test right now, as the dev platform is back in my office, not home, for today, but perhaps it would be good to know the scope/limitations of this process from a Netburner reference source.

So, something like:

... in xxx.cpp (including in project building file)
char SOMESTRING[]="abcdefgh"
and

then:
char * BUILD_APP_TASKMON = SOMESTRING;
I'm not sure of the proper syntax, I think * can be separated from the variable name by a space, or it doesn't matter... ?

THANK YOU!
dciliske wrote:From what I gather, you want to define what version of the App you are building and embed that into the webpage that gets sent out. Having recently done some redesign work on the comphtml utility and htmldecomp for the device, variables still do indeed work. However, they must be variables.

To do what you are looking for you must use

Code: Select all

/*
* foobar.h
*
* Created on: Jun 7, 2012
* Author: XXXX
*/

#ifndef FOOBAR_H_
#define FOOBAR_H_

char *BUILD_APP_TASKMON = "This is my taskmon";

#endif /* FOOBAR_H_ */
And then call it in the html file like this

Code: Select all

<p><b><!--VARIABLE BUILD_APP_TASKMON --></b>
What you were doing with the define does not set a value for the actual variable, but simply defining a macro to replace the name. The reason you get nothing out is that BUILD_APP_TASKMON is a char*, but has not been given a value. In the boot process of Netburner modules all of memory is zeroed out. So when you go to dereference the pointer to walk the string, the first byte is a null char and it stops.

Re: Writing value of application variable to a dynamic HTML

Posted: Wed Jun 13, 2012 9:00 am
by dciliske
Yes, you can point it to a variable from an alternate .h or .c file. If it's declared in a .h, simply include it. However, if it is in an alternate .c file, you will need to declare the variable you want to reference extern, specifically

Code: Select all

extern C
{
    char *externalString;
}
The reason for the "extern C" block, as opposed to simply declaring the variable "extern", is to prevent the C++ compiler from doing name mangling. If you declared the variable in a .cpp file (or some other C++ file extension) then it will have had its name mangled and should not go in an "extern C" block.

Re: Writing value of application variable to a dynamic HTML

Posted: Sun Feb 24, 2013 3:55 pm
by sehsamudra
dciliske wrote:
The reason for the "extern C" block, as opposed to simply declaring the variable "extern", is to prevent the C++ compiler from doing name mangling. If you declared the variable in a .cpp file (or some other C++ file extension) then it will have had its name mangled and should not go in an "extern C" block.
Thank you, I forgot to acknowledge this advice, and the system worked out well a few months ago. Restarting dev work on this project this month.