Adafruit CC3000 Basics How to connect to Wifi

Hi,

My aim is to get a simple on/off button on my Mega256 to turn an LED on or off on my dashboard. Basically a “hello world” so I can get to grips with this.

I have followed some tutorials but no luck.

First problem is that at this stage on the tutorial it shows my Device State as “Disconnected”

To try to diagnose I wanted to see if my Mega had successfully connected to wifi etc, but I cant see how to show that.
When using the CC3000 library I could run “while (! displayConnectionDetails())” and that would display My IP etc.
Any ideas how to do that bit and also suggestions on why its not connecting.

#include <Adafruit_CC3000.h>
#include <SPI.h>
#include <ccspi.h>
#include <ThingerCC3000.h>

#define USERNAME “Usernamehere”
#define DEVICE_ID “IPCS”
#define DEVICE_CREDENTIAL “*************”

#define SSID “my ssid”
#define SSID_PASSWORD “my password”

ThingerCC3000 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);

void setup() {
Serial.begin(115200);
Serial.println(F(“Hello!\n”));
// configure wifi network

thing.add_wifi(SSID, SSID_PASSWORD);
Serial.println(F(“After Wifi!\n”));

pinMode(13, OUTPUT);
thing[“D0”] << digitalPin(13);
Serial.println(F(“After thing D0\n”));

}

void loop() {
thing.handle();
// thing.stream(thing[“led”]);
}

Hi,
Add the next line of code at the begining of the sketch

#define _DEBUG_

it should show at the serial console the message what’s going on with the connection.

And please when you show us a code, after you paste it, select all and press the button “</>” in the menu, to set it as preformatted text, because it is easier to read it in that way.

Hope this helps.

Hi,
Thanks. Added that but output shows the following.
With no extra info

01:09:23.564 -> Hello!
01:09:23.564 ->
01:09:23.564 -> After Wifi!
01:09:23.564 ->
01:09:23.564 -> After thing D0
01:09:23.564 ->

#include <Adafruit_CC3000.h>
#include <SPI.h>
#include <ccspi.h>
#include <ThingerCC3000.h>

#define USERNAME “Usernamehere”
#define DEVICE_ID “IPCS”
#define DEVICE_CREDENTIAL “*************”

#define SSID “my ssid”
#define SSID_PASSWORD “my password”

ThingerCC3000 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);

void setup() {
Serial.begin(115200);
Serial.println(F(“Hello!\n”));
// configure wifi network

thing.add_wifi(SSID, SSID_PASSWORD);
Serial.println(F(“After Wifi!\n”));

pinMode(13, OUTPUT);
thing[“D0”] << digitalPin(13);
Serial.println(F(“After thing D0\n”));

}

void loop() {
thing.handle();
// thing.stream(thing[“led”]);
}

You should add it at the very first line of the sketch, and it should show at the serial console the debugging messages.

Ok Thanks that made huge difference.
I am now seeing
Starting connection…
00:48:35.675 -> [NETWORK] CC3000 initialized!
00:48:35.777 -> [NETWORK] Connecting to network My Wifi
00:49:12.148 -> [NETWORK] Getting IP Address…
00:49:12.148 -> [NETWORK] Connected!
00:49:12.148 -> [_SOCKET] Connecting to iot.thinger.io:25200
00:49:12.148 -> [_SOCKET] Using secure TLS/SSL connection: no
00:49:12.148 -> [_SOCKET] Error while connecting!

But after a few attempts it does connect and now I see connected on my device.
I do get this with my cc3000 it takes a few attempts to connect. Not sure if it needs dedicated psu or the likes. The Wifi AP is 1 meter from the CC3000 so no weak signal etc.

After several attempts the following occurs and now it connects.

Next Step getting an LED on my dashboard to go green or red depending on what I send.

0:52:30.005 -> [_SOCKET] Connecting to iot.thinger.io:25200
00:52:30.005 -> [_SOCKET] Using secure TLS/SSL connection: no
00:52:30.140 -> [_SOCKET] Connected!
00:52:30.140 -> [THINGER] Authenticating. User: SpyderManGib Device: IPCS
00:52:30.140 -> [THINGER] Writing bytes: 41 [OK]
00:52:30.240 -> [THINGER] Authenticated
00:52:30.273 -> [THINGER] Writing bytes: 2 [OK]
00:52:30.341 -> [THINGER] Available bytes: 1

Well at least it is connecting! not sure why the device doesn’t connects so effectively, but it is a particular situation, not with the cloud.

