Since the documentation and related example are rather wanting, can someone simply list for me the steps (1:, 2:, 3:, 4:profit!) required to output a C variable to the HTML stream? I have used "<!--FUNCTIONCALL" for years, but have never had luck with "<!--VARIABLE".
For example, are there extra #include files required? And where would they go? Exactly what goes in htmlvar.h (int foo, extern int foo, or...)? Where does htmlvar.h go in one's directories? Do the IDE's settings need to be altered? Etc.
Thank you.
VARIABLE Tags In HTML
Re: VARIABLE Tags In HTML
have a look at C:\nburn\examples\StandardStack\Web\HtmlVariables
Re: VARIABLE Tags In HTML
Thank you for your response. But as I said, the NetBurner example is unclear; it (the version I have anyway) doesn't show one how to use stand-alone variables, just variables as they are returned from functions.
Re: VARIABLE Tags In HTML
Basically, just put the thing you want to be printed in the VARIABLE tag. If you're trying to figure out what to do with different types or how it can figure that out, take a look at the output file 'htmldata.cpp'. This is the result of comphtml, and what actually gets compiled into the application to send the webpages. Looking at this file for for the HtmlVariables example, the DoHtmlVariables table/function has the following calls:
Keep in mind that the function WriteHtmlVariable is a C++ function that has been overloaded to print differently, based on the type of the argument that it is given. Now, as for what you need to put in 'htmlvar.h'. Basically, you should declare extern all the variables you wish to use inside the VARIABLE tag. Also, you should give the definition for any function you wish to use the return value from in a variable tag.
-Dan
Code: Select all
case 1: WriteHtmlVariable(fd,IPCAST(gConfigRec.ip_Addr)); break;
case 2: WriteHtmlVariable(fd,IPCAST(EthernetIP)); break;
case 3: WriteHtmlVariable(fd,IPCAST(gConfigRec.ip_Mask)); break;
case 4: WriteHtmlVariable(fd,IPCAST(EthernetIpMask)); break;
case 5: WriteHtmlVariable(fd,IPCAST(gConfigRec.ip_GateWay)); break;
case 6: WriteHtmlVariable(fd,IPCAST(EthernetIpGate)); break;
case 7: WriteHtmlVariable(fd,IPCAST(gConfigRec.ip_DNS_server)); break;
case 8: WriteHtmlVariable(fd,IPCAST(EthernetDNS)); break;
case 9: WriteHtmlVariable(fd,gConfigRec.baud_rate); break;
case 10: WriteHtmlVariable(fd,gConfigRec.wait_seconds); break;
case 11: WriteHtmlVariable(fd,TimeTick/TICKS_PER_SECOND); break;
case 12: WriteHtmlVariable(fd,FooWithParameters(fd,123)); break;
-Dan
Dan Ciliske
Project Engineer
Netburner, Inc
Project Engineer
Netburner, Inc
Re: VARIABLE Tags In HTML
Thank you for your reply. So that I'm clear, I will answer my own questions (please correct me if I'm wrong).
1) For example, are there extra #include files required?
Yes, #include just "htmlvar.h" in the main C code.
2) And where would they go?
"htmlvar.h" goes in one's project's directories.
3) Exactly what goes in htmlvar.h (int foo, extern int foo, or...)?
extern int foo;
4) Where does "htmlvar.h" go in one's directories?
Wherever it is pointed to within the main C code.
5) Do the IDE's settings need to be altered?
Not necessarily. Standard #include/header file path rules apply (C code versus IDE settings).
1) For example, are there extra #include files required?
Yes, #include just "htmlvar.h" in the main C code.
2) And where would they go?
"htmlvar.h" goes in one's project's directories.
3) Exactly what goes in htmlvar.h (int foo, extern int foo, or...)?
extern int foo;
4) Where does "htmlvar.h" go in one's directories?
Wherever it is pointed to within the main C code.
5) Do the IDE's settings need to be altered?
Not necessarily. Standard #include/header file path rules apply (C code versus IDE settings).
Re: VARIABLE Tags In HTML
1) You are correct.
2) It should go in the main source directory of the project. It may need to go in the resources, or whatever it's called, when building with NBEclipse. The critical issue is that htmldata.cpp includes the file using quotes and not angle brackets. Therefore, the header should be local to that file's compilation path.
3) Yes.
4) See number 2.
5) I don't think so... I'm a command line person, so I don't necessarily whack on Eclipse that much. I guess I should page Forrest on this note...
-Dan
2) It should go in the main source directory of the project. It may need to go in the resources, or whatever it's called, when building with NBEclipse. The critical issue is that htmldata.cpp includes the file using quotes and not angle brackets. Therefore, the header should be local to that file's compilation path.
3) Yes.
4) See number 2.
5) I don't think so... I'm a command line person, so I don't necessarily whack on Eclipse that much. I guess I should page Forrest on this note...
-Dan
Dan Ciliske
Project Engineer
Netburner, Inc
Project Engineer
Netburner, Inc
Re: VARIABLE Tags In HTML
Section 10 of the programmers guide helped me a lot. For example, just the beginning of the include file section:
Now that we understand the resultant code is a function with the variable name, it should be apparent that the resultant htmldata.cpp file created by the HTML source code needs to be able to link to the variable name. For example, to display TimeTick the application would need to include utils.h, otherwise a linker error will occur.
Include files can be handled two ways: you can use an INCLUDE tag in the HTML code, or you can create a header file with the name “htmlvar.h” that will be automatically included if no INCLUDE tags are detected in the HTML source code. If you choose to use the htmlvar.h header file, it must be located in the same directory as the htmldata.cpp file, or if you are using NBEclipse, it must be in the include file path. To add the include file path using NBEclipse:
// Not copying it here, but it goes on with a step by step list and screen shots.
Now that we understand the resultant code is a function with the variable name, it should be apparent that the resultant htmldata.cpp file created by the HTML source code needs to be able to link to the variable name. For example, to display TimeTick the application would need to include utils.h, otherwise a linker error will occur.
Include files can be handled two ways: you can use an INCLUDE tag in the HTML code, or you can create a header file with the name “htmlvar.h” that will be automatically included if no INCLUDE tags are detected in the HTML source code. If you choose to use the htmlvar.h header file, it must be located in the same directory as the htmldata.cpp file, or if you are using NBEclipse, it must be in the include file path. To add the include file path using NBEclipse:
// Not copying it here, but it goes on with a step by step list and screen shots.
Re: VARIABLE Tags In HTML
Thank you gentlemen for your responses.
@rnixon: I read that section a while ago and I think it didn't "sink in" then for two reasons.
1) Most importantly, nowhere in the docs nor example does it say "extern int foo" should be within htmlvar.h to facilitate this feature. It is perhaps obvious in retrospect, but to the newcomer facing many dubious compiler errors, it becomes stabbing in the dark. (@NB: Updating the docs or example to reflect this would be very helpful and reduce costly phone calls and forum posts.)
2) The multiple options for linking these files together is also confusing to the uninitiated who's only versed in C coding, especially when he's already overwhelmed by everything that makes up this brand new NB environment. ...A small example, in the beginning I spent much time figuring out why
didn't work. Because it must be(!):
@rnixon: I read that section a while ago and I think it didn't "sink in" then for two reasons.
1) Most importantly, nowhere in the docs nor example does it say "extern int foo" should be within htmlvar.h to facilitate this feature. It is perhaps obvious in retrospect, but to the newcomer facing many dubious compiler errors, it becomes stabbing in the dark. (@NB: Updating the docs or example to reflect this would be very helpful and reduce costly phone calls and forum posts.)
2) The multiple options for linking these files together is also confusing to the uninitiated who's only versed in C coding, especially when he's already overwhelmed by everything that makes up this brand new NB environment. ...A small example, in the beginning I spent much time figuring out why
Code: Select all
<!-- FUNCTIONCALL
Code: Select all
<!--FUNCTIONCALL