web server

Changing Password for phpmyadmin on Raspberry Pi

I happen to forget my password to phpmyadmin because it was months ago since i installed it with my Apache2 web server. I did a quick search on the net and found a forum post discussing about recovering password for phpmyadmin on XAMPP. I haven’t try this on Raspberry Pi because I managed to recover my root password. (username is root!) However this may be useful for future reference:

You may want to edit this file: “\xampp\phpMyAdmin\config.inc.php” for XAMPP on desktop or “/etc/phpmyadmin/confid.inc.php”

change this line (for XAMPP):

$cfg[‘Servers’][$i][‘password’] = ‘WhateverPassword’;

to whatever your password is. If you don’t remember your password, then run this command in the Shell:

mysqladmin.exe -u root password WhateverPassword

where ‘WhateverPassword’ is your new password.

However I couldn’t find the line for Raspberry Pi. Instead, this may be helpful:
/* Uncomment the following to enable logging in to passwordless accounts, after taking note of the associated security risks. */
// $cfg['Servers'][$i]['AllowNoPassword'] = TRUE;

Web Application Lesson 1

So i have been hearing bad experiences from seniors about this particular module offered to the final year student, Web Design and Application. It was said to be a time-consuming module and the professor has a high expectation on the students.

However I was kind of shocked when the professor actually is a very friendly and helpful person. Perhaps they were talking about some other professors?

Anyway, I installed XAMPP on my Window 7 today. Faced some problems that I am going to note them down.

For Windows:

1. Download XAMPP Portable Lite 1.8.3 PHP 5.5 ZIP file from here.

2. Extract it and move the files to Desktop.

3. Double-click on setup_xampp window batch file. Wait for it to initialize and complete.

4. Run xampp-control application.

5. Start Apache and MySQL. I’ve got errors while starting them!! >> what I did to solve them

– Port 80 in used by system >> change to Port 8000 instead (At Apache, click on “config”>httpd.conf, search for “Listen 80”, change it to “Listen 8000”, save.)

– Apache stopped unexpectedly. >> I stopped MySQL service under Administrative Tool>Service but it doesn’t help. Check for other application that might be using Port 80 (e.g Dreamweaver) but I couldn’t find anything (in fact, I don’t know what else).

– MySQL path in used >> Uninstall the previously installed MySQL.

Finally, I stopped Web Deployment Agent Service and changed it to “Manual start”. Only then I could start MySQL on XAMPP.

The professor said, the best way of learning is to be active and engaged. Do not be scared to ask questions and to clarify. We make mistakes in order to learn. There is nothing wrong to copy but you have to modify it. One nice thing I like about the professor is that he give chance (first warning) to students.ย  At least if you make mistakes unknowingly, you could change for better.

 

WEIRD Web2py

Morning Monday.

So i was renown for being a “Spoiler” because i always cant’ wait to tell my sisters what’s going to happen in the drama series. ๐Ÿ˜ก So, i spoilt quite a few things last week including my sd card and SIM card. My Web2py web app couldn’t work as well.

I asked around in the forum and Google group, desperately finding answers. Then, i reconnect everything and hey, where is the error? ARE YOU SERIOUS? i logged into the Comfort system from my web2py app?! Then, i added another serial command to turn on the light… it turned on. i was shocked. Seriously, totally have no idea what is going on. I didn’t change anything, did I?

Anyway, now i will start hesitating between web2py and cherrypy, again.

Update on cherrypy progress, i manage to get the keypad out but have not able to use it to let user to sign in.

Update on my KDrama, YES, i have finished watching “Rooftop Prince” and it is extremely nice. I cried non-stop towards the end. Such a wonderful and touching story. Will update on it in a post next time! T_T

And Thank God for Easter Day. โค Gloria! Glory to the Lord! ๐Ÿ˜‰

Hello web2py

I have been lazying out on Raspberry Pi recently. Stuck at getting the web app on web2py to open the port at ttyAMA0. However it works fine on CherryPy.

Why. Why. Why.

