Black Lives Matter - Action and Equality. ... Adafruit is part of the Stop Hate for Profit campaign. Adafruit is open and shipping.
0

Message - AIO Connect Failed
Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
Please be positive and constructive with your questions and comments.

Message - AIO Connect Failed

by bmwilton on Thu Dec 17, 2015 6:45 pm

I can connect to my wifi with the CC3000, but I get the AIO Connect Failed message.
This is basically the adafruit_IO_sensors script with some minor mods....... (attached sketch)
I am new to this....... I did some of the Adafruit CC3000 sketches from the "Learn" area and all went OK.

Hello, CC3000!


Initialising the CC3000 ...
Firmware V. : 1.24
MAC Address : 0x70 0xFF 0x76 0x02 0x82 0x92

Deleting old connection profiles

Attempting to connect to WIN_71f5
Connected!
Request DHCP

IP Addr: 192.168.254.17
Netmask: 255.255.255.0
Gateway: 192.168.254.254
DHCPsrv: 192.168.254.254
DNSserv: 192.168.254.254
AIO connect failed
AIO connection dropped. Attempting reconnectAIO connect failed
AIO connection dropped. Attempting reconnectAIO connect failed

____________
SKETCH
___________________
// Required libraries
#include <Adafruit_CC3000.h>
#include <ccspi.h>
#include <SPI.h>
#include <PubSubClient.h>
#include "DHT.h"

// DHT sensor
#define DHTPIN 2 // what pin we're connected to
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);

// Light level sensor
#define LIGHT_SENSOR_PIN A0

// These are the interrupt and control pins
#define ADAFRUIT_CC3000_IRQ 3
#define ADAFRUIT_CC3000_VBAT 5
#define ADAFRUIT_CC3000_CS 10

// Create CC3000 instance
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT, SPI_CLOCK_DIVIDER);

// WiFi network name & password
#define WLAN_SSID "WIN_xxx"
#define WLAN_PASS "xxxxxxxx"
#define WLAN_SECURITY WLAN_SEC_WPA2

// Username & AIO key
#define ADAFRUIT_USERNAME "I put my username here"
#define AIO_KEY "I put my key here"

// Path for sensors
#define TEMPERATURE_PUBLISH_PATH "api/feeds/temperature/data/send.json"
#define HUMIDITY_PUBLISH_PATH "api/feeds/humidity/data/send.json"
#define HEATIX_PUBLISH_PATH "api/feeds/heat-index/data/send.json"

// CC3000 client & MQTT client instances
Adafruit_CC3000_Client client = Adafruit_CC3000_Client();
PubSubClient mqttclient("io.adafruit.com", 1883, callback, client);

// Callback
void callback (char* topic, byte* payload, unsigned int length) {
Serial.println(topic);
Serial.write(payload, length);
Serial.println("");
}

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

// Init DHT sensor
dht.begin();

Serial.println(F("\nInitialising the CC3000 ..."));
if (!cc3000.begin()) {
Serial.println(F("Unable to initialise the CC3000! Check your wiring?"));
for(;;);
}

uint16_t firmware = checkFirmwareVersion();
if (firmware < 0x113) {
Serial.println(F("Wrong firmware version!"));
for(;;);
}

displayMACAddress();

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

/* Attempt to connect to an access point */
char *ssid = WLAN_SSID; /* Max 32 chars */
Serial.print(F("\nAttempting to connect to ")); Serial.println(ssid);

/* NOTE: Secure connections are not available in 'Tiny' mode! */
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);
}

// Connect to AIO
mqtt_connect();

}

void loop(void) {

// Reconnect if we lost connection to AIO
if(! mqttclient.connected()) {
Serial.print(F("AIO connection dropped. Attempting reconnect"));
mqtt_connect();
}



// Measure temperature & humidity
int h = dht.readHumidity();
int t = dht.readTemperature(true);

// Compute heat index in Fahrenheit (the default)
float hif = dht.computeHeatIndex(t, h);

// Publish data on Adafruit.io
mqttclient.publish(TEMPERATURE_PUBLISH_PATH, (char *) String(t).c_str());
delay(2000);
mqttclient.publish(HUMIDITY_PUBLISH_PATH, (char *) String(h).c_str());
delay(2000);
mqttclient.publish(HEATIX_PUBLISH_PATH, (char *) String(hif).c_str());
delay(2000);

// Keep connection to MQTT broker
mqttclient.loop();

}


