All posts by mikek

Making ping work on the ASUS Tinkerboard

To make a long story short:

linaro@linaro-alip:~$ sudo chmod 4755 /bin/ping

And now for the long story:

After the initial setup of my ASUS Tinkerboard and adding it to my local network by using an attached monitor, keyboard and mouse I managed to get it onto my local network so I could SSH into it and remove the monitor etc. from the setup again (btw. the default username/password combination is linaro/linaro).

Using the ping command (after I had SSH’ed into the tinkerboard) gave me the following error:

linaro@linaro-alip:~$ ping google.com
ping: icmp open socket: Operation not permitted

Checking the permission bits of the ping command

linaro@linaro-alip:~$ ls -al /bin/ping
-rwxr-xr-x 1 root root 34752 Nov  8  2014 /bin/ping

showed that it just had normal execution rights, this could be easily fixed with:

linaro@linaro-alip:~$ sudo chmod 4755 /bin/ping

After this command the execution rights were fixed and it was possible to use the ping command:

linaro@linaro-alip:~$ ls -al /bin/ping
-rwsr-xr-x 1 root root 34752 Nov 8 2014 /bin/ping
linaro@linaro-alip:~$ ping google.com
PING google.com (216.58.201.174) 56(84) bytes of data.
64 bytes from arn02s06-in-f14.1e100.net (216.58.201.174): icmp_seq=1 ttl=57 time=33.7 ms
64 bytes from arn02s06-in-f14.1e100.net (216.58.201.174): icmp_seq=2 ttl=57 time=34.0 ms
64 bytes from arn02s06-in-f14.1e100.net (216.58.201.174): icmp_seq=3 ttl=57 time=33.9 ms
64 bytes from arn02s06-in-f14.1e100.net (216.58.201.174): icmp_seq=4 ttl=57 time=33.8 ms
^C
--- google.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3005ms
rtt min/avg/max/mdev = 33.748/33.920/34.058/0.174 ms
linaro@linaro-alip:~$

I don’t know if it was this or some other issue, but this change also seems to have fixed the issues I had with running “sudo apt update”.

Apply command to all folders in Linux

Today in the office I was working on the OpenTele project and had to update all of my folders mapping the repositories from Bitbucket.  I was getting tired, just thinking about going into each folder manually and updating the repositories – so I thought that there must be a way on the command prompt to do it.. after a little search on the net I found the solution:

find . -type d -name .git -execdir git pull \;

The logic behind it is:

find

The command that is used for finding files

.

The names to match in the search

-type d

Find folders (directories)

-name .git

Where the content has the name “.git”.

-execdir git pull

In the folders where .git is found, switch to that folder and execute “git pull”

/;

This marks the end of the command (“/;” won’t be executed)

If you are in doubt or want to test the command, try using “echo” in front of it.  You can also use “{}” on the command line to insert the path of the current directory/folder

QWidget: Cannot create a QWidget without QApplication

(If you are searching for a solution to the above error then look at the last few paragraphs of this post, the first part is just me babbling about why I got my self into a situation where I had the above error).

So, I had an Qt5 application that used qml for the main interface, that worked fine.  I then wanted to extend the application with some content that was dynamically loaded from a website, this website contained some html5 with embedded JavaScript that needed to communicate with the Qt5 application, and the application needed to call into the JavaScript.

It should be straight forward, I first made the Android version, using the Android Webkit browser, it worked out of the box, binding into the Java world with JNI, and then into the WebKit browser, but when it came to using the WebKit that came with Qt, ohh, my.. that was when the trouble began…. of cause it was my lack of knowlegde and not the framework that were the issue.

First I tried with a qml WebView controller, that loaded the page fine, but when it came to the JS integration, I couldn’t figure it out, I then found that the QML WebView, and the QWebView is something completely unrelated (more or less)  where the QML WebView is very limited (unless you go to the private interface) the QWebView is much more reach and allows the integration with JS.

There are many examples on the web on how to use the QWebView class, they all went something like this:

QWebView *view = new QWebView(parent);
view->load(QUrl("http://www.google.com"));
view->show();

Now, what should “parent” be??? – I had no clue, I tried many different things, including leaving it blank, but each time the code crashed when executed…  I finally left it blank, but the code was still crashing with the message that is the title of this post.

