hello
while im going through this codes i had stuck in something, i couldn't understand it
while (client.available()) {
char c = client.read();
result = result + c;
Serial.write(c);}
here its going to read the data from client and save it in c variable but why the c type is char not string? how the client data will be only one character?
#include <Adafruit_CC3000.h>
#include <ccspi.h>
#include <SPI.h>
#include <string.h>
#include "utility/debug.h"
#include <stdlib.h>
// This must control pins
#define ADAFRUIT_CC3000_IRQ 3
// These can be any two pins
#define ADAFRUIT_CC3000_VBAT 8
#define ADAFRUIT_CC3000_CS 10
String result;
const unsigned long
dhcpTimeout = 60L * 1000L, // Max time to wait for address from DHCP "l" mean long number to avoid overflow
connectTimeout = 15L * 1000L, // Max time to wait for server connection
responseTimeout = 15L * 1000L; // Max time to wait for data from server
uint32_t t;//standard with #include <stdlib.h>
// definetion for the name and pass of the network
#define WLAN_SSID "00" // cannot be longer than 32 characters!
#define WLAN_PASS "00"
#define WLAN_SECURITY WLAN_SEC_WPA2 // This can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2
//create an object to spesfy ecah pins and this where are connected
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT,
SPI_CLOCK_DIV2);
#define LISTEN_PORT 8888
Adafruit_CC3000_Server robotServer(LISTEN_PORT);
// Connect to WiFi network
void setup() {
Serial.begin(115200);
result = "";
/* 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); // ToDo: Insert a DHCP timeout!
}
/* Display the IP address DNS, Gateway, etc. */
while (! displayConnectionDetails()) {
delay(1000);
}
// Start listening for connections
robotServer.begin();
Serial.println(F("Listening for connections..."));
}
void loop() {
// Try to get a client which is connected.
Adafruit_CC3000_ClientRef client = robotServer.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
result = "";
}
}
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;
}
}