Apache 2 performance boost with varnish & YSlow

Leave a comment

I am writing this post as part of Tero Karvinen’s course: Linux palvelimena (roughly translated: Linux as a server) http://terokarvinen.com/2012/aikataulu-linux-palvelimena-ict4tn003-4-ja-ict4tn003-6-syksylla-2012.

I am using 32-bit Xubuntu 12.10 (Quantal Quetzal) Daily Build October 9th live-environment.

On this post I will attempt to go through the following:

  • Test apache2′s performance before installing varnish
  • Test apache2′s performance after installing varnish
  • Examine the results
  • Check website rankings with YSlow
  • Fix websites with YSlow’s suggestions

I started by installing apache2, MySQL and getting wordpress working (http://kontsu.wordpress.com/2012/10/03/installing-wordpress-under-apache-2/)

with the exeption of not using phpMyAdmin to create the database and the user. I am using MySQL instead.

Creating the database for wordpress without phpMyAdmin

After installing MySQL and testing that it works, I logged in with root.

$ mysql -u root -p

I added a new database for wordpress.

mysql> create database samuelwp;

(you can see all of the databases with ‘show databases;’)

I created a new user for the new database with the same name and an unique password.

mysql> grant all on samuelwp.* to samuelwp@localhost identified by 'al@#hioBalTokmC@zjKger@k';

I exited (‘exit’) and logged in with the user “samuelwp”

$ mysql -u samuelwp -p

I tested my permissions by trying to create a new database

mysql> create database foo;
ERROR 1044 (42000): Access denied for user 'samuelwp'@'localhost' to database 'foo'

Since I didn’t use phpMyAdmin, I had to install MySQL extension to php which is required by WordPress.

$ sudo apt-get install php5-mysql

so far so good. I’m Skipping ahead to the point when wordpress is installed and tested. (no new themes, plugins or permalinks)

Test without varnish

I made the tests by using apache2′s ab (HTTP server benchmarking tool)

$ ab -n 1000 http://localhost/~xubuntu/wp/wordpress/

01This is ApacheBench, Version 2.3 <$Revision: 655654 $>
02Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
03Licensed to The Apache Software Foundation, http://www.apache.org/
04 
05Benchmarking localhost (be patient)
06Completed 100 requests
07Completed 200 requests
08Completed 300 requests
09Completed 400 requests
10Completed 500 requests
11Completed 600 requests
12Completed 700 requests
13Completed 800 requests
14Completed 900 requests
15Completed 1000 requests
16Finished 1000 requests
17 
18 
19Server Software:        Apache/2.2.22
20Server Hostname:        localhost
21Server Port:            80
22 
23Document Path:          /~xubuntu/wp/wordpress/
24Document Length:        9856 bytes
25 
26Concurrency Level:      1
27Time taken for tests:   107.717 seconds
28Complete requests:      1000
29Failed requests:        889
30   (Connect: 0, Receive: 0, Length: 889, Exceptions: 0)
31Write errors:           0
32Total transferred:      10120904 bytes
33HTML transferred:       9853904 bytes
34Requests per second:    9.28 [#/sec] (mean)
35Time per request:       107.717 [ms] (mean)
36Time per request:       107.717 [ms] (mean, across all concurrent requests)
37Transfer rate:          91.76 [Kbytes/sec] received
38 
39Connection Times (ms)
40              min  mean[+/-sd] median   max
41Connect:        0    0   0.0      0       0
42Processing:    94  108   7.6    107     133
43Waiting:       90  102   7.2    102     124
44Total:         94  108   7.6    107     133
45 
46Percentage of the requests served within a certain time (ms)
47  50%    107
48  66%    111
49  75%    113
50  80%    115
51  90%    118
52  95%    121
53  98%    124
54  99%    126
55 100%    133 (longest request)

The most interesting lines are 28 and 29 which state that most of the connections failed to load. I will try to fix this with Varnish (web application accelerator. Also known as a caching HTTP reverse proxy.) (https://www.varnish-cache.org/)

Installing & configuring varnish

I installed varnish

$ sudo apt-get install varnish

The connections will be routed from varnish to apache so I made some changes to the ports

$ sudoedit /etc/apache2/ports.conf

01# If you just change the port or add more ports here, you will likely also
02# have to change the VirtualHost statement in
03# /etc/apache2/sites-enabled/000-default
04# This is also true if you have upgraded from before 2.2.9-3 (i.e. from
05# Debian etch). See /usr/share/doc/apache2.2-common/NEWS.Debian.gz and
06# README.Debian.gz
07 
08NameVirtualHost *:8080
09Listen 8080
10 
11<IfModule mod_ssl.c>
12    # If you add NameVirtualHost *:443 here, you will also have to change
13    # the VirtualHost statement in /etc/apache2/sites-available/default-ssl
14    # to <VirtualHost *:443>
15    # Server Name Indication for SSL named virtual hosts is currently not
16    # supported by MSIE on Windows XP.
17    Listen 443
18</IfModule>
19 
20<IfModule mod_gnutls.c>
21    Listen 443
22</IfModule>

on the lines 08 and 09 I changed the value from 80 to 8080.

Next I put varnish to listen the port 80

$ sudoedit /etc/default/varnish

001# Configuration file for varnish
002#
003# /etc/init.d/varnish expects the variables $DAEMON_OPTS, $NFILES and $MEMLOCK
004# to be set from this shell script fragment.
005#
006# Note: If systemd is installed, this file is obsolete and ignored.  You will
007# need to copy /lib/systemd/system/varnish.service to /etc/systemd/system/ and
008# edit that file.
009 
010# Should we start varnishd at boot?  Set to "no" to disable.
011START=yes
012 
013# Maximum number of open files (for ulimit -n)
014NFILES=131072
015 
016# Maximum locked memory size (for ulimit -l)
017# Used for locking the shared memory log in memory.  If you increase log size,
018# you need to increase this number as well
019MEMLOCK=82000
020 
021# Default varnish instance name is the local nodename.  Can be overridden with
022# the -n switch, to have more instances on a single server.
023# INSTANCE=$(uname -n)
024 
025# This file contains 4 alternatives, please use only one.
026 
027## Alternative 1, Minimal configuration, no VCL
028#
029# Listen on port 6081, administration on localhost:6082, and forward to
030# content server on localhost:8080.  Use a 1GB fixed-size cache file.
031#
032# DAEMON_OPTS="-a :6081 \
033#              -T localhost:6082 \
034#        -b localhost:8080 \
035#        -u varnish -g varnish \
036#            -S /etc/varnish/secret \
037#        -s file,/var/lib/varnish/$INSTANCE/varnish_storage.bin,1G"
038 
039 
040## Alternative 2, Configuration with VCL
041#
042# Listen on port 6081, administration on localhost:6082, and forward to
043# one content server selected by the vcl file, based on the request.  Use a 1GB
044# fixed-size cache file.
045#
046DAEMON_OPTS="-a :80 \
047             -T localhost:6082 \
048             -f /etc/varnish/default.vcl \
049             -S /etc/varnish/secret \
050             -s malloc,256m"
051 
052 
053## Alternative 3, Advanced configuration
054#
055# See varnishd(1) for more information.
056#
057# # Main configuration file. You probably want to change it :)
058# VARNISH_VCL_CONF=/etc/varnish/default.vcl
059#
060# # Default address and port to bind to
061# # Blank address means all IPv4 and IPv6 interfaces, otherwise specify
062# # a host name, an IPv4 dotted quad, or an IPv6 address in brackets.
063# VARNISH_LISTEN_ADDRESS=
064# VARNISH_LISTEN_PORT=6081
065#
066# # Telnet admin interface listen address and port
067# VARNISH_ADMIN_LISTEN_ADDRESS=127.0.0.1
068# VARNISH_ADMIN_LISTEN_PORT=6082
069#
070# # The minimum number of worker threads to start
071# VARNISH_MIN_THREADS=1
072#
073# # The Maximum number of worker threads to start
074# VARNISH_MAX_THREADS=1000
075#
076# # Idle timeout for worker threads
077# VARNISH_THREAD_TIMEOUT=120
078#
079# # Cache file location
080# VARNISH_STORAGE_FILE=/var/lib/varnish/$INSTANCE/varnish_storage.bin
081#
082# # Cache file size: in bytes, optionally using k / M / G / T suffix,
083# # or in percentage of available disk space using the % suffix.
084# VARNISH_STORAGE_SIZE=1G
085#
086# # File containing administration secret
087# VARNISH_SECRET_FILE=/etc/varnish/secret
088#
089# # Backend storage specification
090# VARNISH_STORAGE="file,${VARNISH_STORAGE_FILE},${VARNISH_STORAGE_SIZE}"
091#
092# # Default TTL used when the backend does not specify one
093# VARNISH_TTL=120
094#
095# # DAEMON_OPTS is used by the init script.  If you add or remove options, make
096# # sure you update this section, too.
097# DAEMON_OPTS="-a ${VARNISH_LISTEN_ADDRESS}:${VARNISH_LISTEN_PORT} \
098#              -f ${VARNISH_VCL_CONF} \
099#              -T ${VARNISH_ADMIN_LISTEN_ADDRESS}:${VARNISH_ADMIN_LISTEN_PORT} \
100#              -t ${VARNISH_TTL} \
101#              -w ${VARNISH_MIN_THREADS},${VARNISH_MAX_THREADS},${VARNISH_THREAD_TIMEOUT} \
102#          -S ${VARNISH_SECRET_FILE} \
103#              -s ${VARNISH_STORAGE}"
104#
105 
106 
107## Alternative 4, Do It Yourself
108#
109# DAEMON_OPTS=""

on the line 046 I changed the value from 6081 to 80.

Test with varnish

$ ab -n 1000 http://localhost/~xubuntu/wp/wordpress/

01This is ApacheBench, Version 2.3 <$Revision: 655654 $>
02Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
03Licensed to The Apache Software Foundation, http://www.apache.org/
04 
05Benchmarking localhost (be patient)
06Completed 100 requests
07Completed 200 requests
08Completed 300 requests
09Completed 400 requests
10Completed 500 requests
11Completed 600 requests
12Completed 700 requests
13Completed 800 requests
14Completed 900 requests
15Completed 1000 requests
16Finished 1000 requests
17 
18 
19Server Software:        Apache/2.2.22
20Server Hostname:        localhost
21Server Port:            80
22 
23Document Path:          /~xubuntu/wp/wordpress/
24Document Length:        9853 bytes
25 
26Concurrency Level:      1
27Time taken for tests:   0.434 seconds
28Complete requests:      1000
29Failed requests:        0
30Write errors:           0
31Total transferred:      10177990 bytes
32HTML transferred:       9853000 bytes
33Requests per second:    2303.39 [#/sec] (mean)
34Time per request:       0.434 [ms] (mean)
35Time per request:       0.434 [ms] (mean, across all concurrent requests)
36Transfer rate:          22894.40 [Kbytes/sec] received
37 
38Connection Times (ms)
39              min  mean[+/-sd] median   max
40Connect:        0    0   0.0      0       0
41Processing:     0    0   4.3      0     136
42Waiting:        0    0   4.3      0     136
43Total:          0    0   4.3      0     136
44 
45Percentage of the requests served within a certain time (ms)
46  50%      0
47  66%      0
48  75%      0
49  80%      0
50  90%      0
51  95%      0
52  98%      0
53  99%      0
54 100%    136 (longest request)

A picture comparing the results of the test:

Now that varnish is enabled there were 0 failed requests and the speed in which the test was completed was over 200 times faster. Instead of having 9 connections in 1 second there were 2303.

Testing websites with YSlow

Yslow is an extension of Firefox which can be downloaded from tools -> add-ons. Yslow needs Firebug extension to work so install it before installing YSlow.

After I had installed both extensions I tested YSlow on the wordpress website I had created.

I got a grade C. The “errors”/notices I received:

  • Use a content delivery network
  • Add Expires headers
  • Configure entity tags
  • Avoid URL redirects>

(I could raise the grade to B. By clicking “Add as CDS -button” on everything possible in the content delivery network tab.)

I got even more notices when checking my (this) blog at wordpress.com. I don’t belive that there is much I can do to make the grade better.

By testing the index.php test page I got a grade A. With only the following notice: “Add Expires headers”.

I couldn’t come up with any real fixes I could do with the websites I tested so I concluded my homework here.

Installing wordpress under apache 2

1 Comment

I am writing this post as part of Tero Karvinen’s course: Linux palvelimena (roughly translated: Linux as a server) http://terokarvinen.com/2012/aikataulu-linux-palvelimena-ict4tn003-4-ja-ict4tn003-6-syksylla-2012.

I am using 32-bit Xubuntu 12.10 (Quantal Quetzal) Daily Build October 1st live-environment. First impressions after getting to the desktop: I like the new theme, it’s not only a blue background anymore, the highlighting and the terminal have also received a blue color, as a whole the appearance feels more refined. It also seems that my harddrives are were listed twice (i hit F5 on the desktop to refresh).

On this post I will attempt to go through the following:

  • Install Apache 2
  • Install MySQL database
  • Install phpMyAdmin and create a database which wordpress will use
  • Install wordpress
  • Install a new theme to wordpress
  • Install a new plugin to wordpress
  • Activate permalinks in wordpress

Apache 2 & php support

I started by installing Apache 2, testing it and adding php support and also tested that it worked (Check my previous post to find out how to do this). While I was writing the test html/php page I noticed that nano color codes the html-tags! (EDIT: Easy to read yellow color with php files. Not so easy to read blue color with basic html files)

MySQL server

I started the installation by using the command

$ sudo apt-get install mysql-server

The installer asked me for a password (strong recommended)

If you forget the password you can change it with the following command:

$ sudo dpkg-reconfigure mysql-server-5.5

After the installation was completed, I tested that it worked

$ mysql
mysql> show databases;


+--------------------+
| Database |
+--------------------+
| information_schema |
| test |
+--------------------+
2 rows in set (0.00 sec)

And by writing “exit” I exited MySQL.

phpMyAdmin

To make things easier, I installed phpMyAdmin.

$ sudo apt-get install phpmyadmin

In the beginning of installation, the used webserver will be asked. It might seem that apache2 is defaultly chosen but in reality it is only highlighted. You need to hit space before hitting enter. The picture below shows when apache2 is chosen.

When asked if I want to configure phpMyAdmin, I selected yes. The MySQL administrator password is required before the installer can continue.

Next it asks for phpMyAdmin password, by leaving it blank, the program generated a password for me.

Next I opened the phpMyAdmin page with firefox ( localhost/phpmyadmin )

After logging in I opened the privileges tab and clicked “Add a new User”. As seen on the picture below: I wrote a user name, chose local as host from the drop down menu, clicked the generate a password button and chose the second option to create a database with the same name.

I logged out by clicking the logout button on the top left (small button looking like an opened door) and logged in again to test the new user I had created.

I tested the same thing with MySQL:

$ mysql -u samuelwp -p
(-u user -p password) The password will be entered after hitting enter

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| samuelwp |
| test |
+--------------------+
3 rows in set (0.00 sec)

WordPress

I created a new folder for wordpress under public_html and moved in it.

$ mkdir wordpress
$ cd wordpress/

and downloaded the latest release of wordpress (as a tar.gz) from http://wordpress.org/download/

I copied and extracted the file

$ cp /home/xubuntu/Downloads/wordpress-3.4.2.tar.gz .
(the last dot is for the current folder)

$ tar -xzf wordpress-3.4.2.tar.gz

I opened WordPress’ address with firefox and proceeded with the installation

The database name and username are the same. After filling the username and password fields and editing the prefix (changing the Table Prefix is optional but might add security since the default value is changed) I pressed submit.

WordPress installation informed me that it could not create the configuration file so I copied the text and pasted it to a file called wp-config.php inside the wordpress -folder. And clicked the “Run the install” button.

I filled the user data proceeded to install WordPress.

(The site can be found at: http://localhost/~xubuntu/wordpress/wordpress/)

A new theme for WordPress

So now that WordPress is installed I searched for a new theme at http://wordpress.org/extend/themes/ and decided to download a theme called “Toolbox”, unzipped it and moved it to wordpress’ theme folder

$ cd
$ cd Downloads/
$ unzip toolbox.1.4.zip
$ cp -r toolbox /home/xubuntu/public_html/wordpress/wordpress/wp-content/themes/

In wordpress’ Dashboard I opened the Appearance -menu and Clicked “Activate” on the Toolbox -theme

After that I navigated to the site by clicking “Visit Site” from the top by hovering mouse on the site’s title

A new plugin for WordPress

I searched for a new plugin at http://wordpress.org/extend/plugins/ and decided to download a plugin called “bbPress”

I unzipped it and moved it to wordpress’ plugins -folder (/home/xubuntu/public_html/wordpress/wordpress/wp-content/plugins/)

In wordpress’ Dashboard I opened the Plugins -menu and Clicked “Activate” on the bbPress -plugin.

I opened the new Forums -menu and created a new forum and after that I created a new Topic and chose the forum I created as the used forum.

I navigated to the website again to see the new forum. I couldn’t find it so I went back to the dashboard and chose Appearance and Widgets. I added the (bbPress) Forums List to Sidebar 1

Now the Forum can be found at the bottom right corner of the website.

Activating permalinks

In wordpress Dashboard I opened settings and Permalinks and chose “Day and name” -option and clicked Save Changes

WordPress informed me that it didn’t have permission to update .htaccess -file and asked me to copy the configurations in it.

In terminal I moved to the first wordpress folder and created the .htaccess file and pasted the text and saved.

My hello world! post wouldn’t load anymore (Not found). I found out from another student’s blog (http://lyriano.wordpress.com/2012/09/30/kurssitehtava-6-sisallonhallintajarjestelmat-ja-wordpress-asennus/) in the same course who had found the answer to the error. Apparently I had to enable apache2′s rewrite -mod and restart apache 2.

$ sudo a2enmod rewrite
$ sudo service apache2 restart

And the site seems to work again with permalinks. I decided to make a second test by creating a new post in wordpress and by opening them both I noticed that the Permalinks work correcly.

Virtual hosting with apache 2

Leave a comment

I am writing this post as part of Tero Karvinen’s course: Linux palvelimena (roughly translated: Linux as a server) http://terokarvinen.com/2012/aikataulu-linux-palvelimena-ict4tn003-4-ja-ict4tn003-6-syksylla-2012.

On this post I will attempt to go through the following:

  • Installing & configuring apache 2 web server
  • Run 3 virtual servers with different settings
    1. php enabled
    2. php NOT enabled
    3. password authentication (see apache2-doc)
  • Produce the following http-statuses in the apache log
    1. 200
    2. 404
    3. 403
    4. 500
    5. 304 (a bonus)
  • Analyze the log

I am using 32-bit xubuntu live-environment

1. Installing & configuring apache 2 web server

I first started by installing apache 2 server on my computer
$ sudo apt-get update
$ sudo apt-get install apache2

I opened firefox and tested that apache 2 works correctly by writing localhost in the address bar.

I enabled users to host files over the internet:
$ sudo a2enmod userdir

and restarted the server to apply the changes
$ sudo service apache2 restart

I created a folder under home called public_html
$ mkdir public_html

I searcher through the apache2-doc to determine the third website

$ sudo apt-get install apache2-doc
$ cd /usr/share/doc/apache2-doc/manual
$ firefox index.html

By looking at the available modules I picked authentication

I created 3 separate folders for each virtual server

$ cd
$ cd public_html/
$ mkdir php nophp authentication

1.1 php supported website

I started by creating a simple php file in the appropriate folder

$ cd php/
$ nano index.php

01<html>
02 <head>
03  <title>This website supports php!</title>
04 </head>
05 <body>
06  <?php
07   print "this is php, 1+2 is ".(1+2);
08  ?>
09 </body>
10</html>

At the moment the php file won’t show.

to get php working I did the following:

$ sudo apt-get install libapache2-mod-php5

$ cd /etc/apache2/mods-enabled/

$ sudoedit php5.conf

the terminal on the left shows the original file and the one on the right shows how it must be modified to enable php.

$ sudo service apache2 restart

$ firefox http://localhost/~xubuntu/php/

1.2 php unsupported website

I copy the php file from the php -folder to nophp -folder and move inside the nophp -folder.

$ cd
$ cd public_html/
$ cp php/index.php nophp/
$ cd nophp/

To disable php from the nophp -folder I did the following:

I moved to the folder where apache stores the settings for virtual websites.

$ cd /etc/apache2/sites-available/

and edited the default -file

$ sudoedit default

This is how the relevant part of the file looks like after the changes (I added the third directory part with the “address” home/xubuntu… The lines 15-20 from the snippet of code below)

01<VirtualHost *:80>
02    ServerAdmin webmaster@localhost
03 
04    DocumentRoot /var/www
05    <Directory />
06        Options FollowSymLinks
07        AllowOverride None
08    </Directory>
09    <Directory /var/www/>
10        Options Indexes FollowSymLinks MultiViews
11        AllowOverride None
12        Order allow,deny
13        allow from all
14    </Directory>
15    <Directory /home/xubuntu/public_html/nophp/>
16        <FilesMatch "\.(php5?|phtml)$"> 
17                 Order Deny,Allow
18                 Deny from All
19            </FilesMatch>
20    </directory>

source for the disabling of php: http://stackoverflow.com/questions/1271899/disable-php-in-directory-including-all-sub-directories-with-htaccess by Lance Rushing.

$ sudo service apache2 restart

Now when I open the address http://localhost/~xubuntu/nophp/ in firefox I get the forbidden error.

Optional but I decided to add a new index file with only html in it.

$ cd
$ cd public_html/nophp/

$ nano index.html

1<html>
2 <head>
3  <title>This website does not support php</title>
4 </head>
5 <body>
6  <p>Only HTML here</p>
7 </body>
8</html>

Now after reloading the webpage we don’t get an error anymore.

1.3 password authenticated website

Next up password protection!

$ cd
$ cd public_html/authentication/

I created a simple html file to add some content

$ nano index.html

1<html>
2 <head>
3  <title>Very important user</title>
4 </head>
5 <body>
6  <h1>Welcome!</h1>
7 </body>
8</html>

I created a password for the “website” (username=”xubuntu”)

$ htpasswd -c .htpasswd xubuntu
(-c = create. makes a new file, if a file exists it is overwritten)

I made some changes to apache’s default -file again (lines 7-14)

$ sudoedit /etc/apache2/sites-available/default

01<Directory /home/xubuntu/public_html/nophp/>
02        <FilesMatch "\.(php5?|phtml)$"> 
03                 Order Deny,Allow
04                 Deny from All
05            </FilesMatch>
06    </directory>
07    <Directory /home/xubuntu/public_html/authentication/>
08        AllowOverride AuthConfig
09        AuthName "Please insert your login data."
10        AuthType Basic
11        AuthUserFile /home/xubuntu/public_html/authentication/.htpasswd
12        AuthGroupFile /dev/null
13        require user xubuntu
14    </Directory>

source for the creation of the password file and default -file modification: http://www.yolinux.com/TUTORIALS/LinuxTutorialApacheAddingLoginSiteProtection.html search for “using the program htpasswd” (first of the two hits) and “WITHOUT using the .htaccess file.”

$ sudo service apache2 restart

1.4 Adding names for the virtual websites

It is possible to add a domain name locally (only seen on this computer) so next I will be giving a name to the websites I created and test them.

I checked my ip with ifconfig -command (eth0 -> inet addr) and opened the hosts -file where I can map hostnames to IP addresses.

$ ifconfig
$ sudoedit /etc/hosts

the modified file: (I added the six lines starting with “192.”)


127.0.0.1 localhost
127.0.1.1 xubuntu

192.168.0.100 ilovephp.com
192.168.0.100 http://www.ilovephp.com

192.168.0.100 ihatephp.com
192.168.0.100 http://www.ihatephp.com

192.168.0.100 auth.com
192.168.0.100 http://www.auth.com

# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

I added the information of the websites under /etc/apache2/sites-available/

$ cd /etc/apache2/sites-available/

$ sudoedit ilovephp.com

1<VirtualHost *:80>
2 ServerName ilovephp.com
3 ServerAlias www.ilovephp.com
4 DocumentRoot /home/xubuntu/public_html/php
5</VirtualHost>

$ sudoedit ihatephp.com

1<VirtualHost *:80>
2 ServerName ihatephp.com
3 ServerAlias www.ihatephp.com
4 DocumentRoot /home/xubuntu/public_html/nophp
5</VirtualHost>

$ sudoedit auth.com

1<VirtualHost *:80>
2 ServerName auth.com
3 ServerAlias www.auth.com
4 DocumentRoot /home/xubuntu/public_html/authentication/
5</VirtualHost>

Next I enabled the sites:

$ sudo a2ensite ilovephp.com
$ sudo a2ensite ihatephp.com
$ sudo a2ensite auth.com

and I reloaded the server to apply the changes (restart not required this time)

$ sudo service apache2 reload

and now I can use the new addresses to access the virtual websites. (You might need to delete your cookies and/or cache if it doesn’t seem to work)

2. Creating http errors & checking the log

The log containing the http errors or status codes is in the other_vhosts_access.log where I’ll be going now:

$ cd
$ cd /var/log/apache2/

I can see the last 10 lines of a file by using tail

$ tail other_vhosts_access.log

the first status code was 200 which is when nothing is wrong and the site loads normally.
I opened http://ilovephp.com/ with firefox and checked the log

$ tail other_vhosts_access.log
ilovephp.com:80 192.168.0.100 - - [30/Sep/2012:09:37:58 +0000] "GET / HTTP/1.1" 200 380 "-" "Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:14.0) Gecko/20100101 Firefox/14.0.1"
You can see the status code “200″ after the date: “GET / HTTP/1.1″ 200 380 “…

next up 404 (file not found):

http://ilovephp.com/thiswillproducea404

$ tail other_vhosts_access.log
ilovephp.com:80 192.168.0.100 - - [30/Sep/2012:09:40:33 +0000] "GET /thiswillproducea404 HTTP/1.1" 404 506 "-" "Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:14.0) Gecko/20100101 Firefox/14.0.1

At this point I realized that my settings in nophp and authentication don’t seem to work anymore. php isn’t blocked and the password isn’t asked. Something to do with part 1.4? I will try to find out the reason.

Creating a deb metapackage

Leave a comment

I am writing this post as part of Tero Karvinen’s course: Linux palvelimena (roughly translated: Linux as a server) http://terokarvinen.com/2012/aikataulu-linux-palvelimena-ict4tn003-4-ja-ict4tn003-6-syksylla-2012.

On this post I will go through the following:

  • Create a deb metapackage
  • Add a python file to the metapackage
  • Test the metapackage
  • Install & configure Apache 2 to enable sharing of a repository
  • Create the repository
  • Add the metapackage to the repository
  • Test the repository with another computer

I am using a 32-bit Xubuntu 12.04.1 live dvd environment. My instructions and testing are based on instructions found in Tero’s blog (http://terokarvinen.com/2011/create-deb-metapackage-in-5-minutes and http://terokarvinen.com/2011/update-all-your-computers-with-a-deb-repository)

Creating the metapackage

I started by installing equivs:
$ sudo apt-get update
$ sudo apt-get install equivs

(To keep everything organized I made a folder for the metapackage $ mkdir meta and $ cd meta/)

I created the base for the metapackage with the command $ equivs-control kontsus-musthave.cfg
I opened the file with nano $ nano kontsus-musthave.cfg

After I was finished editing the file, I pressed “Ctrl+x” to exit, ‘y’ to save changes and “Enter” to confirm the filename.

Now to build the deb package $ equivs-build kontsus-musthave.cfg

Uh-oh: syntax error in control file: long description and info

I re-opened the file to see where the problem lies. My error was that I had removed the space from the text under “Description:” so it didn’t recognize the text below it as part of the description text.

at this point I could test that the package works, but I want to test adding a file of my own to the list of files to install. (the command for testing: $ sudo apt-get install gdebi-core
$ sudo gdebi kontsus-musthave_0.1_all.deb)

Adding your own files in the package

I’ll be making a hello world file with python

$ mkdir python
$ cd python
$ nano helloWorld.py

The file:

print "Hello World!"

and to test the file: $ python helloWorld.py

I re-opened the .cfg file in the meta folder and made the following changes as seen on the picture

I used lintian to verify that the metapackage is “legit” ($ sudo apt-get install lintian
$ lintian kontsus-musthave_0.2_all.deb)

I got the following warning: E: kontsus-musthave: non-standard-dir-in-var var/HelloWorld.py/
W: kontsus-musthave: file-in-unusual-dir var/HelloWorld.py/home/xubuntu/meta/python/helloWorld.py

So I made the following changes (starting from the meta -folder):

$ mkdir build
$ cd build
$ cp /home/xubuntu/meta/kontsus-musthave.cfg /home/xubuntu/meta/build/
$ cp /home/xubuntu/meta/python/helloWorld.py /home/xubuntu/meta/build/
$ nano kontsus-musthave.cfg

$ equivs-build kontsus-musthave.cfg
$ lintian kontsus-musthave_0.3_all.deb

E: kontsus-musthave: non-standard-dir-in-var var/HelloWorld.py/
W: kontsus-musthave: file-in-unusual-dir var/HelloWorld.py/helloWorld.py

last try:

Also in text:

Section: misc
Priority: optional
Standards-Version: 3.9.2

Package: kontsus-musthave
Version: 0.4
Maintainer: kontsu
Depends: gedit, chromium-browser
Files: helloWorld.py /Helloworld.py
Description: must have programs
long description and info
kontsu’s must have programs when using the live-cd (or dvd)
.
second paragraph

The error:

E: kontsus-musthave: non-standard-toplevel-dir HelloWorld.py/
W: kontsus-musthave: file-in-unusual-dir HelloWorld.py/helloWorld.py

at this point I’ll just ignore the error and see what happens:

EDIT: The correct place for your own files are /usr/local/bin
I’ll have to try the following in the file:
Files: HelloWorld.py /usr/local/bin/HelloWorld.py

(if you didn’t install gdebi: $ sudo apt-get install gdebi-core)
$ sudo gdebi kontsus-musthave_0.4_all.deb

I answered ‘y’ when I was asked “Do you want to install the software package?”

The program installed gedit and ignored chromium as I had it already installed. The Python file appeared in a folder “HelloWorld.py” under root directory. I was expecting that the file would go there but why it created the folder I do not know.

Installing & configuring apache 2 web server

I installed apache 2 web server:
$ sudo apt-get install apache2

enabled users to host files over internet:
$ sudo a2enmod userdir

restarted apache in order to apply the change:
$ sudo service apache2 restart

created the folder where the file will be shared:

$ cd
$ mkdir public_html
$ cd public_html/
$ mkdir -p repository/conf

Creating a repository & adding the metapackage

While in the public_html folder I created the repository file

$ nano repository/conf/distributions

The text in the file:

Codename: precise
Components: main
Suite: precise
Architectures: i386 amd64 source

install reprepro
$ sudo apt-get install reprepro

add the deb package to the repository:
$ reprepro -VVVV -b repository/ includedeb precise /home/xubuntu/meta/build/kontsus-musthave_0.4_all.deb

Testing the repository

I have deleted chromium and gedit to test the repository out. ($ sudo apt-get remove chromium-browser gedit)
(this is the part you would do in a client computer)

I opened the list of sources (where apt downloads packages) and added the repository there (the ip can be found out by using ifconfig on the host/server computer $ ifconfig)

$ sudoedit /etc/apt/sources.list.d/repository.list

The text in the file:

deb http://172.28.9.208/~xubuntu/repository precise main

and now to test:

$ sudo apt-get update
$ sudo apt-get install kontsus-musthave

the repository worked locally and installed gedit and chromium-browser to my live session.

I also tested the repository on another computer over local network and it worked there also.

The Honeynet Challenge

Leave a comment

I am writing this post as part of Tero Karvinen’s course: Linux palvelimena (roughly translated: Linux as a server) http://terokarvinen.com/2012/aikataulu-linux-palvelimena-ict4tn003-4-ja-ict4tn003-6-syksylla-2012.

My objective on the assignment:

  1. Show step by step how you identify and recover the deleted rootkit from the / partition.
  2. What files make up the deleted rootkit?
  3. What information can you find from the perpetrator by legal means?
  4. Analyze the rootkit.

I’ll start of by saying that once again I am using a live environment and in addition I am using a computer with no personal data nor any important information. I am using xubuntu 12.04.1 LTS 32-bit.

EDIT: I couldn’t find the rootkit. Many accomplished walk throughs can be found at the same website where the image was downloaded from. Although I got close on a few ocasions. For example if I had used “tsk_recover” instead of “tsk_recover -e” I would have gotten only the deleted files, or if I had stopped to think why there was a tgz-file in the root directory or while using meld why were there files called linsniffer and logclear.

Preparations

I downloaded the file “honeynet.tar.gz” from the website http://old.honeynet.org/scans/scan15/. Using Terminal I created a new folder called “Challenge” under /home/xubuntu with the command $ mkdir Challenge and after that moved to the folder where the file was downloaded $ cd /home/xubuntu/Downloads/ I uncompressed the file with the command $ tar -xzvf honeynet.tar.gz (x-extract, z-ungzip, v-verbose, f-file). I checked the README for information before starting with the challenge $ cat README.

I moved a copy of “honeypot.hda8.dd” to the Challenge-folder I made earlier. $ cp honeypot.hda8.dd /home/xubuntu/Challenge/
$ cd /home/xubuntu/Challenge

I created a new folder called “Recovered” where I can serch and read files without worrying that I ruin something important, I also created a new folder “Mounted” where I will mount the image $ mkdir Mounted Recovered. I installed sleuthkit so I could copy the files from “honeypot.hda8.dd” to the “Recovered” folder $ sudo apt-get install sleuthkit
$ tsk_recover -e honeypot.hda8.dd Recovered/ (e-all files) I got confirmation that there were 1651 files recovered.

Mounting the image

I mounted the image by using the following $ sudo mount -ro,loop,noexec,nodev /home/xubuntu/Challenge/honeypot.hda8.dd /home/xubuntu/Challenge/Mounted/
I opened a second terminal and I made it so that the other one is in the “Mounted” folder and the other one in the “Recovered” one, as in the picture below.

So if I happen to make the mistake of opening a file in Mounted, I most likely need to copy a new image from the “Download” folder and do a new mount.

Searching for the rootkit

I started off by searching for files between the dated 14th and 16th of March, since the date of the infection was 15th somewhere in the world with possibly a different time zone. ls -l in the mount folder showed that almost all of the folders matched the criteria. I first opened a third terminal and opened the “Challenge” folder and went through all the files with “diff” which checks for differences between files. So I went through every folder using the command $ diff Mounted/bin/ Recovered/bin/ through to $ diff Mounted/tmp/ Recovered/tmp/. I was hoping to find a file that only existed on the backup I made in the folder “Recovered” but ended up finding nothing interesting.

I basically tried the same thing with a graphical program called “meld” $ sudo apt-get install meld and meld to open. File -> new -> Directory comparison -> I added the folders I created earlier as seen on the picture.

After pressing ok the files are showed on the screen. I removed the filters and clicked off the “show new button” so it only showed modified files. And I got none the wiser.

I tried to search through the of both folders (Mounted & Recovered) for files with the following word “rm” (remove) $ grep -R "rm " * after skimming through the files I tried a nother search grep -R "rm -r" * and after checking a few files for any clues, I came to the impression that this was a nother dead end.

Conclusion

After ~6 hours of searching (documenting included) I couldn’t find the rootkit with my level of skill and knowledge of the system. I succeeded taking a backup of the files on the image and in mounting said image. I failed to find the rootkit and the follow up tasks, using the methods listed above.

Checking workloads on different resources

Leave a comment

I am writing this post as part of Tero Karvinen’s course: Linux palvelimena (roughly translated: Linux as a server) http://terokarvinen.com/2012/aikataulu-linux-palvelimena-ict4tn003-4-ja-ict4tn003-6-syksylla-2012.

On this post I will go through the following:

  • Install munin
  • Check a process with the following tools: top, iotop, netstat and lsof
  • Use stress-program to see the load on different resources
  • Go through the data collected by munin

EDIT: I added a ‘$’ character to make it easier to read commands that I use in the terminal, so don’t copy those!

So we start of by installing munin $ sudo apt-get install munin. I opened firefox and wrote the following address file:///var/cache/munin/www/localdomain/localhost.localdomain/index.html.

top, iotop, netstat and lsof

I decided to use a screensaver as the process which I wanted to analyze the load on my computer. I will open 6 screensaver daemons by using the following command on terminal: $ /usr/lib/xscreensaver/glcells & six times. It is faster to use the “up-key” after you have done it once. (you can check other available screensavers by using $ xscreensaver-demo and swapping the name. Remember the ‘&’ at to the end).

Using the command $ top, we can see how much resources, cpu and memory the screensavers are using. Next I tried using iotop $ sudo apt-get install iotop $ sudo iotop but I didn’t see anything useful since it shows the data of the disc and I am using a live-environment.

Next up was netstat which monitors your network statistics ( $ netstat ). I couldn’t find a trace of GLCells while using netstat, which was expected since it is a screensaver.

lsof shows you a lists of open files ( $ sudo lsof|less we need administrative rights to use it and less shows it a screen at a time so it is easier to read). I found a lot of hits, so I decided to try with only one GLCells opened. I closed all of the GLCells with the command $ killall glcells and opened a new one with the same command as before and after that I retried the lsof. This time the amount was more manageable. I killed the last GLCells with the same command as before.

stress

Next I am going to use stress (“tool to impose load on and stress test systems” -from man page) $ sudo apt-get install stress I’ll be testing my processor by using the following command $ stress --cpu 8 --timeout 120s The top-program showed that the stress test took 100% of my cpu.



munin data

There were a lot of graphs so I took which I believed were the most interesting ones.

Memory usage: Surprisingly (at least for me) it seems that the cache took the biggest chunk of my memory followed by active and inactive programs and apps. I seem that I had only 1.6gb of free ram out of 6gb which seems pretty little compared to what I did.

Processes: Most of my programs were “sleeping” and I had a zombie too, I also had 1 process actively running.

CPU usage: If I understood the graph correctly: most of the time my processor was idle and when in use, I was spending it the most.

CPU frequency scaling: The workload distributed equally to all four cores and the spike at the end resulted from the stress test which almost doubled the load on each core.

Burning a xUbuntu Live dvd and remote access with ssh

3 Comments

I am writing this post as part of Tero Karvinen’s course: Linux palvelimena (roughly translated: Linux as a server) http://terokarvinen.com/2012/aikataulu-linux-palvelimena-ict4tn003-4-ja-ict4tn003-6-syksylla-2012.

On this post I will go through the following:

  • Downloading xUbuntu 12.04 (32-bit)
  • Burning a live dvd (cd should still work as well.)
  • Using ssh to remotely connect to a computer with a ssh server

Downloading and burning a xUbuntu live dvd

I started of by heading to xUbuntu’s download page http://xubuntu.org/getxubuntu/. There were two different types of downloads available: the image file or a torrent of said file. I decided to go with the torrent, but as the link seemed to be down I googled for it instead with “xubuntu 12.04.1 torrent” and the first link took me to a website called http://cdimage.ubuntu.com/xubuntu/releases/12.04.1/release/. I chose and downloaded the file on the following line: xubuntu-12.04.1-desktop-i386.iso.torrent 23-Aug-2012 22:51 27K Desktop CD for PC (Intel x86) computers (BitTorrent download). But as the files are the same at xUbuntu’s site you can download the image from one of the mirrors at xUbuntu’s website mentioned above (if you are not sure which version is the right one take the i386 version ie 32-bit).

After the file had downloaded I located the file and clicked it with my mouse 2 and chose Open with -> Windows Disc Image Burner (On windows 7). I cliked the “Verify disc after burning (optional) and burn. The disc is ejected after the burning is completed.

When opened the contents of the disc should look the same as on the image below. Not the single iso-file I started burning.

If you would like to use an usb stick instead of a disc; check my Installing Ubuntu 12.04 LTS on an Asus eee pc 901 -post.

Booting to the live-environment

Close the disc tray (leave the disc in of course) and restart your computer. If your computer doesn’t automatically detect the disc you might need to go to bios settings to change the booting priority.

Read this if your disc didn’t boot to xUbuntu:
Restart your computer and hit the key that takes you to Bios (Mine was the Del-key). Once in Bios I switched to the boot-tab and selected “Boot Device Priority” in there I put my Disc as the top choise. Just to make sure keep the other drives in the correct order. (If you had hdd1, hdd2 and DVD-drive. Swap it like this DVD-drive, hdd1, hdd2. Since it might swap the two hdds if you only move the DVD-drive to the top) the drive order might not matter anything but if you have problems booting back to your installed operating system, you might want to re-check the order.

The disc took a while to boot, after it is ready you are asked to select one of the following “Try Xubuntu” and “Install Xubuntu”. I chose “Try Xubuntu” so it won’t install anything to my computer.

Connecting remotely

Since I don’t have access to many computers at the moment I will test the remote connection locally to another user using ssh.

First we need to open the Terminal which is found in the upper left corner by clicking the white mouse -> Accessories -> Terminal Emulator.

Once the Terminal was open I wrote sudo apt-get update, which updates the list of available programs to install (sudo or super user do, means you want to use administrative rights, apt is the program that handles the installations). Next I will install the ssh-server by sudo apt-get install openssh-server the installation asked if I wanted to really install the program, I pressed ‘y’ to install (I believe that in live environment programs are installed in RAM and dissapear after the computer is restarted).

After the installation has finished I will add a new user by doing the following command sudo adduser samuel next I need to enter a password for the new user samuel. The other information can be left empty. ssh samuel@localhost will connect me to the new user. ssh will ask if I can trust the address it is connecting, since I know it’s my own I write “yes” and hit enter. samuel’s password is asked in order to connect, once entered I have successfully connected to the other user.There is not much to see since the user was just created and there is no content, to get out simpy write “exit”.

Sending the public key through ssh

I’ll be following the instructions I found at https://help.ubuntu.com/community/SSH/OpenSSH/Keys to create public and private keys and sending the public key through ssh (normally to a remote computer). I use the command ssh-keygen -t rsa to generate a private and public key. I left the filename empty and just hit enter, after that I entered a passphrase.

I am sending the public key to the “remote” computer with ssh-copy-id samuel@localhost. After I was done sending the public key, I tried to login through ssh once again (as the terminal suggested) only this time using the passphrase.

Older Entries

Windows 7 and Ubuntu 12.04 dualboot setup

Leave a comment

I’m still gathering my thoughts so the text may appear messy.

I’ve come to the point that my computer needs to be formatted and I decided to do a dualboot setup. The thing is I have a brand new ssd drive and my old hdd drive and I’m still wondering what would be the best configuration. I’ll propably be using Windows mostly for gaming and use a few software only available on it, so I will propably benefit most by using my ssd with Windows.

On Ubuntu I’ll propably do most of my homework, especially programming. I will be using them both for surfing and media so I’ll need a shared portion for them both, I believe NTFS file system is the best solution for that.

The thigs that aren’t clear to me yet and need investigation are:
1. Should I install the whole Windows 7 on the ssd or only the programs & games I want to benefit from the higher loading speed.
2. If I install Windows 7 on the ssd and Ubuntu on the hdd which bootloader should I use? Will there be problems with the mbr?
3. How to keep my ssd drive’s life cycle as long as possible.

I’m pretty sure there was more things on my mind, but I can’t really remember at the moment.

The following links were a good read but didn’t really answer all of my questions

http://forum.xda-developers.com/showthread.php?s=606b7cdbfc7fe5680170b5d21215cb82&t=1627197

http://www.linuxbsdos.com/2012/05/17/how-to-dual-boot-ubuntu-12-04-and-windows-7/

http://www.linuxbsdos.com/2012/07/23/dual-boot-ubuntu-12-04-and-windows-7-on-a-computer-with-2-hard-drives/

http://neosmart.net/wiki/display/EBCD/Ubuntu

I’ll update this page as soon as I get this project started. I have schoolwork to do and important files to backup.

Arduino remote thermometer

1 Comment

As part of our course at Haaga-helia (held by Tero Karvinen – http://terokarvinen.com/2012/aikataulu-prototyypin-rakentaminen-bus4tn007-1) this is my final project. Our project actually as this was done with my classmate Niko. So what we did is a “remote” thermometer. Niko has a LM35 thermometer on his arduino which is connected to his computer. The arduino sends the temperature to the serial port, from where a python program uploads it to the net. My python program retreives the information and sends it to the arduino through the serial port. Depending on the temperature the arduino will move the “indicator” to the corresponding position.

What we used:

2x Arduino uno
a LM35 thermometer
a micro servo
5-6 jumper wires

a cardboard box
a dvd
a knife
tape

I used an Asus eee pc 901 (os: Ubuntu 12.04). Python came as default installation and the arduino ide is easy to install by opening the terminal and using the following commands:

sudo apt-get update
sudo apt-get install arduino

We started off by Connecting 2 arduinos to different computers in order to test our respective programs: transferring and receiving. You can find Niko’s code in his blog at http://nikokiuru.com/2012/05/oma-prototyyppi-hellemittari/. The blog is written in finnish so you might want to use an online translator.

and here is my code starting from the python code fetching the data from the internet:

import urllib2 # Connecting to the internet
import serial # serial port (usb)
import time

ser = None

ser = serial.Serial("/dev/ttyACM0")
print("Serial port " + ser.portstr + " opened.")

response = urllib2.urlopen('http://kiekkoliiga.net/~niko/lampomittari/') # get info
html=response.read() # save info
html=float(html)#convert string to float (also known as double)

if html>=30:
	ser.write("5")
	print("Receiving: %s" % html)
	print("Sending: 5")

elif html>=20:
	ser.write("3")
	print("Receiving: %s" % html)
	print("Sending: 3")	

elif html<20:
	ser.write("1")
	print("Receiving: %s" % html)
	print("Sending: 1")

And the actual arduino code:

#include <Servo.h>
char variable;
Servo servo;



void setup()

{

  Serial.begin(9600);

  //pinMode(13, OUTPUT); Test with a led. Now replaced with the servo.write -statements
  servo.attach(13);

}



void loop()

{

  if(Serial.available() > 0)

  {

    variable = Serial.read();

    if(variable == '1')

    {
      servo.write(0);
    }

    if(variable == '2')

    {
      servo.write(45);
    }

    if(variable == '3')

    {
      servo.write(90);
    }

    if(variable == '4')

    {
      servo.write(135);
    }
    
    if(variable == '5')
    {
      servo.write(170);
    }

  }


  delay(20);

}

After the programs worked to our liking we decided to use a dvd disk as the indicator by taping it on the servo. As the case we decided to use a cardboard box.

We cut a hole on the box so that the dvd only shows a part at a time and drew some helpful pictures on the dvd.

To keep the servo in place we sliced a hole on both sides of the box to add a layer and taped the servo on it.

And a video of it working. In the video we change the values directly to the website instead of using the actual program in order to demonstrate the changes on the thermometer.

And more pictures of the project below:

Piezo & arduino

Leave a comment

What I want to achieve: http://www.youtube.com/watch?v=UI2_ab68lTY

What I will use:

arduino uno R2
a red jumper wire
a black jumper wire
a piezo digisound B/C17
a breadboard
a led

How did I connect it all:

The red wire goes from arduino’s digital pin (7) to the plus side of the piezo
The black wire goes from arduino’s ground (gnd) to the minus side of the piezo
all connected through the breadboard
The led is connected to arduino’s digital pin (13) and ground conveniently next to eachother

The first test:

http://www.arduino.cc/en/Tutorial/PlayMelody

/* Play Melody
 * -----------
 *
 * Program to play melodies stored in an array, it requires to know
 * about timing issues and about how to play tones.
 *
 * The calculation of the tones is made following the mathematical
 * operation:
 *
 *       timeHigh = 1/(2 * toneFrequency) = period / 2
 *
 * where the different tones are described as in the table:
 *
 * note 	frequency 	period 	PW (timeHigh)	
 * c 	        261 Hz 	        3830 	1915 	
 * d 	        294 Hz 	        3400 	1700 	
 * e 	        329 Hz 	        3038 	1519 	
 * f 	        349 Hz 	        2864 	1432 	
 * g 	        392 Hz 	        2550 	1275 	
 * a 	        440 Hz 	        2272 	1136 	
 * b 	        493 Hz 	        2028	1014	
 * C	        523 Hz	        1912 	956
 *
 * (cleft) 2005 D. Cuartielles for K3
 */

int ledPin = 13;
int speakerOut = 7;               
byte names[] = {'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C'};  
int tones[] = {1915, 1700, 1519, 1432, 1275, 1136, 1014, 956};
byte melody[] = "2d2a1f2c2d2a2d2c2f2d2a2c2d2a1f2c2d2a2a2g2p8p8p8p";
// count length: 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0
//                                10                  20                  30
int count = 0;
int count2 = 0;
int count3 = 0;
int MAX_COUNT = 24;
int statePin = LOW;

void setup() {
 pinMode(ledPin, OUTPUT); 
}

void loop() {
  analogWrite(speakerOut, 0);     
  for (count = 0; count < MAX_COUNT; count++) {
    statePin = !statePin;
    digitalWrite(ledPin, statePin);
    for (count3 = 0; count3 <= (melody[count*2] - 48) * 30; count3++) {
      for (count2=0;count2<8;count2++) {
        if (names[count2] == melody[count*2 + 1]) {       
          analogWrite(speakerOut,500);
          delayMicroseconds(tones[count2]);
          analogWrite(speakerOut, 0);
          delayMicroseconds(tones[count2]);
        } 
        if (melody[count*2 + 1] == 'p') {
          // make a pause of a certain size
          analogWrite(speakerOut, 0);
          delayMicroseconds(500);
        }
      }
    }
  }
}

The second test:

http://www.faludi.com/2007/04/23/buzzer-arduino-example-code/ & http://www.faludi.com/itp/arduino/buzzer_example.pde

// Buzzer example function for the CEM-1203 buzzer (Sparkfun's part #COM-07950).
// by Rob Faludi
// http://www.faludi.com

void setup() {
  pinMode(4, OUTPUT); // set a pin for buzzer output
}

void loop() {
  buzz(4, 2500, 500); // buzz the buzzer on pin 4 at 2500Hz for 500 milliseconds
  delay(1000); // wait a bit between buzzes
}


void buzz(int targetPin, long frequency, long length) {
  long delayValue = 1000000/frequency/2; // calculate the delay value between transitions
  //// 1 second's worth of microseconds, divided by the frequency, then split in half since
  //// there are two phases to each cycle
  long numCycles = frequency * length/ 1000; // calculate the number of cycles for proper timing
  //// multiply frequency, which is really cycles per second, by the number of seconds to 
  //// get the total number of cycles to produce
 for (long i=0; i < numCycles; i++){ // for the calculated length of time...
    digitalWrite(targetPin,HIGH); // write the buzzer pin high to push out the diaphram
    delayMicroseconds(delayValue); // wait for the calculated delay value
    digitalWrite(targetPin,LOW); // write the buzzer pin low to pull back the diaphram
    delayMicroseconds(delayValue); // wait againf or the calculated delay value
  }
}



My modified code is based on the code I found and used on the second test

/* Buzzer example function for the CEM-1203 buzzer (Sparkfun's part #COM-07950).
 by Rob Faludi
 http://www.faludi.com

edited to use morse code
by kontsu
http://kontsu.wordpress.com/
*/

int ledPin=13;
int speakerOut =7;
int beepFreq=2500;

void setup()
{
  pinMode(ledPin, OUTPUT);
  pinMode(7, OUTPUT);
}

void shortMessage()
{
  digitalWrite(ledPin, HIGH);
  delay(0);//needed?!
  buzz(speakerOut, beepFreq, 150);
  delay(150);
  digitalWrite(ledPin, LOW);
  delay(100);
}

void longMessage()
{
  digitalWrite(ledPin, HIGH);
  delay(0);//needed?!
  buzz(speakerOut, beepFreq, 400);
  delay(400);
  digitalWrite(ledPin, LOW);
  delay(100);
}

void loop()
{
m();
o();
r();
s();
e();
delay(1000);
c();
o();
d();
e();
delay(1000);
v();
two();
delay(10000);
}

void buzz(int targetPin, long frequency, long length)
{
  long delayValue = 1000000/frequency/2;
  long numCycles = frequency * length/ 1000;
 
 for (long i=0; i < numCycles; i++)
 {
    digitalWrite(targetPin,HIGH);
    delayMicroseconds(delayValue);
    digitalWrite(targetPin,LOW);
    delayMicroseconds(delayValue);
  }
}

void a()
{
  shortMessage();
  longMessage();
  digitalWrite(13, LOW);
  delay(1000);
}

void b()
{
  longMessage();
  shortMessage();
  shortMessage();
  shortMessage();
  digitalWrite(13, LOW);
  delay(1000);
}

void c()
{
  longMessage();
  shortMessage();
  longMessage();
  shortMessage();
  digitalWrite(13, LOW);
  delay(1000);
}

void d()
{
  longMessage();
  shortMessage();
  shortMessage();
  digitalWrite(13, LOW);
  delay(1000);
}

void e()
{
  shortMessage();
  digitalWrite(13, LOW);
  delay(1000);
}

void f()
{
  shortMessage();
  shortMessage();
  longMessage();
  digitalWrite(13, LOW);
  delay(1000);
}

void g()
{
  longMessage();
  longMessage();
  shortMessage();
  digitalWrite(13, LOW);
  delay(1000);
}

void h()
{
  shortMessage();
  shortMessage();
  shortMessage();
  shortMessage();
  digitalWrite(13, LOW);
  delay(1000);
}

void i()
{
  shortMessage();
  shortMessage();
  digitalWrite(13, LOW);
  delay(1000);
}

void j()
{
  shortMessage();
  longMessage();
  longMessage();
  longMessage();
  digitalWrite(13, LOW);
  delay(1000);
}

void k()
{
  longMessage();
  shortMessage();
  longMessage();
  digitalWrite(13, LOW);
  delay(1000);
}

void l()
{
  shortMessage();
  longMessage();
  shortMessage();
  shortMessage();
  digitalWrite(13, LOW);
  delay(1000); 
}

void m()
{
  longMessage();
  longMessage();
  digitalWrite(13, LOW);
  delay(1000);
}

void n()
{
  longMessage();
  shortMessage();
  digitalWrite(13, LOW);
  delay(1000); 
}

void o()
{
  longMessage();
  longMessage();
  longMessage();
  digitalWrite(13, LOW);
  delay(1000);
}

void p()
{
  shortMessage();
  longMessage();
  longMessage();
  shortMessage();
  digitalWrite(13, LOW);
  delay(1000);
}

void q()
{
  longMessage();
  longMessage();
  shortMessage();
  longMessage();
  digitalWrite(13, LOW);
  delay(1000);
}

void r()
{
  shortMessage();
  longMessage();
  shortMessage();
  digitalWrite(13, LOW);
  delay(1000);
}

void s()
{
  shortMessage();
  shortMessage();
  shortMessage();
  digitalWrite(13, LOW);
  delay(1000);
}

void t()
{
  longMessage();
  digitalWrite(13, LOW);
  delay(1000);
}

void u()
{
  shortMessage();
  shortMessage();
  longMessage();
  digitalWrite(13, LOW);
  delay(1000);
}

void v()
{
  shortMessage();
  shortMessage();
  shortMessage();
  longMessage();
  digitalWrite(13, LOW);
  delay(1000);
}

void w()
{
  shortMessage();
  longMessage();
  longMessage();
  digitalWrite(13, LOW);
  delay(1000);
}

void x()
{
  longMessage();
  shortMessage();
  shortMessage();
  longMessage();
  digitalWrite(13, LOW);
  delay(1000);
}

void y()
{
  longMessage();
  shortMessage();
  longMessage();
  longMessage();
  digitalWrite(13, LOW);
  delay(1000);
}

void z()
{
  longMessage();
  longMessage();
  shortMessage();
  shortMessage();
  digitalWrite(13, LOW);
  delay(1000);
}

void zero()
{
  longMessage();
  longMessage();
  longMessage();
  longMessage();
  longMessage();
  digitalWrite(13, LOW);
  delay(1000);
}

void one()
{
  shortMessage();
  longMessage();
  longMessage();
  longMessage();
  longMessage();
  digitalWrite(13, LOW);
  delay(1000);
}

void two()
{
  shortMessage();
  shortMessage();
  longMessage();
  longMessage();
  longMessage();
  digitalWrite(13, LOW);
  delay(1000);
}

void three()
{
  shortMessage();
  shortMessage();
  shortMessage();
  longMessage();
  longMessage();
  digitalWrite(13, LOW);
  delay(1000);
}

void four()
{
  shortMessage();
  shortMessage();
  shortMessage();
  shortMessage();
  longMessage();
  digitalWrite(13, LOW);
  delay(1000);
}

void five()
{
  shortMessage();
  shortMessage();
  shortMessage();
  shortMessage();
  shortMessage();
  digitalWrite(13, LOW);
  delay(1000);
}

void six()
{
  longMessage();
  shortMessage();
  shortMessage();
  shortMessage();
  shortMessage();
  digitalWrite(13, LOW);
  delay(1000);
}

void seven()
{
  longMessage();
  longMessage();
  shortMessage();
  shortMessage();
  shortMessage();
  digitalWrite(13, LOW);
  delay(1000);
}

void eight()
{
  longMessage();
  longMessage();
  longMessage();
  shortMessage();
  shortMessage();
  digitalWrite(13, LOW);
  delay(1000);
}

void nine()
{
  longMessage();
  longMessage();
  longMessage();
  longMessage();
  shortMessage();
  digitalWrite(13, LOW);
  delay(1000);
}

Installing Ubuntu 12.04 LTS on an Asus eee pc 901

9 Comments

There are a few ways to install a new os on an eee pc but I believe that the easiest way is the following I did:

What I used:

1. Asus eee pc 901 with Ubuntu 11.10

2. Kingston 8gb DataTraveller (smaller will do of course)

3. ubuntu-12.04-desktop-i386.iso

How I did it:

I downloaded the iso-file from ubuntu’s website at http://www.ubuntu.com/download/desktop

[UPDATE] Ubuntu 12.04 might be slow on the older eee pc’s like my 901 so you might want to try Xubuntu instead http://xubuntu.org/getxubuntu/ The installation should be the same as on the basic Ubuntu version.

after that I plugged my usb to the laptop and started the Startup Disc Creator -program which is defaultly installed on ubuntu.

I clicked the “Other…” button and located the downloaded iso file.

I checked that the creator used my Kingston on the “Disc to use:” option.

Next part doesn’t really matter which one you choose. Depends do you wan’t to use the usb stick as a bootable device or just an installer.

- the first option allows you to save changes and files to your usb while you use it.

- the second option discards all changes after you shut down.

I chose the latter since I will only use the usb to install.

I clicked the “Make Startup Disk” button.

After a while the program asked administrator priviledges to install the bootloader to my usb.

After the program finished I restarted my computer.

I hit F2 so that the eee pc went to BIOS SETUP UTILITY where I could select my usb as the main bootable device. I opened the Boot tab and checked the Hard Disk Drives and moved the usb as first drive (if it isn’t found there check the Boot Device Priority).

I moved to the Exit tab and selected the Exit & Save Changes option and hit enter.

After the computer had started and fully loaded. I clicked the Try ubuntu option so I could check if typing, sound, video and internet worked correctly before installing it.

I opened the examples folder on the desktop and opened the how fast.ogg file to test video and sound.

I went to the internet and googled a a familiar website and clicked it open. Everything looked fine so I can confirm that typing worked, I could connect to the internet and the colors are shown correctly.

I returned to desktop and clicked the install ubuntu icon.

After selecting a language and deciding if I want to download updates as I install. My installation stopped in an unexpected error. Or so I thought. I left my computer running by itself on the “error screen” for about an hour and when I returned, to my surprise the installer had moved on to the next question. As an added note my 4gb drive doesn’t work anymore so I installed Ubuntu with default settings on the 16gb drive.

The rest of the installation went fine without any problems. The new Ubuntu version works great although the booting and shutting down (and it seems the “unity menu” takes a second or two to open) aren’t exatly fast anymore. Then again it might be because of the slower 16gb drive.

Graphical interface with Python on Windows 7

Leave a comment

I started by installing Python and other required software to my 64-bit windows 7 computer. Source: Make: Arduino Bots and Gadgets -book and http://botbook.com/links.html For now stick with the files presented on botbook’s website, until I find a solution to my problem. Might have something to do with the 64-bit installation. The instructions should be the same regardless of file versions (as long as they are for the same python version).

1. Download and install Python: www.python.org/ftp/python/2.7.3/python-2.7.3.amd64.msi
1+.Make sure that the installers on the libraries find the python installation folder when you install them.
2. Download and install pycairo: http://ftp.gnome.org/pub/GNOME/binaries/win32/pycairo/1.8/pycairo-1.8.10.win32-py2.7.msi
3. Download and install pygobject: http://ftp.gnome.org/pub/GNOME/binaries/win32/pygobject/2.28/pygobject-2.28.3.win32-py2.7.msi
4. Download and install pygtk: http://ftp.gnome.org/pub/GNOME/binaries/win32/pygtk/2.24/pygtk-2.24.0.win32-py2.7.msi
5. Download gtk+: http://ftp.se.debian.org/pub/gnome/binaries/win32/gtk+/2.24/gtk+-bundle_2.24.10-20120208_win32.zip

5 a) create a folder named “gtkbundle” in your c\Program Files (x86)\
5 b) extract previously downloaded gtk+ bundle and copy all the folders to the folder created on 5 a)

6. a) Open start menu’s computer properties and open the advanced system settings.
6. b) Click the “Environment Variables” button
6. c) Locate “Path” under “System variables” and click edit
6. d) Do not change anything! scroll to the end and add the following (depends on installation directory) “;C\Program Files (x86)\gtkbundle\bin;C:\Python27
6. e) save and exit
6. f) close all command prompts if any and open a new one and write “gtk-demo” and hit enter. A new window should open displaying GTK’s features. More info at: http://www.gtk.org/download/index.php

