Author Topic: Probably Stupid Question, How To Enter "ip_addr_t *addr"?  (Read 2469 times)

0 Members and 1 Guest are viewing this topic.

Offline The DoktorTopic starter

  • Regular Contributor
  • *
  • Posts: 163
  • Country: us
Probably Stupid Question, How To Enter "ip_addr_t *addr"?
« on: May 08, 2018, 02:04:52 am »
I'm trying to use the SNTP client in an esp8266 with the Arduino IDE. Having some trouble, no doubt caused by misunderstanding.

#include<sntp.h> //works

under setup
sntp_set_timezone(-5); //works
sntp_setserver(u8_t index, ip_addr_t *addr) //this I can't figure out

I found these functions in Kolban's esp8266 book. I'm no programmer by any measure, but usually beat my way through any problems by means of persistence, google, and wine(not the Linux kind :) )

The 1st parameter is the servers index, no problem here it accepts 0, 1, or 2. The address has me stumped. I'm trying to use my local NTP server, located at 192.168.0.105 and accessed by several devices on my LAN. I can't figure out how to enter that address. I've tried:

192.168.0.105(error: too many decimal points in number)
"192.168.0.105" (error: cannot convert 'const char*' to 'ip_addr_t* {aka ip4_addr*}' for argument '2' to 'void sntp_setserver(unsigned char, ip_addr_t*)')
192,168,0,105 (error: too many arguments to function 'void sntp_setserver(unsigned char, ip_addr_t*)')
"192,168,0,105"(error: cannot convert 'const char*' to 'ip_addr_t* {aka ip4_addr*}' for argument '2' to 'void sntp_setserver(unsigned char, ip_addr_t*)')

I can't think of any other way to express that address. What am I doing wrong?

 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11238
  • Country: us
    • Personal site
Re: Probably Stupid Question, How To Enter "ip_addr_t *addr"?
« Reply #1 on: May 08, 2018, 02:31:27 am »
Code: [Select]
ip_addr_t addr;

// Initialize addr according to whatever it is

sntp_setserver(0, &addr);

You need to lookup whatever ip_addr_t is and setup fields accordingly (assuming it is a structure).

And if this code is based on LwIP, then initialization will look like this
Code: [Select]
IP4_ADDR(&addr, 192,168,0,105);
« Last Edit: May 08, 2018, 02:35:42 am by ataradov »
Alex
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4199
  • Country: us
Re: Probably Stupid Question, How To Enter "ip_addr_t *addr"?
« Reply #2 on: May 08, 2018, 02:43:38 am »
It looks like ip_addr_t is defined in tools/sdk/lwip2/include/lwip/ip_addr.h, along with macros to initialize it.
perhaps something like
Code: [Select]ip_addr_t remote_ip = IPADDR4_INIT_BYTES(192, 168, 0, 105);
sntp_setserver(index, &remote_ip);
Since ip_add_t is a relatively complex structure (handles IPv6 and IPv4 as a union, for instance), I don't think you'll be able to use a literal constant in the function call...
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf