Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Wednesday, July 20, 2016

Phone As Raspberry Pi Screen


I usually have to work on a cluster in the college and all I need is a client to connect to that cluster. The Raspberry Pi is a great alternative to my laptop which has recently started to die of old age.

The problem I face with the PI is however quiet a different one. I usually don't have a projector / display around to see what I'm typing in. This is a workaround to that problem. Since I almost always have my phone around, I decided to use that as a display. 

Do note that this does not mean that you will have full graphics. It just let's you see what you are typing on a terminal in the Pi. For full graphics you would need some sort of VNC setup.



Let's get started.
  1. Hardware Required
    1. Raspberry Pi
    2. Wifi Dongle
    3. Keyboard
    4. Mobile Phone (Android / iPhone etc)
    5. Working internet connection (For setup purposes)
  2. Software required
    1. On Raspberry pi
      1. ssh-daemon (This is preinstalled if you are using NOOBS). Otherwise use sudo apt-get install sshd
      2. Tmux ( can be installed via sudo apt-get install tmux)
      3. In case you don't like tmux for some reason, you may be able to use screen in a similar fashion as described.
    2. On phone
      1. Some sort of SSH client. I use Juice SSH but you are free to use any one.
      2. Since I have never used Apple, I'm going to leave finding an SSH client there to you. comment below if you find one that you have used.
  3. Other requirements
    1. A keyboard for the PI would be nice, though you can use your laptop too in case you do not have one.
    2. The Raspberry pi needs to be able to connect with a network beforehand. See this resource.
    3. In case you have a router lying around, connect the Pi, phone (and laptop if needed) to the same router. Otherwise set up a WiFi hotspot in your phone and connect everything to that.
  4. Steps
    1. Power on the Pi
      1. Switch on the Pi.
      2. Plug in the wireless dongle.
      3. Let the Pi connect to the network
    2. Power on the laptop
      1. SSH into the raspberry pi
        1. ssh pi@192.168.xxx.xxx
        2. Windows users can use Putty
        3. Install Tmux via sudo apt-get install tmux
        4. use raspi-config command to make sure that the login procedure is login to command line
        5. exit the ssh session (Ctrl + d)
    3. Reboot the Pi
      1. Connect a keyboard
      2. You will be logged in to the PI user automatically as per the last config.
      3. type tmux new-session -s main
        1. This opens a new tmux session.
    4. SSH into the Pi using your phone (Juice SSH)
    5. Using your phone type in tmux attach -t main to the terminal you have just opened.

You can now see the same tmux session which is running on your PI. Whatever you type in the keyboard appears on your phone. This allows you to use your phone as a temporary display for the Raspberry pi terminal.

Here's a demo video.

Saturday, July 9, 2016

Nested Tmux Sessions

I use Tmux on my local machine and also prefer to use it once I'm logged in to remote machines. This posed a problem as commands intended for the remote Tmux were intercepted by the local Tmux.

A solution was found here: http://www.stahlke.org/dan/tmux-nested/

I'm not going to be repeating good advice again so here's my tmux.conf with the necessary changes.

set -g status-bg colour40
setw -g window-status-current-bg colour40

bind -n C-t new-window -a
bind -n S-left  prev
bind -n S-right next
bind -n S-C-left  swap-window -t -1
bind -n S-C-right swap-window -t +1

bind -n M-F11 set -qg status-bg colour25
bind -n M-F12 set -qg status-bg colour40
bind -n S-up \
 send-keys M-F12 \; \
 set -qg status-bg colour25 \; \
 unbind -n S-left \; \
 unbind -n S-right \; \
 unbind -n S-C-left \; \
 unbind -n S-C-right \; \
 unbind -n C-t \; \
 set -qg prefix C-a
bind -n S-down \
 send-keys M-F11 \; \
 set -qg status-bg colour40 \; \
 bind -n S-left  prev \; \
 bind -n S-right next \; \
 bind -n S-C-left swap-window -t -1 \; \
 bind -n S-C-right swap-window -t +1 \; \
 bind -n C-t new-window -a -c "#{pane_current_path}" \; \
 set -qg prefix C-b

Cheers!

Wednesday, April 13, 2016

