Monday, 20 March 2017

Domain Presentation



Here is the google docs link to my Powerpoint presentation which I recently presented to the class.

https://docs.google.com/presentation/d/1FXcSMFlPn0nIsB0yet2WYVQCi9WNr3lQt7EEMXUay00/edit?usp=sharing
     

Monday, 13 March 2017

HTTP SERVER ON PI.

Accessing wifi in Arduino

 open the serial monitor and enter the code given down below.
Code: 
#include <ESP8266WiFi.h>
const char* ssid = "aneesh";
const char* password = "raspberry";
const char* host = "www.google.com";
void setup() {
Serial.begin(115200);
delay(100);
// We start by connecting to a WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
int value = 0;
void loop() {
}

Arduino on PI


  • The first step is to load the Arduino environment to PI, by using the following commands


 sudo aptget update
 sudo aptget distupgrade

  • Next, Install Arduino IDE with,

sudo aptget install Arduino (Click Y to add any dependencies)
  •  To disable the serial login (for Raspberry- Pi 3),

 sudo systemctl stop serialgetty@ttyS0.service
 sudo systemctl disable serialgetty@ttyS0.service

  •  The next step is to disable the boot info, for this we need to edit the             /boot/cmdline.txt file by deleting the “console=serail0,115200″ as shown.


 dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p6 rootfstype=ext4 elevator=deadline rootwait 

To link the serial port to the Arduino IDE, we create a permanent link that maps AMA0 to S0.

  • Now create a file by “ sudo nano"

Enter the following code in the newly created file

KERNEL==“ttyAMA0”, SYMLINK+=“ttyS0”,GROUP=“dialout”,MODE:=0666
KERNEL==“ttyACM0”, SYMLINK+=“ttyS1”,GROUP=“dialout”,MODE:=0666
and save it to: /etc/udev/rules.d/

And then to link the new avrdude-autoreset to avrdude so that the new version runs instead.
sudo ln s /usr/bin/avrdudeautoreset /usr/bin/avrdude

  • Adding the sleepy Pi to the Arduino environment, to run the Arduino environment we need to create the sketchbook folder and then “hardware” & “Sleepy_pi ” in sketchbook.

 mkdir /home/pi/sketchbook
 mkdir /home/pi/sketchbook/hardware
 mkdir /home/pi/sketchbook/hardware/Sleepy_pi

  • Now create another file “boards.txt” in Sleepy_pi folder and the file contains the following code,
sleepypi.name=Sleepy Pi
    sleepypi.upload.protocol=arduino
    sleepypi.upload.maximum_size=30720
    sleepypi.upload.speed=57600
    sleepypi.bootloader.low_fuses=0xFF
    sleepypi.bootloader.high_fuses=0xDA
    sleepypi.bootloader.extended_fuses=0x05
    sleepypi.bootloader.path=arduino:atmega
    sleepypi.bootloader.file=ATmegaBOOT_168_atmega328_pro_8MHz.hex
    sleepypi.bootloader.unlock_bits=0x3F
    sleepypi.bootloader.lock_bits=0x0F
    sleepypi.build.mcu=atmega328p
    sleepypi.build.f_cpu=8000000L
    sleepypi.build.core=arduino:arduino
    sleepypi.build.variant=arduino:standard
    8. As a final step, Reboot the Pi to complete and load all changes.

     sudo reboot

    HTTP Server on PI

     HTTP Webserver on Pi to host a full website or to display some information to other machines on our network. There are various web server that are available with different advantages and usage. Among them, I choose Apache, which is a popular web server application and install it on Pi.
    • Install Apache2 package by ” sudo aptget install apache2 y
    • To Test the webserver,
    • We have a test HTML file in Apache folder, so when we type our Pi’s IP address (like http://198.162.10.22) we will get a default web page as shown in the following figure.

    References:

    Monday, 6 March 2017

    IN CLASS HOST-Access Point SETUP

    In this experiment, the aim is to make raspberry pi as an access point of Wifi.


    Items Required:

    • Raspberry Pi. 
    • Ethernet cable.
    • WiFi adapter.
    • SD Card with Raspbian installed in it.
    • Power supply for your Pi & a Micro USB cable.
    This post is about the experience of Host access point setup in class:
    • Connect Raspberry Pi to the router.
    • Change the password into desired one from "raspberry" which is by default.
    Now getting into the protocols and type out commands in the command-line interpreter of the Raspberry Pi:

    • The first step is to install the required packages for setting up access point by 

    "sudo apt-get install dnsmasq hostapd "
    ( 'hostapd' - This is the package that allows you to use the built in WiFi as an access point. 'dnsmasq' - This is a combined DHCP and DNS server that's very easy to configure).

    • Since I have used Raspberry Pi-3 which has very latest version of the RaspianThe interface configuration is handled by dhcpcd. It shall ignore wlan0, as we will be configuring it with a static IP address elsewhere. we do this by opening dhcpcd configuration file with "Sudo nano /etc/dhcpcd.conf" and add the following line in the dhcpcd "denyinterfaces wlan0".
    • Static IP needs to be configured, with “sudo nano /etc/network/interfaces” and edit the wlan0 section should look as follows:

    allow-hotplug wlan0  
    iface wlan0 inet static  
        address 172.24.1.1
        netmask 255.255.255.0
        network 172.24.1.0
        broadcast 172.24.1.255
    #    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
    Now, restart dhcpcd with sudo service dhcpcd restart and then reload the configuration for wlan0 with sudo ifdown wlan0; sudo ifup wlan0.
    • Next step is to configure hostapd by creating a new configuration file sudo nano /etc/hostapd/hostapd.conf with the following contents:


    # This is the name of the WiFi interface we configured above

    interface=wlan0


    # Use the nl80211 driver with the brcmfmac driver
    driver=nl80211

    # This is the name of the network
    ssid=Pi3-AP

    # Use the 2.4GHz band
    hw_mode=g

    # Use channel 6
    channel=6

    # Enable 802.11n
    ieee80211n=1

    # Enable WMM
    wmm_enabled=1

    # Enable 40MHz channels with 20ns guard interval
    ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40]

    # Accept all MAC addresses
    macaddr_acl=0

    # Use WPA authentication
    auth_algs=1

    # Require clients to know the network name
    ignore_broadcast_ssid=0

    # Use WPA2
    wpa=2

    # Use a pre-shared key
    wpa_key_mgmt=WPA-PSK

    # The network passphrase
    wpa_passphrase=raspberry

    # Use AES, instead of TKIP
    rsn_pairwise=CCMP

    "sudo /usr/sbin/hostapd /etc/hostapd/hostapd.conf" can be used to verify if the hostapd is working.
    Until this stage was the work done in the class and rest was done as a homework assignment. The post followed by this post will clearly explain how it is done.

    Open up the default configuration file with sudo nano /etc/default/hostapd and find the 
    line #DAEMON_CONF="" and replace it with DAEMON_CONF="/etc/hostapd/hostapd.conf"





    •  To Configure DNSMASQ create a new file with
    sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig
    sudo nano /etc/dnsmasq.conf
    and paste the file with the contents as follows:
    interface=wlan0      # Use interface wlan0  
    listen-address=172.24.1.1 # Explicitly specify the address to listen on  
    bind-interfaces      # Bind to the interface to make sure we aren't sending things elsewhere  
    server=8.8.8.8       # Forward DNS requests to Google DNS  
    domain-needed        # Don't forward short names  
    bogus-priv           # Never forward addresses in the non-routed address spaces.  
    dhcp-range=172.24.1.50,172.24.1.150,12h # Assign IP addresses between 172.24.1.50 and 172.24.1.150 with a 12 hour lease time.
    • Now the next step is to Setup IPv4 forwarding
    This step enables packet forwarding

    open up the sysctl.conf file with sudo nano /etc/sysctl.conf, and remove the # from the beginning of the line containing net.ipv4.ip_forward=1. This will enable it on the next reboot, but because we are impatient, activate it immediately with: 
    sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"

    need to share our Pi's internet connection to our devices connected over WiFi by the configuring a NAT between our wlan0 interface and our eth0 interface. We can do this using the following commands:

    sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE  
    sudo iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT 
    sudo iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT  

    we need these rules to be applied every time we reboot the Pi, so run  sudo sh -c "iptables-save > /etc/iptables.ipv4.nat" to save the rules to the file /etc/iptables.ipv4.nat. Now we need to run this after each reboot, so open the rc.local file with sudo nano /etc/rc.local and just above the line exit 0, add the following line:

    " iptables-restore < /etc/iptables.ipv4.nat "


    Now we are done with setting up our wifi on Raspberry Pi. This can be hosted using the following commands:

    sudo service hostapd start

    sudo service dnsmasq start

    To check if we have got everything configured correctly reboot with “sudo reboot”


    References: