Hi,
I'm working on a project to change some LED's based on a data on a webpage. Right now I'm able to connect to my wireless router and print the contents of the webpage to my serial monitor using a WebClient example from Adafruit. I would now like to grab my target data from the incoming stream.
I've read about char arrarys but I'm in over my head there. I was thinking that a good option would be to use the TextFinder library but I do not know how to 'pair' my CC3000 module/library to the TextFinder functions since it was written for the Ethernet library.
What would I use instead of "client" below?
TextFinder finder( client );
Correct me if I'm wrong, but I think that my CC3000 sketch uses "www" instead of "client" for it's commands.
Adafruit_CC3000_Client www = cc3000.connectTCP(ip, 80);\
But when I use "TextFinder finder( www );" I get the following error message. Is it even possible to use the Adafruit_CC3000 library and TextFinder?
In function 'int getWaves()':
139: error: no matching function for call to 'TextFinder::TextFinder(Adafruit_CC3000_Client&)'
C:\Users\sam\Documents\Arduino\libraries\TextFinder/TextFinder.h:63: note: candidates are: TextFinder::TextFinder(Stream&, int)
C:\Users\sam\Documents\Arduino\libraries\TextFinder/TextFinder.h:43: note: TextFinder::TextFinder(const TextFinder&)
Here is my full code. Thanks for reading!
/***************************************************
* 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
****************************************************/
#include <Adafruit_CC3000.h>
#include <ccspi.h>
#include <SPI.h>
#include <string.h>
#include "utility/debug.h"
#include <TextFinder.h>
#include <Adafruit_NeoPixel.h>
#define PIN 2
Adafruit_NeoPixel strip = Adafruit_NeoPixel(12, PIN, NEO_GRB + NEO_KHZ800);
// 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
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT,
SPI_CLOCK_DIV2);
#define WLAN_SSID "wifi"
#define WLAN_PASS "pass"
#define WLAN_SECURITY WLAN_SEC_WPA
#define IDLE_TIMEOUT_MS 3000
#define WEBSITE "feeds.feedburner.com"
#define WEBPAGE "/surfline-rss-surf-report-south-san-diego"
uint32_t ip;
void setup(void)
{
strip.begin();
colorWipe(strip.Color(255, 0, 255), 50);
Serial.begin(115200);
}
void loop() {
initWifi();
deleteOldConn();
connectWifi();
requestDCHP();
int wreq=getWaves();
delay(10000);
}
// Fill the neopixels one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
}
//Start up cc3000 wifi chip
void initWifi(void){
Serial.println(F("CC3000 and beyond\n"));
Serial.print("Free RAM: ");
Serial.println(getFreeRam(), DEC);
Serial.println(F("\nInitialising the CC3000 ..."));
if (!cc3000.begin())
{
Serial.println(F("Unable to initialise the CC3000! Check your wiring?"));
while(1);
}
}
// Delete any old connection data on the module
void deleteOldConn(void){
Serial.println(F("\nDeleting old connection profiles"));
if (!cc3000.deleteProfiles()) {
Serial.println(F("Failed!"));
while(1);
}
}
//connect to wireless network
void connectWifi(void){
/* 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!"));
Serial.println(F("\n"));
}
// Wait for DHCP to complete
void requestDCHP(){
Serial.println(F("Requesting DHCP..."));
while (!cc3000.checkDHCP())
{
delay(100); // ToDo: Insert a DHCP timeout!
}
Serial.println(F("DCHP Done."));
Serial.println(F("\n\n"));
}
// search for wave data
int getWaves(){
uint32_t ip = 0;
String readString = "";
Serial.println(F("Connecting to website..."));
while (ip == 0) {
if (! cc3000.getHostByName(WEBSITE, &ip)) {
Serial.println(F("Couldn't resolve!"));
}
delay(500);
}
cc3000.printIPdotsRev(ip);
Adafruit_CC3000_Client www = cc3000.connectTCP(ip, 80);
\
//TextFinder finder( www );
Serial.println(F("Text Return:"));
if (www.connected()) {
www.fastrprint(F("GET "));
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("-------------------------------------"));
Serial.println(F("\n"));
}