My actual problem:

I wrote a test program found on the book (mentioned in sources) to make a window

The code:

The error:

Adding libraries to arduino on ubuntu

Leave a comment

I encountered a problem while trying to execute my PING + iButton program on Ubuntu since I couldn’t find where the OneWire library should be placed. Long story short after googling around the net I found that when you install arduino through apt it creates a “sketchbook” folder in your home folder. So I first navigated to /home/’username’/sketchbook/ and created a folred named libraries and copied the unzipped OneWire folder in libraries and restarted arduino. ( /home/’username’/libraries/OneWire/ )

Ping and iButton together

Leave a comment

Since I had both the Ping and iButton at hand I decided to test them together. My intention is to make it so that the PING only works when the iButton receives the right key/button. If the wrong key is put the led will bling three times. The course

 

 

 

 

 

Lauri and Suvi’s modified code:

[edit]

Code unusable since wordpress decides to change it. Example ” is &quot;

[edit2]

Should be fixed

#include <OneWire.h>

//iButton
OneWire ds(7); //onewire 7th slot.
byte addr[8]; //iButton's fingerprint.
int but[6] = {195,133,181,20,0,0};
String keyStatus="";//why does wordpress change my code?!

//PING
const int pingPin = 8;//Ping sensor on 8th slot
long int duration, distanceCm;
int limitCm = 20;//distance

