Saturday, February 6, 2016

Making Raspberry Pi Web Controls

Easy Writer: Setup for Raspberry Pi PHP

source: http://www.php5dp.com/easy-writer-setup-for-raspberry-pi-php/

PHP Design Pattern

Easy Writer: Setup for Raspberry Pi PHP

RaspPHPFocus on writing PHP Code
In fiddling around with PHP on a Raspberry Pi running on a Debian Linux OS more or less directly from a terminal mode, I realized that the focus (in my case) was getting the Linux commands right and very little with actually writing PHP programs. Most queries about getting the setup right involved Linux system administration and not PHP programming.
This short post is for Raspberry Pi users (and perhaps Linux users in general), and it focuses on setting up your Raspberry Pi so that you can use default Raspberry Pi editors (LeafPad) and the File Manager to work with PHP programs. Once set up, you will find the process of creating server-side programs in PHP much easier with no need to use the  terminal editors after setting up your system.
Installing Apache and PHP
Because PHP is a server-side language, you will need both a server and PHP installed on your Raspberry Pi. Using the Root Terminal (Accessories → Root Terminal), enter the following line:
sudo apt-get install apache2 php5 libapache2-mod-php5
Press the Enter key and patiently wait until it’s completed the setup. Once done, you computer will have both a web server and PHP installed. To test whether installation was successful, open a browser from the main menu (Internet → NetSurf Web Browser) and enter the following:
  http://localhost/
