Friday, April 24, 2015

Remote computer radio.

 Set up your own computer based radio. radio-locator.com is a good place to start for looking to find available stations.




Many radio stations will let you listen to their live stream, Sometimes you can find and use the link on their web page. Sometimes you have to venture through web page html to find it the file and download it from their server. So if that file gets updated, you will need to get the file again.




A play list might look like:


$ cat klolfmaac.pls
[playlist]
File1=http://2243.live.streamtheworld.com:80/KLOLFMAAC_SC
File2=http://2243.live.streamtheworld.com:3690/KLOLFMAAC_SC
File3=http://2243.live.streamtheworld.com:443/KLOLFMAAC_SC
Title1=KLOLFMAAC_SC
Title2=KLOLFMAAC_SC-Bak
Length1=-1
NumberOfEntries=3
Version=2

or

$ cat koda-fm.m3u
http://107.14.43.102:80/7/597/20097/v1/auth.akacast.akamaistream.net/koda-fm
http://koda-fm.ng.akacast.akamaistream.net:80/7/597/20097/v1/auth.akacast.akamaistream.net/koda-fm
http://koda-fm.ng.akacast.akamaistream.net:80/7/597/20097/v1/auth.akacast.akamaistream.net/koda-fm
http://koda-fm.ng.akacast.akamaistream.net:80/7/597/20097/v1/auth.akacast.akamaistream.net/koda-fm


iHeart and Tunein radio are a bit more to decipher.

So log in to the remote server and install your files (the shell file and the play lists). Then modify the shell file for the location of the play lists. Make the shell file executable.

$ chmod +x radio,sh
What I do is install screen so I can let go of the script if I need to and then come back later to it.

$ screen
<ctrl>A d) to disconnect

Get screen sessions

$ screen -ls

Then reconnect with:

$ screen -r <session number or name>


Then just run it


$ ./radio.sh

Press q to quit
$ exit to leave screen session.


[code]
#!/bin/bash
#
# Script to emulate a radio.
#
while :
do
clear
echo "************************"
echo "* Radio tuner          *"
echo "************************"
echo "* [1] Alvin            *"
echo "* [2] 91.7 classical   *"
echo "* [3] 88.7 global      *"
echo "* [4] Kuhf news        *"
echo "* [5] KPFT             *"
echo "* [6] Koda             *"
echo "* [7] KTBZ             *"
echo "* [8] KSBJ             *"
echo "* [9] KGLT             *"
echo "*                      *"
echo "* [0] Exit/Stop        *"
echo "************************"
echo
echo "Enter your menu choice [1-9 or 0]: "
read -n 1 yourch
case $yourch in
1) mplayer -playlist http://www.kaccradio.com/images/KACCRadio.asx  ;;
2) mplayer -playlist  http://www.publicbroadcasting.net/kuhf/ppr/kuha_128.m3u  ;;
3) mplayer -playlist  http://www.publicbroadcasting.net/kuhf/ppr/kuhfglobal_128.m3u  ;;
4) mplayer -playlist http://www.publicbroadcasting.net/kuhf/ppr/kuhfnews_128.m3u  ;;
5) mplayer -playlist http://kpft.org/KPFT-hifi.wma ;;
6) mplayer -playlist koda-fm.m3u  ;;
7) mplayer -playlist ktbz-fm.m3u  ;;
8) mplayer -playlist ksbjfmaac.pls  ;;
9) mplayer -playlist kglkfmaac.pls ;;
0) exit 0;;
*) echo "Oopps!!! Please select choice 1,2,3,4,5,6,7,8, or 9"
echo "Press Enter to continue. . ." ; read ;;
esac
done
[/code]

Update:  Shoutcast stations work also.

Go to http://www.xatworld.com/radio-search/



One example: (xmas music)

mplayer http://108.61.73.120:8118



mplayer for other operating systems.

Playlists from somafm.com

