CC3000 & EMIC conflict?

by iBucky on Sat Feb 15, 2014 6:49 pm

Is there a conflict running a CC3000 shield and EMIC chip on a UNO or am I missing something?

I have the following code on an UNO with the CC3000 shield and a EMIC chip. the CC3000 code runs as expected and gets on my network. Using Kode.com as my php server and web site I can send data to my CC3000 and it displays on my serial monitor, but the emic doesn't 'talk'. I can even hardcode my 'result' and the emic doesn't 'talk' the text. Am I missing something or is there a conflict I'm missing?

Memory? But it doesn't seem so as I can continue to send text to the device.

I will note the CC3000 successfully runs sample code and the emic successfully runs sample code by themselves.

I have comments stripped out to reduce the foot print. Also I'll note the "EMIC Test complete" text displays on my serial monitor every time text is sent to the device.

Thank you in advance.

Code: Select all
// include the SoftwareSerial library so we can use it to talk to the Emic 2 module
#include <SoftwareSerial.h>

#include <Adafruit_CC3000.h>
#include <ccspi.h>
#include <SPI.h>
#include <string.h>
#include "utility/debug.h"

String result;

#define ADAFRUIT_CC3000_IRQ   3
#define ADAFRUIT_CC3000_VBAT  5
#define ADAFRUIT_CC3000_CS    10

#define rxPin 2    // Serial input (connects to Emic 2 SOUT)
#define txPin 4    // Serial output (connects to Emic 2 SIN)
#define ledPin 13  // Most Arduino boards have an on-board LED on this pin

//int resultLength;

#define WLAN_SSID       "MyNetwork"
#define WLAN_PASS       "password"
#define WLAN_SECURITY   WLAN_SEC_WPA2

#define LISTEN_PORT           8888   

Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT,
                                         SPI_CLOCK_DIVIDER);

Adafruit_CC3000_Server talkerServer(LISTEN_PORT);

SoftwareSerial emicSerial =  SoftwareSerial(rxPin, txPin);


void setup()
{
  Serial.begin(115200);
 
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);
 
  emicSerial.begin(9600);
 
  delay(500);

//  digitalWrite(ledPin, LOW);  // turn LED off
  emicSerial.print('\n');             // Send a CR in case the system is already up
  while (emicSerial.read() != ':');   // When the Emic 2 has initialized and is ready, it will send a single ':' character, so wait here until we receive it
  delay(10);                          // Short delay
  emicSerial.flush();                 // Flush the receive buffer
  Serial.println("EMIC Setup Complete");

  /* Initialise the module */
  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);
  } 

  while (! displayConnectionDetails()) {
    delay(1000);
  }
 
  // Start listening for connections
  talkerServer.begin();
 
  Serial.println(F("Listening for connections..."));
 


void loop()
{
  // Try to get a client which is connected.
  Adafruit_CC3000_ClientRef client = talkerServer.available();
  if (client) {
     boolean currentLineIsBlank = true;
     // Check if there is data available to read.
     while (client.available()) {
     
       char c = client.read();
       result = result + c;
//       Serial.write(c);
       
       // Delete HTTP headers
      if(result.endsWith("Content-Type: text/html"))
      {
        result="";
      }
       
       if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");
          client.println();         
//          client.println("BackAtYou");                   
       }
       if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        }
        else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
       
     }
     // give the web browser time to receive the data
    delay(5);
    // close the connection:
    client.close();
    Serial.println("client disconnected");
   
    // ToDo Format result and extract the variables
   Serial.print("Incoming:");
   Serial.println(result);
   
   //result = "Say something"

  }

// Speak some text

    if(result.length() > 1 ) {

      emicSerial.print('S');
      emicSerial.print(result);
      emicSerial.print('\n');
      digitalWrite(ledPin, HIGH);
      while (emicSerial.read() != ':');   
      digitalWrite(ledPin, LOW);
 
    Serial.println("EMIC Test complete");
 
    }

   delay(50);
    result = "";
}

