need help with Talk back, commands and fields
Show older comments
Hi,I try to control some relays thr TalkBack app.
Using ESP 8266.
Everything connecting to Internet.
I got stuck on how to activate relay. I used Key, used ID. I cant find how to send command thru TalkBack
I dont know what Command ID for, and how to send command string.
Need some help please
Also here is my code and some screenshots:
#include "ThingSpeak.h"
#include "ESP8266WiFi.h"
const char ssid[] = "XXX"; // your network SSID (name)
const char pass[] = "YYY"; // your network password
#define RELAY1 12
#define RELAY2 13
#define RELAY3 14
#define RELAY4 16
WiFiClient client;
//---------Channel Details---------//
unsigned long counterChannelNumber = 123; // Channel ID
const char * myCounterReadAPIKey = "ZZZ"; // Read API Key
const int FieldNumber1 = 1; // The field you wish to read
const int FieldNumber2 = 2; // The field you wish to read
const int FieldNumber3 = 3; // The field you wish to read
const int FieldNumber4 = 4; // The field you wish to read
//-------------------------------//
void setup()
{
Serial.begin(115200);
WiFi.mode(WIFI_STA);
ThingSpeak.begin(client);
}
void loop()
{
//----------------- Network -----------------//
if (WiFi.status() != WL_CONNECTED)
{
Serial.print("Connecting to ");
Serial.print(ssid);
Serial.println(" ....");
while (WiFi.status() != WL_CONNECTED)
{
WiFi.begin(ssid, pass);
delay(5000);
}
Serial.println("Connected to Wi-Fi Succesfully.");
}
//--------- End of Network connection--------//
//---------------- Channel 1 ----------------//
Serial.print("Reading field 1 ");
long R_Status = ThingSpeak.readLongField(counterChannelNumber, FieldNumber1, myCounterReadAPIKey);
int statusCode = ThingSpeak.getLastReadStatus();
if (statusCode == 200)
{
Serial.print("Read field 1 Successful ");
// Serial.println(temp);
}
else
{
Serial.println("Unable to read channel / No internet connection");
}
Serial.println(R_Status);
if(R_Status==1)
{
digitalWrite(RELAY1, HIGH); //Relay 1 ON
Serial.println("Relay 1 ON");
}
if(R_Status==2)
{
digitalWrite(RELAY1, LOW); //Relay 1 OFF
Serial.println("Relay 1 OFF");
}
Serial.print("Reading field 2 ");
delay(5000);
long R_Status2 = ThingSpeak.readLongField(counterChannelNumber, FieldNumber2, myCounterReadAPIKey);
int statusCode2 = ThingSpeak.getLastReadStatus();
if (statusCode2 == 200)
{
Serial.print("Read field 2 Successful ");
// Serial.println(temp);
}
else
{
Serial.println("Unable to read channel / No internet connection");
}
Serial.println(R_Status2);
if(R_Status2==1)
{
digitalWrite(RELAY2, HIGH); //Relay 2 ON
Serial.println("Relay 1 ON");
}
if(R_Status2==2)
{
digitalWrite(RELAY2, LOW); //Relay 2 OFF
Serial.println("Relay 1 OFF");
}
Serial.print("Reading field 3 ");
delay(5000);
long R_Status3 = ThingSpeak.readLongField(counterChannelNumber, FieldNumber3, myCounterReadAPIKey);
int statusCode3 = ThingSpeak.getLastReadStatus();
if (statusCode3 == 200)
{
Serial.print("Read field 3 Successful ");
// Serial.println(temp);
}
else
{
Serial.println("Unable to read channel / No internet connection");
}
Serial.println(R_Status3);
if(R_Status3==1)
{
digitalWrite(RELAY3, HIGH); //Relay 3 ON
Serial.println("Relay 3 ON");
}
if(R_Status3==2)
{
digitalWrite(RELAY3, LOW); //Relay 3 OFF
Serial.println("Relay 3 OFF");
}
Serial.print("Reading field 4 ");
delay(5000);
long R_Status4 = ThingSpeak.readLongField(counterChannelNumber, FieldNumber4, myCounterReadAPIKey);
int statusCode4 = ThingSpeak.getLastReadStatus();
if (statusCode4 == 200)
{
Serial.print("Read field 4 Successful ");
// Serial.println(temp);
}
else
{
Serial.println("Unable to read channel / No internet connection");
}
Serial.println(R_Status4);
if(R_Status4==1)
{
digitalWrite(RELAY4, HIGH); //Relay 4 ON
Serial.println("Relay 4 ON");
}
if(R_Status4==2)
{
digitalWrite(RELAY4, LOW); //Relay 4 OFF
Serial.println("Relay 4 OFF");
}
delay(10000); // ThingSpeak will only accept updates every 10 seconds.
}

Answers (2)
Have you taken a look at the Thingspeak examples? This one might be relevant to what you're trying to do:
6 Comments
Pavel Plotinnov
on 15 Feb 2020
Vinod
on 16 Feb 2020
Change that line to:
const char * myTalkBackKey = "API_KEY";
Where API_KEY is replaced with your key.
Pavel Plotinnov
on 16 Feb 2020
Vinod
on 17 Feb 2020
I think you may not be reading the error in the Arduino IDE "expected primary-expression before '<' token." Please fix that and tell me if you still see that error, or a different error.
Pavel Plotinnov
on 18 Feb 2020
Pavel Plotinnov
on 18 Feb 2020
Pavel Plotinnov
on 18 Feb 2020
0 votes
3 Comments
Vinod
on 18 Feb 2020
Please look at the help on the right side of the specific talkback page:
https://thingspeak.com/apps/talkbacks/<YOUR_TALKBACK_ID>
To execute a talkback command, you need to make a POST request to.
https://api.thingspeak.com/talkbacks/<YOUR_TALKBACK_ID>/commands/execute.json
I'd recommend trying this out with an app like postman
Pavel Plotinnov
on 19 Feb 2020
Vinod
on 19 Feb 2020
Please change GET to POST in postman.
Please refer to the help on the right side of the Talkback page.
Communities
More Answers in the ThingSpeak Community
Categories
Find more on Act on Data in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

