An IoT-based Framework for an Optimal Monitoring and Control of Cyber-Physical Systems: Application on Biogas Production System