Hi everyone.
I am trying to work with the CC3000 WIFI Shield, and have huge problems. There are two scenarios when i run this project.
When I run the project, the first loop usually goes fine, it connects to the server and sends the data. But the second time in the loop everything goes wrong. Sometimes it disconnects to the server and the if-statement fails, other times the project is hanging trying to send data to the server.
I really hope to get help, after using 3 days intensive on this error.
I have copied my code below.
// Include required libraries
#include <Adafruit_CC3000.h>
#include <SPI.h>
#include <MemoryFree.h>;
// WiFi network
#define WLAN_SSID "SSID" // cannot be longer than 32 characters!
#define WLAN_PASS "password"
#define WLAN_SECURITY WLAN_SEC_WPA2 // This can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2
// 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
// Create CC3000 & DHT instances
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT,
SPI_CLOCK_DIV2); // you can change this clock speed
// Local server IP, port, and repository
uint32_t ip = cc3000.IP2U32(192,168,0,10);
int port = 93;
String yourdata;
Adafruit_CC3000_Client client;
void setup(void)
{
Serial.begin(115200);
// Initialise the CC3000 module
if (!cc3000.begin())
{
while(1);
}
// Connect to WiFi network
cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY);
Serial.println(F("Connected to WiFi network!"));
// Check DHCP
Serial.println(F("Request DHCP"));
while (!cc3000.checkDHCP())
{
delay(100);
}
client = cc3000.connectTCP(ip, port);
Serial.println(freeMemory(), DEC);
}
void loop(void)
{
humidityTemperature();
delay(3002);
}
void humidityTemperature () {
// sent in your POST request
String cpr = "1547844444";
yourdata = "temp1=" + cpr;
Serial.println(F("Starting connection to server..."));
// Send request
if (client.connected()) {
client.println(F("POST /add.php HTTP/1.1"));
// EDIT: 'Host' to match your domain
client.println(F("Host: 192.168.0.10:93"));
client.println(F("User-Agent: Arduino/1.0"));
client.println(F("Connection: close"));
client.println(F("Content-Type: application/x-www-form-urlencoded;"));
client.print(F("Content-Length: "));
client.println(yourdata.length());
client.println();
client.println(yourdata);
Serial.println(F("Connected & Data sent"));
delay(100);
}
else {
Serial.println(F("Connection failed"));
// client.stop();
//BLÅ LED SEND DATA
}
}