A simple web server mainly based on ideas from Jasper Schuurmans Netduino web server

Dependents:   RdBlindsServer SpideyWallWeb RdGasUseMonitor

You are viewing an older revision! See the latest version

Homepage

This is based on a Netduino web server from Jasper Schuurmans http://www.schuurmans.cc/multi-threaded-web-server-for-netduino-plus

There is some more info in a blog post here ...

http://robdobson.com/2013/10/moving-my-window-shades-control-to-mbed/

Essentially you have a server that can serve files from local or SD card file systems and has a mechanism for registering REST "commands" that result in callbacks. The following code snippets are from the blog. There is a full project using this code here ... http://mbed.org/users/Bobty/code/RdBlindsServer/

int main (void)
{
    // setup ethernet interface
    eth.init(); //Use DHCP
    eth.connect();
    printf("IP Address is %s\n\r", eth.getIPAddress());
 
    // setup web server
    webServer.addCommand("", RdWebServerCmdDef::CMD_LOCALFILE, NULL, "index.html", true);
    webServer.addCommand("gear-gr.png", RdWebServerCmdDef::CMD_LOCALFILE, NULL, NULL, true);
    webServer.addCommand("blind", RdWebServerCmdDef::CMD_CALLBACK, &handleCmd_blindControl);
    webServer.init(PORT, &led2);
    webServer.run();
}

void handleCmd_blindControl(char* cmdStr, char* argStr)
{
    printf("BLINDS COMMAND %s %s\n\r", cmdStr, argStr);
    if (argStr == NULL)
        return;
    char* pch = strtok (argStr,"/");
    if (pch == NULL)
        return;
    int blindNum = pch[0] - '0';
    if (blindNum < 1 || blindNum > MAX_WINDOW_SHADES)
        return;
    int blindIdx = blindNum-1;
    char* pDirn = strtok (NULL,"/");
    if (pDirn == NULL)
        return;
    char* pDuration = strtok (NULL,"/");
    if (pDuration == NULL)
        return;
    pWindowShades[blindIdx]->DoCommand(pDirn, pDuration);
}


All wikipages