/**************************************************************************/
/*!
    @brief  Tries to read the IP address and other connection details
*/
/**************************************************************************/
bool displayConnectionDetails(void)
{
  uint32_t ipAddress, netmask, gateway, dhcpserv, dnsserv;
 
  if(!cc3000.getIPAddress(&ipAddress, &netmask, &gateway, &dhcpserv, &dnsserv))
  {
    Serial.println(F("Unable to retrieve the IP Address!\r\n"));
    return false;
  }
  else
  {
    Serial.print(F("\nIP Addr: ")); cc3000.printIPdotsRev(ipAddress);
    Serial.print(F("\nNetmask: ")); cc3000.printIPdotsRev(netmask);
    Serial.print(F("\nGateway: ")); cc3000.printIPdotsRev(gateway);
    Serial.print(F("\nDHCPsrv: ")); cc3000.printIPdotsRev(dhcpserv);
    Serial.print(F("\nDNSserv: ")); cc3000.printIPdotsRev(dnsserv);
    Serial.println();
    return true;
  }
}
iBucky
 
Posts: 76
Joined: Wed Jan 11, 2012 9:40 pm

Re: CC3000 & EMIC conflict?

by adafruit_support_mike on Sun Feb 16, 2014 3:35 pm

I don't know of any ocnflict, but the CC3000 library is fairly large. Take a look at our tutorial on memory debugging and throw a few memory measurement statements into your code: http://learn.adafruit.com/memories-of-an-arduino

C code won't automatically fail if the microcontroller runs out of memory, and there are cases where the total free memory is large enough, but there's no contiguous block large enough for the data structure you want to create.
When you void a product warranty, you give up your right to sue the manufacturer if something goes wrong and accept full responsibility for whatever happens next. And then you truly own the product.
User avatar
adafruit_support_mike
 
Posts: 7015
Joined: Thu Feb 11, 2010 1:51 pm

Re: CC3000 & EMIC conflict?

by fmbfla on Mon Feb 17, 2014 6:25 pm

I think you need to set the emic up AFTER you set up the CC3k
Code: Select all
/***************************************************
  This is an example for the Adafruit CC3000 Wifi Breakout & Shield

  Designed specifically to work with the Adafruit WiFi products:
  ----> https://www.adafruit.com/products/1469

  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing
  products from Adafruit!

  Written by Kevin Townsend & Limor Fried for Adafruit Industries. 
  BSD license, all text above must be included in any redistribution
 ****************************************************/

/*

This example does a full test of core connectivity:
* Initialization
* SSID Scan
* AP connection
* DHCP printout
* DNS lookup
* Ping
* Disconnect
It's a good idea to run this sketch when first setting up the
module.

*/
#include <SoftwareSerial.h>

#include <Adafruit_CC3000.h>
#include <ccspi.h>
#include <SPI.h>
#include <string.h>
#include "utility/debug.h"
#define rxPin 2    // Serial input (connects to Emic 2 SOUT)
#define txPin 4    // Serial output (connects to Emic 2 SIN)
// These are the interrupt and control pins
#define ADAFRUIT_CC3000_IRQ   3  // MUST be an interrupt pin!
// These can be any two pins
#define ADAFRUIT_CC3000_VBAT  5
#define ADAFRUIT_CC3000_CS    10
// Use hardware SPI for the remaining pins
// On an UNO, SCK = 13, MISO = 12, and MOSI = 11
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT,
                                         SPI_CLOCK_DIV2); // you can change this clock speed but DI
SoftwareSerial emicSerial =  SoftwareSerial(rxPin, txPin);

#define WLAN_SSID       "Router"        // cannot be longer than 32 characters!
#define WLAN_PASS       "password"
// Security can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2
#define WLAN_SECURITY   WLAN_SEC_WPA2



/**************************************************************************/
/*!
    @brief  Sets up the HW and the CC3000 module (called automatically
            on startup)
*/
/**************************************************************************/
void setup(void)
{
  Serial.begin(115200);
  Serial.println(F("Hello, CC3000!\n"));
pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);
 
  displayDriverMode();
  Serial.print("Free RAM: "); Serial.println(getFreeRam(), DEC);
  emicSerial.begin(9600);
  /* Initialise the module */
  Serial.println(F("\nInitialising the CC3000 ..."));
  if (!cc3000.begin())
  {
    Serial.println(F("Unable to initialise the CC3000! Check your wiring?"));
    while(1);
  }

  /* Optional: Update the Mac Address to a known value */
