The continuous evolution of new wireless technologies has given birth to new application areas for the Internet of Things (IoT) such as Smart Cities, Smart Home, Intelligent Transport Systems, Wireless Sensor Networks, etc. IoT is a network of networks that enables, via small wireless electronic devices called "sensor", to identify and communicate with physical objects. The main IoT objective is to measure and exchange data between physical and virtual worlds. However, the use of these sensors in applications characterized by the coexistence of different traffic loads in the same network could lead to power consumption and latency problems. In this article, we present a new efficient algorithm called (BMPriority-based CSMA/CA) based on message priority and battery energy level of sensor to manage access to the transmission channel. More precisely, our algorithm uses a weighting function to calculate the contention window during which a sensor node must wait before starting its data transmission. Simulation results show that our proposed protocol outperforms S-MAC, IEEE 802.15.4, and ECA-MAC protocols in terms of optimizing Packet Delivery Ratio (PDR), end-to-end latency, and throughput.