Has anyone thought about mDNS support for SWI-Prolog?


I expect the answer is “no”, but figured I’d put it out there anyway.

I am currently using SWI-Prolog as the central controller for a home automation system where I’ve added the MQTT library to SWI and the Prolog code mostly reacts to MQTT messages and sends new messages as part of the response. The other cool thing is that I’ve got lots of Arduino/ESP8266 devices which are both sensors and controlled devices, and those devices can send/receive MQTT messages as well as provide a REST API for stateless status queries. Part of the code for these devices provides an OTA ability which I’ve come to find out uses mDNS (multicast DNS) for device discovery.

So what I’d like to be able to do is to have SWI-Prolog listen for mDNS announcements so it could then dynamically discover these Arduino devices that it could then manage - once Prolog is aware that the device exists it could then query for its actual IP address and use a REST API call to query that devices capabilities.


I doubt anything is there. The UDP support should be fine though and as I read the mDNS spec I don’t think it takes a rocket scientist to implement the protocol. Alternatives is binding to a C library or possibly getting this as a service from the OS?


I suppose the easiest way for me to do this is implement the mDNS scan in Python or Node.js and send the discovery info via MQTT which I’ve already got running in Prolog. I’m just brainstorming possibilities.


If you already have a Python or Node service in the config that might be a pragmatic idea. I very much doubt setting this up in Python/Node and make the communication work is any simpler that taking a C implementation for mDNS and link it with Prolog or, glancing the specs, write a little Prolog code that sends and listens to the UDP channel. Such an approach is normally easier to deploy and debug as well.