My first Cordova App



Well it’s been an interesting 30 or so days. Among other things I have been attempting to build a mobile app with Apache Cordova, an open source tool for writing HTML/JS/CSS and deploying to most popular mobile operating systems.

At first development looked like they would take a few hours, mostly because I was using native plugins and building using Phonegap build, a free(for open source) build service provided by Adobe. Yep.. Adobe being the good guys, impressive 🙂 I couldn’t have been more wrong…

PhoneGap Vs Cordova

PhoneGap and Cordova are not the same thing, I’m going to talk about Cordova here. The reason being is that Phonegap Build could not be used as it didn’t have support for the phonegap-nfc plugin. If I was doing a project that didn’t depend on phonegap-nfc development would have been a lot easier and quicker.

So the first takeaway is if you are building a simple app that will use phonegap build supported plugins then use phonegap build, you will have way more fun.

Cordova is horribly fragmented

The plugin system is broken, badly. I had some majorly catastrophic few weeks just trying to bring the phonegap-nfc plugin into my project using cordova-cli. I “solved” this by getting someone else to build using cordova-cli 2.7.0. Various things were to blame here but eventually I settled on using Eclipse (an IDE I really dislike) and things got relatively stable to the point where I was able to use a modified BarcodeScanner branch to introduce new plugin functionality.

I want to be clear about how badly broken things are here though.. The plugin spec/documentation is near non existent, in fact only Adobe internal guys have it at the point of me writing this. Thankfully the Adobe guys took a little time out to help me get things working.. Good guy Adobe!

Debug tools

Debugging Cordova is horrible assuming you actually get past the 50 or so barriers to installation most of the errors messages are ambiguous, that’s if you get one.. Expect to see a lot of “Error is Null” or “File cannot be found” Exception errors.. To get around these you will basically need to do lots of going forward/backward and iterating in small steps, testing / compiling each time you make a change..

I ended up using Weinre for improving styling and issuing debug commands and I used logcat/eclipse console for compile / JS errors. Weinre has a weird issue where if an error happens it blocks future JS execution so never actually reports the error back to your remote console, pretty insane and creates a fair amount of pain until you are used to it. logcat’s filtering functionality is really broken and as my crappy LG phone throws an error every few MS that ends up spamming my logcat which makes spotting application errors pretty difficult.

An amazing community

The Cordova community and guys on IRC were amazing, really pulling me through some really challenging times.

Starting to hate Eclipse less

Using eclipse is horrible but it gets less bad once you get used to it. If you are familiar, using git behind your file structure but .gitignoring your bin folders will save you a fair amount of pointless data. In general git will save you a lot of pain though, see what I mentioned above about doing lots of small iterations and testing each one..

Mobile Dev is slow until it works

Until you have Cordova setup and your plugins working correctly things will be an uphill struggle but once you get everything setup you can quickly use your favorite JS development tools to quickly integrate new modules/functionality and that’s really when things start to make a lot of sense with cordova. I actually found myself enjoying the last 2 days of this project (yep ~28 days getting a working Android platform and 2 days actually building the app), I’m not looking forward to doing other platforms though..

Cordova in the future

Cordova 3 is going to be exciting, the move away from plugins and towards features should ensure plugin developers actively maintain their code meaning that more plugin should install with very little friction. I’m certainly going to be sticking with Cordova and will use it again in future projects. I think July/August time we can see plugin support stabilizing and that’s when things should get really interesting 🙂



Your system does not meet the requirements to create android projects: undefined

Cordova platform add android errors with

Your system does not meet the requirements to create android projects: undefined

Did you remember to

chown -R YOURUSERNAMEHERE /usr/local/lib/node_modules/cordova

You can check with..

ls -lsh /usr/local/lib/node_modules/cordova

You should see your username, not root..

If so..
Let’s do a quick update of Cordova:

cordova -v
# review the version you are at 
npm update cordova
cordova -v
# review the new version

Let’s make sure android works and the path is set to the android binary:

android

This brings up the Android SDK Manager.

Test an emulator by hitting up:
Tools > Manage AVDS, creating an image then hit Start. If your Android emulator works then continue, else something is up with your ADT/SDK deployment

Open up a CLI, type:

export | grep PATH

Make sure your Android SDK platform-tools and tools folders are available in the PATH variable.

Going okay? Let’s update the Android SDK

android update sdk

Now try visit your cordova app folder and try

cordova platform add android

Still no luck?
Try using the master2 branch of the cordova-cli repo *Warning, this is dangerous.

cd ~
git://github.com/apache/cordova-cli.git
cd ~/cordova-cli
git checkout master2
sudo npm install -g
exit
cordova -v

The above should output a new cordova version #

Post a comment! 🙂

Monitoring a Wind Turbine with a Raspberry Pi

saphonian_turbine_bladeless

As a weekend project I wanted to receive an email if my wind turbine wasn’t generating power when it should. I didn’t want to spend loads of money on fancy new equipment so I hacked it together mostly with equipment I had lying about.

Requirements

– Wind Turbine or Solar Panel (obviously)
– Bridge rectifier (converts the AC from the turbine to DC)
– Some sort of voltage regulator (10-24v –> 12v) (or to 5v and skip below)
– Car cigarette lighter mobile phone charger (£5)
– Raspberry Pi (£35)
– Delta Sigma ADC (£25)
– USB Cable (£1)
– 1 Hour free
– Met Office API Key (free — UK Only)

Steps

– Wire up the turbine and bridge rectifier
– Pop the bridge rectifier into the voltage regulator
– Put the regulated voltage through the car voltage adapter, this will give you 5v out
– Wire the 5v from the turbine into channel 0 on the Delta Sigma
– Pop the ADC into the Pi, follow this guide for setting up the software.

How it works

– The Pi asks the Met Office what the current wind speed is.
– If the wind speed is above a threshold then the Pi checks the turbine
– If the turbine isn’t generating 5v then email me.

Next Steps

– Use Machine Learning to find a better balance on announcements
– Rate limit announcements.
– Measure integer of turbine output instead of boolean state.
– Wire the Owl energy monitor up to the AC output of the grid tie inverter.
– Store value of state in something like Graphite or using Nagios for announcements

The conection to the server was unsuccessful

The application Error

The conection to the server was unsuccessful (file://android_asset/www/index.html)

Was caused by a script being inaccessible during the page load..

For me changing:

<script src="http://oldplace:8080/target/target-script-min.js"></script>

To

<script src="http://newplace:8080/target/target-script-min.js"></script>

Fixed it

Collaborative drawing with Etherdraw

Today Etherdraw hit Version 2, major noticeable difference is that edits are now saved and visible on reload.

Collaborative drawings are now way faster, more reliable and it should be easier for future development.

It’s really cool how much my projects are now being maintained by other people and I’m really grateful for their efforts and time. At the same time I’m glad I chose open source 🙂

Enjoy!

Have a play – remember to invite / join someone else and draw collaboratively, it’s a bit boring by yourself 🙂

Developers visit the git repo.