I am building humanoid robot with 20 servos, the robot using Arduino Mega 2560 and Adafruit CC3000 wifi shield.
My project is to move the robot servos according to commands stored on the server PC computer.
For communication testing, i have installed on the PC WampServer and written a simple php file for the server:
Code: Select all
<?php
echo "f";
?>
But, as i was testing the communication, i had issues with the timing of communication.
The problem i have is the long time it takes me to receive one char : about 10 seconds.
I have no idea how to decrease the time taken for me to receive data from server PC.
the arduino code:
Code: Select all
#include <Adafruit_CC3000.h>
#include <ccspi.h>
#include <SPI.h>
#include <string.h>
#include "utility/debug.h"
#include<stdlib.h>
// Define CC3000 chip pins
#define ADAFRUIT_CC3000_IRQ 3
#define ADAFRUIT_CC3000_VBAT 5
#define ADAFRUIT_CC3000_CS 10
// WiFi network (change with your settings !)
#define WLAN_SSID "MYHOMENETWORK" // cannot be longer than 32 characters!
#define WLAN_PASS "MYHOMENETWORKPASSWORD" //password
#define WLAN_SECURITY WLAN_SEC_WPA2 // This can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2
// Create CC3000 instances
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT,
SPI_CLOCK_DIV2);
// Local server IP, port, and (change with your settings !)
uint32_t ip = cc3000.IP2U32(10,0,0,1); //********CHANGE IS NEEDED
int port = 6345;
char c;
Adafruit_CC3000_Client client;
uint16_t len;
String start_request = "";
String end_request = "";
void setup() {
Serial.begin(115200);
Serial.println(F("\nInitializing..."));
if (!cc3000.begin())
{
Serial.println(F("Couldn't begin()! Check your wiring?"));
while(1);
}
// Connect to WiFi network
if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY))
{
Serial.println(F("failed!"));
while(1);
}
// Display connection details
Serial.println(F("Request DHCP"));
while (!cc3000.checkDHCP())
{
delay(100); // ToDo: Insert a DHCP timeout!
}
cc3000.printIPdotsRev(ip);
// Prepare request
start_request = start_request + "\n" + "--AaB03x" + "\nSOMETHING TO SEND\n" + "Content-Transfer-Encoding: binary" + "\n" + "\n";
end_request = end_request + "\n" + "--AaB03x--" + "\n";
len = start_request.length() + end_request.length();
}
void loop() {
Serial.println("\n\n******START MAIN LOOP*******\n\n");
unsigned long Time1=millis();
Serial.println("Starting connection to server...");
client = cc3000.connectTCP(ip, port);
Serial.print(F("\nTime taken for connection to finnish in ms: "));
Serial.println(millis()-Time1);
Serial.println(F("\n\n### SENDING DATA: ###\n\n"));
unsigned long Time2=millis();
if (client.connected())
{
Serial.println(F("Connected !"));
client.println(F("GET /arduino-camera-wifi/c.php HTTP/1.1"));
client.println("Host: localhost");
client.println("User-Agent: Arduino");
client.println("Accept: text/html");
client.println();
}
else
{
Serial.println(F("Connection failed"));
}
Serial.print(F("\nTime taken to send request in ms: "));
Serial.println(millis()-Time2);
Serial.println(F("\n\n### RECEIVING DATA: ###\n\n"));
unsigned long Time3=millis();
while (client.connected())
{
if (client.available())
{
c=client.read();
Serial.print(c);
}
}
Serial.println(F("\nTime taken to Receive data in ms: "));
Serial.print(millis()-Time3);
Serial.print(F("\n"));
client.close();
Serial.print(F("\n Total Time taken for main loop in ms: "));
Serial.println(millis()-Time1);
}
The answers:
Code: Select all
Initializing...
Started AP/SSID scan
Connecting to MYHOMENETWORK...Waiting to connect...Connected!
Request DHCP
10.0.0.1
******START MAIN LOOP*******
Starting connection to server...
Connect to 10.0.0.1:6345
Time taken for connection to finnish in ms: 9
### SENDING DATA: ###
Connected !
Time taken to send request in ms: 215
### RECEIVING DATA: ###
HTTP/1.1 200 OK
Date: Thu, 17 Apr 2014 10:37:02 GMT
Server: Apache/2.4.4 (Win64) PHP/5.4.12
X-Powered-By: PHP/5.4.12
Content-Length: 1
Content-Type: text/html
f
Time taken to Receive data in ms:
10014
Total Time taken for main loop in ms: 10242
Can you help me to understand why it takes that long, and how can i fix it.
thank you.