Would it be better to just focus on CherryPy? :/ but i think Web2Py is newer and probably better and easier!
That is if and only if i am determined enough to finish reading (and digesting) through the 583 pages web2py manual. But it is so tiring to read it through the screen and time-wasting to study during working hours. If only i have an iPad or something.

Wait, did i just think of the Amazon Kindle or something? Haha, right. I should do something meaningful in the train while on my way to work, rather than sleeping. How about knitting? (That’s too outstanding. You probably wouldn’t want the whole pack of Sardine (we call the commuters that) to stare at you and start guessing your age.)

Not sure if it is a good idea to learn web2py and cherrypy concurrently. just hope that Mr Massimo can solve my problems soon.

Websites KIV:
Your first CherryPy application

CherryPy Tutorial

The CherryPy Documentation

Work related stuffs to do tomorrow:
– testing Z-wave responses (forgot to do it today!!!)

Understoodย  some Z-Wave problems today.

Other stuffs to do tonight:
– unofficial strategy planning with new team
– reply business emails
– EH, FINISH UP MY PROJECT REPORT!

– revamp website too.

CherryPy Progress!

Good Day! i got stuck in testing the new Z-Wave firmware so here I am, back for more CherryPy!

Thanks to Mefarmer and ax25 who explained to me about what’s going on with the CherryPy and gave me clues on how to proceed! It is a nice of motivation. ๐Ÿ™‚

Let me restart my CherryPy journey and you can refer to my discussion with mefarmer in this forum thread. Do download the mobile_website.zip from there too as i could not upload the file here.

Before that, i forgot to mention about jQuery Mobile!! i think it is an awesome app. Check out the themeroller! Awesome awesome!! i’m so excited to make some web apps!!!! Wait. is web2py totally different from this? :O

The last time i edited the tutorial.conf file by changing the port number and tools.staticdir.root. But the web app wouldn’t show up when i type in the localhost:portnumber. Today, i changed the port number to 8020 which is not in used by any server. I think Web2py has taken up localhost:80 by default and :8080 seems to have some error… i did use it to display “Hello world” from the tutorial file included with the installation.

Anyway, moving on to remote_control.py.
Adding #!/usr/bin/python will allow user to run the script automatically by typing python myscript.py in the terminal. remote_control.py, when run, will return a html file (webpage) which shows a sleek nice black layout with 3 buttons in the first row and a slider in the second row.

The jQuery Mobile framework is using a block style class convention called ui-grid.
There are four preset configurations layouts that can be used in any situation that requires columns:

  • two-column (using the ui-grid-a class)
  • three-column (using the ui-grid-b class)
  • four-column (using the ui-grid-c class)
  • five-column (using the ui-grid-d class)

Within the grid container, child elements are assigned ui-block-a/b/c/d/e in a sequential manner which makes each “block” element float side-by-side, forming the grid. The ui-block-a class essentially clears the floats which will start a new line (see multiple row grids, below).

To display the 3 buttons, here is the code (for one of the buttons):

<div class ="ui-grid-b">// 3 columns
block
block (refer below)
</div>

<div>
<button type="button" id="new_1" data-role="button" data-transition="fade" >
new_1 //word on the button
</button>
</div>

Read more here.

As for the slider, the data-role will be “slider” and it has more things to set (e.g option) (refer remote_control.py)

Inside the html file shown in the example, we can add “scripts” in the form of “script src” (which direct to a script file) or “script type” which we can directly add in the script below it. in this case, a javascript was included. this will get the clicks and send them to the server using ajax:

$("#unique_id").click(function () {$.post('/request',{key_pressed:"unique_id"})});

