Bridging the Internet of Things and Grid of Things for Effective Optimization