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

18F67j50 http client problem

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



Joined: 16 May 2006
Posts: 95

View user's profile Send private message

18F67j50 http client problem
PostPosted: Mon Oct 08, 2018 8:26 am     Reply with quote

Hi all..
I have a big problem. I used pic18f67j50 and enc28j60. I created new project with ccs wizard. I used http client project. I tried below option.

1- auto ip (dhcp enable) connect to www.mypage.com result is OK
2- auto ip (dhcp enable) connect to 216.70.123.120 (example ip) result OK

3- static ip (dhcp disable) connect to 216.70.123.120 (example ip) result OK
4- static ip (dhcp disable) connect to www.mypage.com result is FAIL

what is the problem?
Thanks
temtronic



Joined: 01 Jul 2010
Posts: 9097
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Oct 08, 2018 8:42 am     Reply with quote

well I tried going to www.mypage.com.. and my W7 FFox says insecure connection, and it'll track my PC. Also nothing comes up(I assume that's my browser protecting me...)
I'll assume the PC with www.mypage.com is running from needs to be configured to allow the PIC (and me..) to connect.
respected



Joined: 16 May 2006
Posts: 95

View user's profile Send private message

PostPosted: Mon Oct 08, 2018 8:48 am     Reply with quote

mypage.com (this is an example address)

my web page is www.mcugomsis.site

ip 35.233.222.163
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Mon Oct 08, 2018 10:11 am     Reply with quote

How is it going to find the IP address of www.mypage.com?.
Remember DHCP supplies the DNS address as well.
I'd suspect it can't resolve the name to an IP address.
respected



Joined: 16 May 2006
Posts: 95

View user's profile Send private message

PostPosted: Mon Oct 08, 2018 11:36 am     Reply with quote

I thing i solved problem. If I wait 30 sec. it has not problem. Because HttpClientIsBusy() function returned value 0. 30 sec. later returned value 1 and i can send data.
respected



Joined: 16 May 2006
Posts: 95

View user's profile Send private message

PostPosted: Wed Oct 10, 2018 8:45 am     Reply with quote

if(DNSBeginUsage()) DNSResolveROM("mcugomsis.site",DNS_TYPE_A);
DNSEndUsage();

printf(lcd_putc,"%03u:%03u:%03u:%03u",ResolvedInfo.IPAddr.v[0],ResolvedInfo.IPAddr.v[1],ResolvedInfo.IPAddr.v[2],ResolvedInfo.IPAddr.v[3]);

returned 000.000.000.000

I don't understand how is it resolve dns
respected



Joined: 16 May 2006
Posts: 95

View user's profile Send private message

PostPosted: Thu Oct 11, 2018 12:59 am     Reply with quote

I think this is only my problem or all moderator don't know how to resolve. or they don't want to share any info.

TCPIPCONFIG.h
Code:
#ifndef __TCPIPCONFIG_H
#define __TCPIPCONFIG_H

#include "GenericTypeDefs.h"
#include "Compiler.h"

#define STACK_USE_ICMP_SERVER    1
#define STACK_USE_TCP            1
#define STACK_USE_DHCP_CLIENT    1



#define STACK_CCS_SMTP_TX_SIZE    0
#define STACK_CCS_SMTP_RX_SIZE    0

#define STACK_CCS_HTTP2_SERVER_TX_SIZE    0
#define STACK_CCS_HTTP2_SERVER_RX_SIZE    0

#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  (101ul)

#define MY_DEFAULT_GATE_BYTE1     (192ul)
#define MY_DEFAULT_GATE_BYTE2     (168ul)
#define MY_DEFAULT_GATE_BYTE3     (1ul)
#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      1

#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

#endif



main.c

Code:
                                                                                                                           
#include <main.h>   
int1 g_MyHttpSending = FALSE;
char device_id[10]="ac109021";
float T=2;
int16 sendcontrol=0;

#int_timer1                                     
void timer1()                                             
{
  sendcontrol++; 
   set_timer1(32767);
}


 
void MyHttpSend(void)
{


sprintf(http_data,"%s&Temp=%03.1f",device_id,T);
     HttpClientSetHostPort(80);
     static char cgi[256];                                                 
     cgi[0] = 0;       
   
     
       HttpClientSetHostNameROM((rom char*)"mcugomsis.site");
       HttpClientSetUrlROM((rom char*)"/data.php");       
       HttpClientAppendCgiROM(cgi, (rom char*)"Id", (char*)http_data,sizeof(cgi));   
                                                                                                                                 
       HttpClientSetCgiGet(cgi);                 
       HttpClientStart();   

       StackTask();
       StackApplications();
     

}   
 
 


void IPAddressInit(void)
 {                                                       
 
   //AppConfig.Flags.bIsDHCPEnabled = TRUE;
   // DHCPEnable(0); //enable nicWide stack support.

      //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;                         
   
      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;
     
   }
   