/**************************************************************************/
/*!
@brief Tries to read the CC3000's internal firmware patch ID
*/
/**************************************************************************/
uint16_t checkFirmwareVersion(void)
{
uint8_t major, minor;
uint16_t version;

#ifndef CC3000_TINY_DRIVER
if(!cc3000.getFirmwareVersion(&major, &minor))
{
Serial.println(F("Unable to retrieve the firmware version!\r\n"));
version = 0;
}
else
{
Serial.print(F("Firmware V. : "));
Serial.print(major); Serial.print(F(".")); Serial.println(minor);
version = major; version <<= 8; version |= minor;
}
#endif
return version;
}

/**************************************************************************/
/*!
@brief Tries to read the 6-byte MAC address of the CC3000 module
*/
/**************************************************************************/
void displayMACAddress(void)
{
uint8_t macAddress[6];

if(!cc3000.getMacAddress(macAddress))
{
Serial.println(F("Unable to retrieve MAC Address!\r\n"));
}
else
{
Serial.print(F("MAC Address : "));
cc3000.printHex((byte*)&macAddress, 6);
}
}


/**************************************************************************/
/*!
@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;
}
}

void mqtt_connect() {

char client_name[30];

// generate new client name
sprintf(client_name, "adafruit-cc3000-%ul", micros());

// attempt connection
if (mqttclient.connect(client_name, AIO_KEY, NULL)) {
Serial.println(F("Connected to AIO"));
} else {
Serial.println(F("AIO connect failed"));
}

}

bmwilton
 
Posts: 14
Joined: Mon Dec 14, 2015 3:10 pm

Re: Message - AIO Connect Failed

by bmwilton on Fri Dec 18, 2015 2:13 pm

I still can't this Sketch to work. I really would like to use adafruit io, but the example sketch cannot connect.
I have managed to get a Dashboard working with the same hardware and a Sketch that uploads via dweetio and freeboard dashboard.

bmwilton
 
Posts: 14
Joined: Mon Dec 14, 2015 3:10 pm

Re: Message - AIO Connect Failed

by jwcooper on Fri Dec 18, 2015 2:32 pm

Please try again, we were in the process of running server changes that impacted availability. The next server changes will be on Monday.

jwcooper
 
Posts: 679
Joined: Tue May 01, 2012 9:08 pm

Re: Message - AIO Connect Failed

by bmwilton on Sun Dec 20, 2015 12:01 pm

I have tried this again with the same failures.
I have started my first Sketches with the "PubSubClient.h" library as it was in the CC3000 IOT learn section. Should I continue with this path or should I move to the MQTT library? Is there a preferred way to accomplish using Adafruit IO? Your examples use both and say both are great ways to use Adafruit IO.
Being new to this, I am trying to learn a path, understand it, and then spread out a little.
Thanks.............

bmwilton
 
Posts: 14
Joined: Mon Dec 14, 2015 3:10 pm

Re: Message - AIO Connect Failed

by bmwilton on Sun Dec 20, 2015 2:00 pm

Now I tried using the mqtt_cc3k example (modified just for publish for DHT11 sensor) from the Adafruit_MQTT_Library_master and still have connection problems....
_________________________
Adafruit Bob's MQTT demo
Free RAM: 846

Init the CC3000...Firmware V. : 1.24

Deleting old connection profiles

Attempting to connect to WINxxxx...Connected!
Requesting DHCP
Unable to retrieve the IP Address!


IP Addr: 192.168.254.17
Netmask: 255.255.255.0
Gateway: 192.168.254.254
DHCPsrv: 192.168.254.254
DNSserv: 192.168.254.254
Connecting to MQTT... io.adafruit.com -> 199.167.40.63
Connection failed
Firmware V. : 1.24

Deleting old connection profiles

Attempting to connect to WINxxxx...
_____________________________________________________________________________
Sketch (NOTE, I 'xxxxxxx' over IDs and pswds.............)
______________________________________________________________________________

/***************************************************
Adafruit MQTT Library CC3000 Example

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/Ladyada for Adafruit Industries.
MIT license, all text above must be included in any redistribution
****************************************************/
#include <Adafruit_SleepyDog.h>
#include <Adafruit_CC3000.h>
#include <SPI.h>
#include <DHT.h>
#include "utility/debug.h"
#include <Adafruit_MQTT.h>
#include <Adafruit_MQTT_CC3000.h>