/*
  uint8_t macAddress[6] = { 0x08, 0x00, 0x28, 0x01, 0x79, 0xB7 };
   if (!cc3000.setMacAddress(macAddress))
   {
     Serial.println(F("Failed trying to update the MAC address"));
     while(1);
   }
*/
 
  uint16_t firmware = checkFirmwareVersion();
  if ((firmware != 0x113) && (firmware != 0x118)) {
    Serial.println(F("Wrong firmware version!"));
    for(;;);
  }
 
  displayMACAddress();
 
  /* Optional: Get the SSID list (not available in 'tiny' mode) */
#ifndef CC3000_TINY_DRIVER
  listSSIDResults();
#endif
 
  /* Delete any old connection data on the module */
  Serial.println(F("\nDeleting old connection profiles"));
  if (!cc3000.deleteProfiles()) {
    Serial.println(F("Failed!"));
    while(1);
  }

  /* Attempt to connect to an access point */
  char *ssid = WLAN_SSID;             /* Max 32 chars */
  Serial.print(F("\nAttempting to connect to ")); Serial.println(ssid);
 
  /* NOTE: Secure connections are not available in 'Tiny' mode! */
  if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) {
    Serial.println(F("Failed!"));
    while(1);
  }
   
  Serial.println(F("Connected!"));
 
  /* Wait for DHCP to complete */
  Serial.println(F("Request DHCP"));
  while (!cc3000.checkDHCP())
  {
    delay(100); // ToDo: Insert a DHCP timeout!
  } 

  /* Display the IP address DNS, Gateway, etc. */ 
  while (! displayConnectionDetails()) {
    delay(1000);
  }
 
#ifndef CC3000_TINY_DRIVER
  /* Try looking up www.adafruit.com */
  uint32_t ip = 0;
  Serial.print(F("www.adafruit.com -> "));
  while  (ip  ==  0)  {
    if  (!  cc3000.getHostByName("www.adafruit.com", &ip))  {
      Serial.println(F("Couldn't resolve!"));
    }
    delay(500);
  } 
  cc3000.printIPdotsRev(ip);
 
  /* Do a quick ping test on adafruit.com */ 
  Serial.print(F("\n\rPinging ")); cc3000.printIPdotsRev(ip); Serial.print("..."); 
  uint8_t replies = cc3000.ping(ip, 5);
  Serial.print(replies); Serial.println(F(" replies"));
  if (replies)
   emicSerial.print('\n');             // Send a CR in case the system is already up
  while (emicSerial.read() != ':');   // When the Emic 2 has initialized and is ready, it will send a single ':' character, so wait here until we receive it
  delay(10);                          // Short delay
  emicSerial.flush();                 // Flush the emic receive buffer
  emicSerial.print("V18\n");//Volume
  emicSerial.print("W175\n"); //Speed
  emicSerial.print("N1\n");//Voice
  emicSerial.print("C5000\n");// delay with comma in millis
  delay(10);
  emicSerial.print('S');
  emicSerial.print(replies);
  emicSerial.print(" ");
  emicSerial.print(" ,Ping successful!");
  emicSerial.flush();
    Serial.println(F("Ping successful!"));
#endif

  /* You need to make sure to clean up after yourself or the CC3000 can freak out */
  /* the next time you try to connect ... */
  Serial.println(F("\n\nClosing the connection"));
  cc3000.disconnect();
}

void loop(void)
{
  delay(1000);
}

/**************************************************************************/
/*!
    @brief  Displays the driver mode (tiny of normal), and the buffer
            size if tiny mode is not being used

    @note   The buffer size and driver mode are defined in cc3000_common.h
*/
/**************************************************************************/
void displayDriverMode(void)
{
  #ifdef CC3000_TINY_DRIVER
    Serial.println(F("CC3000 is configure in 'Tiny' mode"));
  #else
    Serial.print(F("RX Buffer : "));
    Serial.print(CC3000_RX_BUFFER_SIZE);
    Serial.println(F(" bytes"));
    Serial.print(F("TX Buffer : "));
    Serial.print(CC3000_TX_BUFFER_SIZE);
    Serial.println(F(" bytes"));
  #endif
}

