# ------------------------------------------------------------
# Copyright © 2026/2027 Dr. Mohammad Alja'afreh. All rights reserved.
# PSUT IoT Engineering Learning Platform
# ------------------------------------------------------------
# ---- Runs on sensor node room-102  (IP 192.168.1.32)
import socket
 
# UDP socket: no connect(), every datagram carries its address.
tx = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# Permission to send to the broadcast address.
tx.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
 
# Unicast: only the Pi receives this datagram.
tx.sendto(b'room-102,26.1', ('192.168.1.20', 7000))
# Broadcast: every device on 192.168.1.x listening on port 7000.
tx.sendto(b'HELLO room-102', ('192.168.1.255', 7000))
