        else if(gps_read_buffer.indexOf("$GPGGA,") == 0)
        {
          #ifdef GPS_DEBUG_ON
-         debug_info("--GPS BUF GGA--");
+         debug_info(F("--GPS BUF GGA--"));
          debug_info(gps_read_buffer);
          #endif
          push_out_nmea_sentence(false);

      pop_off_message_queue();
      if(latest_message_to_send.length() > 0)
      {
        for(i = 0; i < latest_message_to_send.length() ; i++)
        {
            wifi_client.write(latest_message_to_send.charAt(i));
        }
        wifi_client.write('\r');
        wifi_client.write('\n');
        #ifdef WIFI_DEBUG_ON
        debug_info("Sent via wifi: " + latest_message_to_send);
        #endif
        wifi_communication_state = waiting_for_response;
        wifi_read_buffer = "";
      }
      else
      {
        wifi_read_buffer = "";
        wifi_client.stop();
        wifi_client.flush();
        wifi_client.stop();
        wifi_client.stop();
        wifi_communication_state = idle;
      }
    }
  }    
  #ifdef WIFI_DEBUG_ON
  debug_info("QD wr()");
  #endif
}

void hop_on_home_network(int encryption_type)
{
  wifi_on_home_network = false;
  gprs_apn.toCharArray(temp_string_a, 40);
  gprs_password.toCharArray(temp_string_b, 40);
  if(encryption_type == 5)
  {
    if(WiFi.begin(temp_string_a, 1, temp_string_b) == WL_CONNECTED)
    {
      #ifdef WIFI_DEBUG_ON
      debug_info("WiFi home net wep");
      #endif
      wifi_on_home_network = true;
    }
    else
    {
      #ifdef WIFI_DEBUG_ON
      debug_info("WiFi home net wep error");
      #endif
    }        
  }
  else
  {      
    if(WiFi.begin(temp_string_a, temp_string_b) == WL_CONNECTED)
    {
      #ifdef WIFI_DEBUG_ON
      debug_info("WiFi home net");
      #endif
      wifi_on_home_network = true;
    }
    else
    {
      #ifdef WIFI_DEBUG_ON
      debug_info("WiFi home net error");
      #endif
    }
  }
}

void wifi_scan()
{
  
  //
  //  We always scan for networks unless we are already attached to our
  //  preferred network, favouring our set network but using any open one we
  //  can find as well
  //
  
  if(WiFi.status() == WL_CONNECTED && wifi_on_home_network)
  {
    return;
  }

  wifi_on_home_network = false;
  boolean see_home_network = false;
  boolean see_open_network = false;
 
  byte home_encryption_type = 0;
  String open_network_name;

  byte numb_networks = WiFi.scanNetworks();
  for (int i = 0; i < numb_networks; i++)
  {
    if(gprs_apn.equals(WiFi.SSID(i)))
    {
        home_encryption_type = WiFi.encryptionType(i);
        see_home_network = true;
        #ifdef WIFI_DEBUG_ON
        debug_info("Saw home net: " + String(WiFi.SSID(i)));
        #endif
    }
    else if(WiFi.encryptionType(i) == 7)
    {
      see_open_network = true;
      open_network_name = WiFi.SSID(i);
        #ifdef WIFI_DEBUG_ON
        debug_info("Saw open net: " + String(WiFi.SSID(i)));
        #endif
    }    
    #ifdef WIFI_DEBUG_ON
    else
    {
        debug_info("Saw other net: " + String(WiFi.SSID(i)));
    }
    #endif
  }

  if(WiFi.status() != WL_CONNECTED)
  {
    #ifdef WIFI_DEBUG_ON
    debug_info("No wifi connection");
    #endif
    if(see_home_network)
    {
      hop_on_home_network(home_encryption_type);
    }
    else if(see_open_network)
    {
      open_network_name.toCharArray(temp_string_a, 40);
      if(WiFi.begin(temp_string_a) == WL_CONNECTED)
      {
        #ifdef WIFI_DEBUG_ON
        debug_info("wifi open net: " + open_network_name);
        #endif
      }
      else
      {
        #ifdef WIFI_DEBUG_ON
        debug_info("wifi open net error");
        #endif
      }
    }
  }
  else
  {
    //
    //  We are connected, but if not to home and we can see home, we want to connect to that
    //

    if(!String(WiFi.SSID()).startsWith(gprs_apn) && see_home_network)
    {
      WiFi.disconnect();
      hop_on_home_network(home_encryption_type);
    }
  }
}



#else


#endif


/*
  Adafruit CC3000 wireless library settings
*/

#ifdef WIFI_NOT_CELL
#define ADAFRUIT_CC3000_IRQ   3
#define ADAFRUIT_CC3000_VBAT  5
#define ADAFRUIT_CC3000_CS    10
#endif

/*
  Some AES variables
*/

#define MAX_AES_CIPHER_LENGTH 1024
//#define MAX_AES_CIPHER_LENGTH 1536
//#define MAX_AES_CIPHER_LENGTH 2048
AES aes;
byte iv[16];
byte volatile_iv[16];
