Problems with posting to ThingSpeak

Hello everyone,

I need help with a project that I have been working on. I am trying to send temperature data to ThingSpeak using a Leonardo with CC3000 wifi shield. I am able to connect to the network fine with it but I can not figure out how to post to ThingSpeak. I have looked at sample code from other users with no luck. When I try to compile the code I keep getting the error "exit status 1
'updateThingSpeak' was not declared in this scope". I am confused as to where and how to declare 'updateThingSpeak' as I don't see this done anywhere in the examples that I have been using. Is this not declared in the library?

Here is my code if you could please take a look and tell me what im doing wrong.

#include <ThingSpeak.h>
#include <Adafruit_CC3000.h>
#include <ccspi.h>
#include <SPI.h>
#include <string.h>
#include "utility/debug.h"

#define ADAFRUIT_CC3000_IRQ   3
#define ADAFRUIT_CC3000_VBAT  5
#define ADAFRUIT_CC3000_CS    10
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS,
                         ADAFRUIT_CC3000_IRQ,
                         ADAFRUIT_CC3000_VBAT, SPI_CLOCK_DIVIDER);

// Use these lines for Home (Braciole) network.
//#define WLAN_SSID       "Braciole"
//#define WLAN_PASS       "XXXXXXXXXXXXXXXXXXX"
//#define WLAN_SECURITY   WLAN_SEC_WPA2

// Use these lines for cell phone teather.
#define WLAN_SSID       "Verizon-SM-N910V-06AE"
#define WLAN_PASS       "XXXXXXXXX"
#define WLAN_SECURITY   WLAN_SEC_WPA2


// Analog read pins
const int pitOut = A0;
const int meatOut = A1;

// ThingSpeak Settings Meat temp API Key
char thingSpeakAddress[] = "api.thingspeak.com";
String writeAPIKey = "XXXXXXXXXXXXXXXXXXX";
const int updateThingSpeakInterval = 16 * 1000;  // Time interval in milliseconds to update ThingSpeak

void setup()

{

  delay(10000);
  Serial.begin(115200);
  while (!Serial);
  Serial.println(F("Hello, CC3000!\n"));
  Serial.println(F("\nInitialising the CC3000 ..."));
  if (!cc3000.begin())
  {

    Serial.println(F("Unable to initialise the CC3000! Check your wiring?"));
    while (1);
  }

  Serial.println(F("\nDeleting old connection profiles"));
  if (!cc3000.deleteProfiles()) {
    Serial.println(F("Failed!"));
    while (1);
  }

  char *ssid = WLAN_SSID;
  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!"));
  {
    delay(100); // ToDo: Insert a DHCP timeout!

    Serial.println(F("Eat my meat, You know you like it!"));

  }
}


void loop()
{
  // TC1 is on analog 0, TC on analog 0 displays pit temp
  int pit = analogRead(0);

  // Equation to calculated temp in DegC
  double Vin1 = (5 * pit);
  float vinl1 = Vin1 / 1024;
  double VpitOut1 = vinl1 - 1.25;
  double pitDegC = VpitOut1 / 0.005;

  // Convert pit temp from DegC to DegF and round
  double pitDegF = (pitDegC * 9) / 5 + 32;
  int rPitDegF = round(pitDegF);

  // TC2 is on analog 1, TC on analog 1 displays meat temp
  int meat = analogRead(1);

  // Equation to calculated temp in DegC
  double Vin = (5 * meat);
  float vinl = Vin / 1024;
  double VmeatOut = vinl - 1.25;
  double meatDegC = VmeatOut / 0.005;

  // Convert meat temp from DegC to DegF and round
  double meatDegF = (meatDegC * 9) / 5 + 32;
  int rMeatDegF = round(meatDegF);

  Serial.print("Pit=");
  Serial.print(rPitDegF);
  Serial.println(F("DegF     "));
  Serial.print("Meat=");
  Serial.print(rMeatDegF);
  Serial.println(F("DegF"));


  updateThingSpeak("field1=");



  delay(5000);
}
Arduino: 1.6.7 (Windows 7), Board: "Arduino Leonardo"

