1
00:00:00,450 --> 00:00:07,440
First let's go to the server P Y why in this lesson we will be sending commands to the back end side

2
00:00:07,740 --> 00:00:11,110
which will enable the drone to fly accordingly.

3
00:00:11,350 --> 00:00:12,600
Set the app Mark.

4
00:00:12,640 --> 00:00:22,880
App route decorator the API you are l will be API slash command methods will be post and not get.

5
00:00:23,170 --> 00:00:29,460
If you are planning on doing a test you can use get instead of post in this lesson.

6
00:00:29,470 --> 00:00:37,730
I'll set it to post define a function named command command will be using a request to receive the commands

7
00:00:37,730 --> 00:00:41,450
from the front end side to request.

8
00:00:41,550 --> 00:00:49,630
We need to import that request function so go to the top and set from flask import request.

9
00:00:50,220 --> 00:00:59,910
Since we're at the top I also want you to set from flask import J Spotify which will be used later on.

10
00:00:59,940 --> 00:01:01,500
Now let's go back.

11
00:01:01,500 --> 00:01:02,770
Set CND.

12
00:01:02,790 --> 00:01:05,610
As for command to request form.

13
00:01:05,610 --> 00:01:07,590
Get Command.

14
00:01:07,590 --> 00:01:11,520
Let's also set a logger to see if the commands have been sent.

15
00:01:11,520 --> 00:01:13,360
Set logger info.

16
00:01:13,380 --> 00:01:17,850
Action will be command and the log will be CMT.

17
00:01:17,850 --> 00:01:23,390
The return will be J Spotify which we just imported and status will be success.

18
00:01:24,580 --> 00:01:31,110
The status code will be two hundred writing with the tuple type is the way to do flask.

19
00:01:31,480 --> 00:01:34,920
The back end side will be only creating the log.

20
00:01:34,930 --> 00:01:40,740
Now let's go onto the front end side open controller H2 CML.

21
00:01:40,870 --> 00:01:47,500
Here we want to write a javascript using the J query so set script first.

22
00:01:47,500 --> 00:01:50,650
We will set a function named send command.

23
00:01:50,950 --> 00:01:59,180
The first argument will be command and if there is a parameter that will also be included we will set

24
00:01:59,180 --> 00:02:03,410
the console log with action send Command.

25
00:02:03,500 --> 00:02:11,180
Command will be command and parameters will be parameters and the parameters we want to receive the

26
00:02:11,180 --> 00:02:11,700
command.

27
00:02:11,700 --> 00:02:13,950
So we add command.

28
00:02:14,360 --> 00:02:21,830
The data will be sent to the back end using post that you are L is API slash command and we send the

29
00:02:21,830 --> 00:02:25,760
parameters once the back end receives the command.

30
00:02:25,850 --> 00:02:33,860
The back end will be sending the status code 200 by setting done the status code will be received.

31
00:02:33,860 --> 00:02:38,740
Set function and Jason which will be sent from the back end.

32
00:02:39,230 --> 00:02:41,310
The function will simply be logging.

33
00:02:41,360 --> 00:02:50,410
So we set console log with action send command and Jason with Jason the log will be sent to the back

34
00:02:50,410 --> 00:02:53,530
end using the Jason type.

35
00:02:53,560 --> 00:02:58,040
Next we need to set the command to be sent from the front end side.

36
00:02:58,150 --> 00:02:58,480
Right.

37
00:02:58,480 --> 00:03:01,690
Div tag class to controller box

38
00:03:06,030 --> 00:03:11,720
data all will be set to control group which will check what it looks like later.

39
00:03:12,120 --> 00:03:14,610
Data type will be horizontal.

40
00:03:18,690 --> 00:03:20,450
Next we set the ailing.

41
00:03:20,670 --> 00:03:22,820
We'll be using a button shaped link.

42
00:03:22,890 --> 00:03:31,090
We don't want to have this link used as a regular a link so we'll set it to hash set data roads a button

43
00:03:31,150 --> 00:03:33,020
for the button shaped link.

44
00:03:33,310 --> 00:03:41,420
Once we click the button we want to send a command to the back end to take off although this is a link

45
00:03:41,480 --> 00:03:44,870
we don't want to start any action besides sending a command.

46
00:03:45,410 --> 00:03:48,530
So the return will be set to false.

47
00:03:48,710 --> 00:03:56,400
The button name will be set to take off and we close the A10 copy this entire row to create another

48
00:03:56,400 --> 00:04:02,730
button the next button will be land so set the command to land and also the button name.

49
00:04:03,900 --> 00:04:08,850
Now let's see how this site looks like run the script and hit the link.

50
00:04:08,850 --> 00:04:13,580
Once you see the top page click on controller.

51
00:04:13,810 --> 00:04:15,190
You can see the two buttons.

52
00:04:15,190 --> 00:04:19,700
We created the takeoff button and the land button.

53
00:04:19,770 --> 00:04:23,590
Let's check the script to see how we created these buttons.

54
00:04:23,640 --> 00:04:30,970
The data rule control group puts together the two buttons as we set the data taped to horizontal.

55
00:04:31,080 --> 00:04:36,460
The buttons will be set side by side as we chose the data Rhodes button.

56
00:04:36,480 --> 00:04:42,040
The link will be shown in a button shape if this button were to be a normal link.

57
00:04:42,160 --> 00:04:48,670
The page will low the designated site but here we set the button to load a javascript which sends a

58
00:04:48,670 --> 00:04:55,190
command to the backend side using the send command function let's check and see if the commands are

59
00:04:55,190 --> 00:04:57,260
working.

60
00:04:57,380 --> 00:04:58,660
This is the back inside.

61
00:04:58,970 --> 00:05:01,140
Let's hit the take off button.

62
00:05:01,310 --> 00:05:04,930
You can see the log showing the take off command being received.

63
00:05:05,730 --> 00:05:08,340
Let's try the land button as well.

64
00:05:08,520 --> 00:05:12,890
You see that action is command and the command is land.

65
00:05:12,890 --> 00:05:18,450
Do you remember where we set the logger in the beginning of this lesson and we set the logger and the

66
00:05:18,450 --> 00:05:19,040
server.

67
00:05:19,050 --> 00:05:28,010
P Why file according to the logger the action and command has been logged we've completed sending commands

68
00:05:28,010 --> 00:05:29,690
to the back end.

69
00:05:29,700 --> 00:05:36,800
Next we need to make the drone fly based on these commands but before we set the drone let's add some

70
00:05:36,800 --> 00:05:38,420
more commands to the front end.

71
00:05:38,480 --> 00:05:39,530
In our next lesson.
