Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to transfer text files bewtween pic18f2620 & ftp ser

Status
Not open for further replies.

haseeb123

Newbie level 6
Joined
Jun 7, 2011
Messages
14
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,416
hello

Im planning on a new project.

I want to setup a simple ftp communication from the pic to an ftp server.
Data to be sent will be simple txt files and no picture.
The pic is a PIC18F2620. I plan on using a GPRS modem that can support ftp protocol such as the Cinterion BG2 wireless module.
I will be using the CCS compiler.

Please can someone point me in the right direction on how to achieve
this task?

Haseeb
 

Hello



I have finally managed to successfully and reliably transfer SMS texts from my PIC to my mobile via the Cinterion BG2 modem. It works brilliantly!. So that part of the experiment is successful and i know for

sure now that all my hardware is running smoothly. Im using CCS compiler and PIC18F2620 with

internal oscillator @ 4Mhz.



Now I want to send data from my PIC to my ftp server. I have written the command lines as below.

However it is not working. What I aim to do is to send a string 'haseeb' and get that saved into

a standard txt file inside a directory on my ftp server. It is my own ftp server so it is always connected

and a dedicated online connection.



You will notice in my code that I never look for incoming acknowledgments from the modem and just

put a delay instead. This has worked fantasticaly with the txting. So im assuming the same

will be true for ftp variant as well. The reason for not looking for the incoming from modem is simply

because i could not get the 'OK' read into my PIC. I tried everything from RX Interrupts to manual

and it would not work, altough i do get pulsing levels on my RX pin when i scope it.



Please can someone help me with my ftp experiment to achieve the desired objective.



Haseeb



Code:
fprintf(Modem,"AT+CGATT=1 \r\n");                  // Attach to GPRS Service



  delay_ms(100);



 fprintf(Modem,"AT+CGDCONT=1,\”IP\”,”blueinternet\”,\”194.153.69.27\”,0,0 \r\n");   



  delay_ms(100);
     
 // Define Packet Data Protocol (PDP) context


 fprintf(Modem,"AT+QIDNSCFG=\”158.043.192.001\”,\”158.043.128.001\”  \n\r");    



  delay_ms(100);



 // Configure domain server


 fprintf(Modem,"AT+QIREGAPP=\”blueinternet\”,\”\”,\”\” \n\r");  



  delay_ms(100);



 //Start TCP/IP task and set APN, User Name, Password


 fprintf(Modem,"AT+QIACT \r\n");             //Bring up wireless connection



  delay_ms(100);



 fprintf(Modem,"AT+QILOCIP \r\n");        // Get local IP address



  delay_ms(100);



 fprintf(Modem,"AT+QISTAT \r\n");        // Get connection Status



  delay_ms(100);



 fprintf(Modem,"AT+QIDNSIP=0 \r\n");      // Connect with IP address (0)or Domain name server (1)



  delay_ms(100);



 fprintf(Modem,"AT+QIHEAD=1 \r\n");       // Add an IP header when receiving data



  delay_ms(100);
 
 fprintf(Modem,"AT+QIOPEN=\”TCP\”,\”121.241.426.371\”,21 \r\n");       //Start up TCP /UDP connection



  delay_ms(100); 



 fprintf(Modem,"AT+QISEND  \r\n");  // Send data through TCP /UPD connection 


 fprintf(Modem,"haseeb  \x1a");  // Send data through TCP /UPD connection
 

I have not tried reading in other replies from the modem.

However, I dont think i need to since when i communicate with the modem then my program
dedicatedly sits and waits in a loop and thats how the txting has worked brilliantly.

Anyway can you help with ftp?

Haseeb
 

I would at least monitor the modem responses with a PC serial logger application, to see, where the protocol fails.
 

Hello


I have now managed to read in 'OK' replies from the modem successfully and I have confirmed this with the texting
mode as that works brilliantly. I can read in modem replies successfully via hyper terminal.


Anyway my main problem is with ftp and I’m enclosing in the program code for you all to have a look at.


