###### Abstract  
The Internet of Things defines a global and comprehensive network whose task is to monitor and control the physical world by collecting, processing, and analyzing data sensed by IoT devices. This network has succeeded in various areas, and one of its most important applications is in smart agriculture because there are many demands for producing high-quality foodstuff in the world. These demands need new production schemes in the agriculture area. In IoT, communication security is essential due to the extensive heterogeneity of IoT devices. In this paper, a cluster-tree-based secure routing approach using the dragonfly algorithm (CTSRD) is proposed for IoT. The proposed scheme presents a distributed and lightweight trust mechanism called weighted trust (W-Trust). W-Trust reduces the trust value corresponding to malicious nodes based on a penalty coefficient to isolate this node in the network. Furthermore, it improves the trust value of honest IoT devices based on a reward coefficient. Additionally, CTSRD introduces a trust-based clustering process called T-Clustering. In this clustering process, cluster head nodes (CHs) are selected among honest IoT nodes. Finally, CTSRD establishes a routing tree based on the dragonfly algorithm (DA) between CHs. This tree is called DA-Tree. To evaluate the quality of the routing tree, a new fitness function is provided in CTSRD. DA-Tree finds a secure, stable, and optimal routing tree to balance the consumed energy and boost the network lifetime. CTSRD is compared with EEMSR and E-BEENISH with regard to the network lifetime, consumed energy, and packet delivery rate. This comparison shows that our scheme can uniformly distribute the consumed energy in IoT and improves the energy consumption and network lifetime. However, it has a slightly lower packet delivery rate than EEMSR. Internet of Things (IoT); smart agriculture; routing; dragonfly algorithm (DA); wireless sensors networks (WSNs) 2020 ac  
to the Internet by 2025 [2]. Another prediction in [3] stated that 50 billion IoT devices will be in use around the world by 2030. In IoT, devices process and transfer data through intelligent sensors without human intervention [4]. As a result, sensor nodes are one of the main components of the Internet of Things. Wireless sensor networks (WSNs) provide a framework for managing sensor nodes [5; 6]. In WSN-based IoT, a number of sensor nodes work together to monitor the environment. They are connected to the Internet via the base station or sink node. Sensor nodes used in WSN-based IoT networks have many restrictions on energy sources, radio range, and processing power. Given that achieving the longest lifetime is a very important issue in these networks, the main challenge in these networks is to save the energy of sensor nodes [7; 8]. IoT can be used in many areas, for example, healthcare, smart transportation, smart homes, smart cities, and smart factories. One of its most important applications is smart agriculture. For example, Cropx uses the Internet of Things in agriculture [9]. The company has installed sensors to manage water consumption in agricultural lands. It has developed tools for managing the use of pesticides and fertilizers and collecting information about soil and air quality using algorithms and machine learning techniques. This technology has revolutionized the agricultural field because it provides a set of various tools for farmers to address the many challenges it presents. Farmers can be connected to their farmland equipped with IoT devices from anywhere and at any time [10; 11]. IoT-based technologies can potentially reduce the production cost of agricultural products and increase farmland productivity. Smart agriculture utilizes sensors and actuators to regulate and monitor agricultural processes. IoT sensors can measure soil temperature, NPK, water content, photosynthetic radiation, soil-water conditions, and soil oxygen level [12; 13].