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.

[PIC] PIC18F87J60 send GET to HTTP server

Status
Not open for further replies.
It looks like it can only handle requests to it. That is, to act as a web server. Not a client.

Perhaps that is the limitation of that PIC?
 

I have found library that does that but my code sends a valid GET once and then gets stuck/broken until I hardware reset the chip....

I am using function Net_Ethernet_Intern_startSendTCP to start TCP connection.

Code:
#include "__NetEthInternal.h"



SOCKET_Intern_Dsc *clientSock;

                    // ipconfig /all

unsigned char   myMacAddr[6] = {0x00, 0x14, 0xA5, 0x76, 0x19, 0x3f} ;   // my MAC address
unsigned char   myIpAddr[4]  = {192, 168, 0, 123 } ;                   // my IP address
unsigned char   gwIpAddr[4]  = {192, 168, 0, 1 } ;                   // gateway (router) IP address
unsigned char   ipMask[4]    = {255, 255, 255,  0 } ;                   // network mask (for example : 255.255.255.0)
/// not sure, but ipconfig says so..
unsigned char   dnsIpAddr[4] = {208, 67, 222, 222 } ;                   // DNS server IP address

unsigned char   getRequest[15];                                        // HTTP request buffer
unsigned char   dyna[31] ;                                             // buffer for dynamic response



SOCKET_Intern_Dsc *socketHTML;
volatile int sentFlag = 0;
  volatile int wantToSent = 0;
void Net_Ethernet_Intern_UserTCP(SOCKET_Intern_Dsc *socket) {
  unsigned int    len;
  

  // I listen only to web request on port 80
//  if(socket->destPort != 80) {
 ///   Net_Ethernet_Intern_putStringTCP("Hello", socket);
//    return;
 /// }
     if(socket == clientSock && wantToSent == 1)
     {
                unsigned char sendline[64];
                unsigned char host[32] = {     "192.168.0.100" };
                unsigned char page[32] = {     "/test.php" };
                unsigned char remoteIpAddr[4] = {0};
                unsigned char sntpPkt[48]     = {0};
                unsigned char poststr[64] = { 0 };

     wantToSent = 0;

              sprintf(sendline,
                   "GET %s HTTP/1.0\r\n"
                   "\r\n", page);
    Net_Ethernet_Intern_putStringTCP(sendline, socket);
   // Net_Ethernet_Intern_disconnectTCP(socket);
   sentFlag = 1;
                   return;
     }
     if(socket == clientSock && sentFlag == 1)
     {
                           if (Net_Ethernet_Intern_bufferEmptyTCP(clientSock))
                           {
                              Net_Ethernet_Intern_disconnectTCP(clientSock)  ;
                              clientSock = 0;
                              }
     }

}

////////////////////////////////////////////////////////////////////////////////

unsigned int    Net_Ethernet_Intern_UserUDP(UDP_Intern_Dsc *udpDsc) {


  return(0);
}

// Initialization of Timer1
unsigned int cnt;
void MCUInit() {

  ADCON1 |= 0x0F;      // Configure AN pins as digital
  CMCON  |= 7;         // Disable comparators

  cnt = 0;             // Initialize cnt
  TRISB = 0;           // PORTB is output
  PORTB = 0xFF;        // Initialize PORTB

  T0CON  = 0xC4;       // Set TMR0 in 8bit mode, assign prescaler to TMR0
  INTCON = 0xC0;       // Set GIE, PEIE
  TMR0IE_bit = 1;      // Enable TMRO interrupt

}

// Interrupt routine
void interrupt() {
  if (TMR0IF_bit) {
    cnt++;             // Increment value of cnt on every interrupt
    if (cnt >= 2500) {
      PORTD = ~PORTD;  // Toggle PORTB LEDs
      cnt = 0;         // Reset cnt
      Net_Ethernet_Intern_UserTimerSec++;
    }
    TMR0L  = 96;
    TMR0IF_bit = 0;    // clear TMR0IF
  }
}

char i;

void test()
{
        unsigned char remoteIpAddr[4] = {192,168,0,100};
        Net_Ethernet_Intern_sendUDP( remoteIpAddr, 11000, 11000, "Hello from PIC18 Ethernet!", 48 );
        Delay_ms(1);
}


void main() {
int port = 1100;
  int cnt = 0;
          ADCON1 = 0xff;
  TRISA.F0 = 0; //Makes PORTA0 or RA0 Output Pin
  TRISA.F1 = 0; //Makes PORTA1 or RA1 Output Pin

  for(i = 0; i < 5; i++)
  {
    PORTA.F0 = 1; //LED ON
    PORTA.F1 = 1; //LED ON
    Delay_ms(200); //1 Second Delay
    PORTA.F0 = 0; //LED OFF
    PORTA.F1 = 0; //LED OFF
    Delay_ms(200); //1 Second Delay

  }

        MCUInit();

     //   OSCTUNE = 0b01000000;
        PORTD = 0;
        TRISD = 0;                // set PORTD as output,
        PORTA = 0 ;
        TRISA &= ~0b11 ;        // RA0 and RA1 will be used as
                                // ethernet's LEDA and LEDB

        Net_Ethernet_Intern_Init(myMacAddr, myIpAddr, Net_Ethernet_Intern_FULLDUPLEX) ; // init ethernet board
        Net_Ethernet_Intern_confNetwork(ipMask, gwIpAddr, dnsIpAddr);
        Delay_ms(1000);



        Net_Ethernet_Intern_stackInitTCP();


        while(1)
         {

        unsigned char remoteIpAddr[4] = {192,168,0,100};
       // Net_Ethernet_Intern_sendUDP( remoteIpAddr, 11000, 11000, "Hello from PIC18 Ethernet!", 48 );
          again:
                                         port = 1000;
 while( Net_Ethernet_Intern_connectTCP(remoteIpAddr, 80, port, &clientSock) != 1)
 {
          Net_Ethernet_Intern_doPacket();
 }
   i = 0;
     while (clientSock->state != 3)
     {
        i++;
          Net_Ethernet_Intern_doPacket();
          if(i > 1000)
            goto again;
     }
     wantToSent = 1;
        sentFlag = 0;
       //Call Net_Ethernet_Intern_UserTCP function
       Net_Ethernet_Intern_startSendTCP(clientSock);
       //Net_Ethernet_Intern_disconnectTCP(sock);
        while(sentFlag != 1)
        {
          Net_Ethernet_Intern_doPacket();
        }
    while( clientSock != 0)
    {
          Net_Ethernet_Intern_doPacket();
    }
    for(i = 0; i < 1000; i++)
     {
     delay_ms(1);
          Net_Ethernet_Intern_doPacket();
     }
       }
    
}

Any ideas what's wrong?
 

Perhaps that is the limitation of that PIC?
The PIC in question is not the limiting factor, but the library is. The Microchip IP stack (in the Microchip Application Library - it may not be usable with the MikroC compiler but I've used it many times with free Microchip IDE and compilers) can certainly handle this.
Susan
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top