Ubuntu / Raspian / Rapsberry Pi Connection Problems

So today I was messing around with a Raspberry Pi using Raspian. It turns out if you have an ethernet connection without Internet and a Wi-Fi connection with Internet, the Pi / Raspian is too dumb to figure out that it should use the Wi-Fi connection for things like dns lookups and web traffic. Slightly annoying. I’m sure there’s a way to fix this – but time is not on my side today.

Update: It turns out it’s more of a widespread linux problem. This morning on Ubuntu I tried connecting one Wi-Fi adapter to an AP that was not connected to the Internet and a second one that was. It seemed that again the traffic tried to take the path through the first adapter.

Updated DNS Zone Update tool for Hostmonster

A couple years ago I posted a slightly modified script for hostmonster to update the dns zone entries for subdomains. It used mechanize and ruby. However, since then my script broke as hostmonster made some changes to their backend. Another guy made some changes that seemed to work for a while, but again it has broken. My previous post about this is here.

The culprit seems to be the mixture of javascript / ajax and the fact that hostmonster returns an empty page when you append the /ajax onto the dnszone url. No worries though, I found another way to do it.

Using Watir and Headless, it is possible to achieve the same functionality.

You need to add a few things to ubuntu to make it work:
sudo apt-get install ruby ruby-dev xvfb
sudo gem install watir
sudo gem install headless

Here’s the updated script (note, you can still use the same cron jobs and ip scripts etc. from the previous two techniques.:

#!/usr/bin/ruby
(more…)

IEEEE CCECE 2014 and Cognitive Agent Simulation

This past week I attended IEEE Canadian Conference on Electrical and Computer Engineering (CCECE2014) in Toronto, Canada. I was there because of two papers I was a co-author on. The work was part of a side project I was involved in on cognitive agent simulation. The idea was inspired by the observation that in the spring time, many newborn animals are struck as they cross the street. Later in the year, it seems that fewer animals meet this fate. So have the animals which survived observed the doomed creates being struck, learned something about the environment, and managed to become more intelligent? We aimed to model this type of environment, and then re-create the most basic intelligence to try to replicate this behaviour with a cognitive agent.

I was responsible for implementing the simulation tool and the naiive learning algorithm which we also presented at the conference. The simulator was created in c/c++ and was designed in such a way that later on the intelligence algorithms could be swapped out, so that we could also experiment with more sophisticated learning algorithms.

(more…)

Hackathons!

I’ve recently participated in a couple of hackathons to keep brushed up on my coding skills. In both instances, the hackathons were motivated by working with open data, which I also find interesting. Open data is usually datasets that government has sitting in a database somewhere that may be useful for apps, programs or visualization that they do not necessarily have time to do themselves. Since the people of the country technically “own” the data, there has been a movement lately to release it to the people to use. In both hackathons, I worked with my friend (and media and design expert) – Carlos Saavedra.

The first was the “Open Data Guelph” hackathon which was put on by the City of Guelph. You can see the data sets available at the Guelph Open Data website. Since we were given data like bus routes, heritage site locations, parks, bicycle paths and elevation / topographic data our motivation was “build you own adventure” to discover the city of Guelph. The easiest data to work with was the park data since it was csv and followed a regular easy to read format. There were also some data sets which used XML. This was also quite easy to handle in PHP because there are built-in functions to parse XML. The tricky data was ESRI shapefiles. There were a few PHP libraries available to read these types of files, but given the time constraints (24 hours) of the hackathon, we didn’t end up getting to use this data. In the end, we ended up getting the bus data sets, and the park data sets working.

You can try our app here: myCity Guelph Adventure Game.

The second was the “CODE (Canadian Open Data Experience)” competition by the Government of Canada. This competition had much more data, and the sets were very large compared to the Guelph data. For instance, one of the sets for labour force data was 65 megabytes and had over 500,000 lines of records to parse. For this app, we decided given the datasets we had available, we would create an app for immigrants to help them find a good city to live in. It is well known in Canada that the typical choice is Toronto, however maybe there are places where people may have a better fit given certain preferences. We used criteria like climate, tolerance for crime, housing prices, desired income level, type of job industry the person is looking for, and whether they were part of a particular visible minority to determine which city may be best for them. Here’s a quick demo video of the “newRoots app“. You can try the app yourself at the newRoots app page.

You can also follow our team’s twitter account – @2electricsheep

OpenGL Console Library for Blackberry Native SDK (Playbook)

Over the break, I decided to try my hand at some Blackberry native SDK programming since I recently got a playbook. I looked around the App World and noticed there weren’t any telnet/ssh tools available for free (that worked the way I wanted) so I thought this would be a good starter project.

However, for the look I wanted, I wanted to maximize the screen space for the console application to show as much text as possible and worked off the hello world example on the SDK webpage. Essentially, the simple “library” (note: library is used very loosely here) initializes the display, shows the keyboard and supports some simple output using putch and puts functions that I implemented. It can also show a blinking cursor and user input at a prompt. In case someone else can use the code I have made it available. Check back soon to see the source for the telnet portion of the app I made as well or look for it on the App World.

Simple Telnet - Example Application
Simple Telnet – Example Application using the conosole library

In order to use the library, you need to make use of the bbutil.c and bbutil.h files that are included in many of the examples provided by RIM. I have provided them here alongside my own code so that it is easier to follow along. I also provide two more files: glconsole.c and glconsole.h. You just need to #include “glconsole.h” in your source in order to use the library. All of the functions available to you are listed in the “glconsole.h” file as well. I will go over the important ones in this article.

First is gl_init(). This function initializes the library, the screen, font etc. This function should be called before using anything else in the library. Similarly, gl_cleanup() is used to free memory and should be called before your app is terminated.

After initialization, you may now use the puts and putch functions to display characters to the screen. gl_putch(char c) takes a single character and displays it onto the screen. It can handle newlines which are represented as ‘\n’ and tabs which are represented as ‘\t’. Backspaces by user input is handled as a ‘\b’ character. This is similar to how people on The osdev.rg website often handle character output in their custom operating systems. I’m not sure how it relates with normal c standards, but I imagine it is similar. Eventually I hope to implement a printf() type of function, but at the moment the putch() and puts() functions serve what I am doing well enough. Note: puts() is the same as putch() but instead takes a (char *) ie) a string. The string should also be null-terminated, or it will just continue until it hits a null character. The characters are automatically scrolled when the bottom of the screen is reached.

