0

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.

AIO_CONNECT_FAILED

by papakujawa on Mon Jan 27, 2020 11:07 pm

Hardware: Adafruit Metro Express, adafruit WINC1500, DHT22.
Status: AIO_CONNECT_FAILED ( status = 11 from AdafruitIO_Definitions.h )

Using the WiFi101 library I can successfully connect to the internet and send data to dweet.io.
Using the Adafruit IO Temperature & Humidity Example #15, it will not connect to Adafruit IO.

Added a few print statements to AdafruitIO_WINC1500.h and AdafruitIO.cpp which yields:
Connecting to Adafruit IO
AdafruitIO_WINC1500
AdafruitIO_WINC1500.h - networkStatus(): 255
AIO_NET_DISCONNECTED
AdafruitIO::status() - net_status_t: 1io.status(): AdafruitIO_WINC1500.h - networkStatus(): 255
AIO_NET_DISCONNECTED
AdafruitIO::status() - net_status_t: 11
.AdafruitIO_WINC1500.h - networkStatus(): 255
AIO_NET_DISCONNECTED
AdafruitIO::status() - net_status_t: 1io.status(): AdafruitIO_WINC1500.h - networkStatus(): 255
AIO_NET_DISCONNECTED
AdafruitIO::status() - net_status_t: 11

The IO_USERNAME and IO_KEY were cut and pasted from AIO Key.
The WIFI_SSID and WIFI_PASS were cut and pasted from the working routine.

The Feed and Dashboard were created following the example (as far as I can tell).

Any idea what I missed to get the example working?

----------------------------------------------------------

Working code:
Code: Select all | TOGGLE FULL SIZE
[/*

  This example connects to an unencrypted WiFi network.
  Then it prints the  MAC address of the WiFi shield,
  the IP address obtained, and other network details.

  Circuit:
   WiFi shield attached

  created 13 July 2010
  by dlf (Metodo2 srl)
  modified 31 May 2012
  by Tom Igoe
*/
#include <SPI.h>
#include <WiFi101.h>
#include <Wire.h>
#include <Adafruit_RGBLCDShield.h>
#include <utility/Adafruit_MCP23017.h>

#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>

#include "arduino_secrets.h"
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
char ssid[] = SECRET_SSID;        // your network SSID (name)
char pass[] = SECRET_PASS;    // your network password (use for WPA, or use as key for WEP)
int status = WL_IDLE_STATUS;     // the WiFi radio's status

// Thing name - Dweet.io
String thingName = "xxxxxxxxxxx";
// Server
char server[] = "dweet.io";

// Connection interval
unsigned long lastConnectionTime = 0;           
const unsigned long postingInterval = 10L * 1000L;

Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();

#define DHTPIN 2     // Digital pin connected to the DHT sensor
#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321

DHT dht(DHTPIN, DHTTYPE);
float humidity, fahrenheit;
long rssi;

// Create a Wi-Fi client
WiFiClient client;

void setup() {
/*
  // start the serial connection
  Serial.begin(115200);
 
  // wait for serial monitor to open
  while(! Serial);
*/
  uint8_t i = 0;

  // Set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  dht.begin();
  lcd.clear();

  // Check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    lcd.setCursor(0, 0);
    lcd.println("No WiFi shield");
    // don't continue:
    lcd.setCursor(0, 1);
    lcd.println("Halt!");
    while (true);
  }

  // Attempt to connect to WiFi network:
  while ( status != WL_CONNECTED) {
    lcd.setCursor(0, 0);
    lcd.print("Connecting: ");
    lcd.setCursor(0, 1);
    lcd.print(ssid);

    // Connect to WPA/WPA2 network:
    status = WiFi.begin(ssid, pass);

    // wait 10 seconds for connection:
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Waiting 10 sec.");   
    delay(10000);
  }

  // you're connected now, so print out the data:
  printCurrentNet();

}


void loop() {

  // Read incoming data
  while (client.available()) {
    char c = client.read();
    Serial.write(c);
  }
 
  readButtons();
  delay(1000);

}

void printCurrentNet() {
  // print the SSID of the network you're attached to:
  lcd.setCursor(0, 0);
  lcd.print("Connected: ");
  lcd.print(WiFi.SSID());

  // print the received signal strength:
  rssi = WiFi.RSSI();
  lcd.setCursor(0, 1);
  lcd.print("signal: ");
  lcd.print(rssi);
}

