void ntp_setup(void)
{
    tv_t tv;
    tz_t tz;
	time_t sec;

    if(!network_init)
		return;

	if(ntp_init == 0)
    {
        ip_addr_t *addr = (ip_addr_t *)os_zalloc(sizeof(ip_addr_t));
		ipaddr_aton("192.168.200.1", addr);
		sntp_setserver(1,addr);
		ipaddr_aton("192.168.200.240", addr);
		sntp_setserver(2,addr);
        sntp_init();
        os_free(addr);
		ntp_init = 1;
        DEBUG_PRINTF("NTP:1\n");
    }
	if(ntp_init == 1)
	{
		// they hard coded it to +8 hours from GMT
		sec = sntp_get_current_timestamp();
		if(sec > 10)
		{
			ntp_init = 2;
		}
	}
    if(ntp_init == 2)
    {
		sntp_stop();
		DEBUG_PRINTF("NTP:2\n");

		// they return GMT + 8
        sec = sec - (8UL * 3600UL);

		// we are GMT - 4
        sec = sec - (4UL * 3600UL);

        tv.tv_sec = sec;
        tv.tv_usec = 0;
        tz.tz_minuteswest = 0;

        settimeofday(&tv, &tz);

        DEBUG_PRINTF("SEC:%ld\n",sec);
        DEBUG_PRINTF("TIME:%s\n", ctime(&sec));
		ntp_init = 3;
    }
}
Esempio n. 2
0
/**
 * Initialize one of the NTP servers by IP address, required by DHCP
 *
 * @param numdns the index of the NTP server to set must be < SNTP_MAX_SERVERS
 * @param dnsserver IP address of the NTP server to set
 */
