Real-Time Environmental Monitoring and Control Using Cyber-Physical Systems: A Case Study in Agriculture