// DHT sensor
#define DHTPIN 2
#define DHTTYPE DHT11

// DHT instance
DHT dht(DHTPIN, DHTTYPE);

/*************************** CC3000 Pins ***********************************/

#define ADAFRUIT_CC3000_IRQ 3 // MUST be an interrupt pin!
#define ADAFRUIT_CC3000_VBAT 5 // VBAT & CS can be any digital pins.
#define ADAFRUIT_CC3000_CS 10
// Use hardware SPI for the remaining pins
// On an UNO, SCK = 13, MISO = 12, and MOSI = 11

/************************* WiFi Access Point *********************************/

#define WLAN_SSID "WINxxxx" // can't be longer than 32 characters!
#define WLAN_PASS "xxxxxxxxx"
#define WLAN_SECURITY WLAN_SEC_WPA2 // Can be: WLAN_SEC_UNSEC, WLAN_SEC_WEP,
// WLAN_SEC_WPA or WLAN_SEC_WPA2

/************************* Adafruit.io Setup *********************************/

#define AIO_SERVER "io.adafruit.com"
#define AIO_SERVERPORT 1883
#define AIO_USERNAME "xxxxxxxxx"
#define AIO_KEY "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

/************ Global State (you don't need to change this!) ******************/

// Setup the main CC3000 class, just like a normal CC3000 sketch.
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT);

// Store the MQTT server, username, and password in flash memory.
// This is required for using the Adafruit MQTT library.
const char MQTT_SERVER[] PROGMEM = AIO_SERVER;
const char MQTT_USERNAME[] PROGMEM = AIO_USERNAME;
const char MQTT_PASSWORD[] PROGMEM = AIO_KEY;

// Setup the CC3000 MQTT class by passing in the CC3000 class and MQTT server and login details.
Adafruit_MQTT_CC3000 mqtt(&cc3000, MQTT_SERVER, AIO_SERVERPORT, MQTT_USERNAME, MQTT_PASSWORD);

// You don't need to change anything below this line!
#define halt(s) { Serial.println(F( s )); while(1); }

// CC3000connect is a helper function that sets up the CC3000 and connects to
// the WiFi network. See the cc3000helper.cpp tab above for the source!
boolean CC3000connect(const char* wlan_ssid, const char* wlan_pass, uint8_t wlan_security);

/****************************** Feeds ***************************************/

// Setup feeds for temperature & humidity & heatix
const char TEMPERATURE_FEED[] PROGMEM = AIO_USERNAME "/feeds/temperature";
Adafruit_MQTT_Publish temperature = Adafruit_MQTT_Publish(&mqtt, TEMPERATURE_FEED);

const char HUMIDITY_FEED[] PROGMEM = AIO_USERNAME "/feeds/humidity";
Adafruit_MQTT_Publish humidity = Adafruit_MQTT_Publish(&mqtt, HUMIDITY_FEED);

const char HEATIX_FEED[] PROGMEM = AIO_USERNAME "/feeds/heat-index";
Adafruit_MQTT_Publish heatix = Adafruit_MQTT_Publish(&mqtt, HEATIX_FEED);


/*************************** Sketch Code ************************************/