boolean readSensor() {
  // Wait a few seconds between measurements.
  delay(2000);

  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  humidity = dht.readHumidity();
  // Read temperature as Celsius (the default)
  // float t = dht.readTemperature();
  // Read temperature as Fahrenheit (isFahrenheit = true)
  fahrenheit = dht.readTemperature(true);

  // Check if any reads failed and exit early (to try again).
  if (isnan(humidity) || isnan(fahrenheit)) {
    lcd.setCursor(0, 0);
    lcd.print(F("Failed DHT read!"));
    return false;
  }
  else {
    return true;
  }
}

void readButtons() {
  uint8_t buttons = lcd.readButtons();

  if (buttons) {
    lcd.clear();
    lcd.setCursor(0, 0);
    if (buttons & BUTTON_UP) {
      lcd.print("UP ");
      //lcd.setBacklight(RED);
    }
    if (buttons & BUTTON_DOWN) {
      delay(1000);
      lcd.setCursor(0, 1);
      lcd.print("signal: ");
      lcd.print(rssi);
    }
    if (buttons & BUTTON_LEFT) {
      if (readSensor()) {
        lcd.print(F("Humidity: "));
        lcd.print(humidity);

        lcd.setCursor(0, 1);
        lcd.print(fahrenheit);
        lcd.print(F(" F "));
      }
    }
    if (buttons & BUTTON_RIGHT) {
      IPAddress ip = WiFi.localIP();
      lcd.print("IP Address: ");
      lcd.setCursor(0, 1);
      lcd.println(ip);
    }
    if (buttons & BUTTON_SELECT) {
      lcd.print("Send Request ");
    // Send request
    httpRequest(fahrenheit, humidity);
    }
  }
}


// Make HTTP request
void httpRequest(float temperature, float humidity) {

  // Close existing connection
  client.stop();

  // Connect & send request
  if (client.connect(server, 80)) {
    lcd.setCursor(0, 0);
    lcd.print("connecting...");

    // Prepare request
    String request = "GET /dweet/for/";
    request += String(thingName);
    request += "?temperature=" + String(temperature);
    request += "&humidity=" + String(humidity);
    request += " HTTP/1.1";
   
    // Send the HTTP request:
    client.println(request);
    client.println("Host: dweet.io");
    client.println("User-Agent: ArduinoWiFi/1.1");
    client.println("Connection: close");
    client.println();
   
    lcd.setCursor(0, 1);
    lcd.print("Data Sent");

    // Note the time that the connection was made:
    lastConnectionTime = millis();
  }
  else {
    // if you couldn't make a connection:
    lcd.setCursor(0, 1);
    lcd.print("connection failed");
  }
}/code]

-----------------------------------------------------

Temperature code not connecting:

[code]/ Adafruit IO Temperature & Humidity Example
// Tutorial Link: https://learn.adafruit.com/adafruit-io-basics-temperature-and-humidity
//
// Adafruit invests time and resources providing this open source code.
// Please support Adafruit and open source hardware by purchasing
// products from Adafruit!
//
// Written by Todd Treece for Adafruit Industries
// Copyright (c) 2016-2017 Adafruit Industries
// Licensed under the MIT license.
//
// All text above must be included in any redistribution.

/************************** Configuration ***********************************/

// edit the config.h tab and enter your Adafruit IO credentials
// and any additional configuration needed for WiFi, cellular,
// or ethernet clients.
#include "config.h"

/************************ Example Starts Here *******************************/
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>

// pin connected to DH22 data line
#define DATA_PIN 2

// create DHT22 instance
DHT_Unified dht(DATA_PIN, DHT22);

// set up the 'temperature' and 'humidity' feeds
AdafruitIO_Feed *temperature = io.feed("temperature");
//AdafruitIO_Feed *humidity = io.feed("humidity");

int loopCount = 0;

void setup() {

  // start the serial connection
  Serial.begin(115200);

  // wait for serial monitor to open
  while(! Serial);

  // initialize dht22
  dht.begin();

  // connect to io.adafruit.com
  Serial.println("Connecting to Adafruit IO");
  io.connect();

  // wait for a connection
  while(io.status() < AIO_CONNECTED) {
Serial.print("io.status(): ");
Serial.println(io.status());
    Serial.print(".");
    if (++loopCount >= 30) {
      loopCount = 0;
      Serial.println(".");
    }
    delay(500);
  }

  // we are connected
  Serial.println();
  Serial.println(io.statusText());

}