/**************************************************************************/
/*!
    @brief  Tries to read the CC3000's internal firmware patch ID
*/
/**************************************************************************/
uint16_t checkFirmwareVersion(void)
{
  uint8_t major, minor;
  uint16_t version;
 
#ifndef CC3000_TINY_DRIVER 
  if(!cc3000.getFirmwareVersion(&major, &minor))
  {
    Serial.println(F("Unable to retrieve the firmware version!\r\n"));
    version = 0;
  }
  else
  {
    Serial.print(F("Firmware V. : "));
    Serial.print(major); Serial.print(F(".")); Serial.println(minor);
    version = major; version <<= 8; version |= minor;
  }
#endif
  return version;
}

/**************************************************************************/
/*!
    @brief  Tries to read the 6-byte MAC address of the CC3000 module
*/
/**************************************************************************/
void displayMACAddress(void)
{
  uint8_t macAddress[6];
 
  if(!cc3000.getMacAddress(macAddress))
  {
    Serial.println(F("Unable to retrieve MAC Address!\r\n"));
  }
  else
  {
    Serial.print(F("MAC Address : "));
    cc3000.printHex((byte*)&macAddress, 6);
  }
}


/**************************************************************************/
/*!
    @brief  Tries to read the IP address and other connection details
*/
/**************************************************************************/
bool displayConnectionDetails(void)
{
  uint32_t ipAddress, netmask, gateway, dhcpserv, dnsserv;
 
  if(!cc3000.getIPAddress(&ipAddress, &netmask, &gateway, &dhcpserv, &dnsserv))
  {
    Serial.println(F("Unable to retrieve the IP Address!\r\n"));
    return false;
  }
  else
  {
    Serial.print(F("\nIP Addr: ")); cc3000.printIPdotsRev(ipAddress);
    Serial.print(F("\nNetmask: ")); cc3000.printIPdotsRev(netmask);
    Serial.print(F("\nGateway: ")); cc3000.printIPdotsRev(gateway);
    Serial.print(F("\nDHCPsrv: ")); cc3000.printIPdotsRev(dhcpserv);
    Serial.print(F("\nDNSserv: ")); cc3000.printIPdotsRev(dnsserv);
    Serial.println();
    return true;
  }
}

/**************************************************************************/
/*!
    @brief  Begins an SSID scan and prints out all the visible networks
*/
/**************************************************************************/

void listSSIDResults(void)
{
  uint8_t valid, rssi, sec, index;
  char ssidname[33];

  index = cc3000.startSSIDscan();

  Serial.print(F("Networks found: ")); Serial.println(index);
  Serial.println(F("================================================"));

  while (index) {
    index--;

    valid = cc3000.getNextSSID(&rssi, &sec, ssidname);
   
    Serial.print(F("SSID Name    : ")); Serial.print(ssidname);
    Serial.println();
    Serial.print(F("RSSI         : "));
    Serial.println(rssi);
    Serial.print(F("Security Mode: "));
    Serial.println(sec);
    Serial.println();
  }
  Serial.println(F("================================================"));

  cc3000.stopSSIDscan();
}
fmbfla
 
Posts: 69
Joined: Fri Jun 08, 2012 5:48 pm

Re: CC3000 & EMIC conflict?

by iBucky on Tue Feb 18, 2014 1:33 am

fmbfla - Your code works, but as soon as I add my loop() code the the EMIC stops talking. Memory drops to 520. At 667 it was still talking, so I believe Mike is right this is mostly a memory issue.

So I switch to my MEGA loaded everything and the setup() hangs

On the initial boot it hangs on cc3000.begin

I hit reset on the shield and the cc3000 will initialize and connect to my network, BUT

it will hang on the emicSerial object. Serial Monitor just sits without any other responses.

Any ideas? Yes, I've followed the instructions on http://learn.adafruit.com/adafruit-cc3000-wifi/cc3000-shield and have the 2x3 header and the jumpers solder

I actually get the similar responses with my code and fmbfla

With fmbfla on the reset it will go to Serial.print(F("www.adafruit.com -> ")); and than I do not get anything.
iBucky
 
Posts: 76
Joined: Wed Jan 11, 2012 9:40 pm

Re: CC3000 & EMIC conflict?

by fmbfla on Tue Feb 18, 2014 6:02 pm

