Black Lives Matter - Action and Equality. ... Adafruit is open and shipping.
0

Adafruit IO connectivity problems
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.

Adafruit IO connectivity problems

by Riseley on Wed Jan 27, 2016 11:49 pm

I am a newbie and am trying to set an internet of things dashboard with a light sensor per the instructions on your website and seem to be having connection problems as outlined below:

Hello, CC3000!MAC Address : 0x70 0xFF 0x76 0x02 0xE9 0x7D
Deleting old connection profiles
Attempting to connect to NETGEAR11
Hello, CC3000!

Initialising the CC3000 ...
Firmware V. : 1.24
MAC Address : 0x70 0xFF 0x76 0x02 0xE9 0x7D

Deleting old connection profiles

Attempting to connect to NETGEAR11
Connected!
Request DHCP

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

I am using Uno 1.6.5 and have successfully executed the following sketches: buildtest, WebClient, ntp Test, GeoLocation,

My sketch is outlined below:
// Required libraries
#include <Adafruit_CC3000.h>
#include <ccspi.h>
#include <SPI.h>
#include <PubSubClient.h>


// 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 "NETGEAR11"
#define WLAN_PASS "XXXXXXX"
#define WLAN_SECURITY WLAN_SEC_WPA2

// Username & AIO key
#define ADAFRUIT_USERNAME "XXXXX"
#define AIO_KEY "My key"


// Path for sensors
#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);
Serial.println(F("Hello, CC3000!\n"));


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 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"));
}

}



Any advice will be much appreciated.

Riseley
 
Posts: 1
Joined: Mon Jan 25, 2016 11:33 pm

Re: Adafruit IO connectivity problems

by thermalhound on Mon Feb 01, 2016 7:19 am

Hi there.

Not sure I can be of much help, I'm having problems connecting to AIO myself, however I did notice that you have gone a slightly different route to me that I am now going to try.

I am using the adafruit mqtt library to connect but am going to swap over to the pubsub client that you have used.

When looking at your code I noticed that you have called
Code: Select all | TOGGLE FULL SIZE
mqttclient.connect(client_name, AIO_KEY, NULL)

It may be worth trying something along the lines of
Code: Select all | TOGGLE FULL SIZE
mqttclient.connect(client_name, ADAFRUIT_USERNAME, AIO_KEY)

If I have any success with this I'll post my code up later

thermalhound
 
Posts: 2
Joined: Sun Jan 31, 2016 7:52 pm

Re: Adafruit IO connectivity problems

by adamp2 on Fri Feb 26, 2016 1:26 am

Yes, I am having the same problem.
Has anyone been successful with this sketch?

Serial Monitor:

Hello, CC3000!


Initialising the CC3000 ...
Firmware V. : 1.24
MAC Address : 0x08 0x00 0x28 0x57 0x9A 0x2D

Deleting old connection profiles

Attempting to connect to My Network
Connected!
Request DHCP

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

The Sketch:

adafruit_io_sensors

// DHT sensor
#define DHTPIN 7 // what pin we're connected to
#define DHTTYPE DHT22 // DHT 22
DHT dht(DHTPIN, DHTTYPE);

// Light level sensor
#define LIGHT_SENSOR_PIN A0 //might need to change name to AMBIENT_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 "My Network"
#define WLAN_PASS "**************"
#define WLAN_SECURITY WLAN_SEC_WPA2

// Username & AIO key
#define ADAFRUIT_USERNAME "My Username"
#define AIO_KEY "My Key"

// Path for sensors
#define AIR_TEMPERATURE_PUBLISH_PATH "api/feeds/air_temperature/data/send.json" //made change to reflect path designated in dashboard
#define HUMIDITY_PUBLISH_PATH "api/feeds/humidity/data/send.json"
#define AMBIENT_LIGHT_SENSOR_PUBLISH_PATH "api/feeds/ambient_light_sensor/data/send.json" //made change to reflect path designated in dashboard

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

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

void setup(void)
{
Serial.begin(115200);
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 ambient light
float light_level_reading = analogRead(LIGHT_SENSOR_PIN);
int light_level = (int)(light_level_reading/1024.*100.);

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

// Publish data on Adafruit.io
mqttclient.publish(AIR_TEMPERATURE_PUBLISH_PATH, (char *) String(t).c_str()); //made change to reflect path designated in dashboard
delay(2000);
mqttclient.publish(HUMIDITY_PUBLISH_PATH, (char *) String(h).c_str());
delay(2000);
mqttclient.publish(AMBIENT_LIGHT_SENSOR_PUBLISH_PATH, (char *) String(light_level).c_str()); //made change to reflect path designated in dashboard
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"));
}

}

adamp2
 
Posts: 1
Joined: Tue Dec 10, 2013 11:58 pm

Please be positive and constructive with your questions and comments.