When you want to connect an IoT device to anything (or, for that matter, anything to anything), you should take a serious look at Node-RED, a free, open source visual process wiring system from IBM ...
Introduction to PLC programming with OpenPLC, the first fully open source Programmable Logic Controller on the Raspberry Pi, and Modbus examples with Arduino Uno and ESP8286 PLC programming is very ...