This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

RL-ARM http-server

Hello!

I'm trying to run HTTP-server on my LPC1788 board. lwip stack works fine. But when I try to run http-server under RL-ARM programm doesn't start at all. I included to my project follow files: EMAC_LPC177x_8x.c, Net_Config.c, TCP_CM3.lib, TCPD_CM3.lib (and corresponding headers Net_Config.h, EMAC_LPC177x_8x.h). Here my program:

include "LPC177x_8x.h"
#include "debug_frmwrk.h"
#include "RTL.h"

int main (void)
{
   SystemInit();

        debug_frmwrk_init();
        _DBG_("Started!");

        init_TcpNet ();

   while (1)
   {
      main_TcpNet();
   }

}


I want just to try ping my board from my PC Ethernet. Do you mind to explain to me what is wrong?

Regards, Vasilij.

Parents Reply Children
  • I don't exactly understand what you mean, sorry. Should I manualy create tcp_callback?

  • Yep, and need to open a socket too, look into the sample projects provided by keil.

    
    U16 tcp_callback (U8 soc, U8 event, U8 *ptr, U16 usPar) {
    
            // look for project example about what to do on this function
            return (0);
            }
    
    
    
    int main (void) {
    
            SystemInit();
    
            init_TcpNet ();
    
            tcp_soc = tcp_get_socket (TCP_TYPE_SERVER , 0, 120, tcp_callback);
    
            if (tcp_soc != 0) {
                    // Start listening on TCP port 80.
                    tcp_listen (tcp_soc, 80);       }
    
    
            while (1)
                    {
    
                    main_TcpNet ();
    
                    if(DATA_received == __TRUE )
                            {
                            process_incoming();
                            DATA_received = __FALSE;
    
                            }
    
                    }
            }
    
    

  • Sorry, what I gave you relates to TCP server, I'm not sure if that is what you are looking for.

  • It's that what I need! Thank you a lot for your help!

  • It's still don't working. I noticed that in my board used LAN8720 and in and in EMAC_LPC177x_8x.c LAN8700 used. Does it compatible?

  • YES AND THEY HAVE DIFFERENT IDENTIFIER VALUES. YOU MUST EDIT THE FILE.

  • Vasilij,

    Maybe you need to rebuild using the correct PHY constant defined...?

  • Tamir Michael,

    Where is this constant located?

  • I don't use TCPNet anymore, but it should be in EMAC_LPC177x_8x.c:

    #ifdef _DP83848_
      #define PHY_DEF_ADR    DP83848C_DEF_ADR
      #define PHY_ID         DP83848C_ID
    #else
      #define PHY_DEF_ADR    KSZ8001_DEF_ADR
      #define PHY_ID         KSZ8001_ID
    #endif
    

  • Thank you very much, it works!!! Another one question, do you mind?
    I need to dynamically create web pages using data from SD card and send large amounts of data by HTTP. Haw can I manually create HTTP responses?

  • yep, look for example : Keil\ARM\Boards\Keil\MCB1700\EasyWEB

  • You need to read TCPNet's user manual. Normally this is achieved by callback functions the user implements.

  • I try to respond to all tcp massages that come to my board by tcp_send (soc, "OLOLO!", 6); (soc - soket that used). I some changed LEDSwitch sample:

    U16 tcp_callback (U8 soc, U8 evt, U8 *ptr, U16 par) {
      /* This function is called by the TCP module on TCP event */
      /* Check the 'Net_Config.h' for possible events.          */
      par = par;
    
      if (soc != socket_tcp) {
        return (0);
      }
    
      switch (evt) {
        case TCP_EVT_DATA:
          /* TCP data frame has arrived, data is located at *par1, */
          /* data length is par2. Allocate buffer to send reply.   */
        //  procrec(ptr);
                            tcp_send (soc, "OLOLO!", 6);
          break;
    
        case TCP_EVT_CONREQ:
          /* Remote peer requested connect, accept it */
          return (1);
    
        case TCP_EVT_CONNECT:
                            tcp_send (soc, "OLOLO!", 6);
          /* The TCP socket is connected */
          return (1);
      }
      return (0);
    }
    


    But answer doesn't come (I'm using Putty). What is wrong?

  • If I remember well tcp_send cannot be used from inside the callback.

    And before invoking the tcp_send you need to get the tcp buffer which is the only one that tcp_send likes so invoking directly tcp_send (soc, "OLOLO!", 6); !!!! WILL NOT WORK.

    do something like this:

    void send_data (void) {
    
            U32 unMax;
            U8 *ucSendbuf;
            U32 unIndex;
    
            if (tcp_check_send (tcp_soc))
                    {
                    unMax = your_size;
                    ucSendbuf = tcp_get_buf (unMax);
    
                    // copy bytes to send buffer.
                    for (unIndex = 0; unIndex < your_size; unIndex++)
                            {
                            ucSendbuf[unIndex]  = your_data;
                            }
    
                    tcp_send (tcp_soc, ucSendbuf, your_size);
    
                    }
    
            }
    

  • Finally I did it! Once again thanks a lot for your help! My code follow:

    void send_data (U8 tcp_soc)
    {
    
        U32 unMax;
        U8 *ucSendbuf;
                    U8 data[] = "HTTP/1.0 200 Ok\r\nContent-Type: text/html; charset=utf-8\r\nConnection: close\r\n\r\n<html><head>Hello!</head><body> <h1>Nothing to see here</h1></body></html>\n";//
    
            if (tcp_check_send (tcp_soc))
            {
                                            unMax = tcp_max_dsize (sizeof(data));
              ucSendbuf = tcp_get_buf (unMax);
                                            memcpy(ucSendbuf, data, sizeof(data));
              tcp_send (tcp_soc, ucSendbuf, sizeof(data));
           }
    
     }
    
    static void timer_poll () {
      /* System tick timer running in poll mode */
      static U32 time;
    
      if (SysTick->CTRL & 0x10000) {
        time++;
        if (time == 10) {
          /* Timer tick every 100 ms */
          time = 0;
          timer_tick ();
        }
      }
    }
    
    //Opened socket-----
    static U8 socket_tcp;
    
    U16 tcp_callback (U8 soc, U8 evt, U8 *ptr, U16 par) {
    
      par = par;
    
      if (soc != socket_tcp) {
        return (0);
      }
    
      switch (evt) {
    
        case TCP_EVT_DATA:
    flag = 1;
          return (1);
    
        case TCP_EVT_CONREQ:
          return (1);
    
        case TCP_EVT_CONNECT:
          return (1);
    
        case TCP_EVT_ACK:
          return (1);
    
      }
      return (0);
    }
    
    void webServerTsk (void *pvParameters)
    {
            init_TcpNet ();
            socket_tcp = tcp_get_socket (TCP_TYPE_SERVER, 0, 10, tcp_callback);
            if (socket_tcp != 0) tcp_listen (socket_tcp, 80);//PORT_NUM
            for(;;)
            {
                    timer_poll ();
                    main_TcpNet ();
                    if(flag == 1)
                    {
                            //It works and sends data
                            send_data (socket_tcp);
    
                            //It doesn't work and doesn't send data
                            send_data (socket_tcp);
                            flag = 0;
                    }
                    portYIELD();
            }
    }
    

    But now I can't to send more than one TCP message. What I'm doing wrong?