7soul.pls
illstreet.pls
seventies.pls
u80s.pls
thistle.pls
folkfwd.pls
bootliquor.pls
digitalis.pls
groovesalad.pls
secretagent.pls
lush.pls
fluid.pls
sonicuniverse.pls
suburbsofgoa.pls
beatblender.pls
thetrip.pls
brfm.pls
silent.pls
dronezone.pls
spacestation.pls
defcon.pls
deepspaceone.pls
missioncontrol.pls
sf1033.pls
dubstep.pls
cliqhop.pls
poptron.pls
bagel.pls
metal.pls
earwaves.pls
covers.pls
doomed.pls
indiepop.pls

Open java install.


How to download and install prebuilt OpenJDK packages
JDK 7
Debian, Ubuntu, etc.

On the command line, type:

Runtime
$ sudo apt-get install openjdk-7-jre

For development
$ sudo apt-get install openjdk-7-jdk

To make sure you are using the right version

$ sudo update-alternatives --config java

For the browser:

$ sudo apt-get install  icedtea-7-plugin



The openjdk-7-jre package contains just the Java Runtime Environment. If you want to develop Java programs then install the openjdk-7-jdk package.
Fedora, Oracle Linux, Red Hat Enterprise Linux, etc.

On the command line, type:
$ su -c "yum install java-1.7.0-openjdk"

The java-1.7.0-openjdk package contains just the Java Runtime Environment. If you want to develop Java programs then install the java-1.7.0-openjdk-devel package.
JDK 6
Debian, Ubuntu, etc.

On the command line, type:
$ sudo apt-get install openjdk-6-jre

The openjdk-6-jre package contains just the Java Runtime Environment. If you want to develop Java programs then install the openjdk-6-jdk package.
Fedora, Oracle Linux, Red Hat Enterprise Linux, etc.

On the command line, type:
$ su -c "yum install java-1.6.0-openjdk"

The java-1.6.0-openjdk package contains just the Java Runtime Environment. If you want to develop Java programs then install the java-1.6.0-openjdk-devel package.
BSD Port

For a list of pointers to packages of the BSD Port for DragonFly BSD, FreeBSD, Mac OS X, NetBSD and OpenBSD, please see the BSD porting Project's wiki page.

Wednesday, April 22, 2015

Command line sql database setup.


This is just enough to hang yourself with.

#==========================================================================
# pseudo-code or generic instruciions to set up a lamp web server apps on
# Debian based lamp servers you will have to modify it to your needs.
# this is assuming a lamp server is already properly set up.
# Setup is another discussion.
# all rights unreserved by the unknown admin
#**************************************************************************
# Get file from internet chances are you visited the sit and have the
# location of the file to be downloaded.
# use Curl for a directory or wget for a single file. use the man pages for
# additional instructions
wget $website/$subdirectory/$filename
# Extract the file in the home directory (not the destination filename for use
# in the next step.
tar zxvf filename.tar.gz
# move te directory into the web document root for use with http
# webappdirectory will become webappname
sudo mv webappdirectory /var/www/
# if you do not have this directory then a server is not setup
# to set up lamp server:
# sudo aptitude install lamp-server
# or
# sudo apt-get update
# sudo apt-get install lamp-server
#***************************************************************************
# set up your database and create user to manage it.
# Courtesy of Linux Reality home server series by Chess Grffin
mysql>
# When entering commands at the MySQL prompt, you must must have a
# semicolon at the end of each line before pressing Enter.
# To create a database, do the following at the MySQL prompt:
mysql> CREATE DATABASE wordpress;
# This will create a database called “wordpress.” The next step is to
# create a separate non-root MySQL user with a password and to grant all
# privileges to that non-root user. This can be done all in one step as
# follows:
mysql> GRANT ALL PRIVILEGES ON wordpress.* TO ‘bloguser’@’localhost’ IDENTIFIED BY ‘abcd';
# (That is all on one line.)
# Then, do the following:
mysql> FLUSH PRIVILEGES;
mysql> EXIT;
# You will then be back at the regular command prompt.
#*******************************************************************************
# Set permissions for web app directory. (this will vary from app to app)
# read the instructions for the webapp to be sure
# see http://www.draac.com/chmodchart.html for more details
sudo chown -R www-data:www-data /var/www/$webappname
sudo chmod -R 755 /var/www/$webappname
#*******************************************************************************
# test web application
# http://localhost/webappname
# apps may make you go to a special directory first for an install process
links2 http://localhost/webappname
# i.e http://localhost/webappname/install or http://localhost/webappname/config
# io finito
#================================================================

