Hi, Good day. Currently, I'm having this project where I connected and Arduino Mega2560 with a CC3000 Wifi Shield. What I want to do right now is to connect my Arduino to my server(My PC). They are both connected on the same network and via a wireless router. Here is the code:
#include <Adafruit_CC3000.h>
#include <ccspi.h>
#include <SPI.h>
#include <string.h>
#include "utility/debug.h"
#include "RTClib.h"
#include <SD.h>
#include <Wire.h>
#include <Thread.h>
// 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_DIVIDER); // you can change this clock speed but DI
#define WLAN_SSID "noparking" // cannot be longer than 32 characters!
#define WLAN_PASS "qwer123asdf"
// Security can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2
#define WLAN_SECURITY WLAN_SEC_WPA2
#define WEBSITE "192.168.10.103"
#define WEBPAGE "/pages/add.php"
RTC_DS1307 rtc;
Adafruit_CC3000_Client client;
char server[] = "192.168.10.100";
void setup(void) {
Serial.begin(9600);
/*
Checking the Wifi Shield
*/
Serial.println(F("CC3000\n"));
displayDriverMode();
Serial.print("Free RAM: ");
Serial.println(getFreeRam(), DEC);
Serial.println(F("\nInitializing CC3000..."));
if (!cc3000.begin()) {
Serial.println(F("ERROR"));
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);
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);
}
}
void loop(void) {
delay(3000);
if(client.connect(server, 80)) {
Serial.println("Connected");
client.fastrprint("GET /DesignProject/pages/add.php?");
client.fastrprint("loc=");
client.fastrprint("Example");
client.fastrprint("&&");
client.fastrprint("month=");
client.fastrprint("01");
client.fastrprint("Host: ");
client.fastrprint(server);
//client.fastrprint("Content-Type: application/x-www-form-urlencoded" );
client.fastrprint("Connection: close" );
client.println();
} else {
Serial.println("Cannot connect to the server!");
}
}
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
}
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;
}
}
- note that some libraries are for future use.
My question is can you pinpoint what i'm missing or doing wrong? thanks