Scala-IOT: Getting started with RaspberryPi without Monitor or Screen.


Hey folks,

We are back again ! ( Did you miss me? ) A big Moriarty Fan ! 🙂

So where we left was, now we have a basic understanding of IOT i.e. Internet of things and we know which protocol it uses i.e. MQTT and why it uses it ? If you didn’t follow us till here you can check out our previous blogs and then come back here to be in a flow.

1. Scala-IOT : Introduction to Internet Of Things.

2. Scala-IOT : What is Mqtt ? How it is lightweight ?

So in this blog we will talk about how to get started with RaspberryPi. How to  install the Raspbian Jessie on it, and how to configure it so that you would not need any screen to communicate with it !

So the per-requisites would be  :

  • Raspberry Pi 3
  • SD card (8GB+)
  • Power Source ( Mobile charger : I am using  5.0V -2.0 A )

So it looks like in upcoming blogs we would be working on these:

IMG_20160827_203534_HDR

So now we would be going to install the Raspian Jessie on it and configure it so that we can use it without any additional Screen !

So we are going to follow the following steps:

Getting the Raspian Image and writing it on SD Card:

  1. Get the Raspian image from the official Raspberry Pi website.
  2. Write the image to the SD card using the instructions for your laptop OS (this takes some time) Note that you cannot just copy the .img file to the SD card, you need to use the instructions below:

    Eject the SD card from your laptop and insert into the Raspberry Pi SD slot.
    There is also one more resource for the instruction of setting up the SD Card you can find it here.

 

Setting up the Wifi Connection Settings:

After the image has been written on the disk we are going to make some changes to some configuration file , hence please do not remove the SD card yet.

  1. Now comes the important part , setting up the Wifi-connection so that you would not need any screen to login to the RaspberryPi. 😉
    Hence please do not remove the SD Card from your card Reader
    So for this we are going to edit the wpa_supplicant.conf present on your SD card with the following path.

    Path: ${path_to_SD_Card}/etc/wpa_supplicant/wpa_supplicant.conf
  2. In this Configuration file we will provide the settings of your network  for your Raspi3 so that it may connect to your wifi. So you have to provide the following details and your configuration file should look like this
    wpa

    Note:
    Here I have defined for the multiple networks for a single network you can do this by Adding just the following line at the end , and also open the file using the following command from your terminal:

    nano ${path_to_SD_Card}/etc/wpa_supplicant/wpa_supplicant.conf

    And now add the following configuration:

    network={
        ssid="your-network-ssid-name" //in my case it was dungeon_masster 
        psk="your-network-password" //in my case it was brokenwings 
        id="name"//this is optional but is required for multiple configur-
    ation
    }
    

    Exit the terminal using “Ctrl+X” then “Y” and then “Enter”

 

Note: I am providing instructions for RaspberryPi3 as it has in-built wifi, this may be different on other version of Raspian and for any other model which does not have any built-in wifi

Now you are good to go for booting up your Pi.

Booting up the Raspberry Pi :

Connect the power supply to the Raspberry Pi, you will see the RED Light on and after two or three seconds  the Green light starts blinking , it means it has booted up.

Finding your RasberryPi’s IP address for ssh access:

Finding your RaspberryPi IP address can be as troublesome as finding a small bug in your Javascript Code. 😛 and sometimes can be as easy as just finding bug in your Scala Code. 😀

Method 1 : You can look for your Pi’s address in the Active Client Table of your network if you have the admin access.

Client Table

 

Method 2: This comes in handy when you do not have the admin access to the network then nmap comes to save us

Nmap (Network Mapper) is a security scanner. It is used to discover hosts and services on a computer network.

Find your IP using ifconfig:

ifconfig

wlan.png
Use the following command on your terminal to :

sudo nmap -sN 192.168.0.0/24

Note:Use your Ip in the nmap by replacing the last number by 0 and then /24 for scanning all network
This will result in the following to show your Pi’s address

MAC Address: B8:27:AS:LL:AH:UU (Raspberry Pi Foundation)
Nmap scan report for 192.168.0.5

Now we have got the IP address now its the time to login to the Raspi.

Logging in to the RaspberryPi:

Use the following command to login to the raspi

ssh pi@192.168.0.5

By default :

Username: pi
Password: raspberry

Now You have logged in ! Now starts the process of setting up the Raspi.

Configuring Raspberry Pi:

Update the configuration on the Raspberry Pi.

  1. In a terminal window enter the following command
sudo raspi-config

You should now see the configuration tool:

rsapicon

To use the tool select from the main menu using the arrow keys then hit tab to jump to the select button. The space bar or enter key accepts the current selected action (Select or Finish). When an action has been performed use tab key to jump back to the list to select another option.

The following steps need to be taken in the configuration tool:

1: Expand Filesystem

2: Change User Password (default user is pi with default password raspberry)

