 // Prints an ever-increasing counter, and writes back anything
 // it receives.
 #define STATE_INIT 0
-#define STATE_WRITE 1
-#define STATE_WRITE_DONE 2
-#define STATE_READ 3
+#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

        Serial.println("    main()");
        delay(300);

      state = STATE_WRITE_DONE;
      break;

    case STATE_WRITE_DONE:
     Serial.print(STRING_EOS);

      state = STATE_READ;

    case STATE_READ:
    default:

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

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