ESP8266 Developer Zone The Official ESP8266 Forum 2015-08-14T21:50:13+08:00 https://bbs.espressif.com:443/feed.php?f=7&t=953 2015-08-14T21:50:13+08:00 2015-08-14T21:50:13+08:00 https://bbs.espressif.com:443/viewtopic.php?t=953&p=3247#p3247 <![CDATA[Re: transmit UDP from RX callback connection?]]>
viewtopic.php?f=7&t=954

Statistics: Posted by kolban — Fri Aug 14, 2015 9:50 pm


]]>
2015-08-14T21:09:25+08:00 2015-08-14T21:09:25+08:00 https://bbs.espressif.com:443/viewtopic.php?t=953&p=3244#p3244 <![CDATA[transmit UDP from RX callback connection?]]>
I am trying to send a udp packet in response to a udp packet that I am receiving. Here is my code in the RX callback. I am not getting any errors, but I dont ever see the packets with my sniffer. Am I doing this right?

Code:

void RxCallback(void *arg, char *data, unsigned short len)
{
   uint32 txlen;
   uint8 *pResponse = (uint8 *)os_malloc(512);
   struct espconn *pConn = (struct espconn *)arg;
 
   ets_uart_printf("\r\n\r\n\r\n************************************************************\r\nRXCallback got data length = %d\r\n", len);
   DebugData(data, len);
   ets_uart_printf("***** RX UDP Local port is %d local IP is %d.%d.%d.%d \r\n remote port is %d remote IP is %d.%d.%d.%d\r\n",
                                                                                       pConn->proto.udp->local_port,
                                                                              pConn->proto.udp->local_ip[0],
                                                                                                                       pConn->proto.udp->local_ip[1],
                                                                              pConn->proto.udp->local_ip[2],
                                                                              pConn->proto.udp->local_ip[3],
                                                                                pConn->proto.udp->remote_port,
                                                                                pConn->proto.udp->remote_ip[0],
                                                                                                                             pConn->proto.udp->remote_ip[1],
                                                                               pConn->proto.udp->remote_ip[2],
                                                                               pConn->proto.udp->remote_ip[3]);
   txlen = BuildAnswer(data, pResponse);
   ets_uart_printf("Response length = %d\r\n", txlen);
   PrintHeader(pResponse);
   DebugData(pResponse, txlen);

   if(espconn_send(pConn, pResponse, txlen) != 0)
   {
      ets_uart_printf(" UDP fail send\r\n");

   }
   os_free(pResponse);
   }

Statistics: Posted by stickben — Fri Aug 14, 2015 9:09 pm


]]>