If everything works, you will see the message shown in Figure 1 on the right:
Figure 1: Default Web Page
Figure 1: Default Web Page
This location (http://localhost) is the root for your Web pages—PHP and any other Web page you decide to put on your Raspberry Pi Apache server. The name of the file is index.html. On your Raspberry Pi, in the Linux file system, the address is:
  /var/www/
Open the File Manager (Accessories → File Manager) and in the window where you see /home/pi enter /var/www. You will now be able to see the icon for the html file that was automatically created when you installed the Apache server.

Saving PHP and Other Web Files
Before you can start creating and saving PHP programs, you have to make one more adjustment to your file system using the Root Terminal editor. (Accessories → Root Terminal). Enter the following and press the Enter key at the end of each line:
sudo chown www-data:www-data /var/www
sudo chmod 775 /var/www
sudo usermod -a -G www-data pi
sudo reboot
Now you can write (save) files to the www directory and its subdirectories (folders).
PHP Programming Workflow on Raspberry Pi
Now, we’re all set to look at a fairly simple workflow using Raspberry Pi tools. Begin by opening the File Manager from the Pi home:
Figure 2: Pi Home Directory
Figure 2: Pi Home Directory

Navigate to /var/www. You will see the index.html file. Select from the top menu, File →  Create New… →  Folder and name the new folder “php.” This will be the directory where you place your PHP files and PHP-related subdirectories and files. Figure 3 shows how your File Manager will now look with your new php directory/folder.
Figure 3: PHP folder in www root.
Figure 3: PHP folder in www root.

At this point, you’re all set to start working with server-side PHP. To get started, open the php folder by double-clicking it. Next open Leafpad and enter the following program:
<?php
include_once('Client.php');
$worker = new Client();
?>
Save it as billz.php in the /var/www/php/ directory. Next, enter and save the following class as Client.php using Leafpad:
<?php
class Client
{
    function __construct()
    {
        echo "<html><body>";
        echo '<h2>Welcome to OOP PHP,<br/>Raspberry Pi developers!</h2>';
 echo "<img src= 'billGreg.png'>";
 echo "</body></html>";
    }
 
}
?>
Finally, place a graphic—png, gif or jpg—on a USB drive, and plug the drive into your Raspberry Pi USB port or hub. Using the File Manager, copy and paste the graphic into the php directory along with the billz.php and Client.php files. You’re all set to test it. Your file window should look like Figure 4:
Figure 4: PHP files in www/php/ directory
Figure 4: PHP files in www/php/ directory

As you can see, it looks pretty much like what you will see in a Windows or Macintosh directory system. Open your Raspberry Pi browser, and in the URL window enter:
  http://localhost/php/billz.php
Press the Enter key, and you should see your page as shown in Figure 5:
Figure 5: PHP generated content from from a Raspberry Pi server.
Figure 5: PHP generated content from from a Raspberry Pi server.

If you have an internet connection, you can access your Raspberry Pi from another computer either on your LAN or over the internet. I just use my Local Area Network (LAN). Using the terminal command,
  sudo ip addr show
find your IP address. For my LAN, it was 192.168.1.84. Using the URL:
  http://192.168.1.84/php/billz.php
on one of my other computers on the LAN, I am able to use my Raspberry Pi as a Web server and a nice development platform for testing PHP files. (For an internet connection, I can highly recommend the Wi-PI wireless adapter. It is about the size of a USB drive and plugs into your Raspberry Pi.)
Big PHP on Little Systems
The origin of the Raspberry Pi is in the educational field with the goal of getting kids interested in computing. Learning Linux cli code and Python coding (Python comes installed) are two important features of that learning process. Now a server-side language, PHP, can also be part of that process of getting people involved in programming.

Raspberry Pi - WEB UI - wiringPi

source: http://wiringpi.com/download-and-install/


Wiring Pi

GPIO Interface library for the Raspberry Pi

Wiring Pi


HomeDownload and Install

Download and Install

WiringPi is maintained under GIT for ease of change tracking, however there is a Plan B if you’re unable to use GIT for whatever reasons (usually your firewall will be blocking you, so do check that first!)
If you do not have GIT installed, then under any of the Debian releases (e.g. Raspbian), you can install it with:
sudo apt-get install git-core
If you get any errors here, make sure your Pi is up to date with the latest versions of Raspbian:
sudo apt-get update
sudo apt-get upgrade
To obtain WiringPi using GIT:
git clone git://git.drogon.net/wiringPi
If you have already used the clone operation for the first time, then
cd wiringPi
git pull origin
Will fetch an updated version then you can re-run the build script below.
To build/install there is a new simplified script:
cd wiringPi
./build
The new build script will compile and install it all for you – it does use the sudo command at one point, so you may wish to inspect the script before running it.

Plan B

Click on this URL: (it should open in a new page)
https://git.drogon.net/?p=wiringPi;a=summary
Then look for the link marked snapshot at the right-hand side. You want to click on the top one.
This will download a tar.gz file with a name like wiringPi-98bcb20.tar.gz. Note that the numbers and letters after wiringPi (98bcb20 in this case) will probably be different – they’re a unique identifier for each release.
You then need to do this to install:
tar xfz wiringPi-98bcb20.tar.gz
cd wiringPi-98bcb20
./build
Note that the actual filename will be different – you will have to check the name and adjust accordingly.

Test wiringPi’s installation

run the gpio command to check the installation:
gpio -v
gpio readall
That should give you some confidence that it’s working OK.
WiringPi is released under the GNU Lesser Public License version 3.

How to Setup Wi-Fi On Your Raspberry Pi via the Command Line

source: http://www.howtogeek.com/167425/how-to-setup-wi-fi-on-your-raspberry-pi-via-the-command-line/

How to Setup Wi-Fi On Your Raspberry Pi via the Command Line


You configured your headless Raspberry Pi just the way you want it, it’s settled in and running smoothly, but suddenly you want to move it away from its Ethernet tether with a Wi-Fi module. Skip hooking it back up to all the peripherals and quickly add in Wi-Fi support from the command line.

Why Do I Want to Do This?

If you’re a Raspberry Pi enthusiast (or quickly becoming one), you know how annoying it can be to realize that your headless Pi project now needs yet another little tweak that likely necessitates hooking up a monitor and keyboard/mouse to the box.
RELATED ARTICLE
The HTG Guide to Getting Started with Raspberry Pi
Over the last year the Raspberry Pi, a cheap credit-card sized computer, has taken the computing and DIY world by... [Read Article]
The best way to avoid falling into that trap is to configure your Raspberry Pi for remote access. Once you have that configured, however, you still need to know how to do tasks remotely that would previously be handled by a GUI interface (like turning on the Wi-Fi). Today we’re going to walk you through the technical (but simple) way to remotely connect to your Pi and activate a Wi-Fi add-on dongle.

What Do I Need?

For this tutorial you’ll need the following items:
  • 1 Raspberry Pi unit with Raspbian installed (this technique should work on other distributions, but we’re using Raspbian)
  • 1 Ethernet connection to Pi unit (necessary for activating the Wi-Fi functionality remotely)
  • 1 Wi-Fi Dongle (we use this model on all our Pi units with great success)
If you don’t use this Wi-Fi dongle model, we strongly recommend researching the model you intend to purchase to see if it is well supported. To that end, the USB Wi-Fi adapter section of the RPi wiki is very helpful.
In addition to the above items, you need to take a moment to check the configuration of the Wi-Fi node you intend to connect your Raspberry Pi unit to: you’ll need to make note of the SSID, password, and encryption type/method (e.g. the node is using WPA with TKIP shared-key encryption).

Enabling the Wi-Fi Dongle via the Terminal

To get started, power up your Raspberry Pi unit without the Wi-Fi dongle attached. At this point, the only network device should be the onboard Ethernet NIC (which you have connected to your network via Ethernet cable so you can remotely access the headless device).
Connect to your Pi via SSH to access a remote terminal prompt. (If you have not yet configured your device for remote access in this fashion, please review the following tutorial).
At the prompt, enter the following command:
sudo nano /etc/network/interfaces
In the nano text editor, you’ll see something like this:
auto lo
iface lo inet loopback
iface eth0 inet dhcp
That’s the very basic configuration that governs your Pi’s Ethernet connect (indicated by the eth0 portion). We need to add on a very minor bit to enable the Wi-Fi dongle. Use the arrow keys to move down below the existing entry and add the following lines:
allow-hotplug wlan0
iface wlan0 inet dhcp
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp
Once you’ve annotated the file, press CTRL+X to save the file and exit the nano editor. At the prompt again, enter the following command:
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
Compare the contents of the file, if it exists, to the following code. If the file is empty, you can use this code to populate it. Take note of the commented lines (indicated by the # marks) to reference which variable you should use based on your current Wi-Fi node configuration.
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
ssid="YOURSSID"
psk="YOURPASSWORD"

# Protocol type can be: RSN (for WP2) and WPA (for WPA1)
proto=WPA

# Key management type can be: WPA-PSK or WPA-EAP (Pre-Shared or Enterprise)
key_mgmt=WPA-PSK

# Pairwise can be CCMP or TKIP (for WPA2 or WPA1)
pairwise=TKIP

#Authorization option should be OPEN for both WPA1/WPA2 (in less commonly used are SHARED and LEAP)
auth_alg=OPEN

}
When you’re done editing the file, press CTRL+X to save and exit the document. Now is the time to unplug the Ethernet cable and plug in the Wi-Fi dongle.
At the command prompt, enter the following command:
sudo reboot
When the device finishes rebooting, it should automatically connect to the Wi-Fi node. If for some reason it fails to appear on the network, you can always plug the Ethernet cable back in to double check the two files and the variables you altered.

Turning on an LED with your Raspberry Pi's GPIO Pins

http://thepihut.com/blogs/raspberry-pi-tutorials/27968772-turning-on-an-led-with-your-raspberry-pis-gpio-pins


The Code

You are now ready to write some code to switch the LED on.  Turn on your Pi and open the terminal window.
Create a new text file “LED.py” by typing the following:
nano LED.py
Type in the following code:
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(18,GPIO.OUT)
print "LED on"
GPIO.output(18,GPIO.HIGH)
time.sleep(1)
print "LED off"
GPIO.output(18,GPIO.LOW)
Once you have typed all the code and checked it, save and exit the text editor with “Ctrl + x” then “y” then “enter”.

Running the Code

To run this code type:
sudo python LED.py

Learning MS Power APP and FLOW

https://powerapps.microsoft.com/ro-ro/blog/microsoft-powerapps-learning-resources/