Websockets

From ESE205 Wiki
Revision as of 14:11, 15 April 2019 by Amandahua (talk | contribs)
Jump to navigation Jump to search

Overview

This tutorial explains how to create a basic websocket, opening communication between a server on a raspberry pi and a client, and flash an LED on the pi using the web client.

Materials/Prerequisites

  • Raspberry Pi
  • 2 LEDs
  • Female-Male Wires
  • Breadboard
  • Resistors
  • An AWS account

Process

Preparation

Set up a Lightsail or EC2 instance.

Turn on your pi. If you haven't already followed the tutorial for SSH'ing into your pi, you can view it here. If you've set this up, you can SSH into your pi. Otherwise, you can use a monitor setup with an hdmi and external keyboard and mouse to access the terminal from the pi directly.

SSH into your pi and your AWS instance.

Install LAMP

This tutorial explains what we're doing in more depth, but basically you're setting up a website to be hosted on your AWS instance. Run the following commands in your AWS instance (client side).

#update your instance so that it can install LAMP (Linux Apache, MySQL, PHP)
sudo yum update -y

#install LAMP
sudo yum install -y httpd24 php70 mysql56-server php70-mysqlnd

#start the server
sudo service httpd start

#make it so that the server starts on boot
sudo chkconfig httpd on

After you have run these commands, the server should start when you start the instance. However, you're going to want to add a security rule to the instance. You should already have a TCP port 22 rule (for SSH), but now you need to add an HTTP TCP port 80 rule with custom range.

After you've added this rule, test the page by typing in the instance's PUBLIC IP address into the address bar. There should be a test page for the linux AMI instance showing. Please troubleshoot using the tutorial link provided at the beginning of this section.

The root of your server is at /var/www/html. To create a webpage, you're going to need user access. Run the following command:

#add your own username to the apache group
sudo usermod -a -G apache <YOUR USERNAME>

Now, exit your instance and reconnect to allow the changes to happen. After you SSH back into your instance, you can check that you've been added to the group.

#see what groups you're a part of
groups

#give ownership to your user
sudo chown -R <YOUR USERNAME>:apache /var/www

#allow your group to edit the html files
sudo chmod 2775 /var/www
find /var/www -type d -exec sudo chmod 2775 {} \;
find /var/www -type f -exec sudo chmod 0664 {} \;

Creating the Websockets

Authors

Amanda Hua, Tricia Brown, TA: Keith Kamons Spring 2019

Group Link

Our Project Page
Our Weekly Log

External References

Basic Intro
String Communication
LED Communication