Tip:
Highlight text to annotate it
X
Raspberry Pi and Tornado "Hello World"
Click the link in the description to download the codes from Github.
In this video we will see how to create the basic project file to integrating Arduino and Pic,
with Rasberry Pi measuring and controlling physical varialbes through websockets.
The first thing to do is create the following file structure.
Then in our main archive started typing the code.
First import the libraries, then created the classes: "Raspberry", "renderHandler",
"LedHandler", "RaspberryHandler" and "Application".
This code can be downloaded from the repository on Github.
Or if you want you can also pause the video and go line by line by entering the code
in their favorite text editors.
The functions "register" and "unregister" are responsible to create and destroy sessions when
a client connects or disconnects.
The "Ledón" and "ledOFF" functions update the status LED
and "notifyCallbacks" function sends messages in real-time to connected clients.
The "renderHandler" class is responsible for displaying the template and allow the variable "state"
is updated for python and javascript each time an event occurs.
The "LedHandler" class is designed to detect the actions that customers want to run
pressing the buttons "Start the led" and "Turn off the LED" on the main page
index.html
The "RaspberryHandler" class communicates via WebSockets with all clients to detect
when a client connects, disconnects or to update all clients
LED status messages.
In the "callback" function parameters are received as Led status and transmitted
json format to all clients using the Sockets open with each client.
The "Application" class is responsible for integrating all classes and preparing the app
for everything to work, creating the friendly URL, indicating the route where the
folders with templates, images, styles. arhivos CSS and JavaScript functions.
Finally we start the web server on port 5000.
In the "templates" folder the "index.html" file is created.
In line 6 we include jQuery and line 7 include file functions "raspberry.js".
On line 12, the contents of the variable "state" is displayed
and line 15 stores the "session" established for each client.
And this is the result of our simple interface.
A button to change the status LED and a field of red to show the messages.
In the "static/scripts" folder file "raspberry.js" is created. It is very important
consider the variable "ipDir" this must be updated with the IP address of Raspberry Pi.
or the computer where the HTTP server is started. using the same port,
for this case port 5000.
In Windows the command is ipconfig and ifconfig linux command to find
this direction.
With jQuery we add events to buttons and "requestRaspberry" function creates communication
for each client via WebSockets.
Finally, run the application from the console, entering the folder
where they created the project.
It is important to note that Raspberry Pi must add the key word "sudo".
A look have started the server in the address bar of a web browser Digitan
the IP address assigned by the server over port 5000.
Pressing the "Power On Led" button should change the message in red for all
clients connected to the website.
This example works in Windows and Raspberry Pi.
In the following video we will see how to control via the GPIO port of Raspberry Pi.
"Like and Subscribe"