C:\arduino-1.6.7\SketchBook\SerialPrint_Wifi_ThingSpeak\SerialPrint_Wifi_ThingSpeak.ino: In function 'void loop()':

SerialPrint_Wifi_ThingSpeak:109: error: 'updateThingSpeak' was not declared in this scope

   updateThingSpeak("field1=" + rMeatDegF);

                                         ^

exit status 1
'updateThingSpeak' was not declared in this scope

  This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.

Wifi_ThingSpeak_Post.ino (2.78 KB)

Solve this by taking small steps.

First of all, read number 7 about code tags on this page : http://forum.arduino.cc/index.php/topic,148850.0.html
You attached the sketch as well, so it was not a problem :slight_smile:

Please use indents and spaces and brackets always in the same way.
In the menu is an option to format the text of the code: Tools / Auto Format Ctrl+T

In line number 1 is this: #include <ThingSpeak.h>
Which library is that ? Did you install it ? There is a ThingSpeak library in the Library Manager : Sketch / Include Library / Manage Libraries
Is that the library ?
Is the code in the sketch for that library ?
The sketch seems a combination of two sketches.

When you call updateThingSpeak ( "field1=" ) , then all the other parameters should be updated as well. I don't know if that is in the library and other functions should be used for that, or maybe the updateThingSpeak should have all parameters in the text.

You have a delay of 5 seconds, and a variable 'updateThingSpeakInterval' of 16 seconds. I don't know which of the two is used, but that is fast. ThingSpeak might block you. Could you try 1 minute ?

Sorry about not tagging the code, I was wondering how everyone was doing that. I have edited the post to tag the code as well as error messages.

To answer your questions #include<ThingSpeak.h> Is a library I found on Github for ThingSpeak and I did install it as well and update it when prompted under manage library.

This is a combination of multiple sketches. Because I am just learning and have no programming experience I am building my project in steps. It will end up being a temperature controller for a BBQ smoker. It started as reading 2 k-type thermocouples, then turned into printing to an LCD display, then connecting to my home network via wifi. Now I am at the point were I want to be able to monitor the data from my android phone using the ThingView app.

I am a little confused about the library though because I have looked at other code that posts to ThingSpeak and they don't inclue the library in theirs.

I will look over the the suggestions you made and see what I can figure out.

Thanks for the help!

Many libraries on Github are forked. Could you please give a link to what you are using. I'm afraid I will be looking at a different library.
I also don't care if you installed it well :wink: you have to tell me how you have done that. I assume you used the Arduino IDE for the *.zip file ?

Thanks for modifying your top post, but I can't help to notice that the error message does not match the sketch. The error message was caused by different code in the sketch.

I don't use a library for ThingSpeak. They didn't have a library for Arduino a while ago, but they provided code, and I copied that code into my sketch.

For now, all that matters is to send something to ThingSpeak.
Perhaps you could try to upload only a number (for example 1.234) to a channel.
After installing the ThingSpeak library, examples have been added to the Arduino IDE menu. Try one of those (for your own channel of course).

Sorry about the error not matching I have 2 versions of the sketch on my computer. One that has everything in it and another that I made to post to the forum that does not have my passwords for the network connections. If needed I can post the error message which is the same for the sketch that I posted with the passwords removed.

I found the library from ThingSpeaks website saying that it is the official library.

Here is a link to the library on Github:

I installed the library by extracting the folder and putting it in the C:\Arduino-1.6.7\libraries folder. The library does show in the library manager so I assume that it is installed.

I did notice that some of the code that I have seen around does not include the library at the beginning of the sketch and that confused me.

I will try playing with the examples in the IDE menu and see what I can get to work.

Thanks again for the help

In the menu is the settings : File / Preferences
There you can find where your project files are (Sketchbook location). When you go to that folder, there is also a folder "libraries". That is where the libraries needs to be installed.
Please don't change something in the Arduino system files. That is dangerous, updates go wrong, code is in two or more places, and so on.

1 ) Delete your Arduino IDE from C:\Arduino-1.6.7. Keep your projects of course. And install Arduino 1.6.7 again. You really have to remove the Arduino system files first, or you get into trouble. Don't make changes to the Arduino system in C:\Arduino-1.6.7 anymore.