void loop() {

  // io.run(); is required for all sketches.
  // it should always be present at the top of your loop
  // function. it keeps the client connected to
  // io.adafruit.com, and processes any incoming data.
  io.run();

  sensors_event_t event;
  dht.temperature().getEvent(&event);

  float celsius = event.temperature;
  float fahrenheit = (celsius * 1.8) + 32;

  Serial.print("celsius: ");
  Serial.print(celsius);
  Serial.println("C");

  Serial.print("fahrenheit: ");
  Serial.print(fahrenheit);
  Serial.println("F");

  // save fahrenheit (or celsius) to Adafruit IO
  temperature->save(fahrenheit);

  dht.humidity().getEvent(&event);

  Serial.print("humidity: ");
  Serial.print(event.relative_humidity);
  Serial.println("%");

  // save humidity to Adafruit IO
//  humidity->save(event.relative_humidity);

  // wait 5 seconds (5000 milliseconds == 5 seconds)
  delay(5000);

}[/code]

---------------------------------

[code]************************ Adafruit IO Config *******************************/

// visit io.adafruit.com if you need to create an account,
// or if you need your Adafruit IO key.
#define IO_USERNAME  "xxxxxxxxxxx"
#define IO_KEY       "aio_xxxxxxxxxxxxxxxxxxxxxx"

/******************************* WIFI **************************************/

// the AdafruitIO_WiFi client will work with the following boards:
//   - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471
//   - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821
//   - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405
//   - Feather M0 WiFi -> https://www.adafruit.com/products/3010
//   - Feather WICED -> https://www.adafruit.com/products/3056
//   - Adafruit PyPortal -> https://www.adafruit.com/product/4116
//   - Adafruit Metro M4 Express AirLift Lite ->
//   https://www.adafruit.com/product/4000
//   - Adafruit AirLift Breakout -> https://www.adafruit.com/product/4201
//   - Adafruit AirLift Shield -> https://www.adafruit.com/product/4285
//   - Adafruit AirLift FeatherWing -> https://www.adafruit.com/product/4264

#define WIFI_SSID "xxxxxxxxxxx"
#define WIFI_PASS "xxxxxxxxxxxxx"

// uncomment the following line if you are using airlift
// #define USE_AIRLIFT

// uncomment the following line if you are using winc1500
#define USE_WINC1500

// comment out the following lines if you are using fona or ethernet
#include "AdafruitIO_WiFi.h"

#if defined(USE_AIRLIFT) || defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE) ||         \
    defined(ADAFRUIT_PYPORTAL)
// Configure the pins used for the ESP32 connection
#if !defined(SPIWIFI_SS) // if the wifi definition isnt in the board variant
// Don't change the names of these #define's! they match the variant ones
#define SPIWIFI SPI
#define SPIWIFI_SS 10 // Chip select pin
#define NINA_ACK 9    // a.k.a BUSY or READY pin
#define NINA_RESETN 6 // Reset pin
#define NINA_GPIO0 -1 // Not connected
#endif
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS,
                   NINA_ACK, NINA_RESETN, NINA_GPIO0, &SPIWIFI);
#else
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
#endif
/******************************* FONA **************************************/

// the AdafruitIO_FONA client will work with the following boards:
//   - Feather 32u4 FONA -> https://www.adafruit.com/product/3027

// uncomment the following two lines for 32u4 FONA,
// and comment out the AdafruitIO_WiFi client in the WIFI section
// #include "AdafruitIO_FONA.h"
// AdafruitIO_FONA io(IO_USERNAME, IO_KEY);

/**************************** ETHERNET ************************************/

// the AdafruitIO_Ethernet client will work with the following boards:
//   - Ethernet FeatherWing -> https://www.adafruit.com/products/3201

// uncomment the following two lines for ethernet,
// and comment out the AdafruitIO_WiFi client in the WIFI section
// #include "AdafruitIO_Ethernet.h"
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);

papakujawa
 
Posts: 8
Joined: Mon Jan 13, 2020 2:14 am

