How To: Use Thingspeak Talkback Commands with the Arduino Uno Wifi | ThingSpeak Apps | Forum

Avatar

Please consider registering
Guest

Search

— Forum Scope —






— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

Register Lost password?
sp_Feed sp_TopicIcon
How To: Use Thingspeak Talkback Commands with the Arduino Uno Wifi
Avatar
vdcmclou
New Member
Forum Posts: 1
sp_UserOfflineSmall Offline
1
February 7, 2017 - 10:14 am
sp_Permalink sp_Print

Hello,

I am trying to set up a TalkBack command to be sent regularly to my Arduino Uno Wifi (this board). Essentially, what I want to do is sent an email at regularly scheduled intervals, and was planning to use commands sent from the TalkBack app to trigger this command in my board. However, I am having some trouble with my board interpreting the TalkBack Commands. Every time I try and read from the api link, it comes out as a stream of garbage. I have checked my baud rate, and made sure that is correct. I only output garbage when I try and print the data I read in from the site. 

 

I am using this code I modified from the Arduino Yun tutorial, but I am unsure if it is otherwise correct. Currently it does not send an email, and I am just checking if the TalkBack command is being interpreted. It gets stuck in the client.available loop where it prints the garbage data it reads in from the talkback URL. Does anyone have any idea where I am going wrong? Thank you in advance for your help. 

#include "Bridge.h"
#include "HttpClient.h"
#include <Ciao.h>

//ThingSpeak Settings
String thingSpeakAPI = "api.thingspeak.com";
String talkBackAPIKey = "LSIOPWA0LQA6GDBT";
String talkBackID = "13350";
const int checkTalkBackInterval = 15 * 1000; // Time interval in milliseconds to check TalkBack (number of seconds * 1000 = interval)

// Variable Setup
long lastConnectionTime = 0;

void setup()
{
// Setup On-board LED
pinMode(13, OUTPUT);
digitalWrite(13, LOW);
delay(1000);
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);

// Initialize Bridge
// Bridge.begin();

// Initialize Serial
Serial.begin(9600);
// while(!Serial);
}

void checkTalkBack()
{

HttpClient client;

String talkBackCommand;
char charIn;
String talkBackURL = "http://" + thingSpeakAPI + "/talkbacks/" + talkBackID + "/commands/execute?api_key=" + talkBackAPIKey;
Serial.println(talkBackURL);
// Make a HTTP GET request to the TalkBack API:
client.get(talkBackURL);

while(client.available()) {
charIn = client.read();
talkBackCommand += charIn;
Serial.println(talkBackCommand);
delay(1000);
}

// Turn On/Off the On-board LED
if (talkBackCommand == "Off")
{
Serial.println("Succes");
Serial.println(talkBackCommand);
digitalWrite(13, HIGH);
}
else if (talkBackCommand == "TURN_OFF")
{
Serial.println("Fail");
Serial.println(talkBackCommand);
digitalWrite(13, LOW);
}

// Serial.flush();
delay(1000);
}

void loop()
{
// Check ThingSpeak for TalkBack Commands
checkTalkBack();
delay(checkTalkBackInterval);
}

Avatar
rw950431

Forum Posts: 252
sp_UserOfflineSmall Offline
2
February 7, 2017 - 6:17 pm
sp_Permalink sp_Print

Perhaps part of the problem is that you are re-printing the whole string every time you add a new character so if the talkback response is "abc" your code will print 

a

ab

abc

Suggest something like  (based on the Arduino HTTPClient docco)

while(client.available()) {
   charIn = client.read();
   talkBackCommand += charIn;
}

Serial.println(talkBackCommand);

Forum Timezone: America/New_York

Most Users Ever Online: 114

Currently Online: jacktheripper125, pudderz
24 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 252

Vinod: 164

cstapels: 96

piajola: 75

vespapierre: 63

Adarsh_Murthy: 59

Newest Members:

bbruno22

pudderz

Utkya

Poornak26

LindasHed

reddysiva

Forum Stats:

Groups: 4

Forums: 17

Topics: 1313

Posts: 4565

 

Member Stats:

Guest Posters: 1

Members: 5703

Moderators: 0

Admins: 2

Administrators: Hans, lee