The Internet of Things paradigm envisages the presence of many battery-powered sensors and this entails the design of energy-aware protocols. Source coding techniques allow to save some energy by compressing the packets sent over the network, but at the cost of a poorer accuracy in the representation of the data. This paper addresses the problem of designing efficient policies to jointly perform processing and transmission tasks. In particular, we aim at defining an optimal scheduling strategy with the twofold ultimate goal of extending the network lifetime and guaranteeing a low overall distortion of the transmitted data. We propose a Time Division Multiple Access (TDMA)-based access scheme that optimally allocates resources to heterogeneous nodes. We use realistic rate-distortion curves to quantify the impact of compression on the data quality and propose a complete energy model that includes the energy spent for processing and transmitting the data, as well as the circuitry costs. Both full knowledge and statistical knowledge of the wireless channels are considered, and optimal policies are derived for both cases. The overall problem is structured in a modular fashion and solved through convex and alternate programming techniques. Finally, we thoroughly evaluate the proposed algorithms and the influence of the design variables on the system performance adopting parameters of real sensors.