HTTP bridge example (OP-AN-017)

From openPicus Wiki
Jump to: navigation, search

Contents

Download

Application Note PDF

Source Code

Description

This application note uses the NEST Serial expansion board hardware to provide the following services:

  • Loop-back serial data between RS232 and RS485 port (can be disabled via firmware).
  • Web server embedded page (inside the FLYPORT module) with:
    • RS232 and RS485 configuration at run-time
    • Visualization of the RS232 port received data
    • Input text box to send strings directly from browser to RS232 port
    • Visualization of the RS485 port received data
    • Input text box to send strings directly from browser to RS485 port
  • For FLYPORT Wi-Fi only: a Wi-Fi parameters configuration web page
  • Real-time monitor web page of Expansion connector signals

Required Hardware

Required Software and Libreries

Software

  • OpenPicus Free IDE 2.2+

Libraries

  • RS232Helper
  • RS485Helper

Implementation

The application simulates a serial monitor via browser. Both RS232 and RS485 serials can be handled using the above interface, simply opening a browser at the IP address of the FLYPORT module.

Implementation OP-AN-017 1.png


The RS232 and RS485 data received are added to the boxes in the webpage, and the strings wrote inside the text boxes are sent to FLYPORT modules using POST method with the pressure of the “Send it!” buttons. Up to 99 chars at one time can be sent to the Serial Port with one “Send It!” button pressure.
All the callback functions between the web server and the Flyport are located inside the HTTPApp.c file, but every handling of serial ports are done inside the taskFlyport.c. With this separation of concerns, both TCP/IP task and User Task can be executed without lags on firmware.

For every changes of serial ports parameters on web server page, the browser executes a CGI request to the file “serial.cgi”.
This request is handled by Flyport inside the HTTPExecuteGet function, the parameters are parsed. The real changes are done inside the flyportTask.c file, with the using of the flags “RS232ParamsChanged” and “RS485ParamsChanged”.

The web server “serial monitor” dynamic variables (stored inside the serial.xml file) are updated only if the RS232 and RS485 received some new data, in this case using the flags “RS232RxChanged” and “RS485RxChanged”.

FlyportTask() is responsible of the initial setup of the two serial ports, that is done with some default parameters (19200 baud, 8bit data, no parity, 1 bit stop, no HW flow control for RS232). The pins definition for the UART ports are ready for NEST Serial expansion board. The only modification requested by user is to choose between hardware flow control of RS232 (using CTS and RTS) or without those signals.

The Default Network parameters are different between FLYPORT Wi-Fi and FLYPORT Ethernet:

  • FLYPORT Wi-Fi: the module creates an ad-hoc network with SSID name “Nest_Serial_Network” and open security.
With the pressing of SW1 button on the NEST Serial board for at least 5 seconds, this configuration is restored (even if user changed the parameters by :webserver interface). This configuration can be easily changed by openPICUS IDE Wizard tool, and is stored inside the internal FLASH memory of :microcontroller and cannot be changed at run-time.
  • FLYPORT Ethernet: the module has DHCP enabled by default, so its IP Address is provided by the attached router.
With the pressing of SW1 button on the NEST Serial board for at least 5 seconds, this configuration is restored (even if user changed the parameters by :webserver interface). This configuration can be easily changed by openPICUS IDE Wizard tool, and is stored inside the internal FLASH memory of :microcontroller and cannot be changed at run-time.



The infinite loop of the FlyportTask checks continuously for some variables:

  • ParamSet: true if the network parameters are changed inside the conf.htm page of the web server.
  • RS232ParamsChanged: true if the RS232 parameters are changed inside the serial.htm page
  • RS485ParamsChanged: true if the RS485 parameters are changed inside the serial.htm page
  • RS232TxChanged: true if the command to send a new string on RS232 was received by HTTPExecutePost function
  • RS485TxChanged: true if the command to send a new string on RS485 was received by HTTPExecutePost function
  • RS232BufferSize: if it is greater than 0 it means that the RS232 serial port received some data
  • RS485BufferSize: if it is greater than 0 it means that the RS485 serial port received some data


In this way the firmware is always alerted of new statuses and don't loose events when busy in other tasks (for example when writing a large buffer to a serial port).


Serial parameters configurable by web server page

The RS232 is provided with DB9 female (DCE) connector, with TX, RX, and firmware enabled CTS and RTS hardware flow signals. The RS485 is provided with A and B signals, and separated DE and RE signals handle from FLYPORT module. The configurable parameters of the two serial ports can be changed by web server page at run-time.


  • Both RS232 and RS485 baud-rate can be chosen via browser with of values between:
    • 4800
    • 9600
    • 19200
    • 38400
    • 115200
    • 230400
  • Data bits and parity are selectable between:
    • 8 bit data, no parity
    • 8 bit data, even parity
    • 8 bit data, odd parity
    • 9 bit data, no parity
  • Stop bits can be set as:
    • 1 stop bit
    • 2 stop bits

Testing

Credits

Personal tools
Namespaces

Variants
Actions
START HERE
DEVELOPMENT
HARDWARE INFO
RESOURCES
PHASED OUT
Toolbox