6 years, 6 months ago.

Is it possible to continue to run the main infinite loop along with the server ?

Hi, first of all this is really a neat piece of work you have done. I have a question and if it can be addressed, it would be a perfect combination.

When we run your webserver, it interrupts the main infinite loop of mbed.

If we would like to run things like logic control, data logging or similar stuff that is not possible once the webserver starts the loop.

Can this be modified ?

Thank you,

Orhan Dengiz

Edit: this question is about "MiMic RemoteMCU for mbed" at https://mbed.org/users/nyatla/code/MiMicRemoteMCU-for-Mbed/

Question relating to:

libMiMic Rev 46 support back ground task.

Please call Httpd::loopTask() instead of Httpd::loop();

#include "mimic.h"
#include "rtos.h"
/**
 * @file
 * This program is a sample which starts httpd by a subtask.
 * The value counted up by a main thread is returned by Httpd of a subtask.
 */
 
 
static unsigned int counter=0;


LocalFileSystem2 lf("local");
class SimpleHttpd:public MiMic::Httpd
{
private:
    ModUrl modurl; //basic URL parser
public:
    SimpleHttpd(NetConfig& i_cfg):Httpd(i_cfg._inst.services.http_port)
    {
    }
    virtual void onRequest(HttpdConnection& i_connection)
    {
        char url[32];
        int method;
        unsigned int v;
        i_connection.lockHttpd();
        v=counter;
        i_connection.unlockHttpd();
        

        //call ModUrl module.
        if(this->modurl.execute(i_connection,url,32,&method)){
            //send 200 OK and requested URL
            i_connection.sendHeader(200,"text/html",NULL);
            //show current counter value.
            i_connection.sendBodyF(
                "<html><body><h1>Asynchronous test</h1><div>Counter: %u</body></html>",v);
            return;
        }
        
        return;
    }
};


NetConfig cfg; //create network configulation
int main()
{
    Net net;  //create a net instance.

    //try to override setting by local file.
    cfg.loadFromFile("/local/mimic.cfg");
    
    SimpleHttpd httpd(cfg); //create a httpd instance.
    net.start(cfg);
    httpd.loopTask();  //start httpd loop with new task
    for(;;){
        httpd.lock();//prepare to access shared resource
        counter++;
        httpd.unlock();//release a lock.
        Thread::wait(1000);
    }
    return 0;
}
#include "mbed.h"
posted by Ryo Iizuka 11 Jul 2013

1 Answer

6 years, 5 months ago.

I am update libMiMic. please check reply.