DIY web server with OpenPicus FlyPort 2/2

Posted by openPicus | On: Jun 27 2011


The success of FlyPort WiFi module is due to the intuitive and easy programming essential software development environment thanks to the availability of APIs and functions already written and ready to be referenced in your code . The only bad thing is that you need to update the Framework to 4th version.

I think that a possible improvement of the IDE can be precisely to make it multi-platform, and then trying to implement it in Java, for example, as it was done for the Arduino; in this case, the IDE is essential in the size of files and above all there is no worry about the compatibility with your operating system.

The wizard driven on the configuration of the TCP/IP stack makes it easy to implement all the settings without worrying about what is written in the background in the various files that make up the overall project. Webinars whose links are listed at the end of this review show clearly all the ease of use of the IDE and Flyport.

FlyPort: web server exemple

From the OpenPicus site you can, among other things, download a sample project that includes the use of Flyport as a web server through which you can monitor the status of analog and digital inputs, plus you can interact with the board enabling or disabling the 5 digital outputs. Looking at the html code, what we see now is that it is a stylish remake of a web server made available by the Microchip as example of what it can be implemented by adopting their TCP/IP stack, so nothing new to this point of view.

The problem is that using the Ajax commands in the code and JavaScript functions to make the web page more interactive, if you don’t know these type of languages (and unfortunately I am among them) is also difficult to reuse the code to your liking. So I asked myself, while giving up to update the page and then automatically to the status of the inputs, if you can create a Web page easier? On Microchip’s website I found three webinar that demonstrate the use of dynamic variables and the GET and POST methods to send requests to the web server. Using the dynamic variables you can then monitor the status of the inputs, while with the GET method you can, for example, tell the server which outputs must go high and low. At the end of the review there are the links to download the pdf of the slides and the text of the three webinars.

The webpage is designed therefore quite simple: consists of 5 buttons of type “submit”, each associated with a GET method, which pressed individually makes the toggle of its output. depending on the output state, the button will turn green if it’s low and red if too high. Five dynamic variables defined and used as explained by Microchip define background color variation of the button. The following screenshot shows the web page as it appears.

As for the code to be inserted in the FlyPort IDE webserver, here are the C function that handles the reading of the data transferred through the web server using the GET method (for details refer to the Microchip webinar) and the function , also in C, for the returning of the appropriate value to the dynamic variables for the change of color of the button according to the state of its output.

The variable “lights” can have 5 possible numerical values from 0 to 4. Each value identifies one of the possible outputs of FlyPort. The function HTTP_IO_RESULT HTTPExecuteGet reads the value attributed to the variable “lights ” through the GET method (the value is in the end of the URL) and through a switch-case structure makes the toggle of the outputs.

The “void HTTPPrint_led (WORD num)” manages the return of a string to the elements of the dynamic variables led (num) in function in the output state. In particular, for example, if output 4 is high, then the third element of the array “led ” takes the value “red”, while in the opposite case takes the value “green”. These two strings define the value of the “background-color” property button on the web page.

Pressing the button 1, the variable “lights” takes the 0 value and this is given to end of the URL (GET method works behind this principle); the “HTTPExecuteGet” reads the 0 value and is the output toggle “o1″ through API IOPut(o1,toggle); the “HTTPPrint_led” functions reads the state of o1 (actually it does it on all outputs at each cycle) through the API IOGet (o1) and if 0 returns to the LED (0) dynamic variable the string “green”, otherwise the string “red “.

With the technique of dynamic variables and setting of functions similar to HTTPPrint_led you can read the status of inputs (including analog) and return the reading directly on the website. Following the instructions of the first link in Related Link, implement this monitoring is very easy.

FlyPort, future application

If you want to have multiple outputs/ inputs than the Flyport already has, I thought to redesign the “nest” board by entering an on-board expander I / O with 16 channels and managed via SPI. Looking through the suggestions of Microchip, I found the MCP23017 28 pin IC that exactly meets my specifications. This IC has 3 pins to address the device and manage up to 8 I/O expander (ie up to 128 channels) communicating on the same bus.

Conclusion

Flyport module is absolutely advise to anyone wishing to set up quickly a webserver controlled remotely via WiFi communication. The trick is to follow the configuration of TCP/IP stack and write your own code through the IDE software combined with the module and within the sections “Flyport Task” and “Webserver”. The FlyPort code is organized and managed in the form of task FreeRTOS operating system, which frees the programmer from having to organize and combine the various parts of the firmware. The ease of use and programming make this module ideal for those who don’t want to get lost in the configuration of the TCP/IP stack. The IDE is compatible with only Windows operating systems and is not cross platform. This may be the only downside of the Flyport system.

For the codes, please, contact us!

Related link:

slide+text Microchip related to the webinars about the dynamic variables on Get and Post methods
http://techtrain.microchip.com/webseminars/documents/TCPIP_p1_092007.pdf
http://techtrain.microchip.com/webseminars/documents/TCPIP_p2_092007.pdf
http://techtrain.microchip.com/webseminars/documents/TCPIP_p3_092007.pdf

For more information and webinar about Flyport tab:
http://www.openpicus.com/cms/index.php?option=com_content&view=article&i…

For more information about Nest board:
http://www.openpicus.com/cms/index.php?option=com_content&view=article&i…

Other useful links:
http://openpicus.blogspot.com/2011/03/accelerometers-jquery-and-flyport….


2 Comments

  1. Anonymous says:

    wow!!!!!!
    fantastic and nice blog on web server……….

Leave a comment