void setup() {
Serial.begin(9600);

Serial.println(F("Adafruit Bob's MQTT demo"));

Serial.print(F("Free RAM: ")); Serial.println(getFreeRam(), DEC);

// Init sensor
dht.begin();

// Initialise the CC3000 module
Serial.print(F("\nInit the CC3000..."));
if (!cc3000.begin())
halt("Failed");


while (! CC3000connect(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) {
Serial.println(F("Retrying WiFi"));
delay(1000);
}
}

uint32_t x=0;

void loop() {
// Make sure to reset watchdog every loop iteration!
Watchdog.reset();

// Ensure the connection to the MQTT server is alive (this will make the first
// connection and automatically reconnect when disconnected). See the MQTT_connect
// function definition further below.
MQTT_connect();

/* this is our 'wait for incoming subscription packets' busy subloop
Adafruit_MQTT_Subscribe *subscription;
while ((subscription = mqtt.readSubscription(1000))) {
if (subscription == &onoffbutton) {
Serial.print(F("Got: "));
Serial.println((char *)onoffbutton.lastread);
}
}*/

// Now we can publish stuff!
// Grab the current state of the sensor
uint32_t humidity_data = (int)dht.readHumidity(); // need to learn why this needs uint32_t instead of int
uint32_t temperature_data = (int)dht.readTemperature(true);
float heatix_data = (float) dht.computeHeatIndex(temperature_data,humidity_data);

// Publish data
if (! temperature.publish(temperature_data))
Serial.println(F("Failed to publish temperature"));
else
Serial.println(F("Temperature published!"));

if (! humidity.publish(humidity_data))
Serial.println(F("Failed to publish humidity"));
else
Serial.println(F("Humidity published!"));

if (! heatix.publish(heatix_data))
Serial.println(F("Failed to publish HeatIX"));
else
Serial.println(F("HeatIX published!"));


// Repeat every 10 seconds
delay(10000);

// ping the server to keep the mqtt connection alive
if(! mqtt.ping()) {
Serial.println(F("MQTT Ping failed."));
}

}

// Function to connect and reconnect as necessary to the MQTT server.
// Should be called in the loop function and it will take care if connecting.
void MQTT_connect() {
int8_t ret;

// Stop if already connected.
if (mqtt.connected()) {
return;
}

Serial.print("Connecting to MQTT... ");

while ((ret = mqtt.connect()) != 0) { // connect will return 0 for connected
Serial.println(mqtt.connectErrorString(ret));
if (ret < 0)
CC3000connect(WLAN_SSID, WLAN_PASS, WLAN_SECURITY); // y0w, lets connect to wifi again
Serial.println("Retrying MQTT connection in 5 seconds...");
mqtt.disconnect();
delay(5000); // wait 5 seconds
}
Serial.println("MQTT Connected!");
}

bmwilton
 
Posts: 14
Joined: Mon Dec 14, 2015 3:10 pm

Re: Message - AIO Connect Failed

by bmwilton on Sun Dec 20, 2015 5:41 pm

Just a quick note- I installed the MQTT Desktop Client as described in the Adafruit Learn section and I CAN publish from the MQTT Client interface to my dashboard on Adafruit IO, that I am trying to publish to with my Sketches !!!!!!!!!!!!!!!!!!

bmwilton
 
Posts: 14
Joined: Mon Dec 14, 2015 3:10 pm

Re: Message - AIO Connect Failed

by bmwilton on Wed Dec 23, 2015 1:28 pm

Well, I didn't get any help from this forum, or any tech support from adafruit io, but I figured it out.
I was using the adafruit example sketch and it just wasn't working. Maybe there was a problem on the adafruit io side, as they were doing maintenance????
So I ventured off elsewhere and was successfuly at publishing to dweetio/freeboard, emoncms, and thethings.iO........
I am just experimenting with wifi for the first time so, I am still trying to learn how it works.........
This change to the sketch made it work and I am now publishing OK to adafruit io....
(I am putting this info here in case it might help someone else)

Old part of sketch from the example........ (connecting to wifi)

while (! CC3000connect(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) {
Serial.println(F("Retrying WiFi"));
delay(1000);

Replaced with.............

// Connect to WiFi network
Serial.println(F("=> Connecting to WiFi"));
cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY);

Serial.println(F("=> Requesting DHCP"));
while (!cc3000.checkDHCP()) {
delay(100);

Again, I now am trying to figure out why, as I am truly new to this..................

bmwilton
 
Posts: 14
Joined: Mon Dec 14, 2015 3:10 pm

Please be positive and constructive with your questions and comments.