void main()
{                                       
   
   IPAddressInit();   
   TickInit();                                                                                                   

   lcd_init();
   setup_timer_1(T1_EXTERNAL| T1_DIV_BY_1|T1_CLK_OUT );
   set_timer1(32767);                                                   
   
   enable_interrupts(INT_TIMER1);
   enable_interrupts(GLOBAL);   
   StackInit();
   

while(TRUE)     
{

  StackTask();
  StackApplications();
   lcd_gotoxy(1,2);
   printf(lcd_putc,"%03u:%03u:%03u:%03u",MY_IP_BYTE1,MY_IP_BYTE2,MY_IP_BYTE3,MY_IP_BYTE4);
   lcd_gotoxy(1,3);                                                                                     
   printf(lcd_putc,"%02d/%02d/%02Lu /%02Lu :%02Lu",HttpClientIsBusy() ,DHCPBoundOrDisabled(),HttpClientGetResult(),timerkontrol,gonderimkontrol);
   lcd_gotoxy(1,4);
   printf(lcd_putc,"%03u:%03u:%03u:%03u",ResolvedInfo.IPAddr.v[0],ResolvedInfo.IPAddr.v[1],ResolvedInfo.IPAddr.v[2],ResolvedInfo.IPAddr.v[3]);
 


                                                       
if ( (!HttpClientIsBusy())&&(DHCPBoundOrDisabled())&&(sendcontrol>(59)))
  { 
     StackApplications();                 
      g_MyHttpSending = TRUE;                                                                                                   
      MyHttpSend();                             
      sendcontrol=0;         
   
   }                                       
      else if (!HttpClientIsBusy() && g_MyHttpSending)                                               
      {
         g_MyHttpSending = FALSE;                           
                                                                               
                       
      }
     
   
   }//while

} //main             
 


Last edited by respected on Thu Oct 11, 2018 1:16 am; edited 1 time in total
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Thu Oct 11, 2018 1:14 am     Reply with quote

You do understand, that a device wanting to connect to a 'named' location on the internet, has to issue a DNS request to get this resolved to a physical IP address.
To do this is has to know the IP address of the DNS server the network is allowed to use (so either a specific IP for your service provider or a 'public' one like Google). With this it can 'call' this address and ask for the IP address corresponding to the name. Without knowledge of where to go for DNS, the device can't resolve a name to an IP address.
Now your device was being given the IP of the DNS server by DHCP. You have disabled DHCP, so it doesn't know who to ask for the IP address. With DHCP disabled, the code on your device will need to have a legitimate DNS server address 'hard coded'.
I have to ask 'why'?. Just use DHCP. That is what it is there for....
respected



Joined: 16 May 2006
Posts: 95

View user's profile Send private message

PostPosted: Thu Oct 11, 2018 1:27 am     Reply with quote

I have to use static ip. Because there is firewall where i use device.
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Thu Oct 11, 2018 1:38 am     Reply with quote

So setup a static IP on the firewall for the device. You can still use DHCP.
respected



Joined: 16 May 2006
Posts: 95

View user's profile Send private message

PostPosted: Thu Oct 11, 2018 1:40 am     Reply with quote

So just second. You say to me you use DHCP and you can use static ip for device. Is true? If yes how?
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Thu Oct 11, 2018 1:45 am     Reply with quote

Your firewall should have an option to supply a fixed address to specific devices. Static DHCP.

<https://wiki.dd-wrt.com/wiki/index.php/Static_DHCP>
This is an example for a particular router. However most/all offer this.

This is how you can do things like port forwarding for a data server sitting on a network.

Your device then behaves as a normal device on the network, but when the router 'sees' it's particular MAC address in a DHCP request, it will always give it the same IP.
respected



Joined: 16 May 2006
Posts: 95

View user's profile Send private message

PostPosted: Thu Oct 11, 2018 1:54 am     Reply with quote

Thanks for your answers. I think first choice is the best for me.

https://dns.google.com/resolve?name=mcugomsis.site&type=A

answer

Code:
{"Status": 0,"TC": false,"RD": true,"RA": true,"AD": false,"CD": false,"Question":[ {"name": "mcugomsis.site.","type": 1}],"Answer":[ {"name": "mcugomsis.site.","type": 1,"TTL": 59,"data": "35.233.222.163"}],"Comment": "Response from 216.239.34.108."}


This is my ip: 35.233.222.163
Ingmar



Joined: 11 Oct 2018
Posts: 1

View user's profile Send private message

PostPosted: Thu Oct 11, 2018 4:22 am     Reply with quote

respected wrote:
Thanks for your answers. I think first choice is the best for me.

https://dns.google.com/resolve?name=mcugomsis.site&type=A

answer

Code:
{"Status": 0,"TC": false,"RD": true,"RA": true,"AD": false,"CD": false,"Question":[ {"name": "mcugomsis.site.","type": 1}],"Answer":[ {"name": "mcugomsis.site.","type": 1,"TTL": 59,"data": "35.233.222.163"}],"Comment": "Response from 216.239.34.108."}


this is my ip: 35.233.222.163

Thanks for the link.
respected



Joined: 16 May 2006
Posts: 95

View user's profile Send private message

PostPosted: Thu Oct 11, 2018 1:51 pm     Reply with quote

1- i sent to thingspeak my ip address.
2- i want to data like below command (pic or browser)

Code:
http://18.235.222.172/channels/600214/fields/1.json?api_key=.....api_key...&results=2


3- thingspeak's answer

Code:
{"channel":{"id":600214,"name":"IP","latitude":"0.0","longitude":"0.0","field1":"Field Label 1","created_at":"2018-10-11T19:21:47Z","updated_at":"2018-10-11T19:21:47Z","last_entry_id":1},"feeds":[{"created_at":"2018-10-11T19:31:04Z","entry_id":1,"field1":"035.233.222.163"}]}


This is my ip : field1":"035.233.222.163"

After that i used static ip and i sent to server successfully. Because i use ip number (server ip number).

If change my ip later, i can change on the thingspeak.
Maybe my method is stupid, but it works.
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