Lesson IoT and automated Mobile Devices - Internet of Things - ثاني ثانوي
Part 1
1. IoT Fundamentals
2. The IoT in Our Lives
3. Building IoT applications with Arduino
4. Building an IoT cloud application
Part 2
5. IoT Advanced Applications
6. ++IoT Programming With C
7. IoT messaging
8. IoT Wireless Sensor Network Simulation
Linto digital (essan Lesson 3 IoT and Automated Mobile Devices www.leh.edu.sa Smart Industry and Automation Automation is a significant advantage of modern technology and a major contributing factor to the Fourth Industrial Revolution. Smart Industry is enhanced by automation technologies which upscale business production, leading to larger profits. In the following project you are going to create a simulation of a system that will check a factory's storage area for containers with consumable items that will decay if left outside of refrigeration overnight, using an automated vehicle. The automated inspector vehicle follows a predetermined route through the factory storage area, labeling the item containers according to their contents; consumables and non- consumables. Each container has an loT tag that emits a message, using its radio, and informs the vehicle of its contents. There are also some charging stations throughout the storage area to charge the vehicle's battery, as it decreases every time it moves. 396 E
Let's start by creating a new project: To create a new project: > Click on the New Project button on the Toolbar. > Choose your desired location for the project to be stored, type "Storage Product Marking" in the field File name and click on Save. I/CupCarbon IoT 5.0 Project Edit Aldo Display Selection Solver Simulation Map Personal Help 1work Information > Devices & Olojects > Dence Parameters ▸ Radio Parameter ▸ Marker Parameters Simulation Parameters New Expo Catton Berge The PC Local (CCC My onl File Pro2 وزارة التعليم 2173-145 Тра Пgure 8.21 Creating new project 3 Saye
5 Creating a predetermined route First, you will create the route along which the inspector vehicle will move. You will initially add some markers on the map to define the route structure and then enrich it with some more markers. To create the route: > Click on the Marker button on the Toolbar. > Click on the map 5 times, in a similar manner to the picture, creating lines along the aisles. > Press Esc. > Click on the Marker Parameters tab on the parameter menu. > Add more markers to the route by clicking on each of the first 4 markers placed and clicking Insert Markers 4 times. > Click Save. 3 4 وزارة التعليم 1 Ligure 8.22. Creating a route 2
Adding the inspector vehicle node The inspector vehicle will be simulated by a node moving along the route you just created. You will also increase the sensor radius of the node (inner circle) so that it can reach the charging station's range. To add the inspector vehicle node: > Click on the lot Node button on the Toolbar. > Click on the map to place a node. > Click on the All button from the State bar. > Press Esc. > Click on the node and press Shift+0 four times to increase the sensor radius. > Click on the Device Parameters tab on the parameter menu. > Click on the box box to the right of GPS file. > From the drop down menu, choose the route1.gps script and click on the button on the right to insert the route into the node. CoCarbon Projects Storage Product Making 5 4 5 Comm 6 3 2 Figure 8 23 Creating the inspector vehicle mode C 379
710 Adding container nodes Now it is time to add the nodes representing the containers. To add the container nodes: > Click on the loT Node button on the Toolbar. > Click on the map and place 7 nodes near the route, so that their radio radius includes at least 1 marker from the route > Click on the All button from the State bar. > Press Esc. 1 2 وزارة التعليم 3 Figure 8.20 Creating the contanter lodes
Adding charging stations As the inspector vehicle moves, it consumes energy and thus must be charged. You will place a couple of charging stations on the route that will recharge the vehicle's battery when it passes near them. For this purpose the inner radius, the sensor range, will be used this time. To add the charging station nodes: > Click on the Mobile button on the Toolbar. > Click on the map and place 2 nodes spread out along the route, so that the vehicle's sensor radius can reach them. > Press Esc درارة التعليم 1 2 18 Figure 825 Creating the starging Station nodes
Creating the Scripts Let's now take a look at the scripts you will be using, starting with the code for the containers. The two types of containers will have similar scripts. Start by including the library and printing an empty string on the node to remove any prints from previous executions. import time node.print("") The consumables containers will be broadcasting a message, which will include its contents and ID, so it can be used by the inspector vehicle to categorize each container, The ID is an integer and has to be converted ("casted") into a string before being concatenated to the string. A space is placed between the contents info and the ID as only one string can be sent at one time with the send() function and you have to send two pieces of information here; the space will be used as a separator. while node.loop(): node.send("CONSUMABLES" str(node.id()}) After the container analyzes the string it will either send back "1" meaning the containers must be picked or send "2" meaning it must not. In its turn the container prints on itself "PICK" or "DO NOT PICK" and then it sleeps for 1 second. message = node.read() if message = "1": node.print("PICK") elif message == "2": node.print("DO NOT PICK") time sleep(1) درارة التعليم 173-1445 143
Complete Code (consumables.py) import time node.print("") while node.loop(): + str(node.id())) node.send("CONSUMABLES message= node.read() if message == "1": node.print("PICK") elif message == "2": node.print("DO NOT PICK") time.sleep(1) Complete Code (nonconsumables.py) import time node.print("") while node.loop(): The difference in the code between the consumables and nonconsumables is the string they send. In the nonconsumables script, the string "CONSUMABLES" becomes "NONCONSUMABLES". " 4 str(node.id())) ليم 21125-1785 node.send("NONCONSUMABLES message = node, read() if message == "1": node.print("PICK") elif message == "2": node.print("O NOT PICK") time.sleep(1)
Next is the inpector vehicle's script. At the start, the battery is initialized by setting its max energy to 100 energy units with the battery.setEMax() function and then setting its current level to max with the the battery.init() function. import time node.battery.setEMax(100.0) node.battery.init() As each time interval passes, the vehicle will consume a certain amount of energy. To simulate this, use the battery.consume(1.0) function to consume 1 energy unit for each time interval. while node.loop(): node.battery.consume (1.0) To detect if any charging station is within range of the vehicle, use isSensorDetecting() function and if one is detected, use battery.init() to fill its energy to the max. if node.isSensorDetecting(): node.battery.init() Now, the vehicle must check all the messages it has received and answer to their senders, the containers. First the read string is stored in the local variable recvMsg and then using the split() function the concatenated string is divided into two strings, according to the space used earlier, in the form of an array with the name splitMsg. This means that in the first cell of the array, splitMsg101, holds the contents of the container and the second cell, splitMsg[1], holds the container's ID. for n in range(node.bufferSize()): recvMsg = node.read() splitMsg = recvMsg.split() the contents stong is "CONSUMABLES" it sends the string "1" with the send() function to the sender container using its ID. Else if it is "NONCONSUMABLES" it sends the string "2". In the end it sleeps for 200 ms, as it needs to be more responsive than the container nodes, because it communicates with pulmore modes. -
if splitMsg[0] == "CONSUMABLES": node.send("1", int(splitMsg[1])) elif splitMsg[0] == "NONCONSUMABLES": node.send("2", int(splitMsg[1])) time.sleep(0.2) Complete Code (inspector.py) import time node.battery.setEMax(100.0) node.battery.init() while node.loop(): node.battery.consume(1.0) if node.isSensorDetecting(): node.battery.init() for n in range(node.bufferSize()): recvMsg node.read() splitMsg = recvMsg.split() if splitMsg[0] == "CONSUMABLES": node.send("I", int(splitMsg[1])) elif splitMsg[] =="NONCONSUMABLES": node.send("2", int(splitMsg[1])) time.sleep(0.2) ميليم للت ليدر 745
TIF To create a script. > Click on the Python button on the Toolbar. > Type the Python code into the field. > Type inspector in the File name field. > Click Save > Close the Python Editor window. CupCarbon 107 5.0 (C\CupCarbon Projects Storage Pr Python Editor impactor 3 Script Laz inspector.cy T R- Super import time node.battery.setMax (100.0) node.battery.init() while node.loop(); node.battery.consume (1.0) 1f node. IsSensorDetecting(): node battery.init() for n in range (node.bufferSize()): recvMag node.read() splitMsg = reavMsg.split() if splitMag [0] "CONSUMABLES": 2 node.send("1", int (splitMsg [1])) elif splitMag [0] =="NONCONSUMABLES": node.send("2", int (splitMsg [1])) time.sleep(0.2) وزارة التعليم 173-176 Vigure 8 26 Create the scope Save
To insert the script: > Click on the inspector vehicle node. > Click on the Device Parameters tab on the Parameter Menu. > Click on the Script file box. > From the drop down menu, choose the inspector. py script and click on the button on the right to insert the script into the node. > Click on Display > Display/Hide Battery/Buffer levels, from the Menu bar. > Click on the Save Project button on the Toolbar. Cupatilo 6 2 مراد التعليم 3 4 1 CupCarbon lot 5.0 (C\CupCarbon Projects Storage Proc B Me 5 Figure 8.27 Inserting the scrip 349
In a similar way, create the consumables.py and nonconsumables.py scripts and apply the first script to some of the container nodes and the second to the rest, so all container nodes have one of these two scripts. When everything is set, you can click the Run IoT Simulation button from the toolbar to start the simulation. وزارة التعليم 21433 Figure 828 The simulation num h
C Exercises 1 Extend your project by adding more nodes and creating a route with more markers. Do not forget to insert scripts into the new nodes. 2 Identify whether your project is using the minimal number of charging stations. Try removing a station and relocating the others to test your hypothesis. Modify the inspector vehicle's script to consume more energy and run out of battery quicker. Present your findings below. 4 Extend your project by creating a third type of container node, an empty container that will emit the string "EMPTY" and will not be marked by the inspector vehicle. 5 A slow network connection in the factory may have severe implications for the system's functionalities. Modify the script of the inspector vehicle's node to make the node sleep for longer. Are any messages delayed and/or lost? Present your observations below. وزارة التعليم