Sunday, April 1, 2018

Raspberry Pi, NOOBS, LAMP and ALEXA

How to setup a $35 computer using a Raspberry Pi, NOOBS, a LAMP webserver and ALEXA:
by J.B. Wylzan




First, you need the following items:
  • MicroSD card with preloaded NOOBS (or load it yourself here)
  • HDMI monitor
  • HDMI cable
  • USB keyboard and mouse
  • 2.5A microUSB power supply
  • Ethernet cable (for internet connection)
To set up your Raspberry Pi as a computer and configure it to work as a web server using LAMP, which stands for Linux, Apache, MySQL, PHP, follow the quick start guidelines below:

A) Install GUI Linux:

1. Insert all of the items above to the raspberry pi board.
2. Insert the microSD card (this is your hard drive)
3. Power it up by connecting the 2.5A power adapter
4. Once the NOOBS is running, select the "Raspbian" as your operating system
5. When done, shut it down properly using the terminal editor
    -type:  sudo shutdown -h now

To Setup as a Webserver:

B) Install Apache:
 
Apache is a popular web server application you can install on the Raspberry Pi to allow it to serve web pages.

On its own, Apache can serve HTML files over HTTP, and with additional modules can serve dynamic web pages using scripting languages such as PHP.

Install the apache2 package by typing the following command into the terminal:

sudo apt-get install apache2 -y

Test the web server

By default, Apache puts a test HTML file in the web folder. This default web page is served when you browse to http://localhost/ on the Pi itself, or http://192.168.1.10 (whatever the Pi's IP address is) from another computer on the network.

To find out the Pi's IP address, type hostname -I at the command line.

Browse to the default web page, either on the Pi or from another computer on the network, and you should see the following:

Changing the default web page

This default web page is just a HTML file on the filesystem. It is located at /var/www/html/index.html.

Note: The directory was /var/www/html in Raspbian Jessie

Navigate to this directory in the Terminal and have a look at what's inside:

cd /var/www/html
ls -al

As you can see, by default the html directory and index.html file are both owned by the root user, so you'll need to use sudo to edit them.

Try editing this file and refreshing the browser to see the web page change.

Press Ctrl + X and hit Enter to save and exit.

C) Install PHP:
 
PHP is a preprocessor; it's code that runs when the server receives a request for a web page. It runs, works out what needs to be shown on the page, then sends that page to the browser. Unlike static HTML, PHP can show different content under different circumstances. Other languages are capable of this, but since WordPress is written in PHP, that's what we need to use this time.

Install the PHP and Apache packages with the following command:

sudo apt-get install php5 libapache2-mod-php5 -y

Test PHP

Create the file index.php:
sudo nano index.php

Put some PHP content in it:
<?php echo "hello world"; ?>

Now save the file. Next delete index.html because it takes precendence over index.php:
sudo rm index.html

Refresh your browser. You should see "hello world". This is not dynamic but it is still served by PHP. If you see the raw PHP above instead of "hello world", reload and restart Apache like so:
sudo service apache2 restart

Otherwise try something dynamic, for example:
<?php echo date('Y-m-d H:i:s'); ?>
 
Or show your PHP info:
<?php phpinfo(); ?>
 
D) Install MySQL:
 
MySQL (pronounced My Sequel or My S-Q-L) is a popular database engine.

Like PHP, its overwhelming presence on web servers enhanced its popularity. This is why projects like WordPress use it, and why those projects are so popular.

Install the MySQL Server and PHP-MySQL packages by entering the following command into the terminal:
sudo apt-get install mysql-server php5-mysql -y

When installing MySQL you will be asked for a root password. You'll need to remember this to allow your website to access the database.

Now restart Apache:
sudo service apache2 restart 




E) Install Alexa:

Step 1: Setting up your Pi
Step 2: Register for an Amazon developer account
Step 3: Create a device and security profile
  • Allowed Origins: https://localhost:3000
  • Allowed Return URLs: https://localhost:3000/authresponse
Step 4: Clone the sample app
  • cd Desktop
  • git clone https://github.com/alexa/alexa-avs-sample-app.git
Step 5: Update the install script with your credentials
  • cd ~/Desktop/alexa-avs-sample-app
  • nano automated_install.sh
Step 6: Run the install script
  • cd ~/Desktop/alexa-avs-sample-app
  • . automated_install.sh
Step 7: Run your web service, sample app and wake word engine
Terminal 1
  • cd ~/Desktop/alexa-avs-sample-app/samples
  • cd companionService && npm start
Terminal 2
  • cd ~/Desktop/alexa-avs-sample-app/samples
  • cd javaclient && mvn exec:exec
Terminal 3
  • cd ~/Desktop/alexa-avs-sample-app/samples
  • cd wakeWordAgent/src && ./wakeWordAgent -e kitt_ai
Step 8: Talk to Alexa
Step 9: How to Log Out of the Sample App
To log out of the AVS java sample app you must clear your sessionId in /samples/javaclient/config.json, and delete your refresh_tokens file in the /samples/companionService folder. Otherwise, the sample app will authenticate on each reboot.
Solution:
Follow these instructions to log out of the AVS java sample app:
Quit the AVS java sample app (CTRL + C).
Open /samples/javaclient/config.json and clear your sessionId. It should look like this:

"sessionId": ""

Delete the refresh_tokens file in samples/companionService.

The next time you log in you will be prompted to authenticate.

Reference:  github.com/alexa/alexa-avs-sample-app/wiki/Raspberry-Pi


NOTICE: Articles on this site are composed on random thoughts. The transcript may not be in its final form. It maybe updated or even revised in the future.



"Everything is a switch, each one can be turned ON and OFF." ~ Joey Lawsin



Disclaimer:  We shall not be liable for any loss or damage of whatever nature - direct, indirect, consequential, or otherwise - which may arise as a result of your use of any information on this website. However, if you are interested in using any of the projects for personal or educational purposes, please inform the author by email. 

PPublic Domain Notice: Copyright (c) 2000. All rights reserved. This article is part of a book entitled iHackRobot. Copies are welcome to be shared or distributed publicly as long proper citations are observed. Please cite as follows: Biotronics: The Silver Species, Joey Lawsin, 1988, USA.

================================================================== 
The Homotronics® and Homodruinos® logos are registered trademarks.
Copyright Biotronics© Inc. iHackRobot®. All Rights Reserved.
Patent Pending. 2000 © ®

L.A.W.S.I.N. Educational Production
 ==================================================================