The Terminal - (Not the Movie)

"Ah, you think that a GUI is your ally? You merely adopted the GUI. I was born in it, molded by it. I did not see a terminal until I was already a man, by then it was nothing to me but blinding." - the difference between now and then.

As mentioned, I was born in 1994, and computers already had GUI by that time. Ever since I was introduced to computers, all I knew was the GUI. That had, as aptly said, defined my computer using habits. I was dependent on the mouse, I needed WYSIWYG editors and so on. Not that they are a bad thing, but they made the computer a black box for me.In college I was introduced to the command line and that gave way to a whole new experience.

This article is about how I finally embraced the terminal and started my life inside of it. As of now, I have completely un-installed the X server on my Archlinux installation and currently only have the terminal. Note that this is a TTY and not a terminal emulator like terminator and xterm.

Some of the things I had to introduce in my life to make this easier were:
  • MUTT   : for email purposes
  • IRSSI  : for IRC purposes
  • MDP    : for presentation purposes
  • TMUX   : for the sake of sanity.
  • LYNX   : for web browsing purposes
  • GNUPLOT: for plotting purposes ( the text mode is useful)
  • PANDOC : for converting various files to text
These things have made life a lot simpler. The terminal also streamlines your thought process a lot. Though it is a little tough initially, since our daily experience is so enriched by graphics, after a while you begin to see the effects.

The Changes

First off you miss the desktop. With nothing to see, you need to constantly be aware of where you are in the computer and what you want to do. That said, it takes away a lot of distraction by removing the oh-so-good movies folder from your sight.

With the Desktop gone, the file explorer is the next thing that is missed. This bit of tech had us in binds, making exploring as easy as point and click. It does however mask some things in the file system which we would have been better off knowing.

The next thing which hurts us is the browser. Firefox, Chromium and so on are all graphical browsers. We have given all of that up for the sleek, powerful and ad-free environment of terminal based browsers. Keep in mind that the image displaying powers of w3m also do not work as the X server has been removed.

Images and videos do not work. Obviously! That puts a hitch in our world, sure does.  VLC media player to the rescue. Turns out that VLC has a ASCII mode where it can display images and videos as painted by ASCII characters. Here is an example.


Best of all it works in the TTY too. That takes care of seeing a few short tutorials without the X server involved. Do take care though that you are using tmux when you are doing this as it takes over the TTY when a video is run, not allowing you to Ctrl-C it or close it in any other manner (AFAIK).

Another thorn in the side is research papers which are usually PDF files. Pandoc comes to the rescue by allowing us to convert between files. I use another utility called pdftotext.

When professors ask you to give a presentation on some topic, you begin to miss the old PowerPoint. In hindsight though, as Uncle Ben said "With great power comes great responsibility". PowerPoint makes it easy to obscure the message and deliver nothing at all. I have begun using MDP to provide presentations from the terminal itself.

With the browser gone, Gmail and Facebook has been cut off too. Although LYNX provides a decent web browsing experience, the lack of Javascript shows. For email I have started using MUTT and for Facebook, well let's just say that ship has sailed.

With the browser went the ability to use Jupyter notebooks. And so we come to our last program which helps ease the terminal life (pun probably intended). GNUPLOT let's us plot graphs in text mode, allowing us to get a general idea of what the data is like. Of course it is nowhere near the full capability of GNUPLOT but it gets the job done.

And so our life in the terminal is now rolling and work is so much more easier because of it.


Monday, February 8, 2016

Chatting over lan with Linux

Communication within institutes is a pleasure with linux. Especially so since I just discovered this. The netcat or ncat program is needed (Both are interchangeable). On Ubuntu netcat is usually used and on Archlinux ncat is available. To receive communications run

ncat -l 8080
or
netcat -l 8080

This makes the netcat program listen at port 8080.
Now anyone on the same network as you can connect to you by:

ncat 192.168.10.116 8080
or
netcat 192.168.10.116 8080

That is assuming that your IP address is 192.168.10.116

Now, telling your peers that you will be listening at some port allows them to connect to you at any time that your ncat program is running. When you want to go away, simply stop your program.

You can broadcast too. Just get many people to connect to you.