Using Wifly Interface with RTOS to implement a HTTP Server or FTP Server

I recently started a new project where I needed to have a webserver running while the system would collect data over several different interfaces. I could not use LAN to let the device communicate I decided to use WLAN and purchased the roving networks WiFly component.

After playing around with the device I finally found out that the current implementation of the RTOS was not working properly with the WiflyInterface.library.

So I searched the forums for a solution to this problem and I finally found a workaround to the problem. The page I am referring to is the here.

I found also that a few people seemed to have the same issue like me, so I decided to publish some more information around this topic.

RTOS compatible workaround

The current implementation of RTOS (or the Serial class, I do not know exactly) does not clear the interrupt flag accordingly, when you attach your own handler to a Serial Interrupt. Assuming you have created a new project where you implement an HTTP Server which uses the WiflyInterface in an RTOS thread (please note that when you import the RTOS library, the main function is considered as the main thread). In this situation as long as no data is received over the serial interface the program will work. Upon reception of the first data byte the system will hang. I believe this is a generic problem and not really specific to the WiflyInterface. One way of fixing or working around this issue is to modify the rx handler function in the Wifly class :

New handler code

void Wifly::handler_rx(void)
{
    //read characters
    while (wifi.readable()) {
        char c = LPC_UART3->RBR;
        buf_wifly.queue(c);
    }
}

Please note that the above example only works if you intend to use UART3 (Pins TX:p9, RX:p10). This needs to be adjusted in case you use a different UART. A mapping of UART to pins can be found here.

Sample project

I have implemented a HTTP server an created a fork of the Wifly library with some additional improvements.

t.b.d.


Please log in to post comments.