Web2py / Apache – admin disabled because no admin password

If you are running Web2py on Apache and get this error message when you try to log into the admin interface (/admin):

 

admin disabled because no admin password

 

Then you may have forgotten to provide a password during set-up and will have to provide one now to proceed to the admin screens.

 

To do this you need to can do the following:

 

Stop Apache:
[crayon]
apachectl -k stop
[/crayon]
cd to the web2py directory and run web2py.py specifying a new password (greater than 4 characters long?) like this:
[crayon]
sudo python web2py.py -a the_new_passsword
[/crayon]
Then kill the web2py, e.g. via ctrl-c, and then copy parameters_8000.py to parameters_443.py, like this:
[crayon]
sudo cp parameters_8000.py parameters_443.py
[/crayon]
Restart the apache server:
[crayon]
sudo apachectl -k restart
[/crayon]
After doing all of this when you visit /admin you should be asked to provide your password and you should be able to login – well it worked for me anyway! ;-)

 

WPF Slider Not Working with Touch Screen

We hit a problem yesterday when we were testing one of our Microsoft WPF applications on a touch screen set-up, one of the app’s sliders wasn’t correctly responding to touch events and it couldn’t be dragged properly using the touch screen even though mouse control still worked perfectly.

 

It turns out that there is a bug in the WPF software framework related to touch that needs to be programmed around. The problem was fixed by following the instructions detailed here:

 

http://nui.joshland.org/2010/04/why-wont-wpf-controls-work-with-touch.html

 

Many thanks to JOSHB for posting the workaround!

 

Web2py and Apache running on Raspberry Pi

As part of my smart-cam simulation project I have installed web2py and Apache on a Raspberry Pi, the idea here is to simulate the ARM platform on which the smart-cam web UI software will eventually run by using the Pi until the real hardware is sorted out and available. This will allow me to do some proof-of-concept software development sooner rather than later.

 

I was expecting a difficult enough install but it turned out to be very easy, I just executed the automated set-up script that is documented here, under the section called ‘One step production deployment’ (ubuntu).

 

To summarise the steps, with the Pi connected to the network, open a terminal window and execute the following:

 

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

 

Running setup-web2py-ubuntu.sh took a good while (15 mins?), but when it was complete I was immediately able to view the web2py welcome page from another computer on the network!

 

Kids Drawing and Painting app for Raspberry Pi

If you are setting your Raspberry Pi up for the kids you may have noticed the lack of a bundled paint and drawing app, well not to worry TuxPaint is available for a quick install, just launch a terminal and run the following command to install it:
[code]
sudo apt-get install tuxpaint
[/code]
Then you can launch it from one of the program folders off the main menu (can’t remember which!)

 

Happy Christmas! Have fun with your Raspberry Pis!

 

Python & Web2py for Smart Camera user interface?

I am currently in the planning phase of the software build for a new machine vision smart camera. The camera will have an ARM soft core and will run linux. Part of the planning involves thinking about a user interface to control and configure the camera – at the moment I am leaning towards an HTML5 based interface built using python, web2py (or flask) along with a twitter bootstrap based theme.

 

I did briefly toy with the idea of bringing node.js into the mix, but I just can’t bring myself around to the idea, I have a love hate relationship with javascript, that sometimes leans more to the ‘hate’ end of the spectrum!

 

Now here’s the fun bit – I don’t yet have my hands on the camera hardware so I think I will try to run up a proof of concept on my raspberry-pi!

 

Although the pi will be a good bit less powerful than the smart cam it should provide a useful reference point…

 

Put this little fella to work!

 

Attaching files from google drive to a mail in gmail / google apps

Here’s something that I discovered today, google has quite recently made it possible to directly add files from google drive into your emails as attachments (or more specifically, attached links), more details can be found here.

 

But in summary, hit the + at the bottom of the email editing pane, and then click on the icon that looks a bit like a recycling logo…

 

Google apps are getting better all the time!

 

boost C++ read from serial port with timeout example

If you are doing any serial port communications these days in C++ and would like your code to be portable, then you are probably using boost’s asio::serial_port class.

One complication with using serial_port (and boost::asio more generally) is that it doesn’t provide a direct facility to allow synchronous blocking reads to time-out and return if no data arrives within a specified time period. Here is a little example that tries to read a character from COM3 (on windows..)

 

#include <boost/asio/serial_port.hpp>
#include <boost/asio.hpp>
using namespace boost;
char read_char() {
  asio::io_service io;
  asio::serial_port port(io);
  port.open("COM3");
  port.set_option(asio::serial_port_base::baud_rate(115200));
  char c;
  // Read 1 character into c, this will block
  // forever if no character arrives.
  asio::read(port, asio::buffer(&c,1));
  port.close();
  return c;
}

In this example read() will block forever if no data arrives to the serial port, this is not always what you want, especially when dealing with possibly noisy or unreliable rs232 communication.

In order to take advantage of read time-outs you have to issue asynchronous reads and incorporate a deadline_timer which will cancel the read after a specified time, i.e. if the read hasn’t received the data it was expecting before the deadline_timer expires, then it will be cancelled.

Using asynchronous IO in boost is a bit involved and it can be quite quite messy, so I have written small class called blocking_reader which will block while trying to read a single character, and will time out if a character hasn’t been received in a specified number of milliseconds. It can be used like this:

#include <boost/asio/serial_port.hpp>
#include <boost/asio.hpp>
#include "blocking_reader.h"
using namespace boost;
std::string read_response() {
    asio::io_service io;
    asio::serial_port port(io);
    port.open("COM3");
    port.set_option(asio::serial_port_base::baud_rate(115200));
    // A blocking reader for this port that
    // will time out a read after 500 milliseconds.
    blocking_reader reader(port, 500);
    char c;
    std::string rsp;
    // read from the serial port until we get a
    // \n or until a read times-out (500ms)
    while (reader.read_char(c) && c != '\n') {
        rsp += c;
    }
    if (c != '\n') {
        // it must have timed out.
        throw std::exception("Read timed out!");
    }
    return rsp;
}

The above code isn’t the most sensible or efficient but it shows the use of blocking_reader, which in this case times out reads after 500ms.

You open the serial_port as normal and then pass it to blocking_reader’s constructor along with a timeout value. You then use blocking_reader.read_char() to read a single character. If the read times out then read_char() will return false (otherwise it will return true!)

The code for blocking_reader can be downloaded from this GitHub repo

//   Copyright 2012 Kevin Godden
//
//   Licensed under the Apache License, Version 2.0 (the "License");
//   you may not use this file except in compliance with the License.
//   You may obtain a copy of the License at
//
//       http://www.apache.org/licenses/LICENSE-2.0
//
//   Unless required by applicable law or agreed to in writing, software
//   distributed under the License is distributed on an "AS IS" BASIS,
//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//   See the License for the specific language governing permissions and
//   limitations under the License.
//
// blocking_reader.h - a class that provides basic support for
// blocking & time-outable single character reads from
// boost::asio::serial_port.
//
// use like this:
//
// 	blocking_reader reader(port, 500);
//
//	char c;
//
//	if (!reader.read_char(c))
//		return false;
//
// Kevin Godden, www.ridgesolutions.ie
//
#pragma once
#include <boost/asio/serial_port.hpp>
#include <boost/bind.hpp>
#include <boost/asio.hpp>
class blocking_reader
{
    boost::asio::serial_port& port;
    size_t timeout;
    char c;
    boost::asio::deadline_timer timer;
    bool read_error;
    // Called when an async read completes or has been cancelled
    void read_complete(const boost::system::error_code& error,
                        size_t bytes_transferred) {
        read_error = error;
        // Read has finished, so cancel the
        // timer.
        timer.cancel();
    }
    // Called when the timer's deadline expires.
    void time_out(const boost::system::error_code& error) {
        // Was the timeout was cancelled?
        if (error) {
            // yes
            return;
        }
        // no, we have timed out, so kill
        // the read operation
        // The read callback will be called
        // with an error
        port.cancel();
    }
public:
    // Constructs a blocking reader, pass in an open serial_port and
    // a timeout in milliseconds.
    blocking_reader(boost::asio::serial_port& port, size_t timeout) :
                                                port(port), timeout(timeout),
                                                timer(port.get_io_service()),
                                                read_error(true) {
    }
    // Reads a character or times out
    // returns false if the read times out
    bool read_char(char& val) {
        val = c = '\0';
        // After a timeout & cancel it seems we need
        // to do a reset for subsequent reads to work.
        port.get_io_service().reset();
        // Asynchronously read 1 character.
        boost::asio::async_read(port, boost::asio::buffer(&c, 1),
                boost::bind(&blocking_reader::read_complete,
                        this,
                        boost::asio::placeholders::error,
                        boost::asio::placeholders::bytes_transferred));
        // Setup a deadline time to implement our timeout.
        timer.expires_from_now(boost::posix_time::milliseconds(timeout));
        timer.async_wait(boost::bind(&blocking_reader::time_out,
                                this, boost::asio::placeholders::error));
        // This will block until a character is read
        // or until the it is cancelled.
        port.get_io_service().run();
        if (!read_error)
            val = c;
        return !read_error;
    }
};

 

Amazon puts its weight behind node.js

Interesting, the register writes that Amazon is putting more support in place for those that want do deploy on node.js:

 

http://www.theregister.co.uk/2012/12/06/amazon_node_js_support/

 

Seems like nearly everybody is heading the node.js way theses days!

 

How to turn off the magento compile feature in a hurry when you discover it has broken your site #magento

Magento has a ‘compile’ feature which is supposed to get your site to run much faster, what it will most likely do instead is completely break your site, so that you can’t even get in it turn the ‘feature’ off!

 

Don’t panic a quick edit of this file, will get your site up and running again:

 
includes/config.php/
 

Edit the file via FTP or similar and make sure the the following lines are commented out like this:

#define('COMPILER_INCLUDE_PATH', dirname(__FILE__).DIRECTORY_SEPARATOR.'src');
#define('COMPILER_COLLECT_PATH', dirname(__FILE__).DIRECTORY_SEPARATOR.'stat');

Once you have completed the edit your site should work again!

 

Where is the FxCop installer at?

If you, like many others (including me!), are slightly confused about where and how to install Microsoft FxCop and you don’t want all the extra hassle and work of installing the huge Windows 7 SDK just to get an installer which will then install FxCop – then have a look at this blog post:

 

http://blogx.co.uk/Comments.asp?Entry=812

 

If you take a look at the comments you will even see that there is a direct link to the full FxCop installer, which I couldn’t possibly recommend that you use!