The only other really important function is gl_render(). This function is what should be called everytime the screen needs to be refreshed. This is usually in a for loop within your main() function in your app.

It is also possible to resize the screen using the gl_resize() function. By default the screen starts at 80X29 which is the maximum size with no virtualkeyboard showing, at the font size I selected. When the keyboard shows up, it fits 80×14. In some sample code I’ll also show how keyboard input can be handled, how to blink the cursor and how to detect when the keyboard is shown or hidden.

For the rest of this guide, I’ll assume you are using the QNX Momentix IDE available from RIM’s developer website. To start, create a new project by going to File->New Blackberry Tablet OS C/C++ Project. Name it whatever you like, click next. Then choose the C language, and empty Application Project. You can now drag the gl_console.c, glconsole.h, bbutil.c and bbutil.h files into the src folder within the IDE to include them. You will probably want to copy the files and not link them when it asks. Before compiling, there are several libaries which must be linked to the project. You can do this by right clicking your project, going to properties. Then go to C/C++ General->Paths and Symbols->Libraries. Here you can add libraries. Each time you add one, be sure to check “add to all Configurations” so that you don’t need to do this again if you change from a device-debug to device-release build. The following libraries should be included:

  • bps
  • EGL
  • GLESv1_CM
  • freetype
  • png

Now that all this is setup, it is possible to start you main() function and use the library. If you like you can right click on your src folder and click “new file” and create a main.c file or whatever you like to name it. While this isn’t the typical way you would include a library into a project, this way lets you edit the library source to your liking in case you want to further extend it.

The following example shows a skeleton of what is required to get the code to display some text:

#include /* EXIT_FAILURE */
#include /* NULL */
#include /* BPS_SUCCESS */
#include /* screen_event_get_event() */
#include /* NAVIGATOR_EXIT */
#include "glconsole.h"

void handleScreenEvent(bps_event_t *event);

int main(int argc, char * argv[])
{
int exit_application = 0;

if(EXIT_SUCCESS != gl_init())
{
fprintf(stderr, "error init\n");
return 0;
}

gl_puts("Hello gl console world!\n");

for(;;)
{
bps_event_t *event = NULL;
if (bps_get_event(&event, 0) != BPS_SUCCESS)
return EXIT_FAILURE;

if (event)
{
int domain = bps_event_get_domain(event);

if (domain == screen_get_domain())
handleScreenEvent(event);
else if ((domain == navigator_get_domain()) && (NAVIGATOR_EXIT == bps_event_get_code(event)))
exit_application = 1;

if (exit_application)
break;
}
gl_render();
}

gl_cleanup();
return 0;
}

void handleScreenEvent(bps_event_t *event)
{
/* do normal event handling here, see other bb examples */
}

The key parts are calling gl_init() which initializes the library. Then within the main loop, the gl_render() function should be called which will actually render the text. Finally gl_cleanup() should be called before termination to properly free memory.

In the near future I plan to add some support to handle ansi encoded text (specifically for my telnet application) so that it can display colours and move the cursor around the screen using this standard.

Here are the files:
glconsole.h
glconsole.c