Problem with Adafruit cc3000 wifi sheild sending data to thingspeak | ESP8266 Wi-Fi Module | Forum

Avatar

Please consider registering
Guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —






— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed sp_TopicIcon
Problem with Adafruit cc3000 wifi sheild sending data to thingspeak
No permission to create posts
February 9, 2017
10:36 am
Avatar
Rakibul Sharif
New Member
Members
Forum Posts: 1
Member Since:
February 9, 2017
sp_UserOfflineSmall Offline

Hello.I am try to send data thingspeak using adafruit cc3000 wifi shield.After 3-4 times it sending off data.Here is the code.I am using Lm35 for sensing temperature....Help me out.Thank you all

/***************************************************
* This is a sketch to use the online temperature and humidity sensor using Xively
*
* Actual code was written by Marco Schwartz for Open Home Automation
.
****************************************************/

// Libraries
#include <Adafruit_CC3000.h>
#include <ccspi.h>
#include <SPI.h>
#include <string.h>
#include<stdlib.h>
#include "utility/debug.h"
//#include "DHT.h"
#include <avr/wdt.h>

// Define CC3000 chip pins
#define ADAFRUIT_CC3000_IRQ 3
#define ADAFRUIT_CC3000_VBAT 5
#define ADAFRUIT_CC3000_CS 10

// temperature and humidity sensor
//#define DHTPIN 7
//#define DHTTYPE DHT11

// Create CC3000 instances
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT,SPI_CLOCK_DIV2); // you can change this clock speed

// WLAN parameters
#define WLAN_SSID "domain"
#define WLAN_PASS "ATR@5645"

// Security can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2
#define WLAN_SECURITY WLAN_SEC_WPA2

// Xively parameters
// ThingSpeak Settings
char thingSpeakAddress[] = "api.thingspeak.com";
String writeAPIKey = "MSQA5TY5V7UK1H6X";
uint8_t temperature;
uint32_t ip;
// Variable Setup
long lastConnectionTime = 0;
boolean lastConnected = false;
int failedCounter = 0;
int tempPin = A0;
int val;
// for themperature and humidity
//DHT dht(DHTPIN, DHTTYPE);

void setup(void)
{
// Initialize
Serial.begin(115200);
ConnectWifi(); //// Connect with Wifi

}

void loop(void)
{
// Get data & transform to integers
//float h = dht.readHumidity();
val = analogRead(tempPin);
float mv = (val/1024.0)*5000;
float cel = mv/10;
Serial.print("Temperature = ");
Serial.println(cel);
//Serial.print("Humidity = ");
//Serial.println(h);

int temperature = (float) cel;
//int humidity = (int) h;
String tem=String(temperature, DEC); //Thingspeak only data stream is string type
//String hum=String(humidity, DEC); // Converting integer data to string
Serial.print(F("api.thingspeak.com -> "));
while (ip == 0) {
if (! cc3000.getHostByName("api.thingspeak.com", &ip)) {
Serial.println(F("Couldn't resolve!, Restarting....."));
wdt_enable(WDTO_8S); // if host does not response wait 8 sec and restart
while(1){}
}

delay(500);
}
cc3000.printIPdotsRev(ip);
Serial.println(F(""));
Adafruit_CC3000_Client client = cc3000.connectTCP(ip, 80);
// Print Update Response to Serial Monitor
if (client.available())
{
char c = client.read();
Serial.print(c);
}

// Update ThingSpeak
if(client.connected())
{
// Send temperature and humidity data to Thingspeak site
updateThingSpeak("1="+tem);
delay(20000); // Thingspeak needs a 15s delay between 2 data stream.
failedCounter=0;

}
else
{
Serial.println(F("Connection failed"));
failedCounter++;
if (failedCounter==15)
{
Serial.println(F("Connection failed for 15 times, Restarting......"));
wdt_enable(WDTO_8S); // if 10 continuous data upload failed, restart host after 8s.
while(1){}
}
}

}

void updateThingSpeak(String tsData)
{
Adafruit_CC3000_Client client = cc3000.connectTCP(ip, 443);

Serial.println("Connecting to ThingSpeak...");
Serial.println("Sending Data");
client.print("POST /update HTTP/1.1
");
client.print("Host: api.thingspeak.com
");
client.print("Connection: close
");
client.print("X-THINGSPEAKAPIKEY: "+writeAPIKey+"
");
client.print("Content-Type: application/x-www-form-urlencoded
");
client.print("Content-Length: ");
client.print(tsData.length());
client.print("

");

client.print(tsData);
Serial.println(F("Done"));
Serial.println(F("Waiting 25 sec for next sending"));
}

void ConnectWifi(){
Serial.println(F("
Initializing..."));
if (!cc3000.begin())
{
Serial.println(F("Couldn't begin()! Check your wiring?"));
while(1);
}
// Connect to WiFi network
cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY);
Serial.println(F("Connected!"));

/* Wait for DHCP to complete */
Serial.println(F("Request DHCP"));
while (!cc3000.checkDHCP())
{
delay(100);
}

}

Forum Timezone: America/New_York

Most Users Ever Online: 114

Currently Online: Hans, agrisensezm
35 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 261

Vinod: 196

piajola: 85

turgo: 70

vespapierre: 63

Adarsh_Murthy: 62

Member Stats:

Guest Posters: 1

Members: 5703

Moderators: 0

Admins: 2

Forum Stats:

Groups: 4

Forums: 17

Topics: 1313

Posts: 4565

Newest Members:

Archieter, JamesExedo, IrbosHich, brodi, kasko, franklin castro

Administrators: Hans: 387, lee: 457