+ Post New Thread
Results 1 to 5 of 5
  1. #1
    Full Member level 1
    Points: 907, Level: 6

    Join Date
    Apr 2016
    Posts
    116
    Helped
    0 / 0
    Points
    907
    Level
    6

    PIC18F87J60 send GET to HTTP server

    Hey
    I want my PIC18F87J60 to act as client and send GET to HTTP server.
    I am using:
    http://download.mikroe.com/documents...60_library.htm
    I can't see any functions for that.
    any ideas?

    •   AltAdvertisement

        
       

  2. #2
    Full Member level 2
    Points: 1,744, Level: 9

    Join Date
    Feb 2010
    Location
    Pennsylvania, U.S.
    Posts
    131
    Helped
    21 / 21
    Points
    1,744
    Level
    9

    Re: PIC18F87J60 send GET to HTTP server

    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?



    •   AltAdvertisement

        
       

  3. #3
    Full Member level 1
    Points: 907, Level: 6

    Join Date
    Apr 2016
    Posts
    116
    Helped
    0 / 0
    Points
    907
    Level
    6

    Re: PIC18F87J60 send GET to HTTP server

    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?



    •   AltAdvertisement

        
       

  4. #4
    Full Member level 2
    Points: 1,744, Level: 9

    Join Date
    Feb 2010
    Location
    Pennsylvania, U.S.
    Posts
    131
    Helped
    21 / 21
    Points
    1,744
    Level
    9

    Re: PIC18F87J60 send GET to HTTP server

    I don't have any experience with this chip or the application. A quick Google search turned up this, which may be helpful:

    http://forum.mikroe.com/viewtopic.ph...9&hilit=client

    I hope you figure things out, or someone replies with more knowledge.



  5. #5
    Advanced Member level 4
    Points: 7,866, Level: 21

    Join Date
    Jan 2015
    Posts
    1,104
    Helped
    346 / 346
    Points
    7,866
    Level
    21

    Re: PIC18F87J60 send GET to HTTP server

    Quote Originally Posted by upand_at_them View Post
    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



--[[ ]]--