$(“#slider_id”).change(function () {$.post(‘/request’, {key_pressed:”slider_id”+$(this).val()})});

Every button has an unique ID. Then the javascript sets up an event handler that looks for a “click” event with that unique ID. When there is a “click” event, it will do an ajax “post” to “http://localhost/request&#8221; which will send JSON data {key_pressed:”unique_id”}

Server will get the “post” and route it to the “request” function (in the remote_control.py itself). The JSON will be passed in as a dictionary. Inside the “request” function, we get the dictionary as “data” and look for the key “key_pressed”. The value we get from that, is the unique ID we passed in from the javascript ( {key_pressed:”unique_id”} ). in the example, we simply just send ID and use an if statement to look for matching values and print it out.
if key == “new_1”:
# you can do anything you want right here
print “new_1”

Now, to test my own application, this is what i do:
1. Login test
– import serial and time
– in the “request” function, i added

serialport = serial.Serial("/dev/ttyAMA0/", 9600, timeout=0.5)
serialport.write("\x03LI1234\x0D")
response = serialport.readlines(1)
print response
time.sleep(1)

– somehow i need to use a new port number. then i run the python script.
– it’s a success! i got the reply from the device connected to its serial port.

2. other buttons test
– here comes the challenge. serialport belongs to the if key ==”start” only. Does that mean i have to open the serial port everytime i press on any button? well that’s definitely not the best way. I can’t seem to find anywhere to insert that line (serialport =serial.Serial(….))
outside the function? global name “serialport” is not defined
inside the function, outside the “if”? local name “serialport” is not defined.

so in the end, i insert

serialport = serial.Serial("/dev/ttyAMA0/", 9600, timeout=0.5)

in every “if” and “elif” and it works~ whenever i slide the bar to “on”, the testlight turns on, and when i slide to “off”, the testlight turns off. Happy! ๐Ÿ˜€ Arming and disarming works too!! lovely milestone today! ๐Ÿ™‚

IMPORTANT! while i edit the python file, i did not shutdown the server. After i saved my changes, the server will “re-spawn”? i take that as a restart. haha, CherryPy coming back to life huh?

CherryPy!

Yesterday i got to know a new friend called CherryPy, a lovely sweet lady? No, it’s a “minimalist Python Web Framework”. Someone replied to my forum topic and he explained quite a lot about web application.

CherryPy seems to be a good alternative to web2py although she is older.
1. So, let’s start off by installing CherryPy in our RaspberryPi by downloading the tar.gz file from here.

UPDATE: can just install using sudo pip install CherryPy

2. Save it in your home/pi directory and open up the LXTerminal.

3. Type:
tar -xzvf CherryPy-3.2.2.tar.gz

4. Rename the file to CherryPy for ease of access

5. Then go to the directory created by the file extraction
cd CherryPy

6. Type: (user has to be root)
sudo python setup.py install

7. Run the first sample website by going to cherry/tutorial directory and type “python tut01_helloworld.py”
cd cherrypy/tutorial
python tut01_helloworld.py

8. Open your browser (Midori or iceweasel or something else on R-Pi) and type http://localhost:8080 or http://127.0.0.1:8080 at the address bar.

There you go, Hello World! ๐Ÿ™‚

To stop the server, press CTRL+Z. CTRL+C.

** create a new “shutdown” function using “cherry.engine.exit()” and display it as a link on the web app – when clicking that shutdown link, the server will shutdown and the port will be freed. ๐Ÿ˜‰

Now i will download the file from the forum and see what he has got for me!

1. Go back to the home directory (where you have saved the zip file)
unzip mobile_website.zip
2. Then create a new folder named mobile_website (or something else of your choice)
3. Move the extracted files into the folder.
4. Go to that folder direcotry in terminal, type:
gedit remote_conrol.py
(it is also possible to edit the file directly using IDLE or other editors)
5. Add in #!/usr/bin/python at the top of the page
6. Edit the tutorial.conf
nano tutorial.conf

Change tools.staticdir.root =”/home/pi/mobile_website”
CTRL+O
CTRL+X
6. Run python remote_control.py to start the server or double click on the remote_control.py
(Ok, it doesn’t work on my R-Pi)
ChannelFailures: IOError (“Port 80 not free on ‘0.0.0.0’”)

Stuck and waiting for someone to help me in the forum. ๐Ÿ˜ฆ

Web2py Web App Progress

Today is more fruitful than yesterday.
I found out an awesome function in the web2py Administrative Interface. It is the “New Application Wizard” which will guide you through creating the most basic webpage.

Also, i just realized that there is a much better web2py tutorial here: http://www.web2py.com/books/default/chapter/29/03

So today i created a skeleton of my web app using the application wizard. Then i edited the layout.html, index.html, and default.py. I created default/test.html in accordance to the new function test() created in default.py. Also, i uploaded some pictures.

here is a screenshot:
web2py web app

Click on the light button to turn on

 

wev2py webapp

Flash a “welcome home” and the light turned on

 

here are some codes used:
in controller/default.py

def test():
ย ย ย  import serial
ย ย ย  import time
ย ย ย  response.flash=T(“welcome home!”)

in view/default/index.html

{{extend ‘layout.html’}}

<h1>Welcome to <strong>Cytech Comfort</strong></h1><h2>A new way to control your smart home</h2>

<img src = “/Comfort2/static/images/comfort.jpg” width=”268″ height=”79″>
<br>
<a href = “{{=URL(c=’default’, f=’test’)}}”><img src =”/Comfort2/static/images/off.jpg” width =”75″ height=”75″</a>

in view/default/test.html

{{extend ‘layout.html’}}
<h1>Welcome to <strong>Cytech Comfort</strong></h1><h2>A new way to control your smart home</h2>

<img src = “/Comfort2/static/images/comfort.jpg” width=”268″ height=”79″>
<br>
<img src = “/Comfort2/static/images/on.jpg” width =”75″ height =”75″>
<p>the lights are turned on</p>

However i could not proceed to send the serial commands (which is my main purpose!!) to the device i wish to control through Raspberry Pi.

i added the following codes to def test()
try:
serialport= serial.Serial(“/dev/ttyAMA0”, 9600, timeout=1)
except RuntimeError:
print “Error opening port”
quit()

It issued me a ticket:
<class ‘serial.serialutil.SerialException’> could not open port /dev/ttyAMA0: [Errno 13] Permission denied: ‘/dev/ttyAMA0’

Argh, headache. Sore eyes. ๐Ÿ˜ฆ

R-Pi Server up and running again! (change to static IP)

Fresh in the morning, i reinstall web2py from Web2Py webpage to my home directory ( /home/pi) and run the following:

cd /home/pi/web2py
sudo python2.6 web2py.py

I can start server at 127.0.0.1 (localhost) but not my public IP. It encountered an error:

ERROR:Rocket.Errors.Port8000:Socket 10.0.0.189:8000 in use by other process and it won't share

Meh, can’t find any solution from the web.

So i set my Raspberry Pi IP address to static such as follow:
(ref: Using a Static IP Address)

$ sudo nano /etc/network/interfaces

Change the line that reads

iface eth0 inet dhcp

to

iface eth0 inet static

Below this line enter the desired settings:

address 10.0.0.132 # a static IP address of your choice
netmask 255.255.255.0 # from here onwards, it depends on your router settings
network 10.0.0.0
broadcast 10.0.0.255
gateway 10.0.0.100

For the network mask, broadcast address and gateway, type:

$ ifconfig

or

ipconfig

in your same network window command prompt.

CTRL+O to save and CTRL+X to exit.

Then from your same network computer, try to ping to the new static address you just set by typing in the command prompt:

ping

You can do the same thing on Raspberry Pi as well and ping to your same network computer.

Then i reinstall web2py using the following codes which does not require me to run the web2py.py everytime i want to start the server:

sudo su

wget http://web2py.googlecode.com/hg/scripts/setup-web2py-ubuntu.sh
chmod +x setup-web2py-ubuntu.sh

./setup-web2py-ubuntu.sh

Remember to set an admin password when prompted!
Then go to a browser and type:
https://
for my case, https://10.0.0.132
then click “Admnistrative Interface” and it will prompt you for a your password!
And there you go! server up and running! But i am still wondering why must I install web2py… by right, after reinstalling apache, it should give me “It works!” or something. :/