New ThingSpeak App: TalkBack! | 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
New ThingSpeak App: TalkBack!
Avatar
Hans
Natick, MA

Forum Posts: 390
sp_UserOfflineSmall Offline
1
January 21, 2014 - 6:19 pm
sp_Permalink sp_Print

We have developed a new ThingSpeak App and it is available now to all ThingSpeak Users.

The new TalkBack App allows devices to check ThingSpeak for commands to execute. TalkBack is perfect for battery-powered devices that need to sleep most of the time and wake up to see if there is anything to do and then go back to sleep, like a door lock for example. The lock is mostly going to be asleep to save battery power, but it can way up periodically and check TalkBack or be woken up by a button press to see if it should be opened or not.

Devices powered by ThingSpeak and now with TalkBack will be able to both push sensor data to the ThingSpeak Cloud and check TalkBack if any commands are available all in one request. To get started, we have the complete TalkBack API Documentation and an Arduino Yún Tutorial available now.

TalkBack API Documentation: https://thingspeak.com/docs/talkback

Arduino Yún Tutorial: http://community.thingspeak.com/tutorials/arduino/controlling-the-arduino-yun-with-talkback/

Avatar
regis44
New Member
Forum Posts: 1
sp_UserOfflineSmall Offline
2
January 25, 2014 - 12:35 pm
sp_Permalink sp_Print sp_EditHistory

Hello, first, thanks for your great job on ThingSpeak.

I succeeded turn off/on a led with talkbackCommand app and my Arduino Uno ethernet client mode by updating the Command String directly on ThingSpeak website.

Now I wish update the Command String with the APIs and a button scripted with html or php on an external personal website.

Could someone give me an example because I tried a lot of things without success like ? "PUT" method seem doesn't work with an html form.

Thanks for your help.

Régis.

My Arduino Uno code based on ThingSpeak tutorials (talkback commands must start with "_CMD_") :

/*----------------------------------------------------------------*/
#include "SPI.h"
#include "Ethernet.h"

byte mac[] = {0x--, 0x--, 0x--, 0x--, 0x--, 0x--};
const String channelsAPIKey = "--------------------------";
const String talkBackAPIKey = "--------------------------";
const String talkBackID = "--";
const String talkCommandID = "--";
const unsigned int getTalkBackInterval = 10 * 1000;
const unsigned int updateChannelsInterval = 15 * 1000;
String talkBackCommand;

const int RelayPin2 = 7;

long lastConnectionTimeChannels = 0;
boolean lastConnectedChannels = false;
int failedCounterChannels = 0;
long lastConnectionTimeTalkBack = 0;
boolean lastConnectedTalkBack = false;
int failedCounterTalkBack = 0;

// capteurs
float temperature = 0;
float humidity = 0;
float moisture = 0;

EthernetClient client;

void setup()
{
Serial.begin(9600);
pinMode(RelayPin2, OUTPUT);
digitalWrite(RelayPin2, HIGH);
startEthernet();
}

void loop()
{
temperature = (((float)analogRead(A0) * 100) / 1023);
humidity = (((float)analogRead(A1) * 100) / 1023);
moisture = (((float)analogRead(A2) * 100) / 1023);
getTalkBack();
updateChannels();
if(talkBackCommand == "LEDON") digitalWrite(RelayPin2, LOW);
if(talkBackCommand == "LEDOFF") digitalWrite(RelayPin2, HIGH);
}

void getTalkBack()
{
String tsData;
tsData=talkBackID+"/commands/"+talkCommandID+"?api_key="+talkBackAPIKey;
if((!client.connected() && (millis() - lastConnectionTimeTalkBack > getTalkBackInterval)))
{
if (client.connect("api.thingspeak.com", 80))
{
client.println("GET /talkbacks/"+tsData+" HTTP/1.0");
client.println();
lastConnectionTimeTalkBack = millis();
if (client.connected())
{
Serial.println("****************************************");
Serial.println("GET TalkBack command");
Serial.println();
Serial.println("Connecting to ThingSpeak...");
Serial.println();
Serial.println();
Serial.println("Server response ->");
Serial.println();
failedCounterTalkBack = 0;
talkBackCommand="";
while(client.connected() && !client.available()) delay(1); //waits for data
while (client.connected() || client.available())
{
char charIn = client.read();
Serial.print(charIn);
talkBackCommand += charIn;
}
talkBackCommand=talkBackCommand.substring(talkBackCommand.indexOf("_CMD_")+5);
Serial.println();
Serial.println();
Serial.println("...disconnected");
Serial.println();
Serial.println("-----------------------");
Serial.print("Command -> ");
Serial.println(talkBackCommand);
Serial.println("-----------------------");
Serial.println();
}
else
{
failedCounterTalkBack++;
Serial.println("Connection to ThingSpeak failed ("+String(failedCounterTalkBack, DEC)+")");
Serial.println();
lastConnectionTimeChannels = millis();
}
}
else
{
failedCounterTalkBack++;
Serial.println("Connection to ThingSpeak Failed ("+String(failedCounterTalkBack, DEC)+")");
Serial.println();
lastConnectionTimeTalkBack = millis();
}
}
if (failedCounterTalkBack > 3 ) {startEthernet();}
client.stop();
Serial.flush();
}