Sunday, April 19, 2015

Network scanner.


Setting up a network scanner:

Here are the steps to installing and accessing a network scanner from Ubuntu desktop client. It is assumed that the network scanner server is already up and running.

1) Let us first check whether there is a scanner available on our Ubuntu client host. Without any prior setup, you will see the message saying that "No scanners were identified."
$ scanimage -L

2) Now we need to enable saned daemon which comes pre-installed on Ubuntu desktop. To enable it, we need to edit the /etc/default/saned file, and set the RUN variable to yes:
$ sudo vim /etc/default/saned
1
2
# Set to yes to start saned
RUN=yes
 3) Let's edit the /etc/sane.d/net.conf file, and add the IP address of the server where the scanner is installed:
4) Restart saned:
$ sudo service saned restart
5) Let's see if the scanner is available now:

Now we can open "Simple Scan" (or other scanning utility) and start scanning documents. We can rotate, crop, and save the resulting image:
Note: most generic print servers do not support this feature.

Thursday, April 16, 2015

A case for microcontrollers

Cases can be expensive for micro-controllers, but if you can forgo the exactness you can use very inexpensive containers, This is especially true for controllers that might have several layers or capes, and or add-on boards



You can get inexpensive containers 3 or more for a dollar at a discount store.


Once you have your containers, you will want to modify them.




Then lastly you will want to bolt down the board. #4 machine screws should work fine for this. and viola you have your own case.





Tuesday, April 14, 2015

Zenity.

Many programming languages have some way of coding a graphical interface. Some languages like Python have special bindings (PyGTK, PYQT, etc.) and others, like Visual Basic, have their own commands for designing GUIs. As a result, many shell-script writers probably wish there were something like that for shell scripts. Well, there is a special way to code a GUI for scripts in the script itself. A special program called "Zenity" can be used in scripts to make GTK+-based windows. Zenity is used like other commands in a script with parameters and such.

NOTE: Readers should have an understanding of shell scripting to fully grasp this article. Although, knowing how to script is not entirely necessary.

Obviously, the script writer would make a script as usual. Now, the programmer can add Zenity commands or replace echo and read commands with windows that perform the same function.

The basic usage of Zenity is like this - zenity --info --text="Something important"




"zenity" is the command. "--info" declares the type of box/window. "--text=" creates the desired text to be displayed by this info window. The text parameter can display the output of commands and the value of variables. As many scriptwriters will see, Zenity uses the same syntax as shell scripts. Displaying the output of a command is as easy as this - zenity --info --text=`whoami`

NOTE: Zenity also works in batch files (in MS-Windows). Here, Zenity would use the same syntax/rules of batch files. Also, keep in mind that Zenity is a third-party program and not a language, although I seem to make it sound like it is some programming language.

Zenity supports a few different kinds of dialogs as seen below. One useful parameter that can be used on all of them is the "--title=TEXT" parameter, where "TEXT" is the name desired for the window.







The message dialogs (--info, --question, --warning, --error) display some message via the "--text=" parameter. These dialogs create a window that displays a message. The differences between them lies in the icon shown and the type of buttons. For instance, "--question" makes a window with two buttons (yes and no) and a question-mark icon, and "--warning" has one button (okay) and an exclamation-point icon. These message dialogs can be used in place of the echo command.






The "--text-info" dialog is used to display a text file. For example, "zenity --text-info --filename="/home/user/file.txt" would open a text file to be viewed. "--font=FONT" is a parameter used to specify the font to be used. "--editable" makes the displayed text editable, and the text will be sent to stdout when the dialog is closed. Programmers can use "--text-info" to display license terms and have a check-box for accepting the terms (--checkbox=TEXT). HTML is support via the "--html" parameter. The html parameter is needed to use the url parameter which displays webpages in the window (--url=LINK).