Basically I just want to send some data (byte or a string) from my PIC to my ftp site and would like to have that
appear in the ftp root directory as a standard txt file.


From my source code, going all the way down and just before ‘problem 1’, I’m getting OK replies from the modem.
But from ‘Problem 1 ’ and ‘Problem 2’ I’m getting ERROR messages. I’m using CCS compiler and PIC18F2620 with internal
OSC @ 4MHz. The modem im using is the Cinterion BG2 modem and it supports ftp.


Please can you help me to achieve this ftp task.


Thank you
Haseeb


Code:
#include <18F2620.h>


#fuses INTRC_IO,NOWDT,NOPROTECT,NOLVP,NOPUT, NOPBADEN  

// Set Speed to 4Mhz
#use delay(clock=4000000)

// RS232 to Modem
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_B5, STREAM=Modem)
// RTS232 to User Port
#use rs232(baud=9600, xmit=PIN_B4, rcv=PIN_C7, STREAM=User)
 




void Main (void)
{


 char char1;  //variable to store the modem ASCII incoming byte



 //configure I/O directions
  set_tris_A(0b00000001); 
    set_tris_B(0b00100111);     
    set_tris_C(0b11011000);

 

 disable_interrupts(GLOBAL);  // disable all interupts


 
 delay_ms(100); //startup delay



 //turning off all LEDs
 output_low(pin_A1);
 output_low(pin_A2);
 output_low(pin_A3); 
 output_low(pin_A4);



 //Powering up modem...
 output_high(pin_C1);    // Turn on Regulator
 output_high(pin_C5);   // Turn on Pwrkey
 Delay_ms(1000);     // wait 3 sec
 output_low(pin_C5);    // Turn off Pwrkey
 Delay_ms(3000);     // wait 3 sec
 output_high(pin_C5);   // Turn on Pwrkey  
 delay_ms(30000);    // wait for modem to establish connection 




 //modem power up indicator
 output_high(pin_A1);
 delay_ms(500);
 output_low(pin_A1); 
 



 
 
 




 
 // configure apn.......


 fprintf(Modem,"AT^SICS=0,conType,GPRS0\r\n");

 while(TRUE)
 {

  while(!kbhit(Modem));     //wait for char in USART buffer
   
  char1 = fgetc(Modem);   // get user input
      
  if(char1 == 'K')
  {
 
   fprintf(User,"%c",char1); // print to screen   

   delay_ms(100);

   break;
 
  }           

 } 

 fprintf(Modem,"AT^SICS=0,apn,\"greeninternet\"\r\n");

 while(TRUE)
 {

  while(!kbhit(Modem));     //wait for char in USART buffer
   
  char1 = fgetc(Modem);   // get user input
      
  if(char1 == 'K')
  {
 
   fprintf(User,"%c",char1); // print to screen
   
   delay_ms(100);

   break;
 
  }           

 }
 
 fprintf(Modem,"AT^SICS=0,user,userid\r\n");

 while(TRUE)
 {

  while(!kbhit(Modem));    //wait for char in USART buffer
   
  char1 = fgetc(Modem);   // get user input
      
  if(char1 == 'K')
  {
 
   fprintf(User,"%c",char1); // print to screen
   
   delay_ms(100);

   break;
 
  }           

 }

 fprintf(Modem,"AT^SICS=0,passwd,2110\r\n");

 while(TRUE)
 {

  while(!kbhit(Modem));    //wait for char in USART buffer
   
  char1 = fgetc(Modem);   // get user input
      
  if(char1 == 'K')
  {
 
   fprintf(User,"%c",char1); // print to screen
   
   delay_ms(100);

   break;
 
  }           

 } 











 // configure internet sevice..........

 fprintf(Modem,"AT^SISS=0,srvType,none\r\n");

 while(TRUE)
 {

  while(!kbhit(Modem));    //wait for char in USART buffer
   
  char1 = fgetc(Modem);   // get user input
      
  if(char1 == 'K')
  {
 
   fprintf(User,"%c",char1); // print to screen
   
   delay_ms(100);

   break;
 
  }           

 }
 
 fprintf(Modem,"AT^SISS=0,srvType,ftp\r\n");
 
 while(TRUE)
 {

  while(!kbhit(Modem));    //wait for char in USART buffer
   
  char1 = fgetc(Modem);   // get user input
      
  if(char1 == 'K')
  {
 
   fprintf(User,"%c",char1); // print to screen
   
   delay_ms(100);

   break;
 
  }           

 }

 fprintf(Modem,"AT^SISS=0,alphabet,1\r\n");

 while(TRUE)
 {

  while(!kbhit(Modem));    //wait for char in USART buffer
   
  char1 = fgetc(Modem);   // get user input
      
  if(char1 == 'K')
  {
 
   fprintf(User,"%c",char1); // print to screen
   
   delay_ms(100);

   break;
 
  }           

 }

 fprintf(Modem,"AT^SISS=0,conId,0\r\n"); 

 while(TRUE)
 {

  while(!kbhit(Modem));    //wait for char in USART buffer
   
  char1 = fgetc(Modem);   // get user input
      
  if(char1 == 'K')
  {
 
   fprintf(User,"%c",char1); // print to screen
   
   delay_ms(100);

   break;
 
  }           

 } 

 fprintf(Modem,"AT^SISS=0,tcpMR,3\r\n"); 

 while(TRUE)
 {

  while(!kbhit(Modem));    //wait for char in USART buffer
   
  char1 = fgetc(Modem);   // get user input
      
  if(char1 == 'K')
  {
 
   fprintf(User,"%c",char1); // print to screen
   
   delay_ms(100);

   break;
 
  }           

 }
 
 fprintf(Modem,"AT^SISS=0,tcpOT,3000\r\n"); 

 while(TRUE)
 {

  while(!kbhit(Modem));    //wait for char in USART buffer
   
  char1 = fgetc(Modem);   // get user input
      
  if(char1 == 'K')
  {
 
   fprintf(User,"%c",char1); // print to screen
   
   delay_ms(100);

   break;
 
  }           

 }

 fprintf(Modem,"AT^SISS=0,address,\"ftp://232.127.159.192;type=d\"\r\n"); 

 while(TRUE)
 {

  while(!kbhit(Modem));    //wait for char in USART buffer
   
  char1 = fgetc(Modem);   // get user input
      
  if(char1 == 'K')
  {
 
   fprintf(User,"%c",char1); // print to screen
   
   delay_ms(100);

   break;
 
  }           

 }



 // connnect to service...........

 fprintf(Modem,"AT^SISO=0\r\n");  

 while(TRUE)
 {

  while(!kbhit(Modem));    //wait for char in USART buffer
   
  char1 = fgetc(Modem);   // get user input
      
  if(char1 == 'K')
  {
 
   fprintf(User,"%c",char1); // print to screen
   
   delay_ms(5000);

   break;
 
  }           

 }








//problem 1


 fprintf(Modem,"AT^SISS=0,address,\"ftp://232.127.159.192/haseeb;type=a\"\r\n");
 
 while(TRUE)
 {

  while(!kbhit(Modem));    //wait for char in USART buffer
   
  char1 = fgetc(Modem);   // get user input
      
  //if(char1 == 'K')  
  //{
 
   fprintf(User,"%c",char1); // print to screen
   
  // delay_ms(100);

  // break;
 
  //}           

 }




//problem 2

 
 // wait for urc then receive some data.........

 fprintf(Modem,"at^sisr=0,1500\r\n");

 while(TRUE)
 {

  while(!kbhit(Modem));    //wait for char in USART buffer
   
  char1 = fgetc(Modem);   // get user input
      
  //if(char1 == 'K')
  //{
 
   fprintf(User,"%c",char1); // print to screen
   
  // delay_ms(100);

  // break;
 
  //}           

 }

 












 // close connection.........
 //at^sisc=0







 while(TRUE); //stay here forever






}
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top