Tuesday 3 December 2013

I believe in a thing called Drone

Yesterday, Amazon did a big announcement: soon (in the next years) drones will be used to delivery package to your door.
Amazon is not the first one with this idea, but just the fact they have said that (for advertisement o not), it is an incredibly recognition that we are near to the drone's revolution.
I'm a huge fan of drones for civil use... because I'm geek.. you know, geek loves these things.

After this news, a lot of skeptics came out with only one sentence in mind a "I know how drones work dude, this is not possible"

Problems exists, obviously
Every new thing bring with it problems.. problems are everywhere, in every aspect of every project.
And when you have a problem you have to find the right solutions, the best fit solution to the problem.

There are 3 category of drones's problems:
  • Technical Limitations: The drone's expert say for example, that drones don't have enough autonomy to carry something and come back: for all of them I just want to answer, you need research and moneys (like amazon or google?yes) and you can create something that is not available today but tomorrow and of course better. The tecnology change everyday. so I don't bother about these aspect. Your experience is not the only one solution.  I think the answer to question like "what if a drone broke and fall down?/what if a drone crash with a bird/What if a drone crash with another one" will come out.
  • Privacy Concerns and Legal Aspects: these are the real problems. A lot of problems, for example, the FAA is worried about both violence to and from drones...because there are crazy persons who wants to shot to drones... but apart from that, again, I think laws will come out as for every new thing. At the beginning we will have place where drone delivery will be available and other where not. 
Revolutions need time and of course other problems when the first drone will deliver a package will come out.. but for me it just a matter of when not how.
If you are not able to do today something it doesn't mean someone, with a team of expert can do it somewhere in another place soon :)

Finally, you need to dream, dream it is necessary, because if you just stop to this phrase "this is not possible", nothing it will ever change, and this is not just for drones, but for anything.
Call me a believer!
I believe in drone.

Tuesday 5 November 2013

Plot a graph with Arduino Yun

This is a short article, some "tips&tricks" if you need to plot a chart with data generated from the Arduino Yun.
I report it here, just to report my work.

This article starts from this: http://arduino.cc/en/Tutorial/TemperatureWebPanel that explain how to use the Bridge to capture data from a temperature Sensor and make the data accessible from a web page inside an sdcard on the Yun.

Plot a chart
My scripts, it helps to plot the last 5 temperatures.
You have to change a little bit the script on the page and replace some files.