Some of you may wonder how the script can execute differently based on whether the check-box associated with "--text-info" was checked or unchecked. The "$?" shell variable equals "1" when the box is unchecked and "0" when checked. Then, the programmer can have a decision construct that executes code based on the user's choice.

zenity_04.png

NOTE: The $? variable prints the error code of the previously executed command. No actual error is occurring though with Zenity unless you get a number other than zero or one.

Users can enter text in Zenity via the "--entry" dialog. The code {zenity --entry --entry-text="Type" --text="Bang on the keyboard"} makes a window with text giving the user some information (like directions or a question) and an input box. The typed text can be retrieved through the $? variable which will also include "/n0" if no errors occurred. The "sed" or "awk" command can be used to remove the zero and newline when only the entered text is needed. The "--hide-text" parameter makes the text entered in the input box look like dots. This is used when entering private data like a password.

zenity_07.png

NOTE: No encryption is used in Zenity. Please be aware of security risks.

The "--scale" dialog makes a window with a slider. To use a number slider, make code like this -

VALUE=`zenity --scale --text="Select a number" --value="20" --min-value="0" --max-value="200" –step="5"`

zenity_08.png

The selected number will be saved in the variable "VALUE". The backticks are a special form of syntax used in shell scripting to indicate that the code inside is to be executed and that it is not a string. The "--text=TEXT" displays the desired text in the window. The "--value=#" parameter specifies where to start the slider (default = 0). The "--min-value=#" and "--max-value=#" set the limits of the slider (default = 0 and 100, respectively). The "--step=#" parameter sets the incremental value (default = 1). Using the arrow keys to move the slider will yield the set stepping, but not so when using the mouse (a bug perhaps?). To hide the number shown above the slider, use "--hide-value".

When the script is processing data, a progress bar can be displayed (--progress). Zenity offers two kinds. One is the pulsating bar where a box moves back and forth (use the --pulsate parameter) and stops after an end-of-file (EOF) symbol is reached. The second progress bar fills according to percentage. To make such a window, make a command like this -

zenity --progress --text="Working hard or hardly working?" --percentage=0 –auto-close

zenity_10.png

The "--auto-close" parameter makes the window close when 100% is reached. The "--percentage=%" indicates where the bar starts. The bar is filled by piping an integer (number) to Zenity. This is done as seen below. After a command executes, the next echo command tells Zenity to fill the bar more. Once the last command executes, then the bar fills to zero and then closes (if --auto-close is present).

#Progress Bar
(echo "40"; COMPLEX_COMMAND; echo "60"; COMMAND) | zenity --progress --text="Working hard or hardly working?" --percentage=0 --auto-close

#Pulsating Bar
(COMMAND; COMMAND; COMMAND; COMMAND) | zenity --progress --text="Working hard or hardly working?" --percentage=0 --auto-close

To enter a username and password via Zenity, use a command like this -

PRIVATE=`zenity --password --username`

The username and password are saved to the variable PRIVATE. The username parameter is optional, so programmers can use this when only a password is needed. Again, be aware of security issues. If the user closes the window without entering data and clicking "Okay", then $? equals "1" like all other Zenity windows.

zenity_11.png


"--notification" displays a notification bubble or a window depending on the desktop interface. (zenity --notification --text=TEXT)

To select file(s), use the "--file-selection" dialog. "--multiple" allows more than one file to be selected. "--directory" permits the selection of directories. When saving the list of selected files to a variable, the "--separator=STRING" parameter allows the programmer to set the string or character to be used as a division for items in a list. Be careful that the selected files do not contain the string that is to be used as a separator. Otherwise, the list will appear to have different/more files. "--filename=PATH" sets which file or directory is highlighted by default. To use this same dialog to save a file, use the "--save" parameter. Below is an example of the code.

FILE=`zenity --file-selection --multiple --directory --separator="+++"`

zenity_13.png

To select a color, use the --color-selection dialog. "--color=#" sets the initially selected color, and "--show-palette" displays the palette set. The code may look like this - COLOR=`zenity --color-selection --show-palette`.

zenity_14.png

zenity_15.png

