Showing posts with label Apache. Show all posts
Showing posts with label Apache. Show all posts

Sunday, July 10, 2016

Using Web and Cisco Spark to control a Lego EV3 Robot


I have bought the Lego Mindstorms EV3 robot for more than 2 years, however I didn't spend any time on it until recently.  My daughter was sick and she has to stay at home, to keep her busy I built the EV3 together with her and we had run some pre-set missions to make the robot move and did some simple tasks.  It works great, except that I have to use the Mindstorm software to program it.


There is also another iPhone app to give you basic control of your robot, however it only accepts bluetooth connection, which makes me a lot less flexible compare with Wifi.




I have done some googling and find this post:
http://programmablebrick.blogspot.hk/2014/11/seanbot-ev3-robot-controlled-via-web.html

It looks interesting to me and I would want to make it my first EV3 project.  This is what I've done:

1. Get an microSD card.  So happen I've found one old 2GB card at home and I've used that for this project.  Flash it with the ev3dev OS following the instruction in this page, it is based on Debian Linux:
http://www.ev3dev.org/docs/getting-started/

2. Putting the microSD card into my EV3 and power it on.  It will not affect your original firmware in EV3, it is just like dual booting another OS.




3. Setting up the wireless network.  I've bought a wireless USB dongle from a local computer store, and it is less than US$9.  It works like a charm.  I did purposely pick one without 802.11ac, older model, claim to have Linux support.  Just bet on it, provided that it is so cheap.


4. Plug that into the USB port of EV3.  Use the screen on EV3 to choose my home wifi network, and entered the WPA PSK.  It is now connected, and able to access the Internet.


5. SSH to the box.  Use apt-get to get the packages, make sure you did a apt-get upgrade and update before you download the other packages.


sudo apt-get update; sudo apt-get upgrade
sudo apt-get install apache2 libapache2-mod-php5 unzip

6. Download the files in zip in this github project -  https://github.com/dwalton76/LegoEV3D4.  Unzip and copy these contents into your apache document root, in my case it is /var/www/html.  I download it to my Mac and then scp to the EV3, unzip it then copy it to the document root.

7. Install the python-ev3 on EV3 - https://github.com/topikachu/python-ev3.  My version of python is 2.7, therefore these are the commands that I've issued to my EV3.

Python 2.7

apt-get update
apt-get install virtualenv virtualenvwrapper python-setuptools python-smbus python-pil
source /etc/bash_completion.d/virtualenvwrapper
mkvirtualenv ev3_py27 --python=/usr/bin/python2.7 --system-site-packages
workon ev3_py27
easy_install -U python-ev3
type deactive to exit

8. Download the python-ev3 project in zip file - https://github.com/topikachu/python-ev3.  Similar to step 6, copy the content to the EV3.  In python-ev3, there is a ev3 folder.  Make sure this folder is copied to /var/www/html.  You will need to make sure you do this otherwise your LegoR2D2.py will not work.

9. Some python libraries dependencies need to be resolved, and this is what I've done:
easy_install web.py

10.  Start your apache using the command /etc/init.d/apache2 start.  Run the LegoR2D2 python scripts with sudo.  tcp/8080 will be listened after you run the script.


11. Launch your web browser.  I have tried Chrome and Firefox, for some reasons it only works on my Firefox, probably it is something specific to my laptop.  By the way this is what you will see:



12.  Click on the arrows to move your robot!  Is that it?  No!  How about we using a Cisco Spark Chatbot to control the EV3?











Tuesday, December 15, 2009

CIFS Mounted Drive for Apache

My environment: Apache 2.2.9 on Fedora Core 10 x86_64

Although it is not a good idea to do something like this, I’ve come across a case that I need to mount a CIFS drive and serve the content inside for an apache web server on Linux.  After some googling, the trick to make this work is to turn off a parameter called EnableSendfile in httpd.conf

#
# EnableSendfile: Control whether the sendfile kernel support is
# used to deliver files (assuming that the OS supports it).
# The default is on; turn this off if you serve from NFS-mounted
# filesystems.  Please see
#
http://httpd.apache.org/docs/2.2/mod/core.html#enablesendfile
#
EnableSendfile off

Wednesday, May 7, 2008

Configuring Basic Authentication on Apache

Although there are many different authentication methods available for web services, basic authentication is still the simplest and most common authentication method used. This post is target to give you a quick example on how to configure basic authentication on apache.

Create a password file

htpasswd is the command to create a password file, example:
htpasswd -c passwd panda
New password: mypassword
Re-type new password: mypassword
Adding password for user panda

The -c flag is used only when you are creating the file. You can omit the -c flag if you want to add more users to an already created password file.

You should store the file in a secure location. And you should set permissions on the file so that only the webserver can read the file and only root can write to it:

chown root.nogroup /etc/httpd/secret/passwd
chmod 640 /etc/httpd/secret/passwd

Configure httpd.conf


For more information, please refer to official apache doc:
http://httpd.apache.org/docs/2.3/howto/auth.html