One of the main challenges in wireless sensor networks is the limited energy of nodes and their lifetime. In this paper, we utilize compressed sensing theory to reduce the number of transmissions and ultimately increase the lifetime of the wireless sensor network. The data in some wireless sensor networks, in addition to spatial correlation, also have temporal correlation. The proposed method in this paper benefits from both types of correlation to minimize the mean square error of the reconstructed data signal. We also use a sleep/wake algorithm to reduce energy consumption of nodes. The awake nodes in the proposed method are determined using a genetic algorithm, as finding optimal nodes is an NP-Hard problem. After determining the awake nodes, the ant colony algorithm is used to construct the optimal aggregation tree of the awake nodes. Simulation results show that our proposed approach in selecting awake nodes and routing them leads to an improvement of more than 48% in reconstruction error and an increase of more than 18% in network lifetime compared to the evaluated methods.