I then tried to dig into what a QApplication was, and presto… – the issue was not related to the way I launched the webpage, it was in how I made the qml app run.  I originally had code like:

int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);

    QQmlApplicationEngine engine;
    QmlInterface qmlInterface(&app);

    engine.rootContext()->setContextProperty(
                   "cInter", 
                   &qmlInterface);
    engine.load(
      QUrl(
        QStringLiteral("qrc:/main.qml")));

    return app.exec();
}

I then found from the Qt docs, that a QApplication is a QGuiApplication, so replacing QGuiApplication with QApplication removed the run-time error and launched the browser:

int main(int argc, char *argv[])
{
    // QGuiApplication app(argc, argv);
    QApplication app(argc, argv);

    QQmlApplicationEngine engine;
    QmlInterface qmlInterface(&app);

    engine.rootContext()->setContextProperty(
                   "cInter", 
                   &qmlInterface);
    engine.load(
      QUrl(
        QStringLiteral("qrc:/main.qml")));

    return app.exec();
}

 

Do not use numbers or underscores as first characters in Android/Java package names

Well, I’ve been trying different things out at work the last week in order to make some small tests and evaluating different design ideas – I can’t reveal what it’s all about yet, except I could mention some buzz words that doesn’t really say anything (scalability, cross-X, open source, market killer, etc. etc. etc. some of these might be true, some might be wishes and some might just be pure imagination).

Anyway as part of this I have been writing a number of small Android applications – and guess what, I learned the hard way that you can’t use _ (Underscores) or numbers as the first character  like systems.mikek.oneforall is ok, but systems.mikek.1forall isn’t – which might make sense, as numbers are not allowed as the first character in identifiers in many languages (even they are fine for URL’s) – but I was a bit more surprised that prefixing the number with _ wasn’t allowed either – so no systems.mikek._1forall either…  lesson learned 🙂

^__^
Mike

btw. I don’t know if this is just for Android, or generic for Java (actually I only tried it in an app made in the Qt5 framework for Android).

Link to great page about writing Android plugins for Apache Cordova (aka PhoneGab)

Apache Cordova is a tool/library/… for writing cross platform (mobile) applications.  With Cordova you write the code in HTML5, CSS and JS like you would on a homepage, just packed into an application that can run on many different platforms.

But Cordova is more than just that, it also has a number of plug-ins that makes it possible to access systems on the platforms that a normal web application can’t access.  It is even possible to make your own plug-ins.  The plug-ins are typically written in the native language for the platform, like Java for Android, C# for Windows Phone etc.

Unfortunately the “official” Cordova documentation for writing plug-ins are…hmm…aeee… let’s just say, I couldn’t figure it out, but thanks to Google I found this blog post that describes how to write plug-ins in Java for Android.

^__^
Mike

Setting up the Raspberry pi for 1-wire access

The entry describes various info on the Raspberry Pi’s 1-Wire interface.

To enable the 1-Wire module (defaults to GPIO4 on the Raspberry http://words.mikek.systems/wp-admin/post.php?post=1&action=editPi) run the following from the terminal:

$ sudo modprobe w1-gpio
$ sudo modprobe w1-therm

I guess the first line enables the 1-Wire interface, and the second the automatic reading of the DS18B20 temperature sensor.

As an alternative (if you don’t want to manually enter these every time – which would be very inconvenient in a system that is running unsupervised) you can load these two kernel modules automatically by editing /etc/modules, e.g. “sudo nano /etc/modules” (To save with the Nano editor press Ctrl+O and then press enter to confirm the filename, to quit press Ctrl+x. if you are unable to save, then maybe you forgot the “sudo” at the beginning of the line).

Add/ensure the following two lines can be found in /etc/modules:

w1-gpio
w1-therm

Save and close the file, after next reboot the kernel modules will be loaded without intervention.

^__^
Mike

Sources for the information in this post:

https://learn.adafruit.com/downloads/pdf/adafruits-raspberry-pi-lesson-11-ds18b20-temperature-sensing.pdf

http://nwazet.com/code/loading-i2c-spi-and-1-wire-drivers-on-the-raspberry-pi-under-raspbian-wheezy