В общем сегодня было время и я думаю нашел подходящее решение. Клиетны (esp8266) будут слать каждые 10 сек. свою информацию на мултикаст адрес:порт 239.255.255.250:400
Может бы кому понадобится. Код клинта (esp8266) в С:
#include "ets_sys.h"
#include "user_interface.h"
#include "osapi.h"
#include "gpio.h"
#include "os_type.h"
#include <espconn.h>
/* Change to desired SSID name */
const char ssid[32] = "wwwdlan";
/* Enter the Password of the AP */
const char password[32] = "wertwert5";
/* Will hold the SSID and Password Information */
struct station_config stationConf;
struct espconn sendResponse; //udp
esp_udp udp;
// timer
os_timer_t send_udp_device_info;
/******************************************************************************
* FunctionName : user_init
* Description : entry of user application, init user function here
* Parameters : none
* Returns : none
*******************************************************************************/
void send_dev_info(void *pArg)
{
int err;
sendResponse.type = ESPCONN_UDP;
sendResponse.state = ESPCONN_NONE;
sendResponse.proto.udp = &udp;
IP4_ADDR((ip_addr_t *)sendResponse.proto.udp->remote_ip, 239, 255, 255, 250);
sendResponse.proto.udp->remote_port = 4000; // Remote port
err = espconn_create(&sendResponse);
err = espconn_send(&sendResponse, "hi123", 5);
err = espconn_delete(&sendResponse);
}
void user_init(void)
{
/* Select UART 0 and configure the baud rate to 9600 */
uart_div_modify(0, UART_CLK_FREQ / 9600);
os_printf("Demo Example - ESP8266 as Station\r\n");
/* Configure the ESP8266 to Station Mode */
wifi_set_opmode( STATION_MODE );
/* Copy the SSID and Password Info to the structure */
os_memcpy(&stationConf.ssid, ssid, 32);
os_memcpy(&stationConf.password, password, 32);
/* Configure the station to connect to the following AP */
wifi_station_set_config(&stationConf);
/* Connects to the AP */
wifi_station_connect();
os_timer_setfn(&send_udp_device_info, send_dev_info, NULL);
os_timer_arm(&send_udp_device_info, 10*1000, 1);
}
И программа на компе в node.js
var PORT = 4000;
var MULTICAST_ADDR = '239.255.255.250';
var dgram = require('dgram');
var client = dgram.createSocket('udp4');
client.on('listening', function () {
var address = client.address();
console.log('UDP Client listening on ' + address.address + ":" + address.port);
});
client.on('message', function (message, rinfo) {
console.log('Message from: ' + rinfo.address + ':' + rinfo.port + ' - ' + message);
});
client.bind(PORT, function () {
client.addMembership(MULTICAST_ADDR);
});