Remote Relay Control With TI CC3200


#1

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


#2

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?


#3

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.


#4

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


#5

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


#6

Hi!

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

Now I can connect and star developing.


#7

Great! Good to know! :slight_smile:


#8

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


#9

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


#10

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