Ping_start function

hdrut
Posts: 25
Joined: Fri Feb 13, 2015 11:02 am
Location: Argentina

Ping_start function

Postby hdrut » Thu Jun 11, 2015 5:59 am

Hi,

can you give some examples on using the ping_start function ?
I can't seem to make it work...

My code is:



struct ping_option pingopt;

void ping(uint32 ip)
{
pingopt.ip=ip;
pingopt.count = 100;
pingopt.coarse_time = 1;
pingopt.recv_function=NULL;
pingopt.sent_function=NULL;
ping_start(&pingopt);
}


uint32 ipaddr = ((uint32)((192) & 0xff) << 24) | \
((uint32)((168) & 0xff) << 16) | \
((uint32)((4) & 0xff) << 8) | \
(uint32)((100) & 0xff);
os_printf("IP: %u\n", ipaddr);
ping(ipaddr);


Thks

ESP_Faye
Posts: 1614
Joined: Mon Oct 27, 2014 11:08 am

Re: Ping_start function

Postby ESP_Faye » Tue Jun 30, 2015 3:18 pm

Hi,

Please try this

Code: Select all


void ICACHE_FLASH_ATTR
user_ping_recv(void *arg, void *pdata)
{
    struct ping_resp *ping_resp = pdata;
    struct ping_option *ping_opt = arg;

    if (ping_resp->ping_err == -1)
        os_printf("ping host fail \r\n");
    else
        os_printf("ping recv: byte = %d, time = %d ms \r\n",ping_resp->bytes,ping_resp->resp_time);

}
void ICACHE_FLASH_ATTR
user_ping_sent(void *arg, void *pdata)
{
    os_printf("user ping finish \r\n");
}


void ICACHE_FLASH_ATTR
user_test_ping(void)
{
    struct ping_option *ping_opt = NULL;
    const char* ping_ip = "192.168.1.114";

    ping_opt = (struct ping_option *)os_zalloc(sizeof(struct ping_option));

    ping_opt->count = 10;    //  try to ping how many times
    ping_opt->coarse_time = 2;  // ping interval
    ping_opt->ip = ipaddr_addr(ping_ip);

    ping_regist_recv(ping_opt,user_ping_recv);
    ping_regist_sent(ping_opt,user_ping_sent);

    ping_start(ping_opt);

}

Who is online

Users browsing this forum: YimingLi and 6 guests