void setup(void)
{
 Serial.begin(115200);
 pinMode(13, OUTPUT);
}

void loop(void)
{
  getKeyCode(); //check if there is a code and if it is the ds1990a-buttons code.

  Serial.println();
  if(keyStatus=="ok")
  {
    //continue here if getKeyCode has read the right kind of button.
    byte i;
    for( i = 5; i >0; i--)
    {
      Serial.print(" : ");
      Serial.print(addr[i], DEC);
    }
    if(addr[1] == but[0] && addr[2] == but[1] && addr[3] == but[2] && addr[4] == but[3])
    {
      digitalWrite(13, HIGH);
      delay(1);
      //start the PING
      pinMode(pingPin, OUTPUT);

      digitalWrite(pingPin, LOW);

      delayMicroseconds(2);

      digitalWrite(pingPin, HIGH);

      delayMicroseconds(5);

      digitalWrite(pingPin, LOW);

      pinMode(pingPin, INPUT);

      duration = pulseIn(pingPin, HIGH);

      distanceCm = microsecondsToCentimeters(duration);

      Serial.println (distanceCm);

      delay(100);
    }
    else
    {
      //Wrong key/button. Blink led 3 times
      digitalWrite(13, LOW);
      delay(100);
      digitalWrite(13, HIGH);
      delay(250);
      digitalWrite(13, LOW);
      delay(100);
      digitalWrite(13, HIGH);
      delay(250);
      digitalWrite(13, LOW);
      delay(100);
      digitalWrite(13, HIGH);
      delay(250);
      digitalWrite(13, LOW);
      delay(100);
    }
  }
    else if (keyStatus!="")
    {
      Serial.print(keyStatus);
    }
    delay(1000);
  }