Re: AIO_CONNECT_FAILED

by brubell on Tue Jan 28, 2020 11:14 am

Could you try running the adafruitio_00_publish example located in Arduino -> File -> Examples -> Adafruit IO?

brubell
 
Posts: 745
Joined: Fri Jul 17, 2015 10:33 pm

Re: AIO_CONNECT_FAILED

by papakujawa on Tue Jan 28, 2020 2:08 pm

No connection to the IO site when running the 00_publish code.

Serial output:

Connecting to Adafruit IOAdafruitIO_WINC1500
AdafruitIO_WINC1500.h - networkStatus(): 255
AIO_NET_DISCONNECTED
AdafruitIO::status() - net_status_t: 1.AdafruitIO_WINC1500.h - networkStatus(): 255
AIO_NET_DISCONNECTED
AdafruitIO::status() - net_status_t: 1.AdafruitIO_WINC1500.h - networkStatus(): 255
AIO_NET_DISCONNECTED
AdafruitIO::status() - net_status_t: 1.AdafruitIO_WINC1500.h - networkStatus(): 255
AIO_NET_DISCONNECTED
AdafruitIO::status() - net_status_t: 1.AdafruitIO_WINC1500.h - networkStatus(): 255
AIO_NET_DISCONNECTED
AdafruitIO::status() - net_status_t: 1.AdafruitIO_WINC1500.h - networkStatus(): 255
AIO_NET_DISCONNECTED
AdafruitIO::status() - net_status_t: 1.AdafruitIO_WINC1500.h - networkStatus(): 255

papakujawa
 
Posts: 8
Joined: Mon Jan 13, 2020 2:14 am

Re: AIO_CONNECT_FAILED

by brubell on Wed Jan 29, 2020 11:12 am

Assuming you're using the WINC1500 WiFi Shield, have you added the Adafruit IO SSL Certificate to your Winc1500 module:
https://learn.adafruit.com/adafruit-win ... rtificates

brubell
 
Posts: 745
Joined: Fri Jul 17, 2015 10:33 pm

Re: AIO_CONNECT_FAILED

by papakujawa on Wed Jan 29, 2020 1:23 pm

Yes, tried updating twice just to be sure.
Still not connecting.
What else might I have forgotten to do?

Added modified code snippets for printing status.


[img]
Upload1.png
[/img]
Upload2.png
Upload2.png (89.7 KiB) Viewed 73 times

[img]
Upload3.png
[/img]


Code: Select all | TOGGLE FULL SIZE
[  /**************************************************************************/
  /*!
      @brief    Connect the wifi network.
      @return   none
  */
  /**************************************************************************/
  void _connect() {
Serial.println("AdafruitIO_WINC1500");
    if (strlen(_ssid) == 0) {
      _status = AIO_SSID_INVALID;
    } else {
      _disconnect();
      WiFi.setPins(_winc_cs, _winc_irq, _winc_rst, _winc_en);

      // no shield? bail
      if (WiFi.status() == WL_NO_SHIELD) {
        AIO_DEBUG_PRINTLN("No WINC1500 Module Detected!");
        return;
      }

      WiFi.begin(_ssid, _pass);
      _status = AIO_NET_DISCONNECTED;
    }
  }/code]


[code]  /**************************************************************************/
  /*!
      @brief    Network status check.
      @return   An AIO network status value. Lower values represent poorer
     connection status.
  */
  /**************************************************************************/
  aio_status_t networkStatus() {
Serial.print("AdafruitIO_WINC1500.h - networkStatus(): ");
Serial.println(WiFi.status());
    switch (WiFi.status()) {
    case WL_CONNECTED:
Serial.println("WL_CONNECTED");
      return AIO_NET_CONNECTED;
    case WL_CONNECT_FAILED:
Serial.println("WL_CONNECT_FAILED");
      return AIO_NET_CONNECT_FAILED;
    case WL_IDLE_STATUS:
Serial.println("WL_IDLE_STATUS");
      return AIO_IDLE;
    default:
Serial.println("AIO_NET_DISCONNECTED");
      return AIO_NET_DISCONNECTED;
    }
  }[/code]


