Remote Relay Control With TI CC3200

This post will cover how to control two relays remotely from the Internet. This kind of project will allow you to easily turn on and off a light from the internet, open a garage door, open/close blinds, and so on. This This is a very easy project that can be done with a few lines of codes. Will help to know how to define input parameters to the device.

Hardware

In this sample project it is used a Texas Instrument CC3200 board for controlling the relays from the Internet. This chip integrates both the MCU and the Wireless capabilities, similar to the widely known ESP8266. You can use any other MCU as the code for controlling the relays will be exactly the same. The relays are generic ones that can switch up to 10A 250VAC. The relays are connected to pin 5 and 6 of the board, that appears as P61 and P59 in the silk screen. VCC from relays board is connected to 5V near to SW3 button. Check this picture for the pinout reference.

Software

For programming the CC3200 board easily it is required the Energia IDE (0101E0016 as of this writing). Notice that you need to set some jumpers in the board to be able to program it directly from the IDE. Checkout this page for reference. For more information about using this board with the Energia IDE, please visit this other page.

It is also required to install the thinger.io libraries in the Energia libraries folder (normally located under your Documents folder). You can take a look on how to install the libraries for Arduino in this link, but Energia is a bit outdated, so you will need to do it manually. Please, download the source code library from Github, after decompressed rename the library folder name to thinger. Then enter in the thinger folder and copy all the contents located in the subfolder src into the parent directory. You can delete the src subfolder. Now copy the whole thinger folder in your Energia libraries. These steps are required as Energia does not support the latest Arduino library structures.

Picture

Energia Sketch

#include <WiFi.h>
#include <ThingerWifi.h>

#define USERNAME "your_username"
#define DEVICE_ID "your_device_id"
#define DEVICE_CREDENTIAL "your_device_credential"

#define SSID "your_wifi_ssid"
#define SSID_PASSWORD "your_wifi_password"

#define RELAY_1 5
#define RELAY_2 6

ThingerWifi thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);

void setup() {
    pinMode(RELAY_1, OUTPUT);
    pinMode(RELAY_2, OUTPUT);
    
    thing.add_wifi(SSID, SSID_PASSWORD);

    thing["relay_1"] << [](pson& in){
      digitalWrite(RELAY_1, in ? HIGH : LOW);
    };
    
    thing["relay_2"] << [](pson& in){
      digitalWrite(RELAY_2, in ? HIGH : LOW);
    };
}

void loop() {
  thing.handle();
}

Web Control

Once you enter in your device API you will see two different resources for controlling your relays, which are relay_1 and relay_2. You can open this resources and swith the on/off button and click on Run to set the relays states

Sample Video

1 Like

great tutorial.

But when I create a dashboard widget with an on and of state the switch is keeping switing on. It seems that the state is not saved when I click on the on and off button.

The API works when testing. I can switch between on and off through the API. But the dashboard on/off switch keeps automatically swithing to the left. (the right position is not saved).

Do you have any ideas?

Hi! Yes! Try the new examples that are present in the 2.2 library. Something like:

thing["relay"] << digitalPin(2);

Instead the code shown in the example. This will show and keep the current state in the dashboard.

1 Like

Hi,
I’m trying to connect my CC3200 with thinger.io portal to see device connected in device dashboard.
I use Energia 17 and latest CC3200 service pack (CC3100_CC3200_ServicePack_1.0.1.6-2.6.0.5).

When I run example “Remote Relay Control With TI CC3200”, program start but nothing happened in thinger.io portal device dashboard. User_name, device_ID and device_credential should be OK in thinger.io portal and Energia sketch.

Is it possible that I had to open any ports in my router to connect with thinger.io portal?
Connection to router with Energia “ConnectWithWPA” example works fine.

Thanks for any suggestions.
Miha

Hi, try enabling the DEBUG output to see what is happening. Take a look to this section:

http://docs.thinger.io/arduino/#coding-enabling-debug-output

Hi!

With debugger I found problem. Wrong User name:)
Thanks for hint!

Now I can connect and star developing.

Great! Good to know! :slight_smile:

hello !! can you please explain me how i can to upload data (voltage and frequency) frome CC2300 to dashboard ?

from where i can get these OR what should i write in these places -USERNAME, DEVICE_ID, DEVICE_CREDENTIAL

Hi @Aman_Kumar, these are just values from your account:

USERNAME- The user id used to register in the platform (appears at the top right on the console)
DEVICE_ID- A device you manually register in the console
DEVICE_CREDENTIAL- The “password” used while registering the device.

Best

Alvarolb, at the top right on the console appears the email address and not the user id. As a matter of fact I wasn’t able to find out where the user id appears anywhere on the site…

Can you provide me an screenshot of your console? It should show the email address.

@alvarolb You are right it does show my email address but in your post you said “USERNAME- The user id used to register in the platform (appears at the top right on the console)”. I was calling your attention to the fact that, in my view, this is not correct. Moreover if for some reason you don’t remember your real USERNAME (which, again, is not your email address) it seems there is no easy way to recover it from the profile. Please tell me where am I lost. Thanks and regards

Hi,
Please help me in resolving this ThingerWifi.h error:

Hi,

It seems as if the thinger.io library is not correctly installed in the environment, check if it is correctly installed and try again.

Regards.

This seems to be the Arduino IDE version for Energia… Not sure how it evolved along time (does it has library manager?), but at least, as @ega suggests, you should download and install the Thinger.io library.

Thanks a lot @ega and @alvarolb i correctly installed thinger.io but I have this new error on board:

Hi,

I don’t see any specific error that could help me finding what could be causing the issue that is avoiding the successful finish of compilation process, I just see that there is a compilation error, take a moment to see what you are posting, I recommend you to copy the error message and post it as code, in this case a print screen is not so helpful for us, help us to help you.

On other hand I’ve seen that the last Energia IDE was released in 2019, I honestly don’t know if the libraries are backwards compatible with this development environment (at least the lastest versions), and if this is the issue, either know if the last version compatible with the IDE, is compatible with the actual platform version, I hope had explained myself.

But let’s empty the options, paste the error (as code) to see what’s going on.

Regards.

Thanks @ega here is the code being run:
#include <WiFi.h>
#include <ThingerWifi.h>
#include “arduino_secrets.h”

ThingerWifi thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);

void setup() {
// set the boards led to output
pinMode(RED_LED, OUTPUT);
pinMode(GREEN_LED, OUTPUT);
pinMode(YELLOW_LED, OUTPUT);

// configure wifi network
thing.add_wifi(SSID, SSID_PASSWORD);

// pin control example (i.e. turning on/off a light, a relay, etc)
thing[“led”][“green”] << digitalPin(GREEN_LED);
thing[“led”][“yellow”] << digitalPin(YELLOW_LED);
thing[“led”][“red”] << digitalPin(RED_LED);

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

// more details at ARDUINO - Thinger.io Documentation
}

void loop() {
thing.handle();
}

Here is the error message:

Energia: 1.8.11E23 (Windows 10), Board: “CC3200-LAUNCHXL (80MHz)”

:0:15: warning: ISO C99 requires whitespace after the macro name [enabled by default]

In file included from C:\Users\26096\Downloads\Compressed\energia-1.8.10E23\libraries\thinger/ThingerWifi.h:27:0,

             from C:\Users\26096\Downloads\Compressed\energia-1.8.10E23\libraries\thinger\examples\EnergiaCC3200\EnergiaCC3200.ino:2:

C:\Users\26096\Downloads\Compressed\energia-1.8.10E23\libraries\thinger/ThingerClient.h: In member function ‘virtual void ThingerClient::run_reboot()’:

C:\Users\26096\Downloads\Compressed\energia-1.8.10E23\libraries\thinger/ThingerClient.h:346:26: error: ‘NVIC_SystemReset’ was not declared in this scope

     NVIC_SystemReset();

                      ^

Multiple libraries were found for “WiFi.h”
Used: C:\Users\26096\AppData\Local\Energia15\packages\energia\hardware\cc3200\1.0.3\libraries\WiFi
Multiple libraries were found for “ThingerWifi.h”
Used: C:\Users\26096\Downloads\Compressed\energia-1.8.10E23\libraries\thinger
exit status 1
Error compiling for board CC3200-LAUNCHXL (80MHz).

This report would have more information with
“Show verbose output during compilation”
option enabled in File → Preferences.

Hi @Macwilliams, it seems that the board and its libraries does not have implemented the NVIC_SystemReset for rebooting the board. Please, modify the file ThingerClient.h from the thinger.io library and keep the run_reboot method empty:

virtual void run_reboot(){
}

Will check the proper way to reboot this board.