void getKeyCode()
{
 keyStatus="";

 //return to beginning if reader doensn't get any contact from button.
 if ( !ds.search(addr))
{
 //keyStatus="testi";
//tämän kirjoitin testiksi, ja totesinkin lukijan olevan väärässä pinnissä
 //(ohjeen mukainen 2, ei koodin mukainen 12),
 //kun ohjelma tulosti koko ajan pelkkää "testiä".
 ds.reset_search();
 return;
}

if ( OneWire::crc8( addr, 7) != addr[7]) {
keyStatus="CRC invalid";
return;
}

//Check if the button is ds1990a-model.
if ( addr[0] != 0x01) {
keyStatus="not DS1990A";
return;
}

//if the code reached here without any errors the keystatus is ok.
keyStatus="ok";
ds.reset();
}

long microsecondsToCentimeters(long microseconds)
{
  return microseconds / 29 / 2;
}

Everything didn’t go as planned. The output was supposed to show the distance the PING sensor calculated

EDIT

Got the “copy paste error” fixed. just deleted the lines 30-34.

The modified and cleaned code:

#include <OneWire.h>

//iButton
OneWire ds(7); //onewire 7th slot.
byte addr[8]; //iButton's fingerprint.
int but[6] = {195,133,181,20,0,0};
String keyStatus="";

