hello
these codes of wifi cc3000
i have question 2 lines
#define listen_port 80
adafruit_cc3000_server robotserver(listen_port);
and another
adafruit_cc3000_clientref client = robotserver.available();
what doing adafruit_cc3000_server ,adafruit_cc3000_clientref in general & in code ?
these codes of wifi cc3000
i have question 2 lines
#define listen_port 80
adafruit_cc3000_server robotserver(listen_port);
and another
adafruit_cc3000_clientref client = robotserver.available();
what doing adafruit_cc3000_server ,adafruit_cc3000_clientref in general & in code ?
code: [select]
#include <adafruit_cc3000.h>
#include <ccspi.h>
#include <spi.h>
#include <string.h>
#include "utility/debug.h"
#include <stdlib.h>
// must control pins
#define adafruit_cc3000_irq 3
// these can 2 pins
#define adafruit_cc3000_vbat 8
#define adafruit_cc3000_cs 10
string result;
const unsigned long
dhcptimeout = 60l * 1000l, // max time wait address dhcp "l" mean long number avoid overflow
connecttimeout = 15l * 1000l, // max time wait server connection
responsetimeout = 15l * 1000l; // max time wait data server
uint32_t t;//standard #include <stdlib.h>
// definetion name , pass of network
#define wlan_ssid "00" // cannot longer 32 characters!
#define wlan_pass "00"
#define wlan_security wlan_sec_wpa2 // can wlan_sec_unsec, wlan_sec_wep, wlan_sec_wpa or wlan_sec_wpa2
//create object spesfy ecah pins , 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 module */
serial.println(f("\ninitializing..."));
if (!cc3000.begin())
{
serial.println(f("couldn't begin()! check 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 dhcp timeout!
}
/* display ip address dns, gateway, etc. */
while (! displayconnectiondetails()) {
delay(1000);
}
// start listening connections
robotserver.begin();
serial.println(f("listening connections..."));
}
void loop() {
// try client connected.
adafruit_cc3000_clientref client = robotserver.available();
if (client) {
boolean currentlineisblank = true;
// check if there data available 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 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 new line
currentlineisblank = true;
}
else if (c != '\r') {
// you've gotten character on current line
currentlineisblank = false;
}
}
// give web browser time receive data
delay(5);
// close connection:
client.close();
serial.println("client disconnected");
// format result , extract variables
result = "";
}
}
bool displayconnectiondetails(void){
uint32_t ipaddress, netmask, gateway, dhcpserv, dnsserv;
if(!cc3000.getipaddress(&ipaddress, &netmask, &gateway, &dhcpserv, &dnsserv))
{
serial.println(f("unable retrieve 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;
}
}
the first line:
says arduino server, , that, server, listens port 80. clients can connect server using port.
the second line:
checks server, see if client has connected. if so, client object valued, , arduino can determine client wants.
code: [select]
#define listen_port 80
adafruit_cc3000_server robotserver(listen_port);
says arduino server, , that, server, listens port 80. clients can connect server using port.
the second line:
code: [select]
adafruit_cc3000_clientref client = robotserver.available();
checks server, see if client has connected. if so, client object valued, , arduino can determine client wants.
Arduino Forum > Using Arduino > Programming Questions > Adafruit_CC3000_Server vs Adafruit_CC3000_ClientRef
arduino
Comments
Post a Comment