Embedded Servers

Discuss with MikroElektronika software developers about current library development.
Post Reply
Author
Message
Oluwole_Oyetoke
Posts: 19
Joined: 06 May 2013 22:02

Embedded Servers

#1 Post by Oluwole_Oyetoke » 19 Jul 2013 02:06

How can one successfully use an embedded web server with an MCU. Like storing different PHP compatible webpages on an MMC, and refereing to the web browser to open them, based on action happening on the MCU. E.g If pin B0 is heigh, a particular webpage would open, if the device is requested on the web browser. is it possible

borris
Posts: 219
Joined: 22 Aug 2011 07:13

Re: Embedded Servers

#2 Post by borris » 19 Jul 2013 04:35

I have such a webserver on LibStock. No PHP though, that would take a little too much umph. Little mcu's would not be happy with PHP, ASP, etc.

Oluwole_Oyetoke
Posts: 19
Joined: 06 May 2013 22:02

Re: Embedded Servers

#3 Post by Oluwole_Oyetoke » 19 Jul 2013 07:43

Can u please paste the link. Thanks


Oluwole_Oyetoke
Posts: 19
Joined: 06 May 2013 22:02

Re: Embedded Servers

#5 Post by Oluwole_Oyetoke » 19 Jul 2013 14:44

Yea, iv seen it, so how can it be adapted for use. Like a guideline

borris
Posts: 219
Joined: 22 Aug 2011 07:13

Re: Embedded Servers

#6 Post by borris » 19 Jul 2013 22:32

Unfortunately I don't have a tremendous amount of time to elaborate on a tutorial but here are the basics:

If you are looking at the main.c file in the project you'll notice this struct:

Code: Select all

struct webserverConfig_t webConfig =
{
    {0x00,0x14,0xA5,0x76,0x19,0x3F},    //MAC address
    {192,168,1,150},                           //IP address
    {192,168,1,1},                              //Gateway address
    {255,255,255,0},                           //Subnet
    {8,8,4,4},                                    //DNS address
    80,                                             //Port to serve pages
    &webpages,                                 //Webpages available
    MAXPAGES                                   //Max number of pages available
};


These are the webserver settings which are passed to the server initialization.

What is different is the bottom two definitions, &webpages and MAXPAGES.

Just above the struct definition there is this line:

Code: Select all

webpage_t webpages[MAXPAGES];
MAXPAGES is just a constant definition that represents how many individual webpages you have to serve.

webpages is an array and in that array you have the following members:

Code: Select all

typedef struct
{
    uint8_t pageName[13];         // String representation of page
    uint32_t pageSize;               // Size of webpage in bytes
    HTTP_FILE_TYPE pageType;  // Type of page ex. HTTP_HTML, HTTP_CSS, etc.
    const int8_t* pagePtr;         //  If the page is a static page located in ROM pointer is here
    int8_t* dynamicPtr;             // If the page is dynamic and will be located in RAM pointer here
} webpage_t;
What you are going to do is BEFORE the webserverInit is called you are going to populate your webpages array with the pages to serve. To speed things up we are defining addresses and sizes beforehand so that while the server is busy serving requests it doesn't have to do laborious work like sizeof.

In this function:

Code: Select all

void loadWebPages()
{
    /* Setup all pages in an array to speed access */
    strcpy( webpages[0].pageName, "index.htm" );
    webpages[0].pageSize = sizeof( html_code );
    webpages[0].pagePtr = ( const int8_t* ) html_code;
    webpages[0].dynamicPtr = NULL;
    webpages[0].pageType = HTTP_HTM;

    strcpy( webpages[1].pageName, "p1.jpg" );
    webpages[1].pageSize = sizeof( p1 );
    webpages[1].pagePtr = ( const int8_t* ) p1;
    webpages[1].dynamicPtr = NULL;
    webpages[1].pageType = HTTP_JPG;

    strcpy( webpages[2].pageName, "p2.jpg" );
    webpages[2].pageSize = sizeof( p2 );
    webpages[2].pagePtr = ( const int8_t* ) p2;
    webpages[2].dynamicPtr = NULL;
    webpages[2].pageType = HTTP_JPG;

    strcpy( webpages[3].pageName, "p3.jpg" );
    webpages[3].pageSize = sizeof( p3 );
    webpages[3].pagePtr = ( const int8_t* ) p3;
    webpages[3].dynamicPtr = NULL;
    webpages[3].pageType = HTTP_JPG;

    strcpy( webpages[4].pageName, "p4.jpg" );
    webpages[4].pageSize = sizeof( p4 );
    webpages[4].pagePtr = ( const int8_t* ) p4;
    webpages[4].dynamicPtr = NULL;
    webpages[4].pageType = HTTP_JPG;

    strcpy( webpages[5].pageName, "dynadata.js" );
    webpages[5].pageSize = ( uint32_t )strlen( dynamicData );
    webpages[5].pagePtr = NULL;
    webpages[5].dynamicPtr = ( int8_t* ) dynamicData ;
    webpages[5].pageType = HTTP_JAVA;
}
I am listing all the pages found in the http.h file. This represents the catalog that the server is going to search through to find its' valid pages to serve.

If you are going to change the dynamic page size, you'll need to call an additional user defined function to update the dynamic page size.

Those are the basics. Is there anything that is unclear?

Post Reply

Return to “Library Development Discussion”