//PING
const int pingPin = 8;//Ping sensor on 8th slot
long int duration, distanceCm;

void setup(void)
{
 Serial.begin(115200);
 pinMode(13, OUTPUT);
}

void loop(void)
{
  getKeyCode(); //check if there is a code and if it is the ds1990a-buttons code.

  //Serial.println();TEST
  if(keyStatus=="ok")
  {
    //continue here if getKeyCode has read the right kind of button.
    byte i;

    if(addr[1] == but[0] && addr[2] == but[1] && addr[3] == but[2] && addr[4] == but[3])
    {
      keyOk();
    }
    else
    {
      keyNotOk();
    }
  }
    else if (keyStatus!="")
    {
      Serial.print(keyStatus);
    }
    delay(1000);
  }

void getKeyCode()
{
 keyStatus="";

 //return to beginning if reader doensn't get any contact from button.
 if ( !ds.search(addr))
{
 //keyStatus="testi";
 //tämän kirjoitin testiksi, ja totesinkin lukijan olevan väärässä pinnissä
 //(ohjeen mukainen 2, ei koodin mukainen 12),
 //kun ohjelma tulosti koko ajan pelkkää "testiä".
 ds.reset_search();
 return;
}

if ( OneWire::crc8( addr, 7) != addr[7]) {
keyStatus="CRC invalid";
return;
}

//Check if the button is ds1990a-model.
if ( addr[0] != 0x01) {
keyStatus="not DS1990A";
return;
}

//if the code reached here without any errors the keystatus is ok.
keyStatus="ok";
ds.reset();
}

