I'm working on esp8266, nonos sdk v 2.0.0_16_08_10, native c. I'm monitoring the network via wireshark.
I'm trying to send a multicast message over udp.
Receiving udp multicasts works. Sending udp unicasts works. Sending udp multicasts doesn't work.
In my udp send callback function, it is indicated that the message is sent, but I cant catch it via wireshark.
Multicast IP address: 224.0.1.187 Multicast port: 5683
Joining multicast group:
uint32_t mip = wifi_get_ip();
if(mip == 0){
os_printf("ERROR MULTICAST JOIN mip==0\n");
return;
}
ip_addr_t local, remote;
remote.addr = ocf_mgroup.ip.full;
local.addr = mip;
os_printf("multicast result = %d\n", espconn_igmp_join(&local, &remote));
Opening an UDP channel:
uint8_t ICACHE_FLASH_ATTR udp_open(uint8_t ch_no, uint8_t ch_id, uint32_t src_addr, uint16_t src_port, uint32_t dst_addr, uint16_t dst_port){
//ALLOC MEM
udp_conn[ch_no] = (struct espconn*) os_malloc(sizeof(struct espconn));
udp_info[ch_no] = (esp_udp*) os_malloc(sizeof(esp_udp));
//CHANNEL
//ports
udp_info[ch_no]->remote_port = dst_port;
udp_info[ch_no]->local_port = src_port;
//ips
udp_info[ch_no]->remote_ip[0] = (dst_addr) & 0xff;
udp_info[ch_no]->remote_ip[1] = (dst_addr >> 8) & 0xff;
udp_info[ch_no]->remote_ip[2] = (dst_addr >> 16) & 0xff;
udp_info[ch_no]->remote_ip[3] = (dst_addr >> 24) & 0xff;
udp_info[ch_no]->local_ip[0] = (src_addr) & 0xff;
udp_info[ch_no]->local_ip[1] = (src_addr >> 8) & 0xff;
udp_info[ch_no]->local_ip[2] = (src_addr >> 16) & 0xff;
udp_info[ch_no]->local_ip[3] = (src_addr >> 24) & 0xff;
//connection
udp_conn[ch_no]->type = ESPCONN_UDP;
udp_conn[ch_no]->state = ESPCONN_NONE;
udp_conn[ch_no]->proto.udp = udp_info[ch_no];
udp_conn[ch_no]->link_cnt = ch_id;
//HANDLERS
espconn_regist_recvcb(udp_conn[ch_no], udp_receive_handler);
//on send successfull
espconn_regist_sentcb(udp_conn[ch_no], udp_send_handler);
//CRAETE
return espconn_create(udp_conn[ch_no]);
}
Sending a message to ip:port:
uint8_t ICACHE_FLASH_ATTR udp_send_cfg(uint8_t ch_no, uint8_t* data, uint16_t len, uint32_t dst_ip, uint16_t dst_port){
udp_conn[ch_no]->proto.udp->remote_port = dst_port;
udp_conn[ch_no]->proto.udp->remote_ip[0] = dst_ip & 0xFF;
udp_conn[ch_no]->proto.udp->remote_ip[1] = (dst_ip >> 8) & 0xFF;
udp_conn[ch_no]->proto.udp->remote_ip[2] = (dst_ip >> 16) & 0xFF;
udp_conn[ch_no]->proto.udp->remote_ip[3] = (dst_ip >> 24) & 0xFF;
return espconn_sent(udp_conn[ch_no], data, len);
}