Monday, December 19, 2011

Misleading "Out of Memory" Error in SQLite3

(Please take a look at our crowd-funding campaign at igg.me/at/speakfreely.)

The following is recorded in the hope that it may save someone else the hassle of tracking down this kind of error.

While working on Serval 0.08 I have been working with SQLite3 for the first time.

I had the following fairly innocent query causing SQLite to report an "out of memory" error:

int count=sqlite_exec_int64("SELECT COUNT(*) FROM FILES WHERE id='%s' AND datavalid<>0;",hash); 


After spending a bit of time hunting everywhere to find where I could possibly have leaked enough RAM for SQLite3 to get upset, I finally realised that the column datavalid did not exist in the FILES table.  I had meant to update the CREATE TABLE statement, but obviously hadn't gotten around to it.

I updated the CREATE TABLE statement to include a definition for the datavalid column, and the "out of memory" errors are now a thing of the past.

I can only guess that somewhere in SQLite3 when it tries to find the column, it gets a NULL pointer returned, which some other part of itself then interprets as a failure to allocate memory to retrieve the column, rather than the failure of the column itself to exist.

Shopping Serval Style

We are currently preparing to provide the latest Serval mesh telephony technology for use in a disaster response training exercise with a major relief agency in late February 2012 -- about two months from now.  In that time we need to not only get our prototype Field Communications Unit (FCU) kit together, but also finish some software development that is key for making the technology useful for the relief agency.  You can watch a demo of one of the features we are working on in the video below, where I send a photo from one phone to another, without infrastructure.  This is the same technology we have used to send an SMS more than 10,000km without infrastructure.



On the hardware side, we have ordered 50 Huawei IDEOS X1 phones for AUD$71.10 each -- pretty cheap for a fully featured Android smart phone, complete with digital compass, GPS, accelerometers, a capacitive screen and enough CPU and RAM to meet our needs. These phones are network locked, but that doesn't worry us as we won't ever be putting a SIM card in them, because they will be used solely as mesh communications devices.

It turns out that buying 50 phones at a time is an interesting exercise.  People want to know that you are not planning to resell them or export them.  Some shops will even try to limit you to buying five or less at a time.  Those tactics are legal in some places, but not here in sunny South Australia, where we have an excellent Fair Trading Act that correctly classifies such terms of trade as discriminatory, or in some cases as tantamount to bait-and-switch.

In fact, until quite recently the South Australian consumer protection and gambling laws were so strong that cereal-packet competitions could not require a South Australian resident to purchase a product to participate in a trade promotion lottery, because it would be considered gambling, i.e., pay for chance to win.  So when I was growing up it was quite common to see terms and conditions looking quite normal, and then have sections specially for South Australians, that would often say something along the lines of:
"10. To enter, cut the bar code from a packet of XYZ and include it in your entry as proof-of-purchase.  Residents of South Australia are permitted to submit a hand drawn facsimile of the proof-of-purchase.
...
17. Only one entry per household per day.  Residents of South Australia may enter more than once per day."

There were certainly occasions in my childhood when we would go to the effort of getting the coloured pencils out to draw a barcode by hand to get the chance to win a prize.  I think we sometimes did it just because we could.  Sadly, with the introduction of poker machines (Australia has fully 21% of the worlds poker or slot machines --- a statistic that is disturbing given that Australia has only about 1% of the developed-world population) and the general liberalisation of gambling in South Australia the situation has changed, and I believe we have lost our little parochialism.

Anyway, I digress.

After the difficulties I encountered initially in sourcing 50 mobile phones, I eventually went to our local post office to see if they would order me 50, since they had the model I wanted in their catalog.  Not only were they willing to order them (I promised to pay up-front, since it was a large purchase), they also kindly sliced 10% off the price.  So I now have a box of 44 phones in my lounge room, with the remaining 6 on back order:




At this price, the phones don't come with SD cards, which we do need for the Serval Rhizome software to do anything useful, as store-and-forward requires somewhere to store!  So I hunted around, and after some luke-warm experiences with suppliers either being unwilling to give me a decent price for what is clearly a wholesale quantity, or failing to stock enough, I tried OfficeWorks.  They had enough in stock, but were charging $16 for 4GB cards, which I had quotes from other local stores for $7.  So I loaded my basket with 50 memory cards, and proceeded to try their price-matching policy:


However, the large price difference and quantity did trigger concern from their store manager.  He was very friendly and amiable, but did point out that to get the price matched, I had to find a local supplier with the quantity I wanted actually in stock.  But that wasn't easy to arrange, as most of the cheaper suppliers only had a few on hand.  There is of course a silliness in their rule, as I could have bought them in small batches such that each batch was small enough that the cheaper shop held sufficient stock.  But in the end I did manage to find a cheap supplier on eBay who had plenty in stock at $5.80 a piece for SANDisk 4GB class 4 microSD memory cards.  Now we just have to see if they will arrive.

So that covered the phones and memory cards.  The next challenge was to come up with a way to easily charge 50 phones.  Not only did it need to work in my home, but it also had to have the potential to work in a real disaster zone, and one which might not be in Australia.  Having enough power boards to plug 50 little USB charger bricks was not an attractive option, especially since I need to fit all of this into my 23kg luggage limit when I fly, and 50 phones alone are not that light.

What I have decided to do is to chop up a pile of USB leads and wire them up to some automotive 5v accessory power supplies that are commonly used to power portable DVD players and the like.  Apart from being the cheapest 5v high-current power supplies I could find (AUD$40 for 5A), they have the benefit of running on 12v, or in the case of some models, on 12v-24v, so that they can even work in a truck.  This means that in-vehicle mass-charging is possible when the power grid is off.  It also means that they can all be charged using a single cheap 13.8v power supply, which are also quite cheap; you could even use an old computer power-supply.  You can see my prototype here:


So now I just need to get back to writing the software that needs to go on these phones ...

Thursday, December 15, 2011

Serval Developer Release 0.07, and our Roadmap for 2012

It has been some time since our last developer release, and so it is with great pleasure that I am able to announce that Serval BatPhone Developer Release 0.07 is now available for download from the Android Market.



This version offers compatibility with many more models of Android handsets, fixes to a large number of bugs, and some general usability improvements.  Full functionality still requires root permissions on your phone, but it does its' best to work on phones without root access.

Personally, what I am most happy about is that we have substantially improved our software development and release process, which has already resulted in a much better quality in the current release, and I am confident will result in increasing quality in future releases.






In the longer-term this is the first of several planned releases that will hopefully bring us to a 1.00 public release around September 2012.  The planned intervening releases and their headline improvements, subject to resourcing, slippages and all the other usual hazards of software development are:

0.08 - Serval Rhizome/MeshMS store-and-forward file distribution core technology.  Automatic update of Serval software over the mesh.

0.09 -  Revamped and consolidated MeshMS API and functionality.  Integrated UI for sending and receiving MeshMS messages, including using the Rhizome store-and-forward facility.The underlying technology has already been demonstrated by sending an SMS between Africa and Australia without reliance on infrastructure.

0.10 - Revamped UI for entire Serval Mesh application.  Voicemail and Push-to-talk group communications.

0.11 - Serval Mapping Integrated (using Rhizome to get map tiles without internet access).  Voice calls moving from SIP+RTP via SipDroid and Asterisk to Serval MSIP and MDP, which will improve performance on lossy wireless networks, allowing clear calls over multi-hop links each with 50% packet loss, and greatly reducing the APK size by removing the full Asterisk deployment it currently contains.

0.12 - Consolidate existing work, and address outstanding issues for first public release.  0.12 will become 1.00RC1 when accepted.

Together, these releases will culminate in a software package that will let you do most mobile-phone type things (voice calls, SMS/MMS, voice mail, push-to-talk) when there is no infrastructure, or for free when infrastructure is available, such as transferring and sharing data among friends and community without having to pay up to $2/MB for SMS traffic or $2/MB for cellular data services.

This is good news for people with very low purchasing power, such as large portions of the population in developing countries as well as for those living in more developed countries such as Australia, where infrastructure is not universally present, especially for those living in rural and remote areas.

But for now, it is back to working on Serval Mesh release 0.08 ...

Thursday, December 1, 2011

Shuttleworth Foundation Intro Video

As many readers will know, my work on the Serval Project is substantially funded by the Shuttleworth Foundation.  They provide my income, thus freeing my time, co-investment in the project, and loads of support in a variety of ways, including a great team of other fellows and support staff.  

Without their support the Serval Project wouldn't be what it is.

The foundation are always on the look out for other people with world changing ideas, and have released a new explanatory video that describes how their fellowship model works.

So if you have an idea that might change the world given half a chance, then I would recommend getting in touch with them, and possibly applying for a fellowship.