UDP broadcast for IoT discovery using Raspberry PI and public wifi - raspberry-pi

A couple questions.
TLDR is sending UDP broadcast packets on a Wifi network to allow for discovery of a IoT device (Raspberry PI) a conventional practice?
Long version: I'm working on an IoT project for a class. Based on other IoT devices I've used (a Christmas carol lighting system and music player), we decided to utilize an already working application (https://github.com/balena-os/wifi-connect). The way it works is it runs on the Raspberry PI and hosts a wifi endpoint through the RPI's network card that the user can connect to. Once a user connects to this Wifi endpoint on his/her Iphone, a Wifi selection and password entry page appears on his/her Iphone. The user enters the Wifi/password that the IoT device (Raspberry PI) should connect to. The entered Wifi will then be connected to by the Raspberry PI. The user can then connect to the entered Wifi as well and now both the user's Iphone and Raspberry PI will be connected to the same Wifi network.
We decided to send UDP packets to the broadcast address of the Wifi network from the IoT device, so that users connected to the Wifi (via their Iphones) can "discover" the IoT devices IP address by listening for UDP packets. Once the user discovers the IoT device's IP address, they can send HTTP RESTful API calls to the IoT device. I was wondering if the described process is conventionally used.
# script we are using to send UDP broadcast packets
import socket
import time
server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
server.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
server.settimeout(0.2)
message = b"message"
while True:
server.sendto(message, ('<broadcast>', 16123))
time.sleep(1)
We tried this setup at a public library, using their free public wifi. However, the UDP broadcast packet discovery process failed. UDP broadcast packets were sent out by the IoT device, but were not received by the Iphone. We're wondering if this has something to do with a firewall. We could successfully send UDP broadcast packets from a Macbook (via a python script) to an IOS emulator residing on the same Macbook, such that the source IP address of the packet was the same as the recipient. Is there a firewall rule such that a broadcast packet sent from IP address [A] can be delivered back to IP address [A] but not to IP address [B].
Also, I didn't mess around with the port number, which might have helped if certain ports were disabled by a firewall. I'm not sure. Help is appreciated. We are both relatively new to this.

DNS-SD (RFC6763) is the a fairly common and standardized way to do network discovery. It actually supports both TCP & UDP services. It was originally invented by Apple under the brand name "Bonjour" for printer discovery.
So yes, it is common to use UDP broadcast packets (via DNS-SD) for IoT device discovery on a Wifi network.

Related

HoloLens 2 stops receiving UDP multicast packets when plugged into Windows -- Why and how do I always enable UDP multicast?

I'm developing apps for the HoloLens 2, and my current project involves a server on LAN that hosts a multiplayer experience. I developed this auto discovery mechanism using UDP multicast so that HoloLens 2 clients can find what ip the server is on just by listening for these UDP multicast packets.
During testing, the battery was running low, so I plugged it into Windows, and all my UDP multicast stuff just stopped working on the HoloLens. I don't know why.
I'm sure there's a setting somewhere for it, but I don't know where or if it can even be changed.
I've encountered this issue before on Windows where I had to go into the network adapter settings for IPv4 and change the interface metric to 1 under advanced TCP/IPv4 settings. With that setting on 1, Windows can receive UDP multicast packets, otherwise it does not.

MQTT broker connect without pre-set IP address

I am building a application to use raspberry as MQTT broker & client and receive the message from ESP32 which is another MQTT client. I need to have ESP32 to get the broker connected without pre-setting IP address manually. Does anyone know how to let raspberry share the IP address wirelessly and safely? Or could the raspberry pi get a static IP address no matter what network configuration user changed? Thank you for any help or discuss.
These two instructions gave some help: to build mDNS lookups in raspberry and mDNS client to receive string input. More logic needed to define the principle of "blind search" but considering the security reason, we preferred to transfer string host name by BLE from app side.
mDNS client in ESP32 to receive string input
How is the ESP32 (DOIT DevKit) finding another host in the same LAN via mDNS?
to build mDNS lookups in raspberry:
http://root42.blogspot.com/2015/02/how-to-setup-mdns-lookups-on-raspberry.html

UDP hole punching with Mobile device on cellular network

I have local server running in my local network.I want to enable external devices to make request to my local server in this case i am testing with android phone on cellular network.For this I am trying to do UDP hole punching.First I am sending http request from the mobile device to public server to give the public server mobile device's information(IP and Ports) so that i can use them to punch a UDP hole in my local server.But the problem is i am getting NAT public IP & public Port and only local IP of the mobile device but not Local Port.And I just learned that cellular network wont let you use mobile local ports.The question now is how would i accomplish UDP hole punching in this case? If there is anything that i mis-stated please correct me.Thank you in advance

Can I plug a cisco phone directly into raspbx ethernet port

Can I plug a cisco SPA303 ip phone directly into the ethernet port of a raspberry pi running raspbx?
I have got raspbx setup and running using a wifi dongle to connect to the router. The system works with the Cisco phone plugged into the router. However, the router is on the other-side of my house and ideally, as the raspbx is wifi, I would like to plug the phone directly into the pi and have it as one unit I can have anywhere in the house.
I have spent a painful amount of hours trying to set this up and I am sure there is a simple fix I am overlooking. Any ideas would be greatly appreciated.
Yes, you can. But you should setup static ip on phone or setup dhcpd server on RPi
Also some cisco phones have double ports(internal simpler switch inside). If so, you can connect one-by-one upto 8 phones.
There are several layers to take into consideration:
Link layer MDI/MDI-X detection of crossover/patch ethernet cable detection.
Static IP address for Raspberry Pi and a DHCP server for the IP phone
TFTP server to provisionize the IP phone
A peer in asterisk for the IP phone

Is it possible to TCP connect to an iPhone listening on a port on a 3G network?

I'm working on an app that relies heavily on P2P, but I currently don't have any SIM cards with which to experiment so I'm testing on a wifi network.
I'd like to know if iPhones on 3G networks are connectable and whether or not I will need to traverse NAT devices.
You're behind the provider's router and your IP address will be something like 10.x.x.x - so you'd have the tell the router, that a TCP connect from the internet to port 9420 should be forwarded to your device. I doubt that they will do this for you.