1 - I've added this at the beginning of the arduino script:
float lastTemp[5];
to save the last 5 temperatures
2 - Replaced  this part
      client.print("Current time on the Yun: ");
      client.println(timeString);
      client.print("
Current temperature: ");
      client.print(temperature);
      client.print(" degrees C");
      client.print("
This sketch has been running since ");
      client.print(startString);
      client.print("
Hits so far: ");
      client.print(hits);
with this one:
      lastTemp[hits%5] = temperature;
      for(int i=0;i<5;i++){       
client.print(lastTemp);

        client.print(";");
      }
      client.println(timeString+";"+startString+";"+hits+";");


So the page from arduino now it retuns all the data plus the last 5 temperature read, separated by ";"

3 - I've replaced the files in /arduino/www/TemperatureWebPanel with the ones HERE: it uses jquery and jflot

This is the final plot:



This is not the rightway
My script plot the last 5 request read from the sensor, but the right way is to leave the arduino part to ciclic fetch the temperature and save it on a file on the sdcard.
The html/js page need to read the same file and plot the temperatures with the data from the file.
I will update it later with a new solution.

Monday 14 October 2013

My First Impressions On The Arduino Yun

These are great years for geek: hardware is cheaper and new gadget come out everyday
It's our time!
Our creativity is screaming inside us, due to the incredible number of things that everyday comes out.
Some days ago I bought an Arduino Board Yun (all the specs here).

I mainly bought it just to support Arduino: because it's an italian project and I was curious to see if the new Yun have the same potential of Arduino Uno.

Anyway reading the specs, these are the things that I like most on this board:

  • The Arduino part of Yun is an Arduino Leonardo's like (mouse and keyboard feature!)
  • ethernet,wifi,sdcard support: no more expensive shell to add (Note: if you can reach internet you can use NTP, so you don't need an RTC)
  • a real processor with Linux: and all the possibilities offered by linux software. The distro is Linino, based on the famous OpenWrt!
  • linux + usb: means attach webcam, pendrive, other usb devices.
  • POE support(from the doc: "The Yún is also compatible with PoE power supply but in order to use this feature you need to mount a PoE module on the board or buy a preassembled one."
  • Wifi capabilities means: no bother with bluetooth, zigbee, android adk... you can write app on mobile that talk with Yun just with http/html/js (for example).
  • Wifi support accesspoint mode: this means you can connect things with wifi using Yun as the hotspot
  • Can be remote programmed: do you need to upgrade the software on the arduino connected in another room? Now you can thanks to wireless
  • Same dimension of the current Arduino Uno.
  
Arduino Uno (left) & Yun (right)

  • Temboo: do you need to use dropbox, flickr, twitter, facebook, google calendar, google docs or other online services with your Yun? Temboo is a framework that let you work with those services easily, standardizing the way you access these API... and it works with your Yun of course!

I don't think Yun is here to beat raspberry pi (maybe only in few project) but to replace existing project with Arduino uno/leonardo with a new powerful version able to: easy connect to internet, communicate with "things", remove expensive shields, improve experience and help you to fast prototype IOT objects.
For now, it seems that the standard Linino image shipped with yun is limited..but it's Opensource Baby... and so..the next step is this: github/repo.
See you soon with new info about Yun!

Thursday 8 August 2013

Windows Phone: the dumbphone

Personally I don't like microsoft product, the only project they've built and I've really apprecciated are Xbox and kinect.
Everytime I think about of a Microsoft product my idea is on something with bug, low quality and problems.
A product that can makes your life harder instead of improve it.
Anyone have hated Bill Gates/Ballmer at least one time in their life.

When 3 years ago, MSFT launched Windows Phone, my feeling was the same, but... you have to try before judge.
My sister bought a nokia 800 windows phone after she lost her android phone, it was cheap and she liked the design; after 5 months, she hate it because every action is complicated and she can't do a lot of things compared to her lost android.
She choose a Nokia because in the past she have one and she was satisfied by the product... but she doesn't know anything about WP.
When Microsoft come out with the new interface, a lot of people thought it was a great thing, it was something new, that break with the past, and also it breaks with windows mobile that was a totally disaster.
I've played a bit with her phone and I totally agree with her: WP sucks.

General Feeling
When you buy a smartphone you suppose it is SMART but WP interface makes the phone dumb: a dumbphone.
To design an interface like WP, you should think your potential client is dumb or not so clever enough to use something advanced ; and advanced doesn't mean harder to use.

Text, Font, Space everything is LARGE
The screen is always filled with text everywhere.
Icons was created to be more immediate, Microsoft designer forgot it.
They have replaced icons with those "genius" live tiles.. a sort of animated square:
- animation is a cool effect, in the first day: boring the rest and it can only help you lose your focus on your actions.. wasting your time.
- battery hungry: they can burn your battery faster than you think.
- a waste of space: you can have just 8-10 square in a screen, while you can put in the same space 16 icons with better result..but microsoft prefer that you scroll and scroll and scroll to reach the function you are searching for instead of just tap on an icon.

App Flow
The general flow in a WP app is to scroll the app horizontally, like a flyer...
So after the first screen, you often have to swype right/left to access the content of your app.
Due to lack of gerarchy in the app.. after some left/right swype searching for your function inside the app, you feel like lost in the application.. Where am I? Where should I have to go?
And if you want to be fast the following times you want to access the app, you should remember where that f*cking function is.. for every app: "how many left/right swype to reach function xyz?"


Apps in the store
I don't know which are the guidelines, but a lot of application I have tested on this Nokia 800, are horrible... the feeling here is they always lack on something, like they were forgot to add something on the UI.
I think the problem is in the UI concept itself.
Minimalism is a good think when used in a clever way,it can make an interface easier... but it is hard to implement.
If you think minimalism is just "remove" things from an UI to make it easier, you are damn wrong.
I have tested also 2 different application for dropbox: one doesn't work (and it was the first search result) and the other one was slow to just upload photos over WIFI!
..a terrible experience

The future
WP doesn't feel that you have bought a smartphone, it's more like you have in your hand the interface of an automatic ticket machine...

For me Windows Phone have no future.
After some initial enthusiasm, people will recognize how frustrating is the WP experience and they will abandon it... unless something iwill happen.
You can see also in windows tablet sales... expecially for RT...

80% of WP are nokia phone: people are buying nokia WP not for WP itself but just because they are Nokia product.
Nokia was famous for create good products in the past... now, the overhall experience of the product will be destroyed by a stupid OS.
Without Nokia, windows phone would be another microsoft fail.

Friday 5 July 2013

YourPhoneAsHomeConsole opensource on github

I've found some time, to check a little bit the code of my last hack: Putting a WebServer Inside a Phone (why? http://pestohacks.blogspot.it/2013/03/putting-webserver-inside-phone.html ).

The code is now OpenSource and Downloadable ON GitHub
This version runs on BlackBerry Z10, it is just a proof of concept.

It is based on mongoose and jawsjs.

After launched the app:
  • your phone and your pc should stay in the same LAN
  • you have to open the browser (chrome is better) from the pc and connect to the phone http://SmartphoneIP:8080
  • play space invaders using your phone as a pad :)

Wednesday 29 May 2013

Blackberry10 and Arduino: how to make them friends

This is an image and a video showing the arduino interacting with my dev alpha C (like a blackberry Q10):


You can find the Bluetooth Cascades app here: https://github.com/blackberry/Cascades-Samples/tree/master/bluetoothsppchat

For arduino just follow the previous tutorial: http://pestohacks.blogspot.it/2013/05/arduino-bluetooth-rn-42-recently-ive.html

Tuesday 21 May 2013

Arduino & Bluetooth RN-42

Recently I've started to deeply experiment with Arduino.
My last experiment involved using bluetooth.
I've bought a bluetooth module: RN-42 , cause it is cheap and there are a lot of tutorial around the web that talk about it.

Connection to the Arduino Uno

The image above rappresent the connection on the front of the chip.
To make it working with Arduino you should connect:
  • RN42 PIN 11 to Arduino 3.3V
  • RN42 PIN 12 to Arduino GND
  • RN42 PIN 13 to Arduino TX
  • RN42 PIN 14 to Arduino RX
  • RN42 PIN 16 to RN42 PIN 15
After that you have to power ON Arduino.

Setup the module
I have used an android application, BlueTerm (free), to setup the module.
The RN-42 have a "command" mode to change the parameter of the module: speed, bluetooth name, and other options.

After power on the module, pair your device (or simply your pc) with the RN-42, the PIN is 1234.
Than use a bluetooth terminal to connect to the module again and type these commands:
$$$
SU,11
S~,3
SN,whatevernameyouwant
---
The $$$ means "enter command mode" instead "---" means "end command mode".
After every command you should see an "ACK" response from the module.

The description of the above commands and all the available commands are reported here : https://www.sparkfun.com/datasheets/Wireless/Bluetooth/rn-bluetooth-um.pdf

Testing the connection
Connect your arduino and launch the ide.
Write the following code:

void setup() {              
   Serial.begin(115200);

}
void loop() {
  Serial.println("hello bt");

 delay(1000);  
}

and then load it with usb connection to arduino.
Now use a bluetooth terminal to connect to the module and read the data.

Check this video if you are searching a good tutorial.

Sunday 24 March 2013

Putting a webserver inside a Phone!

The Project SmartBerryBox

This project born during an hackathon at CodeMotion Conference in Rome.
Thanks to this project I won a wonderful BlackBerry Z10.
The idea is showed in the following video:



What does it happens?
It is an HTML5 game running in the browser.. and the phone, a blackberry 10 devalpha device, it is used as a pad/controller.

This project is full of different tecnology:

  • a standalone webserver: mongoose runs inside the phone
  • the communication between the phone and the browser is made with websockets
  • html5, canvas, jaws js, javascript for drawing and moving the game

How?
1. The server is inside the phone and the browser download the html5 game files, at first connection; like a visit of an html page.
2. The browser establish a websocket connection with the web server.
3. Whenever an event from the controller/the phone touchscreen, occur, the phone send with websocket the controller event(left,right,fire pressure) to the html5 game that update the movement of the player ship, on the canvas.

Why?
Your phone can do more and more..
Don't you want to use those CPU Cores for something useful and funny? :)
Smartphones are replacing portable console but they can replace home console, at least for casual gaming!
And this is just Today!
You just need a browser with HTML5 and websocket capability and your phone.
The browser (inside a smartTv for example) became the screen, the phone is the pad.
Your phone is something that it is able to adapt to different context and games,  just changing UI or use different hardware like the accelerometer.

Imagine a multiplayer game context, where every phone is connected each other and it is able to act as a controller: you and your friends playing in front of the tv: a quiz game, a car race, etc.
Cool, isn't it?

All the code I did, run on a BlackBerry 10 device, but since it is full of opensource tecnology it is easy to port the code to Android, maybe IOS.. with Native SDK.
The fundamental part is running mongoose with USE_WEBSOCKET flag.

I don't think windowsphone is able to run it, due to platform limitation: no native c/c++ code..as I know..

I will give all the code to the community in the next days, a blog post will follow and the source code on github also.
Do you like it?

Monday 25 February 2013

OAuth on getPocket.com with BB10

Introduction
Here it is the description on how to authenticate a BlackBerry10 user in your application, with pocket API.
This tutorial is written for Cascades Developers.
Pocket is a read it later service.
It help user to keep track of new links and read it later, whenever they want.
Pocket have their own API used by over 300  apps.
The authentication process is an OAuth 2.0 variant.
If you have no experience with OAuth check this before continue.
The screenshots and code that follows belongs to a pocket client that I made, called Mnemonia for BlackBerry10, available here.

Initial Setup
Create a new app profile on getpocket.com.
Go to http://getpocket.com/developer/apps/ and register a new application.
Take note somewhere of consumer_key because you will need it soon.

Flow
When you want to authenticate a user, your application have to:
  1. Make a request(all request are POST request) for an appCode to pocket.com with a redirect_uri and consumer_key as params and you will receive an appCode to save locally. The redirect_uri will be the url that pocket will invoke after the user have succesfully authorized the application.
  2. Open a new browser window to pocket.com with the appCode of point 1 and redirect_uri as parameters.At this point the application ask the user to authenticate and approve the app. If the login is succesfully the browser will be redirect to the redirect_uri link.
  3. Finally you can request an access_token and use it for the other operation: add, delete, archive, favourite etc.
Important: point the redirect_uri to a real page like this: where you tell the user that the authentication process is ok and to come back to the application.

Make Post Requests: Cascades's way
The main class for get/post request with QT, it's QNetworkAccessManager (check also this).
You should create in your Class an object QNetworkAccessManager and than connect it to a SLOT function (requestFinished in the example below):

mNetworkAccessManager = new QNetworkAccessManager(this);
connect(mNetworkAccessManager,SIGNAL(finished(QNetworkReply*)),this,SLOT(requestFinished(QNetworkReply*)));

After that all your request with networkAccessManager will finish in methoed requestFinished.

The second things you need is launch the browser, with this call:
navigator_invoke(HTTPSTRINGURL, NULL);

Now we will follow the 3 steps of previous Flow, section but with code:

Step 1: ask the app code.
We have to make a post request and pass our parameters, consumer_key and redirect_uri, in json format.
We create the JSON string manually,



As a result for the first request, requestFinished is called:



Step 2: Launch the Browser
Now that you have the appCode, you can ask authorization to the user:
This is a little function that open a new browser window with the correct parameters.

void YourClassName::launchAuthBrowser() {
    QString authUrl;
    authUrl.append("https://getpocket.com/auth/authorize?request_token=");
    authUrl.append(appCode); // the one retrieved at point 1.
    authUrl.append("&redirect_uri=");
    authUrl.append(YOURREDIRECTURI);
    navigator_invoke(authUrl.toStdString().c_str(), NULL);
}

After this call, a new browser window is presented to the user, asking for their credentials, or to create a new account.
If the authorization went ok, the browser is automatically redirected to YOURREDIRECTURI parameter.

Step 3: Finally the token!
Now your user is back to the app, after have succesfully authorized your app to use his account on pocket.com.



and in the requestFinished methoed I have this code:



The response of this request is a URL: the first value is the Token, the last one is the user username.
This last code is not a good example but just a way to take the parameters data, you should check better if the values you are reading are correct...
You have to check for errors too, watch Step 5 of http://getpocket.com/developer/docs/authentication.

Final consideration
You can save your token in your app/data directory, but you can do better following this link
If you need more assistance or have any critics with this article, write in the comments and let me know :)
.. and if you have the possibility to try Mnemonia, tell me what do you think about it!

Sunday 17 February 2013

BB10: A little survival guide for the newbie developer

Introduction
This guide is made for BB10's developers in particular for Cascades developer with a BB10 device.
These are little advice that I found experimenting with BB10 in these last months.

Log it!
If you want to log something to the console, for better understand how your applications is working you can use qDebug() << "your string"; in c++


 or use console.log on QML


Now to be able to read your log you have to connect to your device with SSH!
To be able to do this, just right click on your usb connected device and select "Launch SSH Session" like in the following image.
After that you have a shell inside the device and you are able to send command directly from the device.
To watch the log produced by your application just type slog2info -w
and for the 2 previouse log:



SSH in device, good not only for logs!
After an ssh connection, you can type some command inside the device for example:
  • pwd: print your working directory
  • cd: to change your current directory
  • cat : print on the console the content of a file
  • ls: list the files and directory in your current directory
There are other commands, like in a unix enviroment, not all working but with just these 4 previous command you have a lot of power... and remember: With great power comes great responsibility.
For example? you can watch the content of a produced file from your app; start moving to /accounts/1000/appdata/ and than to your app directory:


Use "cat" on a file:


Renew your debug token, it is just 2 click!
Your debug token will expire.. To create a new one you can write command from your enviroment or use qde (a customized eclipse for bb10) like that:


Right Click on your usb device, than select Blackberry Tools and than Debug Token Details and you have this dialog.


Select your token and then Renew options and .. that's it!

Do you know any other useful tips?
Please write it in the comments!