try running your code with the bare essentials to make it "TALK".
Remember to "flush" the Emic serial print the '"\n" and such in the same way you do on initial start up and see how it works
I do know that if you use it in start up and want voice changes, you must use the last voice and comment first at the beginning of the set up and the first voice/ comment at the end of setup( i don't know why yet)
I can get mine to change voice, pitch, volume and speed within the loop depending on certain params.
fmbfla
 
Posts: 69
Joined: Fri Jun 08, 2012 5:48 pm

Re: CC3000 & EMIC conflict?

by iBucky on Tue Feb 25, 2014 10:23 pm

I have been able to get the EMIC & CC3000 to work on a Mega. Needed to use A9 (63), A10 (64).

Pin 2 & 3 will not work for the EMIC on a Mega: http://arduino.cc/en/Reference/SoftwareSerial#.UwzANfldXE0

I'm note sure why but the following would not work for the EMIC with the CC3000 attached: RX: 11, 12, 13, 14, 15, 50, 51, 52, 53

Current challenge - the program works for a hand full of connections and than I get an error that the CC3000 isn't responding. Meaning I can connect from a web page to the CC3000 via the tutorial php code. But after a few connections it stops. When I reboot it works again, memory is still very good at 5000+ before it stopped working.

Any ideas why the CC3000 would stop responding after awhile?
iBucky
 
Posts: 76
Joined: Wed Jan 11, 2012 9:40 pm

Re: CC3000 & EMIC conflict?

by adafruit_support_mike on Wed Feb 26, 2014 12:14 am

Does the CC3000 stop responding entirely, or do you just stop getting information from the webpage?

Wireless connections drop out occasionally, so they don't offer the same "plug in the connection and forget about it" convenience as wired connections. You should always call 'client.connected()' before trying to use a connection, just to make sure it still works. If it's dropped, you need to release it and make another connection.
When you void a product warranty, you give up your right to sue the manufacturer if something goes wrong and accept full responsibility for whatever happens next. And then you truly own the product.
User avatar
adafruit_support_mike
 
Posts: 7015
Joined: Thu Feb 11, 2010 1:51 pm

Re: CC3000 & EMIC conflict?

by iBucky on Wed Feb 26, 2014 4:07 pm

<<Does the CC3000 stop responding entirely, or do you just stop getting information from the webpage?>>
Just what I've been wondering - how can you test the two situations? I can say that everytime I reset the Mega the webpage connects at least one time before I get a connection error.

<<You should always call 'client.connected()' before trying to use a connection, just to make sure it still works. If it's dropped, you need to release it and make another connection.>>
I connect in the setup

Code: Select all
  /* Initialise the module */
  Serial.println(F("\nInitializing the CC3000 ..."));
 
  if (!cc3000.begin())
  {
    Serial.println(F("Couldn't begin()! Check your wiring?"));
    while(1);
  }
 
    /* Delete any old connection data on the module */
  Serial.println(F("\nDeleting old connection profiles"));
  if (!cc3000.deleteProfiles()) {
    Serial.println(F("Failed!"));
    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);
  } 

  while (! displayConnectionDetails()) {
    delay(1000);

  // Start listening for connections
  talkerServer.begin();

  Serial.println(F("Listening for connections..."));
  }
 


Then in the Loop I check the availability at the top of the loop and at the bottom of the loop I close the connection. How/Where would I call 'client.connected()' before trying to use a connection. Sorry I'm not sure how/where I'd do that - I follow you concept wise but not sure about the implementation.

Also if it's dropped how to I release and make another connection?
Simply .close and .begin?

Code: Select all
void loop()
{
  // Try to get a client which is connected.
  Adafruit_CC3000_ClientRef client = talkerServer.available();
  if (client) {
     boolean currentLineIsBlank = true;
     // Check if there is data available to read.
     while (client.available()) {
     
       char c = client.read();
       result = result + c;
//       Serial.write(c);
       
       // Delete HTTP headers
      if(result.endsWith("Content-Type: text/html"))
      {
        result="";
      }
       
       if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");
          client.println();         
             
       }
       if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        }
        else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
       
     }
     // give the web browser time to receive the data
    delay(5);
    // close the connection:
    client.close();
    Serial.println("client disconnected");
   
    // Format result and extract the variables ToDo
   Serial.print("Incoming:");
   Serial.println(result);

  }
}
iBucky
 