A calendar dialog (--calendar) also exists. "zenity --calendar" will show a calendar with the current date highlighted. The "--day=#", "--month=#", and "--year=#" parameters set the time to be highlighted and shown when the window appears. The "--date-format=strftime" allows the programmer to set the time format in strftime format (where month is %m, year is %y, etc.). "--text=TEXT" is used to display a message on the window. The selected date can be saved to a variable.

zenity_16.png

"--list" makes a list dialog. The "--column=NAME" parameter can be used as much as needed to make a column of data. To make such a dialog, use a format like the one seen below. If a field contains spaces or other non-alphanum characters, place that field in quotes to indicate that the string is one set of data. If radio-buttons or check-boxes are included, make sure a column is made for them. The "--checklist" and "--radiolist" parameters place check-boxes and radio-buttons in the first column, respectively. "--editable" allows the data to be changed.

Code:
zenity --list \
 --title="Choose your OS" \
 --column="OS" --column="Interface" \
  Ubuntu Unity \
  "OS X" Marble \
  FreeBSD "Command line" \
  Fedora GNOME \
  Minix Command_line \
  Pidora XFCE \
  Lubuntu LXDE \
  "MS-Windows" Metro
zenity_17.png

The last dialog offered by Zenity is forms (--forms) which is used to enter many sets of data. For private data, the "--add-password=FIELD_NAME" parameter can be used to make an input box that does not display the contents. For text that can be seen, use the "--add-entry=FIELD_NAME" parameter. "--text=TEXT" displays a message on the window. "--add-calendar=FIELD_NAME" makes a calendar which is used to select a date. The calendar's output format is specified with "--forms-date-format="strftime". The "--separator=STRING" parameter is used to set how the fields are separated from each other in the output. After the Zenity command and its parameters, ">>" can be used to direct the data to a file. (zenity --forms --PARAMETERS >> data.csv)

Now, that you know about Zenity, you can enhance your favorite scripts and make new ones that are more advanced than what you made before. Enjoy!

Update/upgrade now!

Please keep your systems up to date! 

 

For linux depending on the distro:

$ sudo apt-get update; sud apt-get upgrade
$ sudo yum update; sudo yum, upgrade
$ sudo pacman -Syu

etc
etc

Sunday, April 12, 2015

RPi 1 cased





There are a lot of diy cases on the net. Probably the most notable one is the cardboard case.  You can easily find them on the net by looking for RPi printable cases. Be sure and tell the printing program not to resize image for printing.


This next two were not real impressive and not so easily put together. Kind of flimsy?




This next one seemed a bit complicated.





Then there are the .dxf files with Librecad so you can use them a laser cutter or cnc router.







Friday, April 10, 2015

Your choice


Code tidbits.

#Titanic {
float : none;
}

#Tower-of-pisa {
font-style: Italic;
}

Grandma and Batman


Nana Nana Nana Nana Batman...

Ipv6.



Intro

One of the main benefits of Internet Protocol version 6 (IPv6) over previously used Internet Protocol version 4 (IPv4) is the large address-space that contains (addressing) information to route packets for the next generation Internet.

IPv6 supports 128-bit address space and can potentially support 2128 or 3.4W1038 unique IP addresses (as opposed to 32-bit address space of IPv4). With this large address-space scheme, IPv6 has the capability to provide unique addresses to each and every device or node attached to the Internet.



    
 IPv6


Why we need IPv6 Addressing


An escalating demand for IP addresses acted as the driving force behind the development of the large address space offered by the IPv6. According to industry estimates, in the wireless domain, more than a billion mobile phones, Personal Digital Assistants (PDA), and other wireless devices will require Internet access, and each will need its own unique IP address.


The extended address length offered by IPv6 eliminates the need to use techniques such as network address translation to avoid running out of the available address space. IPv6 contains addressing and control information to route packets for the next generation Internet.


IPv6 addresse formats are divided into three classes:


1) Unicast addresses A Unicast address acts as an identifier for a single interface. An IPv6 packet sent to a Unicast address is delivered to the interface identified by that address.


2) Multicast addresses A Multicast address acts as an identifier for a group/set of interfaces that may belong to the different nodes. An IPv6 packet delivered to a Multicast address is delivered to the multiple interfaces.


