FTPmicro is a small embedded web server as big as a package DIP40, based on the PIC18F67J60.
This chip is a 8-bit PICmicro with an integrated 10BaseT Ethernet controller. Despite the small dimensions, the board has some interesting peripherals, like a microSD card slot, a TC1047 temperature sensor, and many analog and digital I/O pins. But even more important is the software that can be performed on this device. Using the Microchip TCP/IP stack, suited for this particular hardware, it is possible to have, in a few minutes, a working HTTP and UDP server with DHCP client. FTPMicro doesn't need any external component: loading the compiled software in the PIC and powering the device at 5V is all you need. It also has a comfortable connector for the ICD2 programmer/debugger by Microchip. Thanks to the SD memory, a large number of files can be saved, and they will be available to the HTTP server. In this way, you can store a complete web-site, with both static (HTML) and dynamic (CGI) pages. By reading data in real-time and sending commands, it is possible to control any hardware.
FTPmicro is Open Source and you can DIY
The SD memory
The files are stored in the SD card using the FAT16 filesystem, so it is compatible with almost any PC. You can easily transfer any file from a computer to the card (in root directory only), but first you have to format this card with that Filesystem.
The long file names are supported, but a limit is imposed by the following define, located in FAT16.h: The hot-plug feature allow you to insert and remove the SD card whenever you want while the device is turned on.
The choice of the IP address depends on the network in which the device is used, therefore it can be easily modified in the file StackTsk.h, changing the following define:
// esempio: 10.0.0.6 #define MY_DEFAULT_IP_ADDR_BYTE1 (10) #define MY_DEFAULT_IP_ADDR_BYTE2 (0) #define MY_DEFAULT_IP_ADDR_BYTE3 (0) #define MY_DEFAULT_IP_ADDR_BYTE4 (6)
In the same way, it is also possible to change theMAC address:
// esempio: 00:04:A3:00:00:00 #define MY_DEFAULT_MAC_BYTE1 (0x00) #define MY_DEFAULT_MAC_BYTE2 (0x04) #define MY_DEFAULT_MAC_BYTE3 (0xA3) #define MY_DEFAULT_MAC_BYTE4 (0x00) #define MY_DEFAULT_MAC_BYTE5 (0x00) #define MY_DEFAULT_MAC_BYTE6 (0x00)
The IP address can automatically be assigned by a DHCP server. To do that, uncomment the following line in file
always in the StackTsk.h. file
In the example, the Ethernet module LEDs are used like generic LEDs; to make the configuration bit ETHLED is set to OFF; so, to restore the normal utilizing of these LED, modify the configuration to theON.
#pragma config XINST=OFF, WDT=OFF, FOSC2=ON, FOSC=HSPLL, ETHLED=ON
At this point is possible to recomplete the firmware and charge in the PIC.
The HTTP Server
Thanks to the HTTP server, it's possible to communicate with the a card with the a web-server, with any Operating System.
The server is able to draw a file directly from the SD memory and send it to the destination.
Also a request can interact with the software (and so with the hardware) essentially in 2 ways: in "reading", asking the dates through a CGI page, and a "writing" or rather sending the commands.
A CGI (Common Gateway Interface) page is just a html page, that can contain the escape % character followed by a decimal number from two ciphers; this number identifies a variable that will be requested to the program.
In particular is invoked the HTTPGetVar function that is found in the MainDemo.c file:
WORD HTTPGetVar(BYTE var, WORD ref, BYTE* val)
the first parameter identifies the variable about which is requested the value; the second parameter , used for the variables composed from more byte; the last parameter points to the location where we'll write the variable value (we'll write the byte ref-exempt).
The return value it is HTTP_END_OF_VAR if we sent the byte from the variable var, otherwise will be the pointer of the next byte to send, or rather ref+1.
Let's see a short example:
<b>Variabile 1</b>: %01 <br> <b>Varibile 2</b>: <em>%02</em>
In this CGI file there are two variables, so HTTPGetVar will be called with var even to 1, then will return through the val, for example the 'A' character. Successively is recalled the HTTPGetVar, but with var equal to 2; this time let's suppose that the date is a line, that's why this function will be called many times until will be arrived the line term (ex. "Ciao").
At this point the server can send the answer to anyone who asked for the page, that will receive:
<b>Variabile 1</b>: A <br> <b>Varibile 2</b>: <em>Ciao</em>
If to the requested page we add the parameters will be possible to follow the actions to the software.
A request with the parameters has this aspect:
This request is automatically analyzed by the HTTP server and passed to the HTTPExecCmd method, array subform of strings.
The HTTPExecCmd method is defined:
void HTTPExecCmd(BYTE** argv, BYTE argc)
So in the example made first, argv will be:
argv = pagina.htm argv = param1 argv = val1 argv = param2 argv = val2
while argc (elements number) will be 5. Like this, writing the opportune code inside of this method, the PIC can follow different functions upon the received parameters.
Also to the end of the method, argv must contain the number from the page to return, that can be that requested (ex. page.htm) or another one.
|FTPMicro firm4.02.rar||1.23 MB|