long microsecondsToCentimeters(long microseconds)
{
  return microseconds / 29 / 2;
}

void keyOk()
{
      digitalWrite(13, HIGH);
      delay(1);
      //start the PING
      pinMode(pingPin, OUTPUT);

      digitalWrite(pingPin, LOW);

      delayMicroseconds(2);

      digitalWrite(pingPin, HIGH);

      delayMicroseconds(5);

      digitalWrite(pingPin, LOW);

      pinMode(pingPin, INPUT);

      duration = pulseIn(pingPin, HIGH);

      distanceCm = microsecondsToCentimeters(duration);

      Serial.print(distanceCm);
      Serial.println("cm");

      delay(100);
}

void keyNotOk()
{
      //Wrong key/button. Blink led 3 times
      digitalWrite(13, LOW);
      delay(100);
      digitalWrite(13, HIGH);
      delay(250);
      digitalWrite(13, LOW);
      delay(100);
      digitalWrite(13, HIGH);
      delay(250);
      digitalWrite(13, LOW);
      delay(100);
      digitalWrite(13, HIGH);
      delay(250);
      digitalWrite(13, LOW);
      delay(100);
}

iButton

Leave a comment

I followed Suvi’s instructions on how to get iButton working on the UNO.

The iButton had two wires, a white and a brown one. I connected the iButton on the breadboard. I connected the white wire to slot 7 on the UNO and to the 5v through a resistor. I connected the brown wire to ground.