3) Anycast addresses Anycast addresses act as identifiers for a set of interfaces that may belong to the different nodes. An IPv6 packet destined for an Anycast address is delivered to one of the interfaces identified by the address.

(http://en.wikipedia.org/wiki/IPv6_address#Address_formats)

IPv6 Address Notation


IPv6 addresses are denoted by eight groups of hexadecimal quartets separated by colons in between them.


Following is an example of a valid IPv6 address: 2001:cdba:0000:0000:0000:0000:3257:9652


Any four-digit group of zeroes within an IPv6 address may be reduced to a single zero or altogether omitted. Therefore, the following IPv6 addresses are similar and equally valid:


2001:cdba:0000:0000:0000:0000:3257:9652

2001:cdba:0:0:0:0:3257:9652

2001:cdba::3257:9652


The URL for the above address will be of the form:


http://[2001:cdba:0000:0000:0000:0000:3257:9652]/


Network Notation in IPv6


The IPv6 networks are denoted by Classless Inter Domain Routing (CIDR) notation. A network or subnet using the IPv6 protocol is denoted as a contiguous group of IPv6 addresses whose size must be a power of two. The initial bits of an IPv6 address (these are identical for all hosts in a network) form the network s prefix. The size of bits in a network prefix are separated with a / . For example, 2001:cdba:9abc:5678::/64 denotes the network address 2001:cdba:9abc:5678. This network comprises of addresses rearranging from 2001:cdba:9abc:5678:: up to 2001:cdba:9abc:5678:ffff:ffff:ffff:ffff. In a similar fashion, a single host may be denoted as a network with a 128-bit prefix. In this way, IPv6 allows a network to comprise of a single host and above.


Special Addresses in IPv6


          ::/96 The zero prefix denotes addresses that are compatible with the previously used IPv4 protocol.


          ::/128 An IPv6 address with all zeroes in it is referred to as an unspecified address and is used for addressing purposes within a software.


          ::1/128 This is called the loop back address and is used to refer to the local host. An application sending a packet to this address will get the packet back after it is looped back by the IPv6 stack. The local host address in the IPv4 was 127.0.0.1 .


          2001:db8::/32 This is a documentation prefix allowed in the IPv6. All the examples of IPv6 addresses should ideally use this prefix to indicate that it is an example.


          fec0::/10 This is a site-local prefix offered by IPv6. This address prefix signifies that the address is valid only within the local organization. Subsequently, the usage of this prefix has been discouraged by the RFC.


          fc00::/7 This is called the Unique Local Address (ULA). These addresses are routed only within a set of cooperating sites. These were introduced in the IPv6 to replace the site-local addresses. These addresses also provide a 40-bit pseudorandom number that reduces the risk of address conflicts.


          ff00::/8 This prefix is offered by IPv6 to denote the multicast addresses. Any address carrying this prefix is automatically understood to be a multicast address.

          fe80::/10 This is a link-local prefix offered by IPv6. This address prefix signifies that the address is valid only in the local physical link.

Wednesday, April 8, 2015

Remote music gui.



Now let us take a look a remote music controller called mpd. With mplayer we could do everything from the command line, mpd we should be able to use the gui on the remote machine. We will not need to use ssh here either.



You will want to set up your host machines with speakers as before. Then we need to add a new piece of software called mpd. It is available for a wide variety of systems including Android.

http://mpd.wikia.com/wiki/Clients

$ sudo apt-get install mpd




Server does not have to have gui installed. Copy your music files to the server if they are not already there. Then you will want go edit the config file for you file settings and etc.

$ sudo vim /etc/mpd.conf

Once you have that done, you will need to go to the client machine and install the following:


$ sudo apt-get install mpc gmpc

Then go to the gui menu for the  sound and video.   Choose the gnome-music-player-client. Everything is gui from there. You will need to set the servername and the port number (usually 6600). In many cases it will autodetect it for you.

Start playing music from the server.

Note: this could be a perfect project for a Raspberry Pi running Raspian as a host. Then add a tv or monitor so you can also use it as a computer.

Update: Kodi works with MPD.



Eotkd eiyh