2 ) When you want to install a library, open the Library Manager. It is in the menu: Sketch / Include Libraries / Manage Libraries ( = Library Manager).
Search for thingspeak and there it is. Install it. You will be notified of updates.
Open the example : File / Examples / ThingSpeak / WriteVoltage.
Keep that side-by-side with your sketch, to see how to use ThingSpeak.begin() and ThingSpeak.writeField().
Ignore most of the sketch, it is not a very nice simple example sketch, it even confuses me :frowning:

When a library is not in the Library Manager, download the *.zip file from Github (there is often a button on the right side to download the *.zip file). Use the Arduino IDE menu to install the *.zip file : Sketch / Include Library / Add .ZIP Library
You will not be notified of updates.

When a library is not in the Library Manager, and there is not zip file, then you can copy the files to the "libraries" folder that is next to your project folders.
When a library needs to be altered, or is not finished yet, then sometimes, I take the *.cpp and *.h files from a library and copy them to my own project. Change the #include <myLib.h> into #include "myLib.h" and perhaps a few other changes.

Ok, so I uninstalled and reinstalled Arduino 1.6.7 letting it install with all of the default settings and location. I then went into the library manager and was able to add the ThingSpeak library from the list of libraries without using a file from GitHub. I also changed the #include <ThingSpeak.h> to #include "ThingSpeak.h". I then opened the Write Voltage example and removed anything that I had for ThingSpeak from my sketch and added

unsigned long myChannelNumber = XXXXX;
const char * myWriteAPIKey = "XXXXXXXXXXXXXXXX";

// Write to ThingSpeak. There are up to 8 fields in a channel, allowing you to store up to 8 different
// pieces of information in a channel.  Here, we write to field 1.
ThingSpeak.writeField(myChannelNumber, 1, voltage, myWriteAPIKey);
delay(20000); // ThingSpeak will only accept updates every 15 seconds.

I replaced the "voltage" with the number 5 and "5" to see if it would post the number 5 to ThingSpeak with no luck. I guess I dont really understand this line of code. Is the location of the word voltage what will be posted to ThingSpeak?

Thanks again for all the help!

Did you also delete the Arduino system files ?
Can you check at least that the ThingSpeak library that you copied to the system libraries is no longer there ?

Changing the include is only when adding the *.h and *.cpp files to your own project.
You have now a library installed in the normal way, so you need to #include <ThingSpeak.h>

It is like a 4 stage thing, start at the top, and if it fails go to the next option. Only the last option requires to change the include < > into " "

  • Use Library Manager
  • if that fails: Download the .ZIP from Github, use the menu to install it.
  • if that fails: Copy the library to the 'libraries' folder next to the projects folders.
  • if that fails: Copy the *.h and *.cpp into the project and change the < > into " ".

In the example, the voltage is a float.

float voltage = 1.23;

But that parameter can be an integer, long, float, text and String object. I use integer and floats.

Did you call ThingSpeak.begin() ?

The ThingSpeak.writeField() returns an integer. The error codes are in "ThingSpeak.h". It should be 200 for OK_SUCCESS. Perhaps you can print the error for some indication what is wrong.

  float voltage = 1.23;
  int error = ThingSpeak.writeField(myChannelNumber, 1, voltage, myWriteAPIKey);
  Serial.print("error=");
  Serial.println(error);

I can't get to my Mega with Ethernet shield right now to test the ThingSpeak library.

It is possible to test the ThingSpeak channel by writing the whole text in a browser. Have you tried that ?

This install is actually on a different computer. The original computer was my work laptop and when i went to reinstall the IDE it got blocked so I switched to my home laptop until I get back to work on Monday and can have IT allow the software to be installed.

I switched to #include <ThingSpeak.h> and I did forget to call ThingSpeak.begin() so I added it to the code. I used ThingSpeak.begin(Client) because thats what the example used. I am not sure if that is correct or not as I am now getting error messages.

#include <ThingSpeak.h>
#include <Adafruit_CC3000.h>
#include <ccspi.h>
#include <SPI.h>
#include <string.h>
#include "utility/debug.h"

