         Serial.println("    main()");
         delay(300);
 
-      state = STATE_WRITE_DONE;
+      state = STATE_WRITE_DONE_FOR_CONNECT;
       break;
 
-    case STATE_WRITE_DONE:
-     Serial.print(STRING_EOS);
+    case STATE_WRITE_DONE_FOR_CONNECT:
+      Serial.print(STRING_EOS);
+      state = STATE_WRITE_FOR_DISCONNECT;
+      break;
 
+    case STATE_WRITE_FOR_DISCONNECT:
+      //Serial.println("import android,time");
+      //Serial.println("droid = android.Android()");
+      //Serial.println("droid.makeToast('Hello, disconnect')");
+      state = STATE_WRITE_DONE_FOR_DISCONNECT;
+      break;
+
+    case STATE_WRITE_DONE_FOR_DISCONNECT:
+      Serial.print(STRING_EOS);
       state = STATE_READ;
+      break;
 
     case STATE_READ:
     default:

  switch (state) {
    case STATE_INIT:
      if (Serial.peek() == 0xFF ) {
        state = STATE_WRITE;
      }
      break;

    case STATE_WRITE:
        Serial.println("import android");
        Serial.println("import urllib2, json");
        Serial.println("");

// Prints an ever-increasing counter, and writes back anything
// it receives.
#define STATE_INIT 0
#define STATE_WRITE_FOR_CONNECT 1
#define STATE_WRITE_FOR_DISCONNECT 2
#define STATE_WRITE_DONE_FOR_CONNECT 3
#define STATE_WRITE_DONE_FOR_DISCONNECT 4
#define STATE_READ 5

#define STRING_EOS "#_EOS_EOS_EOS_EOS_EOS_"
#define COMMAND_START_TO_LOAD 0xFF
