I’m using: SWI-Prolog version 7.7.19
I’m trying to add dynamic discovery/configuration of devices to my SWI based home automation system. When a new device (display for starters) boots in my house it will publish a MQTT message with a JSON payload that declares its location and capabilities and I’d like my SWI-Prolog code to capture that configuration info into persistent terms it can then use to control those devices. All the MQTT and JSON part of this is already working.
For example a small LCD display might come online and the resulting term might be like:
device(‘lcd1’,‘mac_address1’, lcd(480,320, 16))
and an oled device might be:
I just came across the persistency library which might be used to allow Prolog to keep a database of these devices, but I’m not sure if that library allows a term within a term in the persistent declaration. I’m not totally sure on the form of my terms above, but my thought was that a device has generic attributes like name and mac address, but then has attributes specific to the type of device, width and height for both lcd’s and oled’s and bits per pixel for lcd. In the future other types of devices might not be displays at all, but maybe a sensor type.
Is the persistency library a good fit for this or should I resort to something else like writing terms to a regular file? The reason I’m looking for Prolog to persist this data is that maybe the device boots and advertises itself and then Prolog is restarted and then needs to restore itself so it can function before the next time the device advertises itself again.
As a side note, my HA system currently uses MQTT for all messaging between the components (arduino/ESP8266, Java, Prolog, Python) so using MQTT to do this device configuration/capability advertisement was an easy first step. But the ESP8266 devices are also discoverable via mDNS (which is how their OTA update function works) so eventually I’ll instead have central service discover devices via mDNS and then make a REST call to each new device to return a JSON description of its capabilities. The additional feature that will provide is that I believe mDNS can also help notify when a device goes away so I’ll be able to catch devices as they come and go on my network.