Using Yun with TalkBack and ThingHTTP Same Time | Arduino | Forum

Avatar

Please consider registering
Guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —






— Match —





— Forum Options —





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

sp_Feed sp_TopicIcon
Using Yun with TalkBack and ThingHTTP Same Time
No permission to create posts
February 18, 2015
12:13 pm
Avatar
xking3
New Member
Members
Forum Posts: 1
Member Since:
February 18, 2015
sp_UserOfflineSmall Offline

Example for a Yun Code which has an integrated TalkBack and a Post.
With this code you can Switch on a light on PIN13 and measure it with a light sensor on PIN A0.

This is a mix of two codes i found here on thingspeak Wink

CODE:

#include "Bridge.h"
#include "HttpClient.h"

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

//ThingSpeak Post Settings
String thingSpeakAddress = "http://api.thingspeak.com/update?";
String writeAPIKey = "key=XXXXXXXXXXXXXXX"; //Enter the write API Key for your ThingSpeak Channel
String tsfield1Name = "&field1=";

HttpClient client;

// Variable Setup
long lastConnectionTime = 0;

int Sensor = A0;
int x = 0; //Licht Sensor

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

// Initialize Bridge
Bridge.begin();

// Initialize Serial
Serial.begin(9600);

}

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

void checkTalkBack()
{

String talkBackCommand;
char charIn;
String talkBackURL = "http://" + thingSpeakAPI + "/talkbacks/" + talkBackID + "/commands/execute?api_key=" + talkBackAPIKey;

// Make a HTTP GET request to the TalkBack API:
client.get(talkBackURL);

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

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

Serial.flush();
delay(1000);

//Sensor auslesen
x = analogRead(Sensor);

//Generate Post to ThingSpeak API
// Create string for ThingSpeak post
String request_string = thingSpeakAddress + writeAPIKey + tsfield1Name + String(x, DEC);

// Make a HTTP request
client.get(request_string);

delay (2000);
}

April 24, 2015
10:46 am
Avatar
hanguyen
New Member
Members
Forum Posts: 4
Member Since:
January 7, 2015
sp_UserOfflineSmall Offline

can you upload the code for arduino uno with ESP8266 or/W5100, thanks

Forum Timezone: America/New_York

Most Users Ever Online: 166

Currently Online:
20 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 272

Vinod: 240

piajola: 95

turgo: 70

vespapierre: 63

Adarsh_Murthy: 62

Member Stats:

Guest Posters: 1

Members: 8665

Moderators: 1

Admins: 2

Forum Stats:

Groups: 3

Forums: 14

Topics: 1600

Posts: 5760

Newest Members:

Team_mafia, icXu, emorphistechno, VTVMART, manimozhi, adamhebrew

Moderators: cstapels: 460

Administrators: Hans: 405, lee: 457