void
dhcp_set_ntp_servers(u8_t num, const ip4_addr_t *server)
{
  LWIP_DEBUGF(SNTP_DEBUG_TRACE, ("sntp: %s %u.%u.%u.%u as NTP server #%u via DHCP\n",
    (sntp_set_servers_from_dhcp ? "Got" : "Rejected"),
    ip4_addr1(server), ip4_addr2(server), ip4_addr3(server), ip4_addr4(server), num));
  if (sntp_set_servers_from_dhcp && num) {
    u8_t i;
    for (i = 0; (i < num) && (i < SNTP_MAX_SERVERS); i++) {
      ip_addr_t addr;
      ip_addr_copy_from_ip4(addr, server[i]);
      sntp_setserver(i, &addr);
    }
    for (i = num; i < SNTP_MAX_SERVERS; i++) {
      sntp_setserver(i, NULL);
    }
  }
}
Esempio n. 3
0
void ninit(void)
{
	sntp_init();
	ip_addr_t ip;
	int r = dns_gethostbyname("pool.ntp.org", &ip, ntp_dns_found, NULL);
    if (r == ESPCONN_OK)
    {
    	sntp_setserver(0, &ip);
    }

}
Esempio n. 4
0
LOCAL void ICACHE_FLASH_ATTR sntp_starts_here(){
	ipaddr_aton("192.168.254.30", &NTP1);
	//	sntp_setservername(0, ”bg.pool.ntp.org”); // set server 0 by domain name
	//	sntp_setservername(1, ”us.pool.ntp.org”); // set server 0 by domain name
	sntp_setserver(0,NTP1);
	sntp_set_timezone(+2);
	sntp_init();
	os_timer_disarm(&ds18b20_timer);
	os_timer_setfn(&ds18b20_timer, (os_timer_func_t *)sntp_cb, (void *)0);
	os_timer_arm(&ds18b20_timer, DELAY, 1);

}
irom static app_action_t application_function_ntp_set(const string_t *src, string_t *dst)
{
	int timezone;
	string_new(static, ip, 32);

	if((parse_string(1, src, &ip) == parse_ok) && (parse_int(2, src, &timezone, 0) == parse_ok))
	{
		config.ntp_server = ip_addr(string_to_ptr(&ip));
		config.ntp_timezone = timezone;

		sntp_setserver(0, &config.ntp_server);
		sntp_set_timezone(config.ntp_timezone);
	}

	return(application_function_ntp_dump(src, dst));
}
Esempio n. 6
0
static void
tcpip_init_done(void *arg)
{
  sys_sem_t *sem;
  sem = (sys_sem_t *)arg;

  init_netifs();

#if LWIP_IPV4
  netbiosns_set_name("simhost");
  netbiosns_init();
#endif /* LWIP_IPV4 */

  sntp_setoperatingmode(SNTP_OPMODE_POLL);
#if LWIP_DHCP
  sntp_servermode_dhcp(1); /* get SNTP server via DHCP */
#else /* LWIP_DHCP */
#if LWIP_IPV4
  sntp_setserver(0, netif_ip_gw4(&netif));
#endif /* LWIP_IPV4 */
#endif /* LWIP_DHCP */
  sntp_init();

#if LWIP_SNMP
  lwip_privmib_init();
#if SNMP_LWIP_MIB2
#if SNMP_USE_NETCONN
  snmp_threadsync_init(&snmp_mib2_lwip_locks, snmp_mib2_lwip_synchronizer);
#endif /* SNMP_USE_NETCONN */
  snmp_mib2_set_syscontact_readonly((const u8_t*)"root", NULL);
  snmp_mib2_set_syslocation_readonly((const u8_t*)"lwIP development PC", NULL);
  snmp_mib2_set_sysdescr((const u8_t*)"simhost", NULL);
#endif /* SNMP_LWIP_MIB2 */

  snmp_set_mibs(mibs, LWIP_ARRAYSIZE(mibs));
  snmp_init();
#endif /* LWIP_SNMP */
  
  sys_sem_signal(sem);
}
Esempio n. 7
0
void ntp_setup(void)
{
    tv_t tv;
    tz_t tz;
	time_t sec;
	struct ip_info getinfo;


	// Wait until we have an IP address before we set the time
    if(!network_init)
		return;

	if(ntp_init == 0)
    {
        ip_addr_t *addr = (ip_addr_t *)safecalloc(sizeof(ip_addr_t),1);

		// form pool.ntp.org
		ipaddr_aton("206.108.0.131", addr);
		sntp_setserver(1,addr);
		ipaddr_aton("167.114.204.238", addr);
		sntp_setserver(2,addr);

#if 0
		// Alternate time setting if the local router does NTP
		if(wifi_get_ip_info(0, &getinfo))
		{
			printf("NTP:0 GW: %s\n", ipv4_2str(getinfo.gw.addr));
			printf("NTP:0 IP: %s\n", ipv4_2str(getinfo.ip.addr));
			sntp_setserver(1, & getinfo.gw);
			sntp_setserver(2, & getinfo.ip);
		}
		else
		{
			printf("NTP:0 failed to get GW address\n");
			return;
		}
#endif

        if( sntp_set_timezone(0) )
		{
			printf("NTP: set_timeone OK\n");
			sntp_init();
            safefree(addr);
		    ntp_init = 1;
            printf("NTP:1\n");
		}
		else
		{
			printf("NTP: set_timeone Failed\n");
		}
    }

	if(ntp_init == 1)
	{
		// they hard coded it to +8 hours from GMT
		if( (sec = sntp_get_current_timestamp()) > 10 )
		{
			sntp_stop();
			ntp_init = 2;
		}
	}
	if(ntp_init == 2)
	{
		time_t s;

		tm_t *p;

		printf("NTP:2\n");

		// they return GMT + 8
        // sec = sec - (8UL * 3600UL);

        tv.tv_sec = sec;
		printf("ntp_init: %s\n", asctime(gmtime(&sec)));
		printf("ntp_init: %s\n", ctime_gm(&sec));

        tv.tv_usec = 0;
        tz.tz_minuteswest = 300;
		tz.tz_dsttime = 0;

        settimeofday(&tv, &tz);

        printf("SEC:%ld\n",sec);
        printf("TIME:%s\n", ctime(&sec));
		printf("Zone: %d\n", (int) sntp_get_timezone());
		ntp_init = 3;

		set_dst(tv.tv_sec);

		print_dst_gmt();
		print_dst();

		p = gmtime(&tv.tv_sec);
		mktime(p);
		printf("Localtime: %s\n", asctime(p));
    }
}
Esempio n. 8
0
void ntp_dns_found(const char *name, ip_addr_t *ipaddr, void *arg)
{

	sntp_setserver(0, ipaddr);
}