The pillars of Industry 4.0 require the integration of a modern smart factory, data storage in the Cloud, access to the Cloud for data analytics, and information sharing at the software level for simulation and hardware-in-the-loop (HIL) capabilities. The resulting cyber-physical system (CPS) is often termed the cyber-physical manufacturing system, and it has become crucial to cope with this increased system complexity and to attain the desired performances. However, since a great number of old production systems are based on monolithic architectures with limited external communication ports and reduced local computational capabilities, it is difficult to ensure such production lines are compliant with the Industry 4.0 pillars. A wireless sensor network is one solution for the smart connection of a production line to a CPS elaborating data through cloud computing. The scope of this research work lies in developing a modular software architecture based on the open service gateway initiative framework, which is able to seamlessly integrate both hardware and software wireless sensors, send data into the Cloud for further data analysis and enable both HIL and cloud computing capabilities. The CPS architecture was initially tested using HIL tools before it was deployed within a real manufacturing line for data collection and analysis over a period of two months.