After the wires were in place I went to http://arduino.cc/playground/Learning/OneWire to get the library as Suvi had instructed. Once the OneWire is extracted copy it to the folder arduino-1.0\libraries

Suvi’s code. There is also a video of the iButton in action.

PING ultrasound sensor

Leave a comment

Ping sensor is a lot easier to test than PIR, believe me. I swapped parts with my classmate Lauri from Tero’s class

Lauri’s code below:

/*

PING ultraäänisensorin testaus käyttäen lediä

Lauri Soivi
__________________________________________________________

PING ultrasound sensor test with a led by Lauri Soivi

*/

 

const int pingPin = 7;

const int ledPin = 13;

long int duration, distanceCm;

int limitCm = 20
;//distance

 

void setup()

{

  pinMode(ledPin, OUTPUT);

  Serial.begin(115200);

}

 

void loop()

{

  pinMode(pingPin, OUTPUT);

  digitalWrite(pingPin, LOW);

  delayMicroseconds(2);

  digitalWrite(pingPin, HIGH);

  delayMicroseconds(5);

  digitalWrite(pingPin, LOW);

  pinMode(pingPin, INPUT);

 

  duration = pulseIn(pingPin, HIGH);

  distanceCm = microsecondsToCentimeters(duration);

 

  checkLimit();

  Serial.println (distanceCm);

  delay(100);

}

 

void checkLimit()

{

  if (distanceCm < limitCm){

    digitalWrite(ledPin, HIGH);  

  } else {

    digitalWrite(ledPin, LOW);

  }

}

 

long microsecondsToCentimeters(long microseconds)

{

  return microseconds / 29 / 2;

}

if you get readings that it is hitting something closer than it should, make sure the sensor isn’t hitting something directly beneath it. I had to place the sensor on the edge of the test board because of “weird” readings.

The led is set to slot 13 and ground directly on the UNO, the ping’s wiring is the following:

UNO Wire Color PING
Slot 7 Orange SIG (Signal)
5V Yellow 5V
GND (Ground) Green GND (Ground)

Passive Infra-Red Sensor

Leave a comment

I familiarized myself (and made a test) with a PIR motion sensor as a part of a course at Haaga-Helia held by Tero Karvinen: http://terokarvinen.com/2012/aikataulu-prototyypin-rakentaminen-bus4tn007-1

I found a site with instructions of how to use the motionsensor to blink a led

http://www.instructables.com/id/Arduino-Basics-PIR-Sensor/

I got the PIR and a led hooked to my arduino following the instructions, they also provided an example code to use. My only problem now seems to be how to test the sensor with all the movement around me in the class room.

EDIT

I am using a box to let the PIR calibrate.

Didn’t really notice a difference.

EDIT2

There was a jumper setting under PIR with L and H setting
by default it was set to H. I swiched it to L and tested again.

Now it seems to work as intended.

Symbol H: Output remains HIGH when sensor is retriggered repeatedly. Output is LOW when idle (not triggered).

Symbol L: Output goes HIGH then LOW when triggered. Continuous motion results in repeated HIGH/LOW pulses. Output is LOW when idle.

more information can be found on the PIR sensors pdf at parallax’s website

http://www.parallax.com

