The concept of rimware for the integration of IoT (Internet of Things) and the cloud to form a very powerful cyber-physical system is introduced. The specific implementation, called BlueRim, can scale from isolated NoTs to the global IoT. The rimware provides a middleware layer that enables gateway devices to establish connections between the devices and the cloud with roaming support while requiring them to prove their trustworthiness. The rimware has components that run on both the gateway and the cloud for each application domain. Rimware components are adapters running on the gateway, knowledge base running in the cloud; and access controller, also running in the cloud. As the gateway acts as the conduit, the purpose of authentication is to check whether the gateway is a trusted one. Access control is built on top of authentication, which is initiated from the device side. Rimware uses BLE profiles extensively as a fundamental mechanism for access control.