void updateChannels()
{
String tsData;
tsData="field1="+String(temperature, DEC)+"&field2="+String(humidity, DEC)+"&field3="+String(moisture, DEC);
if(!client.connected() && (millis() - lastConnectionTimeChannels > updateChannelsInterval))
{
if (client.connect("api.thingspeak.com", 80))
{
client.print("POST /update HTTP/1.1\n");
client.print("Host: api.thingspeak.com\n");
client.print("Connection: close\n");
client.print("X-THINGSPEAKAPIKEY: "+channelsAPIKey+"\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(tsData.length());
client.print("\n\n");
client.print(tsData);
lastConnectionTimeChannels = millis();
if (client.connected())
{
Serial.println("****************************************");
Serial.println("Uptade channels");
Serial.println();
Serial.println("Connecting to ThingSpeak...");
Serial.println();
Serial.println("Server response ->");
Serial.println();
failedCounterChannels = 0;
while(client.connected() && !client.available()) delay(1); //waits for data
while (client.connected() || client.available())
{
char charIn = client.read();
Serial.print(charIn);
}
Serial.println();
Serial.println();
Serial.println("...disconnected");
Serial.println();
}
else
{
failedCounterChannels++;
Serial.println("Connection to ThingSpeak failed ("+String(failedCounterChannels, DEC)+")");
Serial.println();
lastConnectionTimeChannels = millis();
}
}
else
{
failedCounterChannels++;
Serial.println("Connection to ThingSpeak Failed ("+String(failedCounterChannels, DEC)+")");
Serial.println();
lastConnectionTimeChannels = millis();
}
}
if (failedCounterChannels > 3 ) {startEthernet();}
client.stop();
Serial.flush();
}

void startEthernet()
{
client.stop();
Serial.println();
Serial.println();
Serial.println("****************************************");
Serial.println("Connecting Arduino to network...");
delay(1000);
if (Ethernet.begin(mac) == 0)
{
Serial.println("DHCP Failed, reset Arduino to try again");
Serial.println("****************************************");
Serial.println();
}
else
{
Serial.println("Arduino connected to network using DHCP");
Serial.println("****************************************");
Serial.println();
}
delay(1000);
}
/*----------------------------------------------------------------*/

Avatar
autoDood
New Member
Forum Posts: 3
sp_UserOfflineSmall Offline
3
March 14, 2014 - 11:44 pm
sp_Permalink sp_Print

Hey Regis!

Thanks for posting that, I haven't quite got it working yet but It's sue helped. I can't get the Uno with and Ethernet shield to Read my talkback commands, everything else works! I've tweaked the code slightly but the print.client seems to be reading my talkback... I see them (Kind of) in the serial monitor but they don't get applied to the talkBackCommand string for some reason, would you be able to do me a favour and explain what data you would put in the black areas in your code? Is this the code that works for you because I would love to get this working :)

Did you get your buttons working on your website? I can help you with some AJAX buttons if you like, using some HTTP requests that will work...

Here is my code...

/*—————————————————————-*/
#include "SPI.h"
#include "Ethernet.h"
#include "DHT.h"
#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0xC0, 0xDE };
const String channelsAPIKey = "3QCA1VSDZHEIYL2B";
const String talkBackAPIKey = "64V6QUYTP3ARBXEN";
const String talkBackID = "213";
char charIn;
String talkBackCommand;
const String talkCommandID = "";
const unsigned int getTalkBackInterval = 10 * 1000;
const unsigned int updateChannelsInterval = 15 * 1000;
const int RelayPin2 = 13;
long lastConnectionTimeChannels = 0;
boolean lastConnectedChannels = false;
int failedCounterChannels = 0;
long lastConnectionTimeTalkBack = 0;
boolean lastConnectedTalkBack = false;
int failedCounterTalkBack = 0;
// capteurs
EthernetClient client;
void setup()
{
Serial.begin(9600);
dht.begin();
pinMode(RelayPin2, OUTPUT);
digitalWrite(RelayPin2, HIGH);
startEthernet();
}

void loop()
{

getTalkBack();
updateChannels();

//-------------------------------------------

if(talkBackCommand == "LEDOFF")
{
digitalWrite(RelayPin2, LOW);
Serial.println("OFF");
}

if(talkBackCommand == "LEDON")
{
digitalWrite(RelayPin2, HIGH);
Serial.println("ON");
}

//--------------------------------------------

}

//-----------------------------------

void getTalkBack(){

// This section I had to change --->

String tsData;
tsData=talkBackID + "/commands/execute?api_key=" + talkBackAPIKey;
if((!client.connected() && (millis() - lastConnectionTimeTalkBack > getTalkBackInterval)))
{
if (client.connect("api.thingspeak.com", 80))
{
client.println("GET /talkbacks/"+tsData+" HTTP/1.0");
client.println();
lastConnectionTimeTalkBack = millis();
if (client.connected())
{
Serial.println("---------------------------------------");
Serial.println("GET TalkBack command");
Serial.println();
Serial.println("Connecting to ThingSpeak");
Serial.println();
Serial.println();
Serial.println("Server response");
Serial.println();
failedCounterTalkBack = 0;

while(client.connected() && !client.available()) delay(2000); //waits for data
while (client.connected() || client.available())
{
char charIn = client.read();
talkBackCommand += charIn;
Serial.print(charIn);
}

talkBackCommand = talkBackCommand.substring(talkBackCommand.indexOf("_CMD_")+5);

Serial.println();
Serial.println();
Serial.println("Disconnected");
Serial.println();
Serial.println("--------");
Serial.println();
Serial.println("talkBack Was");
Serial.println();
Serial.println("--------");
Serial.println();
Serial.println(talkBackCommand);
Serial.println();
Serial.println();
Serial.println("--------");
Serial.println();

}
else
{
failedCounterTalkBack++;
Serial.println("Connection to ThingSpeak failed ("+String(failedCounterTalkBack, DEC)+")");
Serial.println();
lastConnectionTimeChannels = millis();
}
}
else
{
failedCounterTalkBack++;
Serial.println("Connection to ThingSpeak Failed ("+String(failedCounterTalkBack, DEC)+")");
Serial.println();
lastConnectionTimeTalkBack = millis();
}
}
if (failedCounterTalkBack > 3 ) {startEthernet();}
client.stop();
Serial.flush();
}

//---------------------------------------------------

void updateChannels()
{

float humid = dht.readHumidity();
float temp = dht.readTemperature();
String tsData;
tsData="field1="+String(temp - 1, DEC)+"&field2="+String(humid, DEC);
if(!client.connected() && (millis() - lastConnectionTimeChannels > updateChannelsInterval))
{
if (client.connect("api.thingspeak.com", 80))
{
client.print("POST /update HTTP/1.1\n");
client.print("Host: api.thingspeak.com\n");
client.print("Connection: close\n");
client.print("X-THINGSPEAKAPIKEY: "+channelsAPIKey+"\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(tsData.length());
client.print("\n\n");
client.print(tsData);
lastConnectionTimeChannels = millis();
if (client.connected())
{
Serial.println("----------------------------------------");
Serial.println("Updade channels");
Serial.println();
Serial.println("Connecting to ThingSpeak");
Serial.println();
Serial.println("Server response");
Serial.println();
failedCounterChannels = 0;
while(client.connected() && !client.available()) delay(1); //waits for data
while (client.connected() || client.available())
{
char charIn = client.read();
Serial.print(charIn);
}
Serial.println();
Serial.println();
Serial.println("Disconnected");
Serial.println();
}
else
{
failedCounterChannels++;
Serial.println("Connection to ThingSpeak failed ("+String(failedCounterChannels, DEC)+")");
Serial.println();
lastConnectionTimeChannels = millis();
}
}
else
{
failedCounterChannels++;
Serial.println("Connection to ThingSpeak Failed ("+String(failedCounterChannels, DEC)+")");
Serial.println();
lastConnectionTimeChannels = millis();
}
}
if (failedCounterChannels > 3 ) {startEthernet();}
client.stop();
Serial.flush();
}
void startEthernet()
{
client.stop();
Serial.println();
Serial.println();
Serial.println("----------------------------------------");
Serial.println("Connecting Arduino to network");
delay(1000);
if (Ethernet.begin(mac) == 0)
{
Serial.println("DHCP Failed, reset Arduino to try again");
Serial.println("----------------------------------------");
Serial.println();
}
else
{
Serial.println("Arduino connected to network using DHCP");
Serial.println("----------------------------------------");
Serial.println();
}
delay(1000);
}
/*—————————————————————-*/

Avatar
samir_assaad
New Member
Forum Posts: 1
sp_UserOfflineSmall Offline
4
August 14, 2015 - 1:23 pm
sp_Permalink sp_Print

hi All ,

please i need to control led via Ethernet shield but i dont how to control on talkback . please i need your help all tutorials control via wifi module , i need example on Ethernet shield

thanks
regards Cool

Avatar
Aishwarya
New Member
Forum Posts: 1
sp_UserOfflineSmall Offline
5
November 30, 2016 - 11:37 am
sp_Permalink sp_Print

hi,

i am trying thingspeak talkback on arduino using esp8266. But i am not getting how to do that .

If anyone knows, can you share the code please.

thanks

Forum Timezone: America/New_York

Most Users Ever Online: 114

Currently Online: jacktheripper125, pudderz
18 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