Home
Login / Signup
 di 

FTPmicro Tutorial

FTPmicro Tutorial

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
www.ftpmicro.com

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 configuration

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

//#define STACK_USE_DHCP

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:

http://10.0.0.6/pagina.htm?param1=val1¶m2=val2

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[0] = pagina.htm
argv[1] = param1
argv[2] = val1
argv[3] = param2
argv[4] = 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[0] must contain the number from the page to return, that can be that requested (ex. page.htm) or another one.

http://dev.emcelettronica.com/ftpmicro-tutorial-example
http://dev.emcelettronica.com/ftpmicro-tutorial-fat16c
http://dev.emcelettronica.com/ftpmicro-tutorial-sdc
http://dev.emcelettronica.com/ftpmicro-tutorial-smtp
http://dev.emcelettronica.com/ftpmicro-tutorial-example-ansa-news-lcd

AttachmentSize
FTPMicro firm4.02.rar1.23 MB

EEprom 25LC64 of the FTPMicro

Hi,

I have some doubts:
Which is the function of memory EEprom 25LC64 in the FTPMicro?
How can I program this Memory?
which is the file to be programmed into this Memory?

Wrsalasr

Hello, you can store the web

Hello, you can store the web pages into the eeprom.
In the above example i don't use eeprom, because the web pages are stored into the sd memory.
If you have a low kbyte page, you can use the 25LC64 programming it by the picmicro

Twitter on FTPmicro

Hi,
we tested only telnet, so you should modify this string
on RSS.c

static const char rss_request[] = "GET
/statuses/friends_timeline/29478134.rss HTTP/1.1\r\nHost:
twitter.com\r\nAuthorization: Basic cGlwcG86dG9wb2xpbm8=\r\n\r\n";

insert the url of the feed and the sequence of characters is: password (Base64 coding http://www.motobit.com/util/base64-decoder-encoder.asp)

and the url on
static ROM BYTE rss_server_url[] = "www.twitter.com";

Regards

DIY FTPmicro..... why

DIY FTPmicro..... why not?

Open Source hardware and software
www.ftpmicro.com

Are You able to use the soldering iron?

thanks

thanks for this tutorial.. nice article..

Who's online

There are currently 0 users and 21 guests online.

Recent comments