CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

HTTP Client doesn't connect to websites

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
salihonur



Joined: 21 Mar 2020
Posts: 22

View user's profile Send private message

HTTP Client doesn't connect to websites
PostPosted: Sat Mar 21, 2020 6:24 am     Reply with quote

Hi,

I have a problem with HTTP Client. It can connect local IP addresses but not internet hosts or internet IPs with and without custom headers. I have tried many website and IP address.

I think HttpClientSetHostNameROM can't resolve DNS. Both SNTP and CCS SNTP doesn't get the epoch also.

Could you help me what is wrong?

CCS TCP/IP Stack version: 5.42.08
Compiler version: 5.081
MCU: PIC18F46K80

TCPIPConfig.h
Code:
#define STACK_USE_ICMP_SERVER    1
#define STACK_USE_TCP            1
#define STACK_USE_UDP            1
#define STACK_USE_DNS            1
#define STACK_USE_ARP            1
#define STACK_USE_DHCP_CLIENT    1
#define STACK_USE_CCS_SNTP_CLIENT    1
#define STACK_USE_CCS_ANNOUNCE       1
//#define STACK_USE_DNS_SERVER 1


#define STACK_CCS_SMTP_TX_SIZE    0
#define STACK_CCS_SMTP_RX_SIZE    0

#define STACK_USE_CCS_HTTP2_SERVER
#define STACK_CCS_HTTP2_SERVER_TX_SIZE    1500
#define STACK_CCS_HTTP2_SERVER_RX_SIZE    500
#define HTTP_NUM_SOCKETS                  1
#define HTTP_PORT                         (80u)
#define HTTP_USE_DOUBLE_ESCAPE            1
#import(RAW, file="mpfs/mpfsimg.bin", location=MPFS_Start)

#define STACK_USE_CCS_HTTP_CLIENT
#define STACK_MY_HTTPC_RX_SIZE    128
#define STACK_MY_HTTPC_TX_SIZE    128

#define STACK_MY_TELNET_SERVER_TX_SIZE    0
#define STACK_MY_TELNET_SERVER_RX_SIZE    0

#define MY_DEFAULT_HOST_NAME      "CCS_EXAMPLES"

#define MY_DEFAULT_MAC_BYTE1      (0x0)
#define MY_DEFAULT_MAC_BYTE2      (0x20)
#define MY_DEFAULT_MAC_BYTE3      (0x30)
#define MY_DEFAULT_MAC_BYTE4      (0x40)
#define MY_DEFAULT_MAC_BYTE5      (0x50)
#define MY_DEFAULT_MAC_BYTE6      (0x60)

#define MY_DEFAULT_IP_ADDR_BYTE1  (192ul)
#define MY_DEFAULT_IP_ADDR_BYTE2  (168ul)
#define MY_DEFAULT_IP_ADDR_BYTE3  (1ul)
#define MY_DEFAULT_IP_ADDR_BYTE4  (100ul)

#define MY_DEFAULT_GATE_BYTE1     (192ul)
#define MY_DEFAULT_GATE_BYTE2     (168ul)
#define MY_DEFAULT_GATE_BYTE3     (100ul)
#define MY_DEFAULT_GATE_BYTE4     (1ul)

#define MY_DEFAULT_MASK_BYTE1     (255ul)
#define MY_DEFAULT_MASK_BYTE2     (255ul)
#define MY_DEFAULT_MASK_BYTE3     (255ul)
#define MY_DEFAULT_MASK_BYTE4     (0ul)

#define TCP_CONFIGURATION      2

#define TCP_ETH_RAM_SIZE (STACK_CCS_SMTP_TX_SIZE + \
                          STACK_CCS_SMTP_RX_SIZE + \
                          STACK_CCS_HTTP2_SERVER_TX_SIZE + \
                          STACK_CCS_HTTP2_SERVER_RX_SIZE + \
                          STACK_MY_TELNET_SERVER_TX_SIZE + \
                          STACK_MY_TELNET_SERVER_RX_SIZE + \
                          STACK_MY_HTTPC_TX_SIZE + \
                          STACK_MY_HTTPC_RX_SIZE + \
                          100*TCP_CONFIGURATION)

// Define names of socket types
#define TCP_PURPOSE_GENERIC_TCP_CLIENT 0
#define TCP_PURPOSE_GENERIC_TCP_SERVER 1
#define TCP_PURPOSE_TELNET             2
#define TCP_PURPOSE_FTP_COMMAND        3
#define TCP_PURPOSE_FTP_DATA           4
#define TCP_PURPOSE_TCP_PERFORMANCE_TX 5
#define TCP_PURPOSE_TCP_PERFORMANCE_RX 6
#define TCP_PURPOSE_UART_2_TCP_BRIDGE  7
#define TCP_PURPOSE_HTTP_SERVER        8
#define TCP_PURPOSE_DEFAULT            9
#define TCP_PURPOSE_BERKELEY_SERVER    10
#define TCP_PURPOSE_BERKELEY_CLIENT    11
#define TCP_PURPOSE_CCS_SMTP           0x40

#ifndef MAX_HTTP_CONNECTIONS
   #define  MAX_HTTP_CONNECTIONS 1
#endif
#ifndef MAX_UDP_SOCKETS
   #define MAX_UDP_SOCKETS 7
#endif



main.c

Code:

int1 g_MyHttpSending = FALSE;

