-
1Step 1
Create your user program. Include HTTaP.h at the beginning : since it contains many inclusions, you don't need to include them as well.
Like an Arduino sketch, it must contain an infinite loop. This loop must run at least once per second. Inside the loop, call the server's routine.
Here is an example :
#include "HTTaP.h" int main(int argc, char *argv[]) { const char spinner[4]="-\\|/"; int phase=0; while (1) { // do something, dance, sing, whatever, // but set timeout to 1 once in a while. printf("%c%c", spinner[(phase++)&3],0xd); fflush(NULL); // run the server: HTTaP_server(timeout); } }
Note : the server requires to be called with an integer number, that is set to 1 every second, to increment its internal counter.
-
2Step 2
The server is a FSM (Finite States Machine) that contains all the necessary initialisation code. You don't even have to call a "init()" function, the FSM takes care of it.
However if you use the HTTaP protocol, you must modify the "request method" parsing routine and add your own "words", "commands" and their effects.
The code in question is there :
case ETAT2_attente_donnee_entrante : /* receive the request */ ..... /* analyse the request */ if ((recv_len >= 7) && (strncmp("GET /1 ", buffer, 7) == 0)) { // do something here because we received the URI "/1" }
You should be careful with the reply buffer (the pointer b), don't forget to update it to prevent from sending garbage. -
3Step 3
Update all the #defines you can. For example, which features are allowed (is it blocking, polled or both? is file-serving enabled ?)
There are several predefined values in HTTaP.h
-
4Step 4
If you serve files, prepare the hierarchy in a separate directory. An example hierarchy is provided in the latest .tgz archive.
- Update all the access rights and ownerships to make sure they can be accessed by the program.
- If you can use root rights, create a powerless user that will own the files and add more security.
- Check all the file types and create the proper links in the hidden directory for the MIME headers.
-
5Step 5
Don't forget your unit tests... Scripts will save your @$$ !!!
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.