#define ADAFRUIT_CC3000_IRQ   3
#define ADAFRUIT_CC3000_VBAT  5
#define ADAFRUIT_CC3000_CS    10
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS,
                         ADAFRUIT_CC3000_IRQ,
                         ADAFRUIT_CC3000_VBAT, SPI_CLOCK_DIVIDER);

#define WLAN_SSID       "Braciole"
#define WLAN_PASS       "XXXXXXXXXXXXXXXXX"
#define WLAN_SECURITY   WLAN_SEC_WPA2
/*
  #define WLAN_SSID       "Verizon-SM-N910V-06AE"
  #define WLAN_PASS       "XXXXXXX"
  #define WLAN_SECURITY   WLAN_SEC_WPA2
*/

// Analog read pins
const int pitOut = A0;
const int meatOut = A1;

unsigned long myChannelNumber = XXXXX;
const char * myWriteAPIKey = "XXXXXXXXXXXXXXXX";

void setup()

{

  delay(10000);
  Serial.begin(115200);
  while (!Serial);
  Serial.println(F("Hello, CC3000!\n"));
  Serial.println(F("\nInitialising the CC3000 ..."));
  if (!cc3000.begin())
  {

    Serial.println(F("Unable to initialise the CC3000! Check your wiring?"));
    while (1);
  }

  Serial.println(F("\nDeleting old connection profiles"));
  if (!cc3000.deleteProfiles()) {
    Serial.println(F("Failed!"));
    while (1);
  }

  char *ssid = WLAN_SSID;
  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!"));
  {
    delay(100); // ToDo: Insert a DHCP timeout!

    Serial.println(F("Eat my meat, You know you like it!"));

    ThingSpeak.begin(Client);
  }
}