[code]/**************************************************************************/
/*!
    @brief    Status check.
    @return   An AIO status value. Lower values represent poorer connection
              status.
*/
/**************************************************************************/
aio_status_t AdafruitIO::status() {
  aio_status_t net_status = networkStatus();
Serial.print("AdafruitIO::status() - net_status_t: ");
Serial.print(net_status);

  // if we aren't connected, return network status
  if (net_status != AIO_NET_CONNECTED) {
    _status = net_status;
    return _status;
  }

  // check mqtt status and return
  _status = mqttStatus();
  return _status;
}
Attachments
Upload3.png
Upload3.png (130.29 KiB) Viewed 73 times
Upload1.png
Upload1.png (294.83 KiB) Viewed 73 times

papakujawa
 
Posts: 8
Joined: Mon Jan 13, 2020 2:14 am

Re: AIO_CONNECT_FAILED

by papakujawa on Wed Jan 29, 2020 11:38 pm

Turned on the internal debug option in AdafruitIO_Definitions.h:

[code// Uncomment/comment to turn on/off debug output messages.
#define AIO_DEBUG
// Uncomment/comment to turn on/off error output
#define AIO_ERROR][/code]

New message: "No WINC1500 Module Detected!"

Connecting to Adafruit IOAdafruitIO::connect()
AdafruitIO_WINC1500
No WINC1500 Module Detected!
AdafruitIO_WINC1500.h - networkStatus(): 255
AIO_NET_DISCONNECTED

What does this error message indicate?

papakujawa
 
Posts: 8
Joined: Mon Jan 13, 2020 2:14 am

Re: AIO_CONNECT_FAILED

by papakujawa on Thu Jan 30, 2020 12:54 am

FOUND IT! (sort of)

The default pin definitions ( see Serial.print status listing below) do not match up with the actual pins on the Metro M0 Express.
The code snippet corrects the pin definitions and the connection and data upload to Adafruit IO is now working.

What is the correct way to specify these pins in the examples?

Code: Select all | TOGGLE FULL SIZE
  void _connect() {
int8_t cs = 10;
int8_t irq = 7;
int8_t rst = 5;
int8_t en = -1;
Serial.println("AdafruitIO_WINC1500");
    if (strlen(_ssid) == 0) {
      _status = AIO_SSID_INVALID;
    } else {
      _disconnect();
Serial.print("_winc_cs: ");
Serial.println(_winc_cs);
Serial.print("_winc_irq: ");
Serial.println(_winc_irq);
Serial.print("_winc_rst: ");
Serial.println(_winc_rst);
Serial.print("_winc_en: ");
Serial.println(_winc_en);
      // WiFi.setPins(_winc_cs, _winc_irq, _winc_rst, _winc_en);
WiFi.setPins(cs, irq, rst, en);




Connecting to Adafruit IOAdafruitIO::connect()
AdafruitIO_WINC1500
_winc_cs: 8
_winc_irq: 7
_winc_rst: 4
_winc_en: 2
AdafruitIO_WINC1500.h - networkStatus(): 3
WL_CONNECTED
AdafruitIO::status() - net_status_t: 20
Adafruit IO connected.
AdafruitIO::run
AdafruitIO_WINC1500.h - networkStatus(): 3
WL_CONNECTED

papakujawa
 
Posts: 8
Joined: Mon Jan 13, 2020 2:14 am

Re: AIO_CONNECT_FAILED

by papakujawa on Thu Jan 30, 2020 5:08 pm

Where the defaults are set: src/wifi/AdafruitIO_WINC1500.h

Code: Select all | TOGGLE FULL SIZE
  AdafruitIO_WINC1500(const char *user, const char *key, const char *ssid,
                      const char *pass, int winc_cs = 8, int winc_irq = 7,
                      int winc_rst = 4, int winc_en = 2)
      : AdafruitIO(user, key) {
    _winc_cs = winc_cs;
    _winc_irq = winc_irq;
    _winc_rst = winc_rst;
    _winc_en = winc_en;
    _ssid = ssid;
    _pass = pass;
    _mqtt_client = new WiFiSSLClient;
    _mqtt = new Adafruit_MQTT_Client(_mqtt_client, _host, _mqtt_port);
    _http_client = new WiFiSSLClient;
    _http = new HttpClient(*_http_client, _host, _http_port);
  }

papakujawa
 
Posts: 8
Joined: Mon Jan 13, 2020 2:14 am

Please be positive and constructive with your questions and comments.