Posts: 76
Joined: Wed Jan 11, 2012 9:40 pm

Re: CC3000 & EMIC conflict?

by iBucky on Thu Feb 27, 2014 1:23 am

Okay sorry during the previous reply I didn't think it through.

I've added a number of tracers and here's what I'm seeing.

My php file is sending the following to the Arduino CC3000

Code: Select all
    $in = "HEAD / HTTP/1.1\r\n";
    $in .= "Content-Type: text/html\r\n";
 $in .= "S," . $json_a['voice_opt'] . "," . $json_a['talk_text'] . ",E,\r\n\r\n";

    // Send request
    socket_write($socket, $in, strlen($in));

    // Read answer
    while ($out = socket_read($socket, 4096)) {
        echo $out;
    }

    // Close socket
    socket_close($socket);


The Arduino is reading the incoming message with the following Do While look with Serial.prints in my Loop()

Code: Select all
void loop()
{
  // Try to get a client which is connected.
  Serial.print(F("Loop:"));
  Serial.println(L);
  L = L + 1;
 
  Adafruit_CC3000_ClientRef client = talkerServer.available();
  if (client) {
      Serial.println(F("Client Available"));
     boolean currentLineIsBlank = true;
     // Check if there is data available to read.
     while (client.available()) {
       
       char c = client.read();
       result = result + c;
       Serial.println(c);
       
       // Delete HTTP headers
      if(result.endsWith("Content-Type: text/html"))
      {
        result="";
        Serial.println(F("----------------------------"));
        Serial.println(F("Removing HTTP Header"));
        Serial.println(F("----------------------------"));       
      }
       
       if (c == '\n' && currentLineIsBlank) {
        Serial.println(F("----------------------------"));
        Serial.println(F("/n and CurrentlLineIsBlank=True"));
        Serial.println(F("----------------------------"));       
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");
          client.println();         
        Serial.println(F("----------------------------"));
        Serial.println(F("Sent HTTP Response Header"));
        Serial.println(F("----------------------------"));       
       }
       if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
         Serial.println(F("currentLineIsBlank TRUE"));         
        }
        else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
         Serial.println(F("currentLineIsBlank FALSE"));         
        }
                 
      Serial.print(F("DoWhile:"));
      Serial.println(D);
      D = D + 1;         
     
      if (!cc3000.checkConnected()){
        Serial.println(F("STILL CONNECTED"));
      }
     }
     // give the web browser time to receive the data
    delay(50);
    D = 1;
   
    // close the connection:
    client.close();
    Serial.println("client disconnected");
    delay(50);
   
     // Format result and extract the variables
     format_result(TalkCommand,result);
    // Print received values
//     Serial.println("Start ID: " + String(TalkCommand[0]));
//     Serial.println("Voice ID: " + String(TalkCommand[1]));
//     Serial.println("Text To Talk: " + String(TalkCommand[2]));
//     Serial.println("End ID: " + String(TalkCommand[3]));
   //TalkCommand[0] - Start ID
   //TalkCommand[1] - Voice Selection
   //TalkCommand[2] - Text To Say
   //TalkCommand[3] - End ID
  }
// Speak some text
    if(TalkCommand[2].length() > 1 ) {
     
//     Serial.print("Incoming:");
//     Serial.println(TalkCommand[2]);
//
//     Serial.print("Incoming length:");
//     Serial.println(TalkCommand[2].length());
     
     TalkCommand[2].trim();
     TextTalk = TalkCommand[2];
     Voice = TalkCommand[1].toInt();
     
    switch(Voice) {
     case 0: //Paul
       TextTalk = ":-)0" + TextTalk;
       break;
     case 1: //Huge Harry
       TextTalk = ":-)1" + TextTalk;
       break;
     case 2: //Beutiful Betty
       TextTalk = ":-)2" + TextTalk;
       break;
     case 3: //Uppity Ursula
       TextTalk = ":-)3" + TextTalk;
       break;
     case 4: //Doctor Dennis
       TextTalk = ":-)4" + TextTalk;
       break;
     case 5:  //Kit the Kid
       TextTalk = ":-)5" + TextTalk;
       break;
     case 6:  //Frail Frank
       TextTalk = ":-)6" + TextTalk;
       break;
     case 7:  //Rough Rita
       TextTalk = ":-)7" + TextTalk;
       break;
     case 8:  //Whispering Wendy
       TextTalk = ":-)8" + TextTalk;
       break;
    default:
       TextTalk = ":-)0" + TextTalk;   

      Serial.println(TextTalk);   

    }
}