5: Internationalisation Options (set the Locale/Timezone and Keyboard layout for your location. If using WiFi set your country to ensure correct use of WiFi frequencies)

9: Advanced Options:

A2-Hostname (give your pi a unique name)

A7-I2C (specify to load module as default)

Finish (select to reboot)

Your Raspberry Pi will reboot after finishing the configuration. If using a remote connection you will need to wait for the Raspberry Pi to reboot then reconnect (you should get the same IP address, if not use the hostname -I command to discover the new IP address assigned to your Pi.

Updating the firmware and Raspbian OS

Update all packages that have been updated since the Raspbian image was created.

Enter the following commands in a terminal window:

sudo rpi-update
sudo reboot -n

after the last command the Raspberry Pi will reboot. If using a remote terminal reconnect when the Raspberry Pi reboots. To update the raspbian OS enter the following commands:

sudo apt-get update
sudo apt-get -y upgrade
sudo apt-get -y autoremove

Using the Pi’s Desktop: setting up VNC server

VNC is a service that allows the Graphical User Interface of the Raspberry Pi to be access remotely using a VNC client. 1. Install the VNC server using the following command:

sudo apt-get install -y tightvncserver autocutsel

2. Run VNC server and follow the prompts to set an access password. You don’t need a view-only password unless you want to set one:

vncserver

3. Enter the following to setup VNC to run at system startup:

cat >vncserver@.service <<EOF
[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target

[Service]
Type=forking
User=pi
PAMName=login
PIDFile=/home/pi/.vnc/%H:%i.pid
ExecStartPre=-/usr/bin/vncserver -kill :%i > /dev/null 2>&1
ExecStart=/usr/bin/vncserver -depth 24 -geometry 1280x800 :%i
ExecStop=/usr/bin/vncserver -kill :%i

[Install]
WantedBy=multi-user.target
EOF
cat >/home/pi/.vnc/xstartup <<EOF
#!/bin/sh

xrdb $HOME/.Xresources
xsetroot -solid grey
autocutsel -fork
#x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
#x-window-manager &
# Fix to make GNOME work
export XKL_XMODMAP_DISABLE=1
/etc/X11/Xsession
EOF
sudo mv vncserver@.service /etc/systemd/system/
sudo chown root:root /etc/systemd/system/vncserver@.service
sudo systemctl daemon-reload && sudo systemctl enable vncserver@1.service

 

To access the Raspberry Pi you will need a VNC client installed. There are a number of VNC Clients available. The Raspberry Pi web site includes instructions on how to set up and use RealVNC:

Accessing RaspberryPi’s Desktop without external Screen :

Finally you can access your Pi’s Desktop on your Laptop screen:

For this I am using Linux’s Remote Desktop Viewer:

So connect your Pi like this :

RDM

And here it comes what we waited for:

THE PI’s DESKTOP:

pides

Hurray !

Your Raspberry Pi has set up successfully !

In the Upcoming blog we will talk about setting up the scala environment on RasberryPi, till then play around with it ! Try to explore ! And let me know if you find anything interesting ! All comments are welcomed !

Important Note: If you find any trouble in this ping me here or on twitter : @shiv4nsh . I would love to hear from you !
And one More important thing there is an excellent course going on IOT on Coursera , so if you want to learn more..

Join it !
PS: I will be working as a mentor that course too ! So if you find any problem in that course then also I may be of some help !

Thanks ! I hope You enjoyed it !
Stay Tuned for more !

Till then Happy hAKKAing ! 😀

References:

  1. RaspberryPi2 : Basic Setup
  2. A developer’s guide to the Internet of Things (IoT) Course on Coursera

KNOLDUS-advt-sticker

About shiv4nsh

Coder, Gamer, Learner..!!
This entry was posted in IOT, Scala and tagged , , , , , , , , , , , , , , , , , , . Bookmark the permalink.

7 Responses to Scala-IOT: Getting started with RaspberryPi without Monitor or Screen.

  1. Pingback: Scala-IOT : Introduction to Internet Of Things. | Knoldus

  2. Pingback: Scala-IOT: Getting started with RaspberryPi without Monitor or Screen. | Scala Lovers

  3. SamV says:

    Reblogged this on Power to Build and commented:
    Wow, two great, seemingly unconnected, technologies together!? Great post about using Scala with Raspberry Pi! I am going to give it a shot. Thank you. See below for the original post.

  4. Pingback: Scala – IOT : First basic IOT application using Scala on RaspberryPi | Knoldus

  5. Good and useful blog. Just wanted to add: I have found Lightweight X11 Desktop Environment (LXDE) to be easy to set up and use for accessing my Raspberry PI from my Ubuntu. In my application, I had to use a JVM locally running on the PI, as well as using its Chrome browser, not to mention manipulating the sensors (through Arduino/directly attached) through ‘bash’: it all worked very nice.

  6. Pingback: Spark – IoT : Combining Big Data Analysis with IoT | Knoldus

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s