How to fix Airtel DATASHARE problems

I jumped onto an airtel DATASHARE plan as soon as it came out and immediately realized that their support was horrible. Most of the service staff did not that there was a plan. And escalations simply wasted money on their customer care charges.

At one point the customer service told me that the plan was for only data cards. I promptly got a datacard and lo and behold it did work. The plan also works on any 3G phone. Here's how.

Go to pay.airtel.com and choose your circle recharge.  See if your circle provides a DATASHARE plan. In Bangalore it costs 998INR

Now send the following as SMS to 121
DATASHARE ADD Your_Phone_No

Eg: DATASHARE ADD 9876543210

If you get an error that the number is already a child in the system. It indicates that you or someone may have added your phone on their DATASHARE plan. Simply ask them to send the following as SMS to 121

DATASHARE DELETE Your_Phone_No

Airtel also has a website that has rarely worked for me, it apparently lets you manage data sharing.
Http://airtel.in/datashare

Enjoy your plan!

If you have any tips please drop them in as comments.
Category: 0 comments

How to access FTP from Android Application?

I ran into trouble while writing a piece of code to transfer a bunch of images to my server from a custom app. People recommended Apache FTP for Java. But it can't be used as is since Honeycomb. It needs the task to run on a different thread. This makes the UI far more responsive and is a forced better way to write programs for Android.

Step 1:
First download the zip file called Apache Commons Net from
http://commons.apache.org/net/download_net.cgi

Step 2:
Extract the zip file and copy the file called commons-net-xx.jar Into the libs folder of your Android eclipse project



Step 3: Create a new Java Class with the following code.


package com.example.technologyempoweredjanatainitiative;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.SocketException;
import java.net.UnknownHostException;

import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPReply;

import android.os.AsyncTask;
import android.util.Log;


public class FTP_Uploader_AsyncTask extends AsyncTask {

//void FTP_DATA_UPLOAD(String FULL_PATH_TO_LOCAL_FILE)


protected Long doInBackground(String... FULL_PATH_TO_LOCAL_FILE ) {
// encapsulate FTP inside a A sync task

{
System.out.println("Entered FTP transfer function");

FTPClient ftpClient = new FTPClient();
int reply;
try {
System.out.println("Entered Data Upload loop!");
   ftpClient.connect("Ftp.example.com",21);
   ftpClient.login("username", "password");
   ftpClient.changeWorkingDirectory("/directory/");
   System.out.println("Entered Data Upload loop!");
 

   reply = ftpClient.getReplyCode();

 
  if(FTPReply.isPositiveCompletion(reply)){
  System.out.println("Connected Success");
  }else {
  System.out.println("Connection Failed");
  ftpClient.disconnect();
  }
 
 
 
   if (ftpClient.getReplyString().contains("250")) {
       ftpClient.setFileType(org.apache.commons.net.ftp.FTP.BINARY_FILE_TYPE);
       BufferedInputStream buffIn = null;
       System.out.println("Created an input stream buffer");
       System.out.println(FULL_PATH_TO_LOCAL_FILE.toString());
     
       buffIn = new BufferedInputStream(new FileInputStream(FULL_PATH_TO_LOCAL_FILE[0]));
       ftpClient.enterLocalPassiveMode();
     
       System.out.println("Entered binary and passive modes");
       //Handler progressHandler=null;
//ProgressInputStream progressInput = new ProgressInputStream(buffIn, progressHandler);

       //Code to Extract name from the string.
       //http://stackoverflow.com/questions/10549504/obtain-name-from-absolute-path-substring-from-last-slash-java-android
       String Picture_File_name = new File(FULL_PATH_TO_LOCAL_FILE[0]).getName();
     
     
       boolean result = ftpClient.storeFile(Picture_File_name, buffIn); //localAsset.getFileName()
       //ProgressInputStream progressInput = new ProgressInputStream(buffIn, progressHandler);
     
       if (result){
        System.out.println("Success");
       }
     
       //boolean result = ftpClient.storeFile("TEST.jpg", progressInput);
       System.out.println("File saved");
     
     
       //buffIn.close();
       ftpClient.logout();
       ftpClient.disconnect();
   }

} catch (SocketException e) {
   Log.e("Citizen Cam FTP", e.getStackTrace().toString());
   System.out.println("Socket Exception!");
} catch (UnknownHostException e) {
   Log.e("Citizen Cam FTP", e.getStackTrace().toString());
} catch (IOException e) {
   Log.e("Citizen Cam FTP", e.getStackTrace().toString());
   System.out.println("IO Exception!");
}

return null;
}


}

}


To access the ftp  service to upload files call the above class using : 

new FTP_Uploader_AsyncTask().execute(PathForFileToUpload);

How to use Python for coding with ZPL?

ZPL-Zebra Programming Language is used for communicating with Zebra Printers. They are mostly used for RFID and Bar-code printing. As ever, I wanted a bit more control over how my ZPL printer worked and had to get working.
The easiest technique is of course Python. And this is how I did it.

First get the Zebra package from Pypi
pypi.python.org/pypi/zebra/#downloads

Installation is simple. From commandline navigate to the folder containing setup.py and then enter
python setup.py install   [Windows Only]

I presume you've installed all necessary drivers. If you are using Win 7, Windows would have automatically installed them for you. If you're on Linux, you'd need a CUPS driver. Just look at the documentation.

Example Program:
###START OF CODE###

#ZPL commands to be sent to your Printer
label="""
^XA
^FO10,10
^A0,40,40
^FD
Hello World
^FS
^XZ
"""

#End of ZPL commands to print Hello World

from zebra import zebra
z=zebra
z.getqueues                                      #This will return a list of printers installed on your computer. 
z.setqueues('ZDesigner_ZPL_200')  #Set the default printer to your new ZPL printer
z.output(label)                                  #Have fun sending data to your printer.It's as easy as it can get. :)


####END OF CODE####


Reference:
http://bytes.com/topic/python/answers/24160-zebra-printing-language
http://pypi.python.org/pypi/zebra/

Contributors