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.
Locked
User avatar
theoriginalrage
 
Posts: 7
Joined: Sun Dec 06, 2015 2:26 pm

AIO connect failed.

Post by theoriginalrage »

I keep getting this error:
AIO connect failed
AIO connection dropped. Attempting reconnectAIO connect failed
Hardware:
Arduino Uno Rev3
Linksprite CC3000 WiFi Shield
Photoresistor
Green LED
330Ω resistor (for the LED)
10KΩ resistor (for the photoresistor)
Wires

I am using the code from the Humidity/Temperature/Light sensor, modified by taking out the Humidity/Temperature sensor code because I don't have that sensor. I just wanted to see if I could get the readings from my photoresister to show up on Adafruit IO. The only other modification to the code was to put my Adafruit IO username and key in and I added an LED to light on my breadboard when the value of the sensor was below 500. Aside from not being able to get the data to my Adafruit IO dashboard the circuit is working perfectly, I can view the values from the photoresistor in the serial monitor.

I am at a loss as to why it will not connect and display the value on my Dashboard.

My code:

Code: Select all

int LDR = 0;     //analog pin to which LDR is connected, here we set it to 0 so it means A0
int LDRValue = 0;      //that’s a variable to store LDR values
int light_sensitivity = 500;    //This is the approx value of light surrounding your LDR

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

// DHT sensor
#define DHTPIN 7     // 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       "MyRouter"
#define WLAN_PASS       "MyPassword"
#define WLAN_SECURITY   WLAN_SEC_WPA2

// Username & AIO key
#define ADAFRUIT_USERNAME  "theoriginalrage"
#define AIO_KEY  "BANNED"


#define LIGHT_PUBLISH_PATH "api/feeds/Light/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(115200);
  pinMode(13, OUTPUT);
  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 */
  const 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) {
      LDRValue = analogRead(LDR);      //reads the ldr’s value through LDR 
 
    if (LDRValue < light_sensitivity) 
      {
        digitalWrite(13, HIGH);
      }
    else
      {
        digitalWrite(13, LOW);
      }
  
  // Reconnect if we lost connection to AIO
  if(! mqttclient.connected()) {
    Serial.print(F("AIO connection dropped. Attempting reconnect"));
    mqtt_connect();
  }
  
  // Measure ambient light
  float light_level_reading = analogRead(LIGHT_SENSOR_PIN);
  int light_level = (int)(light_level_reading/1024.*100.);
  

  // Publish data on Adafruit.io
  mqttclient.publish(LIGHT_PUBLISH_PATH, (char *) String(light_level).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"));
  }

}
Here is the full error, edited so personal info isn't listed (just my router name):
Hello, CC3000!


Initialising the CC3000 ...
Firmware V. : 1.24
MAC Address : 0x08 0x00 0x28 0x59 0x7D 0x0F

Deleting old connection profiles

Attempting to connect to MyRouter
Connected!
Request DHCP

IP Addr: 192.168.1.14
Netmask: 255.255.255.0
Gateway: 192.168.1.1
DHCPsrv: 192.168.1.1
DNSserv: 192.168.1.1
AIO connect failed
AIO connection dropped. Attempting reconnectAIO connect failed
AIO connection dropped. Attempting reconnectAIO connect failed
AIO connection dropped. Attempting reconnectAIO connect failed
AIO connection dropped. Attempting reconnectAIO connect failed
AIO connection dropped. Attempting reconnectAIO connect failed
AIO connection dropped. Attempting reconnectAIO connect failed
AIO connection dropped. Attempting reconnectAIO connect failed
Attachments
Picture 8.jpg
Picture 8.jpg (182.23 KiB) Viewed 682 times

User avatar
theoriginalrage
 
Posts: 7
Joined: Sun Dec 06, 2015 2:26 pm

Re: AIO connect failed.

Post by theoriginalrage »

Could it have something to do with my routers DHCP settings?
I have a Netgear WNDR3400v3 with firmware V1.0.0.38_1.0.40, there is an update but I did that once and it screwed up my connections so I reverted it back to the 1.0.0.38_1.0.40 and everything started working fine again.

I really don't want to update it for fear of screwing up everything again.

User avatar
theoriginalrage
 
Posts: 7
Joined: Sun Dec 06, 2015 2:26 pm

Re: AIO connect failed.

Post by theoriginalrage »

I was able to make this one work: https://learn.adafruit.com/adafruit-io- ... t/overview
It's totally cool. That moment when I held my breath and pushed the button and then saw Adafruit IO spring into action was worth the headache of working with these for hours. I even took it a step further and made it auto update a post to facebook, then I made the mistake of showing my 4 year old, who pushed the button about a million times so now I have to clean up my facebook posts.

One of the differences between this and the light sensor was that I didn't open the serial monitor. I just went for it and it worked. Which makes me wonder if it is some sort of weird hang up with my router.

I think I'm going to use the button code modified to work for the light sensor. I'll post an update if I get it to work.

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

Re: AIO connect failed.

Post by bmwilton »

Did you figure out why your original code did not work. I am getting the same AIO Connect Failure......

User avatar
Kade_N
 
Posts: 3
Joined: Sun Sep 28, 2014 11:36 am

Re: AIO connect failed.

Post by Kade_N »

I am getting this too...tried both the AIO Basics: Digital Output, the example included with the MQTT library, and my own code to control a Neopixel strip. I am using an Ethernet shield to connect to the internet.

I would say it works about 1 in 10 times. It appears to be completely random. It's completely fine when it does work, which leads me to believe it's more likely an issue on the AIO side rather than with my code.

Any help would be appreciated.

User avatar
jwcooper
 
Posts: 1004
Joined: Tue May 01, 2012 9:08 pm

Re: AIO connect failed.

Post by jwcooper »

Can you try again? We restarted some backend processes hoping to fix this.

We're also moving IO to new servers, likely tomorrow with an expected downtime of 20-30 minutes.

Locked
Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.

Return to “Internet of Things: Adafruit IO and Wippersnapper”