In recent years, the importance of routing protocols in wireless sensor networks and the Internet of Things has been demonstrated by the numerous studies that have been presented in this area. because it is crucial to the network's functionality and effectiveness. Among routing's main goals are lowering latency, enhancing reliability, and averting network collisions. Additionally, it can be claimed that the type of network routing affects service quality, network longevity, and network traffic load control. Thus, in order to lower routing error and boost network performance and efficiency, the firefly is employed in this study to identify the best information transmission path within the network. It is also employed to reduce energy consumption. Taking into account the ability of evolutionary algorithms to optimize specified objective functions, we attempted to lower the network's energy consumption. The network can enhance the number of sending packets with the beginning energy of 3 joules from 1480 rounds to 1798 rounds, based on the proposed algorithm's results. Additionally, by contrasting the approaches described in the same article, it was discovered that the suggested approach can send roughly 40.11% more packets than the RM-LB algorithm and 1.9573% more than the OMS-LB technique. Additionally, it was discovered that by raising the starting energy to 150 joules, the suggested technique outperformed the other two algorithms by 51.23% and 45.17%, respectively, and was able to lengthen the longevity. This was in comparison to the RM-LB method and the OMS-LB method.