My problem is after about 10 or 15 minutes it just stops. Initially, it would loop 8 times and just freeze. At that time in the sketch I had the cc3000 connect to the database outside the loop and leaving the thing connected while looping. I then moved the db connect inside the loop, with it connecting, calling the page, then closing the connection then loop to start it all over again. Once I moved the connect statement inside the loop it would, like I said, run for 10 or 15 minutes then freeze. I did notice in the database table that sometimes during that 10 to 15 minutes it would go 10 or 15 seconds between inserts into the db - meaning some of the loops did not result in an insert into the db. The code is below. Any suggestions would be greatly appreciated.
Code: Select all
#include <Adafruit_CC3000.h>
#include <ccspi.h>
#include <SPI.h>
#include <string.h>
#include <stdlib.h>
#include "utility/debug.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
#define WLAN_SSID "Cepheus-S" // cannot be longer than 32 characters!
#define WLAN_PASS "BANNED"
// Security can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2
#define WLAN_SECURITY WLAN_SEC_WPA2
#define IDLE_TIMEOUT_MS 4000 // Amount of time to wait (in milliseconds) with no data
// received before closing the connection. If you know the server
// you're accessing is quick to respond, you can reduce this value.
/**************************************************************************/
/*!
@brief Sets up the HW and the CC3000 module (called automatically
on startup)
*/
/**************************************************************************/
uint32_t ip;
Adafruit_CC3000_Client www;
/**************************************************************************/
void setup(void)
{
Serial.begin(9600);
/* Initialise the module */
Serial.println(F("\nInitializing Wifi..."));
if (!cc3000.begin())
{
Serial.println(F("Couldn't init Wifi!"));
while(1);
}
// Connect ot he LAN
if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) {
Serial.println(F("Failed!"));
while(1);
} else {
Serial.println(F("\nConnected!"));
}
// Lets get an IP address
Serial.println(F("Requesting IP address..."));
while (!cc3000.checkDHCP())
{
delay(100); // ToDo: Insert a DHCP timeout!
}
/* Display the IP address DNS, Gateway, etc. */
while (! displayConnectionDetails()) {
delay(1000);
}
ip = 0;
ip = cc3000.IP2U32(192, 168, 1, 9);
// Do a ping test on the website
Serial.print(F("\n\rPinging server ")); cc3000.printIPdotsRev(ip); Serial.print(" 5 times... ");
int replies = cc3000.ping(ip, 5);
Serial.print(replies); Serial.println(F(" replies"));
}
/**************************************************************************/
/**************************************************************************/
const int temperaturePin = 0;
float voltage, degreesC, degreesF;
int degF = 0;
char str[3];
void loop()
{
voltage = analogRead(temperaturePin) * 0.004882814;
degreesC = (voltage - 0.5) * 100.0;
degreesF = degreesC * (9.0/5.0) + 32.0;
degF = int(degreesF);
itoa(degF,str,10);
www = cc3000.connectTCP(ip, 80);
if (www.connected()) {
www.fastrprint(F("GET /Arduino/save_temps.php?"));
www.fastrprint(F("temp1="));
www.fastrprint(( str ));
www.fastrprint(F(" HTTP/1.1\r\n"));
www.fastrprint(F("Host: "));
www.fastrprint(F("\r\n"));
www.println();
}
www.close();
delay(5000);
}
/**************************************************************************/
/**************************************************************************/
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("\nObtained Addr: ")); cc3000.printIPdotsRev(ipAddress);
Serial.println();
return true;
}
}