First let's go to the server P Y why in this lesson we will be sending commands to the back end side
which will enable the drone to fly accordingly.
Set the app Mark.
App route decorator the API you are l will be API slash command methods will be post and not get.
If you are planning on doing a test you can use get instead of post in this lesson.
I'll set it to post define a function named command command will be using a request to receive the commands
from the front end side to request.
We need to import that request function so go to the top and set from flask import request.
Since we're at the top I also want you to set from flask import J Spotify which will be used later on.
Now let's go back.
Set CND.
As for command to request form.
Get Command.
Let's also set a logger to see if the commands have been sent.
Set logger info.
Action will be command and the log will be CMT.
The return will be J Spotify which we just imported and status will be success.
The status code will be two hundred writing with the tuple type is the way to do flask.
The back end side will be only creating the log.
Now let's go onto the front end side open controller H2 CML.
Here we want to write a javascript using the J query so set script first.
We will set a function named send command.
The first argument will be command and if there is a parameter that will also be included we will set
the console log with action send Command.
Command will be command and parameters will be parameters and the parameters we want to receive the
command.
So we add command.
The data will be sent to the back end using post that you are L is API slash command and we send the
parameters once the back end receives the command.
The back end will be sending the status code 200 by setting done the status code will be received.
Set function and Jason which will be sent from the back end.
The function will simply be logging.
So we set console log with action send command and Jason with Jason the log will be sent to the back
end using the Jason type.
Next we need to set the command to be sent from the front end side.
Right.
Div tag class to controller box
data all will be set to control group which will check what it looks like later.
Data type will be horizontal.
Next we set the ailing.
We'll be using a button shaped link.
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
for the button shaped link.
Once we click the button we want to send a command to the back end to take off although this is a link
we don't want to start any action besides sending a command.
So the return will be set to false.
The button name will be set to take off and we close the A10 copy this entire row to create another
button the next button will be land so set the command to land and also the button name.
Now let's see how this site looks like run the script and hit the link.
Once you see the top page click on controller.
You can see the two buttons.
We created the takeoff button and the land button.
Let's check the script to see how we created these buttons.
The data rule control group puts together the two buttons as we set the data taped to horizontal.
The buttons will be set side by side as we chose the data Rhodes button.
The link will be shown in a button shape if this button were to be a normal link.
The page will low the designated site but here we set the button to load a javascript which sends a
command to the backend side using the send command function let's check and see if the commands are
working.
This is the back inside.
Let's hit the take off button.
You can see the log showing the take off command being received.
Let's try the land button as well.
You see that action is command and the command is land.
Do you remember where we set the logger in the beginning of this lesson and we set the logger and the
server.
P Why file according to the logger the action and command has been logged we've completed sending commands
to the back end.
Next we need to make the drone fly based on these commands but before we set the drone let's add some
more commands to the front end.
In our next lesson.