Program to control an LED through web browser
We have created a webserver on port 3001
. Now it is time to turn an external LED on and off using a HTML page remotely. Just by changing variable ledPin
in the following JavaScript program to USR0
, you can turn on/off onboard USER0 LED. This will save wiring efforts. We are going to use the JavaScript socket.io
library for this. This library allows real-time, full-duplex, communication by sending and receiving events. Let's install it by running the following command in the BeagleBone shell.
sudo npm install –g socket.io
The npm is Node Package Manager. It is a package manager for JavaScript libraries. It works independent of the Debian package manager. The source code of socket.io
is available here: https://github.com/socketio/socket.io.
HTML code
Let's create an HTML file first. Open Cloud9 IDE and create a new file named led.html
. Write the following code in led.html
:
<!DOCTYPE html> <html> <head> <script src="/socket...