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.
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.
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.
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 ?
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.
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.