Recent

Author Topic: listen broadcast message  (Read 2200 times)

ProfHarry

  • New member
  • *
  • Posts: 9
listen broadcast message
« on: June 05, 2024, 06:05:21 am »
Hello,
I have several ESP32s on a network which send broadcast messages (ASCII texts of 20 to 30 characters) at more or less regular intervals.

What is the easiest way for a beginner to recover these messages in a lazarus application?
Could you give me an example?

Thanks

Thaddy

  • Hero Member
  • *****
  • Posts: 16145
  • Censorship about opinions does not belong here.
Re: listen broadcast message
« Reply #1 on: June 05, 2024, 06:53:33 am »
There is a great example I got from Stackoverflow that should be just he ticket for you:
https://stackoverflow.com/questions/9786011/delphi-synapse-udp-client-server

It uses synapse, but it is light enough. I can probably convert it to fcl-web if required.
If I smell bad code it usually is bad code and that includes my own code.

ProfHarry

  • New member
  • *
  • Posts: 9
Re: listen broadcast message
« Reply #2 on: June 05, 2024, 08:13:01 am »
Thanks,

If I've understood correctly, I'm only using the client part. Is that correct?
I'll take a look at that and probably come back with my newbie questions.

Thaddy

  • Hero Member
  • *****
  • Posts: 16145
  • Censorship about opinions does not belong here.
Re: listen broadcast message
« Reply #3 on: June 05, 2024, 08:25:47 am »
It depends on you having control over the software from the esp32's.
Since you mentioned broadcasting, I assume the protocol to be UDP, but you can also do that differently as long as it is socket based. But indeed, basically you only need a listener.
Take the echo example from stack overflow as an example: instead of echo, you log the identity from the ESP32's and its messages. That takes very few changes to the code.
« Last Edit: June 05, 2024, 08:30:13 am by Thaddy »
If I smell bad code it usually is bad code and that includes my own code.

MarkMLl

  • Hero Member
  • *****
  • Posts: 8007
Re: listen broadcast message
« Reply #4 on: June 05, 2024, 09:04:33 am »
Since you mentioned broadcasting, I assume the protocol to be UDP, but you can also do that differently as long as it is socket based. But indeed, basically you only need a listener.
Take the echo example from stack overflow as an example: instead of echo, you log the identity from the ESP32's and its messages. That takes very few changes to the code.

Note that UDP broadcasts are generally discarded by routers.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

ProfHarry

  • New member
  • *
  • Posts: 9
Re: listen broadcast message
« Reply #5 on: June 05, 2024, 11:53:03 am »
It depends on you having control over the software from the esp32's.

I have several ESP32s doing measurements and I have a control of their code but :
- they connect via DHCP to the wifi network
- I don't know their IP (no access to the DHCP server)
- they have no way of displaying their IP addresses (no LCD or other display)
- I need their IP to access their web servers to display the measurements taken.

The solution I have come up with is to regularly broadcast the name and IP of each ESP32. The lazarus application will be used to locate them and indicate the addresses of each of them.

ProfHarry

  • New member
  • *
  • Posts: 9
Re: listen broadcast message
« Reply #6 on: June 05, 2024, 11:58:46 am »
Note that UDP broadcasts are generally discarded by routers.

This is a Wi-Fi network in a school. The lazarus application is on a laptop on the same network as the ESP32s, so it should work.  Fingers crossed ;-)

MarkMLl

  • Hero Member
  • *****
  • Posts: 8007
Re: listen broadcast message
« Reply #7 on: June 05, 2024, 12:03:40 pm »
Note that UDP broadcasts are generally discarded by routers.

This is a Wi-Fi network in a school. The lazarus application is on a laptop on the same network as the ESP32s, so it should work.  Fingers crossed ;-)

Yes, but in many cases an access point will behave more like a router rather than like a switch.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11931
  • FPC developer.
Re: listen broadcast message
« Reply #8 on: June 05, 2024, 12:18:39 pm »
I do the same with my electronics boards.  They have fixed IP, but I broadcast for other reasons (no need to configure destination IP and sending packets to multiple PCs would require an extra operation to set it)

Originally I used a simple UDP listener based on the Indy10 udp client demo to capture them, so that could be a start. If it doesn't work, try to temporarily disable the firewall.
« Last Edit: June 05, 2024, 12:53:04 pm by marcov »

ProfHarry

  • New member
  • *
  • Posts: 9
Re: listen broadcast message
« Reply #9 on: June 05, 2024, 02:11:25 pm »
Originally I used a simple UDP listener based on the Indy10 udp client demo to capture them, so that could be a start.

Thanks, I'll have a look too.

Curt Carpenter

  • Hero Member
  • *****
  • Posts: 559
Re: listen broadcast message
« Reply #10 on: June 06, 2024, 01:28:01 am »
FWIW my esp's all have an on-board led and I use it during power up to flash the last few digits of their IP address in Morse.   The software required is nothing and it helps me cope with my failing memory.
« Last Edit: June 06, 2024, 01:29:51 am by Curt Carpenter »

Leledumbo

  • Hero Member
  • *****
  • Posts: 8774
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: listen broadcast message
« Reply #11 on: June 16, 2024, 07:07:46 pm »
Sounds like a good candidate for SSDP.

MarkMLl

  • Hero Member
  • *****
  • Posts: 8007
Re: listen broadcast message
« Reply #12 on: June 16, 2024, 07:35:33 pm »
Sounds like a good candidate for SSDP.

Hmm. I'm not sure whether that's really proportional for the simple job of discovering IP addresses, and partially-implemented protocols (i.e. to take minimal space on an ESP used for labwork) cause innumerable problems.

What would work however would be a UDP broadcast from a lab computer to SSDP's port (1900) which should elicit an error response, and then a dump of the computer's ARP cache to get the IP and MAC addresses of everything discovered.

But it would be even easier to use a broadcast ping.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

 

TinyPortal © 2005-2018