and more directly: http://www.parallax.com/Portals/0/Downloads/docs/prod/sens/910-28027-PIRsensor-v1.4.pdf

Arduino HelloWorld

Leave a comment

I Started programming a hello World program to an Arduino UNO on a xubuntu 12.04 beta1 with a program called arduino 1.0 as a part of a course at Haaga-Helia held by Tero Karvinen: http://terokarvinen.com/2012/aikataulu-prototyypin-rakentaminen-bus4tn007-1

I decided to do a program which could translate all the letters to morse code:

void setup()
{
// initialize the digital pin as an output.
// Pin 13 has an LED connected on most Arduino boards:
pinMode(13, OUTPUT);
}

void loop()
{
H();
I();
}

void shortBlink()
{
digitalWrite(13, HIGH);//led on
delay(250);//time before moving to next line of code (ms - milli second)
digitalWrite(13, LOW);//led off
delay(50);
}

void longBlink()
{
digitalWrite(13, HIGH);
delay(750);
digitalWrite(13, LOW);
delay(100);
}

void A()
{
shortBlink();
longBlink();
digitalWrite(13, LOW);
delay(1000);
}

void B()
{
longBlink();
shortBlink();
shortBlink();
shortBlink();
digitalWrite(13, LOW);
delay(1000);
}

void C()
{
longBlink();
shortBlink();
longBlink();
shortBlink();
digitalWrite(13, LOW);
delay(1000);
}

void D()
{
longBlink();
shortBlink();
shortBlink();
digitalWrite(13, LOW);
delay(1000);
}

void E()
{
shortBlink();
digitalWrite(13, LOW);
delay(1000);
}

void F()
{
shortBlink();
shortBlink();longBlink();
digitalWrite(13, LOW);
delay(1000);
}

void G()
{
longBlink();
longBlink();
shortBlink();
digitalWrite(13, LOW);
delay(1000);
}

void H()
{
shortBlink();
shortBlink();
shortBlink();
shortBlink();
digitalWrite(13, LOW);
delay(1000);
}

void I()
{
shortBlink();
shortBlink();
digitalWrite(13, LOW);
delay(1000);
}

As you can see it’s still a work in progress. But what caught me by surprise was that when I installed Arduino 1.0 on my windows 7 and tried to execute the code I got the following errors:

sketch_mar30c:-1: error: expected unqualified-id before 'reinterpret_cast'
sketch_mar30c:-1: error: expected `)' before 'reinterpret_cast'
sketch_mar30c:-1: error: expected unqualified-id before ')' token
sketch_mar30c:74: error: expected unqualified-id before 'reinterpret_cast'
sketch_mar30c:74: error: expected `)' before 'reinterpret_cast'
sketch_mar30c:74: error: expected unqualified-id before ')' token

I first tried to run the code through notepad to see if there was any problems with fonts or other extra what doesn’t belong there. it didn’t fix my problem.

Next I tried to check the code for errors, no luck.

I opened the blink example to see if the syntax was different for some weird reason, the example worked fine even with my modifications similar to the original file I was trying to fix.

So lastly I decided to cut my code from the end so I could find my error:

void setup()
{
// initialize the digital pin as an output.
// Pin 13 has an LED connected on most Arduino boards:
pinMode(13, OUTPUT);
}

void loop()
{
H();
I();
}

void shortBlink()
{
digitalWrite(13, HIGH);//led on
delay(250);//time before moving to next line of code (ms - milli second)
digitalWrite(13, LOW);//led off
delay(50);
}

void longBlink()
{
digitalWrite(13, HIGH);
delay(750);
digitalWrite(13, LOW);
delay(100);
}

void A()
{
shortBlink();
longBlink();
digitalWrite(13, LOW);
delay(1000);
}

void B()
{
longBlink();
shortBlink();
shortBlink();
shortBlink();
digitalWrite(13, LOW);
delay(1000);
}

void C()
{
longBlink();
shortBlink();
longBlink();
shortBlink();
digitalWrite(13, LOW);
delay(1000);
}

The program didn’t show any errors, finally some progress! After adding the following code:

void D()
{
longBlink();
shortBlink();
shortBlink();
digitalWrite(13, LOW);
delay(1000);
}

void E()
{
shortBlink();
digitalWrite(13, LOW);
delay(1000);
}

void F()
{
shortBlink();
shortBlink();longBlink();
digitalWrite(13, LOW);
delay(1000);
}

The error returned. I pinpointed the problem to be on

void F()
{
shortBlink();
shortBlink();longBlink();
digitalWrite(13, LOW);
delay(1000);
}

and finally decided to test to change void F() to something else. It worked again!

I have no idea what the problem could be and why I  couldn’t use “F” but “f” worked fine. I’ll have to double check if this problem was only on the Windows version and not on the Linux one. The problem was found on both operating systems

EDIT:

The finished code:

void setup()
{
// initialize the digital pin as an output.
// Pin 13 has an LED connected on most Arduino boards:
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
}
//http://en.wikipedia.org/wiki/Morse_code
void loop()
{
digitalWrite(12, HIGH);//RED
delay(1);
digitalWrite(11, HIGH);//GREEN
delay(1);
//REST IN YELLOW, THE ACTIUAL PROGRAM
a();
r();
d();
u();
i();
n();
o();
}

void shortBlink()
{
digitalWrite(13, HIGH);//led on
delay(250);//time before moving to next line of code (ms - milli second)
digitalWrite(13, LOW);//led off
delay(50);
}

void longBlink()
{
digitalWrite(13, HIGH);
delay(750);
digitalWrite(13, LOW);
delay(100);
}

void a()
{
shortBlink();
longBlink();
digitalWrite(13, LOW);
delay(1000);
}

void b()
{
longBlink();
shortBlink();
shortBlink();
shortBlink();
digitalWrite(13, LOW);
delay(1000);
}

void c()
{
longBlink();
shortBlink();
longBlink();
shortBlink();
digitalWrite(13, LOW);
delay(1000);
}

void d()
{
longBlink();
shortBlink();
shortBlink();
digitalWrite(13, LOW);
delay(1000);
}

void e()
{
shortBlink();
digitalWrite(13, LOW);
delay(1000);
}

void f()
{
shortBlink();
shortBlink();longBlink();
digitalWrite(13, LOW);
delay(1000);
}

void g()
{
longBlink();
longBlink();
shortBlink();
digitalWrite(13, LOW);
delay(1000);
}

void h()
{
shortBlink();
shortBlink();
shortBlink();
shortBlink();
digitalWrite(13, LOW);
delay(1000);
}

void i()
{
shortBlink();
shortBlink();
digitalWrite(13, LOW);
delay(1000);
}

void j()
{
shortBlink();
longBlink();
longBlink();
longBlink();
digitalWrite(13, LOW);
delay(1000);
}

void k()
{
longBlink();
shortBlink();
longBlink();
digitalWrite(13, LOW);
delay(1000);
}

void l()
{
shortBlink();
longBlink();
shortBlink();
shortBlink();
digitalWrite(13, LOW);
delay(1000);
}

void m()
{
longBlink();
longBlink();
digitalWrite(13, LOW);
delay(1000);
}

void n()
{
longBlink();
shortBlink();
digitalWrite(13, LOW);
delay(1000);
}

void o()
{
longBlink();
longBlink();
longBlink();
digitalWrite(13, LOW);
delay(1000);
}

void p()
{
shortBlink();
longBlink();
longBlink();
shortBlink();
digitalWrite(13, LOW);
delay(1000);
}

void q()
{
longBlink();
longBlink();
shortBlink();
longBlink();
digitalWrite(13, LOW);
delay(1000);
}

void r()
{
shortBlink();
longBlink();
shortBlink();
digitalWrite(13, LOW);
delay(1000);
}

void s()
{
shortBlink();
shortBlink();
shortBlink();
digitalWrite(13, LOW);
delay(1000);
}

void t()
{
longBlink();
digitalWrite(13, LOW);
delay(1000);
}

void u()
{
shortBlink();
shortBlink();
longBlink();
digitalWrite(13, LOW);
delay(1000);
}

void v()
{
shortBlink();
shortBlink();
shortBlink();
longBlink();
digitalWrite(13, LOW);
delay(1000);
}

void w()
{
shortBlink();
longBlink();
longBlink();
digitalWrite(13, LOW);
delay(1000);
}

void x()
{
longBlink();
shortBlink();
shortBlink();
longBlink();
digitalWrite(13, LOW);
delay(1000);
}

void y()
{
longBlink();
shortBlink();
longBlink();
longBlink();
digitalWrite(13, LOW);
delay(1000);
}

void z()
{
longBlink();
longBlink();
shortBlink();
shortBlink();
digitalWrite(13, LOW);
delay(1000);
}

void zero()
{
longBlink();
longBlink();
longBlink();
longBlink();
longBlink();
digitalWrite(13, LOW);
delay(1000);
}

void one()
{
shortBlink();
longBlink();
longBlink();
longBlink();
longBlink();
digitalWrite(13, LOW);
delay(1000);
}

void two()
{
shortBlink();
shortBlink();
longBlink();
longBlink();
longBlink();
digitalWrite(13, LOW);
delay(1000);
}

void three()
{
shortBlink();
shortBlink();
shortBlink();
longBlink();
longBlink();
digitalWrite(13, LOW);
delay(1000);
}

void four()
{
shortBlink();
shortBlink();
shortBlink();
shortBlink();
longBlink();
digitalWrite(13, LOW);
delay(1000);
}

void five()
{
shortBlink();
shortBlink();
shortBlink();
shortBlink();
shortBlink();
digitalWrite(13, LOW);
delay(1000);
}

void six()
{
longBlink();
shortBlink();
shortBlink();
shortBlink();
shortBlink();
digitalWrite(13, LOW);
delay(1000);
}

void seven()
{
longBlink();
longBlink();
shortBlink();
shortBlink();
shortBlink();
digitalWrite(13, LOW);
delay(1000);
}

void eight()
{
longBlink();
longBlink();
longBlink();
shortBlink();
shortBlink();
digitalWrite(13, LOW);
delay(1000);
}

void nine()
{
longBlink();
longBlink();
longBlink();
longBlink();
shortBlink();
digitalWrite(13, LOW);
delay(1000);
}

Arduino Uno working

The program working:

How the wiring was done:

I placed the black wire on the gnd (ground), yellow on 13, grey on 12 and green on 11.

the red led uses the grey and black wire

the yellow led uses the yellow and black wire

the green led uses the green and black wire

Follow

Get every new post delivered to your Inbox.