Here's the Serial output. The last line is the last it does anything. It is stopping while doing the client.println

Loop:144
Loop:145
Loop:146
Loop:147
Client Available
H
currentLineIsBlank FALSE
DoWhile:1
E
currentLineIsBlank FALSE
DoWhile:2
A
currentLineIsBlank FALSE
DoWhile:3
D
currentLineIsBlank FALSE
DoWhile:4

currentLineIsBlank FALSE
DoWhile:5
/
currentLineIsBlank FALSE
DoWhile:6

currentLineIsBlank FALSE
DoWhile:7
H
currentLineIsBlank FALSE
DoWhile:8
T
currentLineIsBlank FALSE
DoWhile:9
T
currentLineIsBlank FALSE
DoWhile:10
P
currentLineIsBlank FALSE
DoWhile:11
/
currentLineIsBlank FALSE
DoWhile:12
1
currentLineIsBlank FALSE
DoWhile:13
.
currentLineIsBlank FALSE
DoWhile:14
1
currentLineIsBlank FALSE
DoWhile:15

DoWhile:16

currentLineIsBlank TRUE
DoWhile:17
C
currentLineIsBlank FALSE
DoWhile:18
o
currentLineIsBlank FALSE
DoWhile:19
n
currentLineIsBlank FALSE
DoWhile:20
t
currentLineIsBlank FALSE
DoWhile:21
e
currentLineIsBlank FALSE
DoWhile:22
n
currentLineIsBlank FALSE
DoWhile:23
t
currentLineIsBlank FALSE
DoWhile:24
-
currentLineIsBlank FALSE
DoWhile:25
T
currentLineIsBlank FALSE
DoWhile:26
y
currentLineIsBlank FALSE
DoWhile:27
p
currentLineIsBlank FALSE
DoWhile:28
e
currentLineIsBlank FALSE
DoWhile:29
:
currentLineIsBlank FALSE
DoWhile:30

currentLineIsBlank FALSE
DoWhile:31
t
currentLineIsBlank FALSE
DoWhile:32
e
currentLineIsBlank FALSE
DoWhile:33
x
currentLineIsBlank FALSE
DoWhile:34
t
currentLineIsBlank FALSE
DoWhile:35
/
currentLineIsBlank FALSE
DoWhile:36
h
currentLineIsBlank FALSE
DoWhile:37
t
currentLineIsBlank FALSE
DoWhile:38
m
currentLineIsBlank FALSE
DoWhile:39
l
----------------------------
Removing HTTP Header
----------------------------
currentLineIsBlank FALSE
DoWhile:40

DoWhile:41

currentLineIsBlank TRUE
DoWhile:42
S
currentLineIsBlank FALSE
DoWhile:43
,
currentLineIsBlank FALSE
DoWhile:44
2
currentLineIsBlank FALSE
DoWhile:45
,
currentLineIsBlank FALSE
DoWhile:46
t
currentLineIsBlank FALSE
DoWhile:47
e
currentLineIsBlank FALSE
DoWhile:48
s
currentLineIsBlank FALSE
DoWhile:49
t
currentLineIsBlank FALSE
DoWhile:50
,
currentLineIsBlank FALSE
DoWhile:51
E
currentLineIsBlank FALSE
DoWhile:52
,
currentLineIsBlank FALSE
DoWhile:53

DoWhile:54

currentLineIsBlank TRUE
DoWhile:55

DoWhile:56

----------------------------
/n and CurrentlLineIsBlank=True
----------------------------


Seems it fails sending the response and therefore still has the connection open so a new request cannot come in.

What should I do with this condition?
iBucky
 
Posts: 76
Joined: Wed Jan 11, 2012 9:40 pm

Re: CC3000 & EMIC conflict?

by iBucky on Thu Feb 27, 2014 2:44 pm

