A Collaborative Internet of Things Architecture for Smart Cities and Environmental Monitoring