SmartConfig for Pet dish project

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
rowenaw
 
Posts: 7
Joined: Mon Nov 04, 2013 9:03 pm

SmartConfig for Pet dish project

Post by rowenaw »

Hi - so as I posted in a previous topic I'm pretty new to Arduino and hardware - although I do have reasonable programming experience in other platforms. I've managed to get the Pet Dish SMS project working ( i Love it ! looks so cool). I've actually made it for a friend of mine so I would like to be able to allow my friend to enter her own SSID details. I was thinking that using the SmartConfig capabilities of the CC3000 so she can change the SSID without having to load aurduino code. Before I try and change the code can I just double check I've worked out the process for this correctly. This is what I've gathered from my reading :
1. Load the SmartConfigCreate code to the Arduino and use the phone app to set the SSID I want.
2. Reload the Petdish code - modified to use the reconnect code (from the sample) instead of the existing code.
3. Then use the app to change the SSID as needed whilst the pet dish is on

If that order is correct - can I confirm I should replace this code from the Petfood dish :
  // Set up the serial port connection.
  Serial.begin(115200);
  Serial.println(F("Hello, CC3000!\n"));
  
  // Set up the CC3000, connect to the access point, and get an IP address.
  Serial.println(F("\nInitializing..."));
  if (!cc3000.begin())
  {
    Serial.println(F("Couldn't begin()! Check your wiring?"));
    while(1);
  }
  if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) {
    Serial.println(F("Failed!"));
    while(1);
  }
  Serial.println(F("Connected!"));
  Serial.println(F("Request DHCP"));
  while (!cc3000.checkDHCP())
  {
    delay(100);
  }
To this code from the SmartConfigReconnect script :
void setup(void)
{
  Serial.begin(115200);
  Serial.println(F("Hello, CC3000!\n"));

  /* Try to reconnect using the details from SmartConfig */
  /* This basically just resets the CC3000, and the auto connect */
  /* tries to do it's magic if connections details are found */
  Serial.println(F("Trying to reconnect using SmartConfig values ..."));
  
  /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
  /* !!! Note the additional arguments in .begin that tell the !!! */
  /* !!! app NOT to deleted previously stored connection details !!! */
  /* !!! and reconnected using the connection details in memory! !!! */
  /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
  if (!cc3000.begin(false, true))
  {
    Serial.println(F("Unable to re-connect!? Did you run the SmartConfigCreate"));
    Serial.println(F("sketch to store your connection details?"));
    while(1);
  }

  /* Round of applause! */
  Serial.println(F("Reconnected!"));
  
  /* Wait for DHCP to complete */
  Serial.println(F("\nRequesting DHCP"));
  while (!cc3000.checkDHCP()) {
    delay(100); // ToDo: Insert a DHCP timeout!
  }

  /* Display the IP address DNS, Gateway, etc. */
  while (! displayConnectionDetails()) {
    delay(1000);
  }
I assume I also need to double check variables etc match and also somehow add the disconnect rule ?

Please let me know if this is the right approach - or better still if you have a version of this code that uses the SmartConfig approach I'd love a copy !

thanks
Rowena

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: SmartConfig for Pet dish project

Post by adafruit_support_rick »

I think I would do it this way. If the reconnect fails, then try doing a create:

Code: Select all

void setup(void)
{
  Serial.begin(115200);
  Serial.println(F("Hello, CC3000!\n")); 

  /* Try to reconnect using the details from SmartConfig          */
  /* This basically just resets the CC3000, and the auto connect  */
  /* tries to do it's magic if connections details are found      */
  Serial.println(F("Trying to reconnect using SmartConfig values ..."));
  
  /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
  /* !!! Note the additional arguments in .begin that tell the   !!! */
  /* !!! app NOT to deleted previously stored connection details !!! */
  /* !!! and reconnected using the connection details in memory! !!! */
  /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */  
  if (!cc3000.begin(false, true))
  {
    /* Try to use the smart config app (no AES encryption), saving */
    /* the connection details if we succeed */
    Serial.println(F("Waiting for a SmartConfig connection (~60s) ..."));
    if (!cc3000.startSmartConfig(false))
    {
      Serial.println(F("SmartConfig failed"));
      while(1);
    }
    Serial.println(F("Saved connection details and connected to AP!"));
  }
  else
  {
    /* Round of applause! */
    Serial.println(F("Reconnected!"));
  }
  
  /* Wait for DHCP to complete */
  Serial.println(F("\nRequesting DHCP"));
  while (!cc3000.checkDHCP()) {
    delay(100); // ToDo: Insert a DHCP timeout!
  }

  /* Display the IP address DNS, Gateway, etc. */  
  while (! displayConnectionDetails()) {
    delay(1000);
  }

}

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”