I saw a mistake I posted in my code.
I put this in to cut done on the Serial monitor output, but didn't change the message.
Code: Select all
      if (!cc3000.checkConnected()){
        Serial.println(F("STILL CONNECTED"));
      }


should be

Code: Select all
      if (!cc3000.checkConnected()){
        Serial.println(F("LOST CONNECTION"));
      }
iBucky
 
Posts: 76
Joined: Wed Jan 11, 2012 9:40 pm

Re: CC3000 & EMIC conflict?

by adafruit_support_mike on Fri Feb 28, 2014 1:00 am

You seem to have a mix of client and server code in the loop.

It's the server's job to close the connection when it's done sending data to the client. You have the server waiting for the client to disconnect, which won't happen because the client is waiting for the server to disconnect.
When you void a product warranty, you give up your right to sue the manufacturer if something goes wrong and accept full responsibility for whatever happens next. And then you truly own the product.
User avatar
adafruit_support_mike
 
Posts: 7015
Joined: Thu Feb 11, 2010 1:51 pm

Re: CC3000 & EMIC conflict?

by iBucky on Fri Feb 28, 2014 2:43 pm

<<You seem to have a mix of client and server code in the loop.>>
I'm sorry I don't understand. Which part is the server/client code? I'm learning/hacking through the "WiFi Controlled Mobile Robot" http://learn.adafruit.com/wifi-controlled-mobile-robot tutorial. Hence, that is where I'm getting the code in my loop.

<<It's the server's job to close the connection when it's done sending data to the client.>>
So I don't need to do the following?

Code: Select all
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");
          client.println();


<<You have the server waiting for the client to disconnect, which won't happen because the client is waiting for the server to disconnect.>>
Where can I learn more about the client and server code with the CC3000? I've gone through the "Adafruit CC3000 WiFi" http://learn.adafruit.com/adafruit-cc3000-wifi seems as thought I've missed something in my research. Where can I find the resource? Thank you in advance.
iBucky
 
Posts: 76
Joined: Wed Jan 11, 2012 9:40 pm

Re: CC3000 & EMIC conflict?

by adafruit_support_mike on Fri Feb 28, 2014 6:04 pm

Information about client-server HTTP transactions is more of a general-internet subject than an Arduino-CC3000 thing. The official rules for HTTP 1.1 live in RFC2616: https://www.ietf.org/rfc/rfc2616.txt That's pretty dry reading though, so here's a shorter version: http://www.pearsonhighered.com/assets/h ... 324547.pdf

iBucky wrote:So I don't need to do the following?

Code: Select all
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");
          client.println();

That text comes from a part of the tutorial which says this:

In return, the server will send a basic answer:

Code: Select all
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close");
client.println();


so no.. not only do you not need to do it, you shouldn't do it.

Pull the code from the Github repo to see what each piece should do: https://github.com/marcoschwartz/arduino-robot-wifi
When you void a product warranty, you give up your right to sue the manufacturer if something goes wrong and accept full responsibility for whatever happens next. And then you truly own the product.
User avatar
adafruit_support_mike
 
Posts: 7015
Joined: Thu Feb 11, 2010 1:51 pm

Re: CC3000 & EMIC conflict?

by iBucky on Sat Mar 01, 2014 1:38 am

I replaced the following from the Do While

Code: Select all
       if (c == '\n' && currentLineIsBlank) {
     
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");
          client.println();         

       }

Note: The above comes from https://github.com/marcoschwartz/arduino-robot-wifi

With this

Code: Select all
       if (c == '\n' && currentLineIsBlank) {
         client.close();
         Serial.println("client disconnected");         
         break;
                }


And it now has run 50+ successful sends without any issues.

Thank you for your input Mike!!
iBucky
 
Posts: 76
Joined: Wed Jan 11, 2012 9:40 pm

Re: CC3000 & EMIC conflict?

by adafruit_support_mike on Sun Mar 02, 2014 6:10 pm

Glad to hear it's working for you.
When you void a product warranty, you give up your right to sue the manufacturer if something goes wrong and accept full responsibility for whatever happens next. And then you truly own the product.
User avatar
adafruit_support_mike
 
Posts: 7015
Joined: Thu Feb 11, 2010 1:51 pm