The broad deployment of battery-powered wireless sensor networks (WSNs) enables a great variety of remarkable applications including remote environmental monitoring, healthcare, air quality monitoring, and so on. On the other hand, energy harvesting (EH) technologies have attracted widespread attention for their perpetual energy supply for sensor nodes. The conjunction of former and latter constitutes the EH-WSNs which no longer rely on a finite battery. Although EH-WSNs could harvest energy from the environment, the harvested and demanded energy do not meet. Thus, such networks suffer from intermittent energy shortage. The primary goal of protocols in such networks is to mitigate the energy shortage at the EH-WSN nodes. To resolve this issue, we propose EDMARA2 (Euclidean Distance Matrix Reconstruction Aided Approach), a hierarchical routing protocol for EH-WSNs based on EDM Reconstruction, k-medoids, and ILP which improves the energy efficiency of EH-WSNs. Hence, it reduces the packet loss. Experiments indicate that EDMARA2 surpasses approaches such as Direct Communication and DEARER about $$2.2\times$$ in the energy efficiency and $$0.5\times$$ in the packet loss percentage. It also yields results almost as efficient as Genie-aided approach.