Any aditional doubt you may have, you know what to do :wink:

Regards.

Ok, I have the dashboard widget on off switch changing my on board led on and off.
Now I cant get the same happening the other way.
I now want to turn a led widget on the dashboard on and off depending on what happens on the board.
for example, when I turn switch on the dashboard I want the led on the dashboard to also come on to show me the led on the arduino is on or off.
Any tips ?

#define _DEBUG_
#include <Adafruit_CC3000.h>
#include <SPI.h>
#include <ccspi.h>
#include <ThingerCC3000.h>
#define USERNAME "SpyderManGib"
#define DEVICE_ID "IPCS"
#define DEVICE_CREDENTIAL "sdfsdfsdfs!"

#define SSID "sdfs"
#define SSID_PASSWORD "sddfegete"

ThingerCC3000 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);
int myVar1 = 0;

void setup() {
  Serial.begin(115200);
  Serial.println(F("Hello!\n"));
  // configure wifi network
   
  thing.add_wifi(SSID, SSID_PASSWORD);


  pinMode(LED_BUILTIN, OUTPUT);
  thing["D0"] << digitalPin(LED_BUILTIN);
  //thing["led"] >> outputValue((LED_BUILTIN));
  Serial.println(LED_BUILTIN);

 //;thing["led1"] >> [](pson& out){
 //   out = "0";
 //};
 
 // pinMode(2, OUTPUT);

  // pin control example (i.e. turning on/off a light, a relay, etc)
 // thing["led"] << digitalPin(2);

  // resource output example (i.e. reading a sensor value, a variable, etc)
  // thing["D0"] >> outputValue(millis());

  // more details at http://docs.thinger.io/arduino/
}

void loop() {
  thing.handle();
    thing["led"] >> outputValue((LED_BUILTIN));
  // thing.stream(thing["D0"]);
  }

Yes sure, with the led indicator widget, check this post:

Any aditional doubt, you know what to do :wink:

Even you may define an output resource like this:

thing["Led"] >> outputValue(digitalRead(LED_PIN));

To feed exclusively the widget, so you basically will have a feedback of the status.

Hi,
Thanks for your continued help. I hope once I get this working it will help others getting basic widgets working in either direction.

The on off working fine
The led widget no go.
The serial montior shows the digitalRead(LED_BUILTIN) working fine as it scrolls 0,1 depending on my OnOff widget. but I cant get my led widget to change.
Code and widgets shown.
Any ideas ?

#define _DEBUG_
#include <Adafruit_CC3000.h>
#include <SPI.h>
#include <ccspi.h>
#include <ThingerCC3000.h>
#define USERNAME "SpyderManGib"
#define DEVICE_ID "IPCS"
#define DEVICE_CREDENTIAL "345345345"

#define SSID "My Wifi"
#define SSID_PASSWORD "My Password"

ThingerCC3000 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);

void setup() {
  Serial.begin(115200);
  Serial.println(F("Hello!\n"));
  // configure wifi network
   
  thing.add_wifi(SSID, SSID_PASSWORD);


  pinMode(LED_BUILTIN, OUTPUT);
  thing["D0"] << digitalPin(LED_BUILTIN); // take input from onnoff widget
  thing["led"] >> outputValue((digitalRead(LED_BUILTIN))); // send to led widget


}

void loop() {
  thing.handle();
  thing["led"] >> outputValue((digitalRead(LED_BUILTIN))); / not sure if we need this here
    Serial.println((digitalRead(LED_BUILTIN))); // show status on serial monitor
  }

Change the “Stream by device” and set it to be polled, for example, every 3 seconds.

The stream by device mode works by coding in the device to exclusively stream a value, I mean in the loop, you need to write when do you want to send the value.

Oh by the way

Not at all, we don’t need this here :wink:

Hi,

You my friend are awesome.

That worked a treat, led now turns on and off following the OnOff switch.

This now puts me in good standing to now receive and send more information etc.

Sometimes a very basic example is required to then build on.

Again thanks for your help.

Thanks a lot sir,

Of course you need to understand the basics to build awesome things on it.

Now that you know how to poll variables from the cloud to a device, I would recommend you how to stream values, in this case it could be more efficient, if you code the device to send the value just when detects a change, so the cloud wont be polling every amount of time without changes on the value.

Here you can find the code example:
https://docs.thinger.io/quick-sart/coding-guide#streaming-resource-data

the widget is adjusted as you previously did.

Hope this helps.