We consider a monitoring application where sensors periodically report data to a common receiver in a time division multiplex fashion. The sensors are constrained by the limited and unpredictable energy availability provided by Energy Harvesting (EH), and by the channel impairments. To maximize the quality of the reported data, the packets transmitted contain newly generated data blocks together with up to $r - 1$ previously unsuccessfully delivered ones, where $r$ is a design parameter; such blocks are compressed, concatenated and encoded with a channel code. The scheme applies lossy compression, such that the fidelity of the individual blocks is traded with the reliability provided by the channel code. We show that the proposed strategy outperforms the one in which retransmissions are not allowed. We also investigate the tradeoff between the value of $r$, the compression and coding rates, under the constraints of the energy availability, and, once $r$ has been decided, use a Markov Decision Process (MDP) to optimize the compression/coding rates. Finally, we implement a reinforcement learning algorithm, through which devices can learn the optimal transmission policy without knowing a priori the statistics of the EH process, and show that it indeed reaches the performance obtained via MDP.