void loop()
{
  // TC1 is on analog 0, TC on analog 0 displays pit temp
  int pit = analogRead(0);

  // Equation to calculated temp in DegC
  double Vin1 = (5 * pit);
  float vinl1 = Vin1 / 1024;
  double VpitOut1 = vinl1 - 1.25;
  double pitDegC = VpitOut1 / 0.005;

  // Convert pit temp from DegC to DegF and round
  double pitDegF = (pitDegC * 9) / 5 + 32;
  int rPitDegF = round(pitDegF);

  // TC2 is on analog 1, TC on analog 1 displays meat temp
  int meat = analogRead(1);

  // Equation to calculated temp in DegC
  double Vin = (5 * meat);
  float vinl = Vin / 1024;
  double VmeatOut = vinl - 1.25;
  double meatDegC = VmeatOut / 0.005;

  // Convert meat temp from DegC to DegF and round
  double meatDegF = (meatDegC * 9) / 5 + 32;
  int rMeatDegF = round(meatDegF);

  Serial.print("Pit=");
  Serial.print(rPitDegF);
  Serial.println(F("DegF     "));
  Serial.print("Meat=");
  Serial.print(rMeatDegF);
  Serial.println(F("DegF"));

  // Write to ThingSpeak. There are up to 8 fields in a channel, allowing you to store up to 8 different
  // pieces of information in a channel.  Here, we write to field 1.
  ThingSpeak.writeField(myChannelNumber, 1, "5", myWriteAPIKey);
  delay(20000); // ThingSpeak will only accept updates every 15 seconds.
Arduino: 1.6.7 (Windows 8.1), Board: "Arduino Leonardo"

C:\Users\Vince\Documents\Arduino\ThingSpeakPost\ThingSpeakPost.ino: In function 'void setup()':

ThingSpeakPost:67: error: expected primary-expression before ')' token

     ThingSpeak.begin(Client);

                            ^

exit status 1
expected primary-expression before ')' token

  This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.

It looks like you have mixed up two different examples. The thing speak function is probably expecting a reference to an Ethernet client called Client but you don't appear to have created such a reference.

That makes sense when looking at the example. But what do I put between the () when i call the ThingSpeak function?

I am sorry if this is all basic stuff. This is my first go at programming anything.

Try the browser first.
Be sure that field 1 is created on ThingSpeak, and use the API key. It is 'XXXXX' as an example, but you have to use your own key:

http://api.thingspeak.com/update?key=XXXXX&field1=1.23

That returns a number. I think '0' if the updates are too fast, or else an incrementing number.
Perhaps you need to update the browser page for your channel. I have tested it in Firefox, and it works.

Ok, so I double checked to make sure field 1 was created and it was. I then tested it using chrome on my android phone entering in my API key and it returned a 1. I then went in to ThingSpeak and saw the value in my data log.

Cool !
You can write a few more numbers, and the number should increase, and on your channel page you should see the graph.

The rest is easy with an Ethernet Shield and ethernet cable, but very hard for the CC3000. I'm not sure how to do it.

You need to declare a "client". That is a client for TCP using the wifi.
I'm using this as an example : Adafruit_CC3000_Library/WebClient.ino at master · adafruit/Adafruit_CC3000_Library · GitHub

After the cc3000.connectToAP() you have to cc3000.checkDHCP(), and after that:

Adafruit_CC3000_Client www = cc3000.connectTCP(ip, 80);

The 'www' is the client.

Then call:

ThingSpeak.begin(www);

Followed by:

  float voltage = 1.23;
  ThingSpeak.writeField(myChannelNumber, 1, voltage, myWriteAPIKey);

Can you ask someone to help you with this ? It is for an advanced programmer. Or try to find an example of the Adafruit CC3000 and ThingSpeak.
For example this: Using CC3000 to POST to Thingspeak - adafruit industries

Or use the tutorial and code from Adafruit to connect to Adafruit.IO
Overview | Adafruit IO Basics: Digital Output | Adafruit Learning System
Then you have a fully tutorial, and Adafruit.IO might even be better than ThingSpeak.

I really dont know anyone that is advanced with coding to help out, that is why I turned here. Do you know of another service that is free and will allow me to post data to that I can view from an android app?

I will continue working through the examples but none of the ones that I have found use the cc3000.

Thanks again for all the help!

Yes, Adafruit IO.

So I was finally able to get a post to ThingSpeak using the CC3000. I used the code in the link provided and edited it and I am now able to update 2 fields with a set number. Now on to adding code to read my thermocouples and posting that data to ThingSpeak.

Thanks a lot for all the help as I would have never figured it out without the help you provided.

Very nice. Well done. Could you share your sketch how to use the CC3000 with ThingSpeak ? It might be useful for others, since I could not find an example for it.

ThingSpeak started to annoy me with ads and not showing all fields. If I have time, I will go someday to Adafruit IO.

Sure I can post it when I get to my computer. I will say I had Adafruit IO working very quickly but I went back to ThingSpeak because I needed an android app that allows you to view your data plotted on a chart. I could not find one for Adafruit IO and I was able to find ThingView that does this.

So I used the code from the link you gave here:

https://forums.adafruit.com/viewtopic.php?f=25&t=57820#p292363

The sketch is pretty big so I will have to figure out what I can eliminate to make it smaller and get other items for my project added to it.

/*************************************************** 
  This is an example for the Adafruit CC3000 Wifi Breakout & Shield

  Designed specifically to work with the Adafruit WiFi products:
  ----> https://www.adafruit.com/products/1469

  Adafruit invests time and resources providing this open source code, 
  please support Adafruit and open-source hardware by purchasing 
  products from Adafruit!

  Written by Limor Fried & Kevin Townsend for Adafruit Industries.  
  BSD license, all text above must be included in any redistribution
 ****************************************************/
 
 /*
This example does a test of the TCP client capability:
  * Initialization
  * Optional: SSID scan
  * AP connection
  * DHCP printout
  * DNS lookup
  * Optional: Ping
  * Connect to website and print out webpage contents
  * Disconnect
SmartConfig is still beta and kind of works but is not fully vetted!
It might not work on all networks!
*/
#include "Adafruit_CC3000.h"
#include <ccspi.h>
#include <SPI.h>
#include <string.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       "XXXXXXXXXX"           // cannot be longer than 32 characters!
#define WLAN_PASS       "XXXXXXXXXXXXXXXXXXX"
// 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  3000      // 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.

// What page to grab!
#define WEBSITE      "api.thingspeak.com" // See? No 'http://' in front of it
#define WEBPAGE      "/update?key=APIKey&field1=250&field2=150"


/**************************************************************************/
/*!
    @brief  Sets up the HW and the CC3000 module (called automatically
            on startup)
*/
/**************************************************************************/

uint32_t ip;

void setup(void)
{
  Serial.begin(115200);
  Serial.println(F("Hello, CC3000!\n")); 

  Serial.print("Free RAM: "); Serial.println(getFreeRam(), DEC);
  
  /* Initialise the module */
  Serial.println(F("\nInitializing..."));
  if (!cc3000.begin())
  {
    Serial.println(F("Couldn't begin()! Check your wiring?"));
    while(1);
  }
  
  // Optional SSID scan
  // listSSIDResults();
  
  Serial.print(F("\nAttempting to connect to ")); Serial.println(WLAN_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);
  }

  ip = 0;
  // Try looking up the website's IP address
  Serial.print(WEBSITE); Serial.print(F(" -> "));
  while (ip == 0) {
    if (! cc3000.getHostByName(WEBSITE, &ip)) {
      Serial.println(F("Couldn't resolve!"));
    }
    delay(500);
  }

  cc3000.printIPdotsRev(ip);
  
  // Optional: Do a ping test on the website
  /*
  Serial.print(F("\n\rPinging ")); cc3000.printIPdotsRev(ip); Serial.print("...");  
  replies = cc3000.ping(ip, 5);
  Serial.print(replies); Serial.println(F(" replies"));
  */  

  /* Try connecting to the website.
     Note: HTTP/1.1 protocol is used to keep the server from closing the connection before all data is read.
  */
  Adafruit_CC3000_Client www = cc3000.connectTCP(ip, 80);
  if (www.connected()) {
    www.fastrprint(F("POST "));
    www.fastrprint(WEBPAGE);
    www.fastrprint(F(" HTTP/1.1\r\n"));
    www.fastrprint(F("Host: ")); www.fastrprint(WEBSITE); www.fastrprint(F("\r\n"));
    www.fastrprint(F("\r\n"));
    www.println();
  } else {
    Serial.println(F("Connection failed"));    
    return;
  }

  Serial.println(F("-------------------------------------"));
  
  /* Read data until either the connection is closed, or the idle timeout is reached. */ 
  unsigned long lastRead = millis();
  while (www.connected() && (millis() - lastRead < IDLE_TIMEOUT_MS)) {
    while (www.available()) {
      char c = www.read();
      Serial.print(c);
      lastRead = millis();
    }
  }
  www.close();
  Serial.println(F("-------------------------------------"));
  
  /* You need to make sure to clean up after yourself or the CC3000 can freak out */
  /* the next time your try to connect ... */
  Serial.println(F("\n\nDisconnecting"));
  cc3000.disconnect();
  
}

void loop(void)
{
 delay(1000);
}

/**************************************************************************/
/*!
    @brief  Begins an SSID scan and prints out all the visible networks
*/
/**************************************************************************/

void listSSIDResults(void)
{
  uint32_t index;
  uint8_t valid, rssi, sec;
  char ssidname[33]; 

  if (!cc3000.startSSIDscan(&index)) {
    Serial.println(F("SSID scan failed!"));
    return;
  }

  Serial.print(F("Networks found: ")); Serial.println(index);
  Serial.println(F("================================================"));

  while (index) {
    index--;

    valid = cc3000.getNextSSID(&rssi, &sec, ssidname);
    
    Serial.print(F("SSID Name    : ")); Serial.print(ssidname);
    Serial.println();
    Serial.print(F("RSSI         : "));
    Serial.println(rssi);
    Serial.print(F("Security Mode: "));
    Serial.println(sec);
    Serial.println();
  }
  Serial.println(F("================================================"));

  cc3000.stopSSIDscan();
}

/**************************************************************************/
/*!
    @brief  Tries to read the IP address and other connection details
*/
/**************************************************************************/
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;
  }
}