Trouble with server connection using CC3000

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
chien_fu
 
Posts: 12
Joined: Tue Dec 10, 2013 9:53 am

Trouble with server connection using CC3000

Post by chien_fu »

I built a version of the wifi-controlled-robot and it is working relatively well.
There is a PHP file that is updated with a certain set of variables that is then dumped into a json file that is read by the robot every 3 seconds or so.

It seems to go well until I connect to the website at which point I seem to have a sporatic connection to the server. I've tried a couple different servers, and the speed should be fine. But when I add this if statement within the while connected loop:

Code: Select all

while (www.connected() && (millis() - lastRead < IDLE_TIMEOUT_MS)) {

if (www.available()) {
      Serial.println("connected");
     
    } else {
      Serial.println("NOT connected");
    }
The majority of my returns are "not connected". After a couple minutes of trying it just stops and everything hangs until a hard reset.
Does anyone know what might be causing the issue with the connection? Full code is posted in the attached text.
robot code.txt
(13.44 KiB) Downloaded 148 times

User avatar
adafruit_support_mike
 
Posts: 67454
Joined: Thu Feb 11, 2010 2:51 pm

Re: Trouble with server connection using CC3000

Post by adafruit_support_mike »

You're probably losing the wifi connection. Try adding a call to 'cc3000.checkConnected()' to see if the radio link is still configured.

Wifi signals are vulnerable to noise, and motors are notorious for generating it, both in the supply rails and as radiated EMF.

chien_fu
 
Posts: 12
Joined: Tue Dec 10, 2013 9:53 am

Re: Trouble with server connection using CC3000

Post by chien_fu »

I tried

Code: Select all

print(cc3000.checkConnected());
and it returns a 1 every time until the Serial feed just stops. The failure doesn't seem to correspond to any particular event that I can tell, but is there any chance it would have something to do with the Arduino reading the JSON file at the same time it is being updated on the server?

User avatar
adafruit_support_mike
 
Posts: 67454
Joined: Thu Feb 11, 2010 2:51 pm

Re: Trouble with server connection using CC3000

Post by adafruit_support_mike »

Darn.. that catches a good 90% of CC3000 connection issues. ;-)

You may be running into a memory problem. Take a look at this tutorial for information about how to check the free SRAM while the code is running: https://learn.adafruit.com/memories-of- ... ree-memory

chien_fu
 
Posts: 12
Joined: Tue Dec 10, 2013 9:53 am

Re: Trouble with server connection using CC3000

Post by chien_fu »

Thanks for the link. I checked the SRAM and it looks to oscillate between 199 and 320 bytes (or bits?) during runtime. The crash doesn't look to correlate with any sudden drop in memory.
I'm at a loss for what else to try...

My motors get a signal, I'm able to control them for a few minutes, everything seems to work fine, then the loop just stops. Motors stay running but all communication is frozen, serial connection and wifi are both unresponsive, even though until the last serial.write(cc3000.checkConnected()); I am still getting a '1'.

Any other thoughts?

User avatar
adafruit_support_mike
 
Posts: 67454
Joined: Thu Feb 11, 2010 2:51 pm

Re: Trouble with server connection using CC3000

Post by adafruit_support_mike »

Try running the robot with the Arduino tethered to a laptop through a USB cable. Put Serial.print() statements into the code to zero in on the area where the code is hanging.

chien_fu
 
Posts: 12
Joined: Tue Dec 10, 2013 9:53 am

Re: Trouble with server connection using CC3000

Post by chien_fu »

This just in... I tried checking to see if the client is available using:

Code: Select all

Serial.println(www.available());
where

Code: Select all

Adafruit_CC3000_Client www = cc3000.connectTCP(ip, port); 
This returns a number counting down from 63 to 1 during the "while(www.available())" loop.

The crash always happens after the number 1. I'm not sure what that means though.. anyone have any insight on that?

User avatar
adafruit_support_mike
 
Posts: 67454
Joined: Thu Feb 11, 2010 2:51 pm

Re: Trouble with server connection using CC3000

Post by adafruit_support_mike »

The return values are the number of bytes of data in the buffer still available to be read. The value '0' is overloaded a bit though.. it can mean 'no data left in the buffer' or it can mean 'no socket'.

The 'available()' method is defined at the end of the file Adafruit_CC3000.cpp. Throw some print statements into that and let's see if we can narrow down the conditions that cause a failure.

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

Return to “Arduino”