The Internet of Things (IoT) is constituted of an important number of constrained nodes limited in terms of power energy, computation capacity, storage capacity. They produce a considerable amount of data, which increases the data flflow in the network. The ineffificient transmission of data via constrained nodes makes the network unstable, the energy consumption increases rapidly, and the data delay increases strictly. To overcome these limitations, we propose a new approach that allows nodes to select the effificient path to transmit data from source nodes to base stations (BSs) to optimize the data flflow in the constrained network. First, we grouped nodes using a density peaks (DP) clustering algorithm based on the coordinate’s location of these nodes. Second, using the group nodes, the assignment of nodes to BSs that are considered as the collectors of data is performed. Third, the nodes make a dynamic and automated path plan to optimize the data flflow in the constrained network. Simulation results on a real network data set demonstrate that our proposal outperforms the state-of-the-art approaches in terms of the number of hops to achieve the cluster head (CH) node, the data delay, the network lifetime, and the number of the alive nodes.