Is wifi_set_event_handler_cb() Broken?

ming
Posts: 4
Joined: Sat Aug 01, 2015 8:33 am

Is wifi_set_event_handler_cb() Broken?

Postby ming » Thu Dec 03, 2015 6:30 am

Just tried SDK 1.5 with my code. The wifi_set_event_handler_cb() always return EVENT_SOFTAPMODE_PROBEREQRECVED when SOFTAP mode is on and a station device is connected. I expected the return code to be EVENT_SOFTAPMODE_STCONNECTED. My code works ok with SDK 1.3. Is wifi_set_event_handler_cb() broken? What is this new EVENT_SOFTAPMODE_PROBEREQRECVED?

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

Re: Is wifi_set_event_handler_cb() Broken?

Postby ESP_Faye » Thu Dec 03, 2015 10:10 am

Hi,

Here is our test code, it can get event "EVENT_SOFTAPMODE_STCONNECTED" when a station connected to ESP8266 softAP, please have a try.

Event "EVENT_SOFTAPMODE_PROBEREQRECVED" means that ESP8266 softAP received a probe request, you can just ignore it.

Thanks for your interest in ESP8266 !
Attachments
wifi_event_test_1.5.0.zip
(155.97 KiB) Downloaded 725 times

ming
Posts: 4
Joined: Sat Aug 01, 2015 8:33 am

Re: Is wifi_set_event_handler_cb() Broken?

Postby ming » Fri Dec 04, 2015 10:17 am

Ok. The wifi_set_event_handler_cb() is fine and I do receive SOFTAP STConnect event (sorry for the false alarm). The problem was in the DNS (for captive portal) code after connect. The remote ip and port in espconn structure pointer passed along in the espconn receive callback always contains zeros in SDK 1.5, whereas in SDK1.3 the values are valid.

See the attached DNS code.

Any idea?

Code: Select all

void ICACHE_FLASH_ATTR init_dns() {
   
    dnsConn.type=ESPCONN_UDP;
   dnsConn.state=ESPCONN_NONE;
   dnsUdp.local_port=(int)53;
   dnsConn.proto.udp=&dnsUdp;   
   
    espconn_regist_recvcb(&dnsConn, dnsQueryReceived);   

   int res = espconn_create(&dnsConn);

    NODE_DBG("DNS server init, conn=%p , status=%d", &dnsConn,res);

}

static void ICACHE_FLASH_ATTR dnsQueryReceived(void *arg, char *data, unsigned short length) {

    struct espconn *conn=arg;

   ...
   
      // SDK 1.5 returns IP=0.0.0.0 Port=0
      // SDK 1.3 returns IP=192.168.4.2 Port=<Some Valid#>
   NODE_DBG("DNS Remote[IP=" IPSTR "][Port=%d]",
      IP2STR(&conn->proto.udp->remote_ip), conn->proto.udp->remote_port);
   espconn_send(conn, (uint8_t*)response, idx+16);
}


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

Re: Is wifi_set_event_handler_cb() Broken?

Postby ESP_Faye » Fri Dec 04, 2015 11:21 am

Hi,

Please use espconn_get_connection_info to get the remote_ip and port.

Here is an example http://bbs.espressif.com/viewtopic.php?f=31&t=440.

Code: Select all

LOCAL void ICACHE_FLASH_ATTR
 user_udp_recv_cb(void *arg, char *pusrdata, unsigned short length)
 {
     
     os_printf("recv udp data: %s\n", pusrdata);
     struct espconn *pesp_conn = arg;
     
       remot_info *premot = NULL;
       sint8 value = ESPCONN_OK;
       if (espconn_get_connection_info(pesp_conn,&premot,0) == ESPCONN_OK){
             pesp_conn->proto.tcp->remote_port = premot->remote_port;
             pesp_conn->proto.tcp->remote_ip[0] = premot->remote_ip[0];
             pesp_conn->proto.tcp->remote_ip[1] = premot->remote_ip[1];
             pesp_conn->proto.tcp->remote_ip[2] = premot->remote_ip[2];
             pesp_conn->proto.tcp->remote_ip[3] = premot->remote_ip[3];
             espconn_sent(pesp_conn, pusrdata, os_strlen(pusrdata));
       }
 }

Who is online

Users browsing this forum: No registered users and 5 guests