/* The CCS HTTP Client library is very flexible in the manners of which
data can be sent to the remote HTTP server an how to read response
data from the remote HTTP server. See the ccs_http_client.h file for
a full documentation of this API. */
char tcpResponse[512];
void MyHttpSend(void)
{
   // there are also non-ROM versions of these functions if you want to
   // dynamically control the parameters.
    debug_writeln("\rHttp client");
   HttpClientSetHostNameROM((rom char*)"kontrol3.com");
   HttpClientSetUrlROM((rom char*)"/test/index.php");
   HttpClientSetHostPort(80);
   
    //char header[1024];
    //strcpy(header, "Connection: keep-alive");
    //strcat(header, "\rUpgrade-Insecure-Requests: 1");
    //strcat(header, "\rUser-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36");
    //strcat(header, "\rAccept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9");
    //strcat(header, "\rAccept-Encoding: gzip, deflate");
    //strcat(header, "\rAccept-Language: tr-TR,tr;q=0.9,en-US;q=0.8,en;q=0.7");
    //strcat(header, "\r\n");
    //HttpClientSetCustomHeaders(header);
   
    //HttpClientSetCustomHeaders("nAccept: *.*\r\nAccept-Language: tr-tr\r\nHost: kontrol3.com\r\nAccept-Encoding: gzip\r\nConnection: Close\r\n\r\n");
   
    HttpClientStart();
   
    debug_write("Status while busy: ");
    debug_writeln(HttpClientGetResult());
}


Code:
if (TRIGGER && !g_MyHttpSending)    // todo: specify action condition, like a button press
      {
            TRIGGER = 0;
         g_MyHttpSending = TRUE;
         MyHttpSend();
           
      }
      else if (!HttpClientIsBusy() && g_MyHttpSending)
      {
         g_MyHttpSending = FALSE;
         // todo: if you want to see the pass/fail of the request,
         //       use HttpClientGetResult()

         // TODO: if you want to see the file returned from the server,
         // the methods for doing this depend on if you called
         // HttpClientSetResponseBuffer(). See the documentation
         // in ccs_http_client.h for more information.
           
            HttpClientSetResponseBuffer(tcpResponse, sizeof(tcpResponse));      // Global degisken olmali
           
            int httpStatus = HttpClientGetResult();
           
            debug_write("Status while not busy: ");
            debug_writeln(httpStatus);
           
            if( !httpStatus )            // OK
            {
                //while(HttpClientIsGetReady());
                debug_writeln(tcpResponse);
            }           
      }



Internet connection result
Code:
Http client
Status while busy: 5
Status while not busy: 3

Http client
Status while busy: 5
Status while not busy: 3

Http client
Status while busy: 5
Status while not busy: 3

Http client
Status while busy: 5
Status while not busy: 3

Http client
Status while busy: 5
Status while not busy: 3



Local IP connection result
Code:
Http client
Status while busy: 5
Status while not busy: 0
{"Base":"BTC","Target":"TRY","Ask":0.005,"Bid":5,"Timestamp":654564564}

Http client
Status while busy: 5
Status while not busy: 0
{"Base":"BTC","Target":"TRY","Ask":0.005,"Bid":5,"Timestamp":654564564}
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Mon Mar 23, 2020 2:45 am     Reply with quote

Look at the driver dns.c and the example ex_dnslookup.c
Understand the TCPIP driver, does not itself automatically perform DNS
lookup.
salihonur



Joined: 21 Mar 2020
Posts: 22

View user's profile Send private message

PostPosted: Tue Mar 31, 2020 4:35 pm     Reply with quote

Finally I have solved the problem. Wink I have added theese lines the end of IPAddressInit function:

Code:

AppConfig.PrimaryDNSServer = AppConfig.MyGateway.Val;
AppConfig.SecondaryDNSServer.Val = 0;


IPAddressInit
Code:
void IPAddressInit(void)
{
    //AppConfig.Flags.bIsDHCPEnabled = 0;
    //DHCPEnable(0);
   
   //MAC address of this unit
   MY_MAC_BYTE1=MY_DEFAULT_MAC_BYTE1;
   MY_MAC_BYTE2=MY_DEFAULT_MAC_BYTE2;
   MY_MAC_BYTE3=MY_DEFAULT_MAC_BYTE3;
   MY_MAC_BYTE4=MY_DEFAULT_MAC_BYTE4;
   MY_MAC_BYTE5=MY_DEFAULT_MAC_BYTE5;
   MY_MAC_BYTE6=MY_DEFAULT_MAC_BYTE6;

   //IP address of this unit
   MY_IP_BYTE1=MY_DEFAULT_IP_ADDR_BYTE1;
   MY_IP_BYTE2=MY_DEFAULT_IP_ADDR_BYTE2;
   MY_IP_BYTE3=MY_DEFAULT_IP_ADDR_BYTE3;
   MY_IP_BYTE4=MY_DEFAULT_IP_ADDR_BYTE4;

   //network gateway
   MY_GATE_BYTE1=MY_DEFAULT_GATE_BYTE1;
   MY_GATE_BYTE2=MY_DEFAULT_GATE_BYTE2;
   MY_GATE_BYTE3=MY_DEFAULT_GATE_BYTE3;
   MY_GATE_BYTE4=MY_DEFAULT_GATE_BYTE4;
   
   //subnet mask
   MY_MASK_BYTE1=MY_DEFAULT_MASK_BYTE1;
   MY_MASK_BYTE2=MY_DEFAULT_MASK_BYTE2;
   MY_MASK_BYTE3=MY_DEFAULT_MASK_BYTE3;
   MY_MASK_BYTE4=MY_DEFAULT_MASK_BYTE4;
   
    AppConfig.PrimaryDNSServer = AppConfig.MyGateway.Val;
    AppConfig.SecondaryDNSServer.Val = 0;
}
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group