Answer the question
In order to leave comments, you need to log in
How to search for multiple devices on a local network?
Hello everyone,
the question is this, I have three esp32s on the network (who doesn't know, this is a small chip with wifi). That is, they connected via wifi and received by IP.
Now I want to scan the local network from my computer and find these three esp32s, does anyone know how to do this?
So far, apart from pinging the broadcast address and seeing who answered, nothing comes to my mind. How, for example, is it done with printers?
Ps: I'm sorry, I seem to have written the question a little wrong. I can of course look at the addresses in the router. But I don't need that.
Example: I turn on these three devices, they connect to the network, then I launch the client (it doesn’t exist yet) and it finds these three devices for me, after that I can make some settings.
You can probably scan the network, but it's long, maybe there is some other way.
Answer the question
In order to leave comments, you need to log in
In general, today there was time and I think I found a suitable solution. Clients (esp8266) will send every 10 seconds. your information on the multicast address: port 239.255.255.250:400
Maybe someone will need it. Clint code (esp8266) in C:
#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);
}
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);
});
If you know the MAC in advance, then through RARP.
If you don’t know the MAC, but you know at least the first few octets (and you probably know this, simply because the network card manufacturer of esp is most likely 1), then ping the broadcast, then find the necessary addresses along this first part of the MAC. Quite cool - raise some service on ESP and knock on it as a client, check that it is really ESP
So in the router, you can set the ip address of each device by its MAC. And since there is no client yet, that is, you will write it. So study the request to the router, by which it issues the ip of the devices and implement it in your client. I don't understand what is the problem
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question