-
-
Save dave-santiano/79ebbaa897b029f2569011f515f4bb97 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SPI.h> | |
#include <WiFi101.h> | |
#include <WiFiSSLClient.h> | |
#include <TembooSSL.h> | |
#include "config.h" // Contains Temboo account information | |
#include <Adafruit_Thermal.h> | |
Adafruit_Thermal printer(&Serial1); | |
WiFiSSLClient client; | |
boolean fake_connection = true; | |
int calls = 1; // Execution count, so this doesn't run forever | |
int maxCalls = 100; // Maximum number of times the Choreo should be executed | |
String inputString = "{\"statuses\":[{\"created_at\":\"Mon Apr 24 11:50:46 +0000 2017\",\"id\":856475499492671488,\"id_str\":\"856475499492671488\",\"text\":\"RT @The_Trump_Train: RETWEET if you are excited for the big TAX REFORM & TAX REDUCTION announcement on Wednesday! #MakeAmericaGreatAgain\",\"truncated\":false,\"entities\":{\"hashtags\":[{\"text\":\"MakeAmericaGreatAgain\",\"indices\":[118,140]}],\"symbols\":[],\"user_mentions\":[{\"screen_name\":\"The_Trump_Train\",\"name\":\"The Trump Train\",\"id\":4102376488,\"id_str\":\"4102376488\",\"indices\":[3,19]}],\"urls\":[]},\"metadata\":{\"iso_language_code\":\"en\",\"result_type\":\"recent\"},\"in_reply_to_status_id\":null,\"in_reply_to_status_id_str\":null,\"in_reply_to_user_id\":null,\"in_reply_to_user_id_str\":null,\"in_reply_to_screen_name\":null,\"user\":{\"id\":786311117656195072,\"id_str\":\"786311117656195072\",\"name\":\"Julio Cesar Vazquez\",\"screen_name\":\"jcvazzy\",\"location"; | |
String outString = ""; | |
void setup() { | |
Serial1.begin(9600); | |
Serial.begin(9600); | |
// For debugging, wait until the serial console is connected | |
delay(4000); | |
while (!Serial); | |
int wifiStatus = WL_IDLE_STATUS; | |
// Determine if the WiFi Shield is present | |
Serial.print("\n\nShield:"); | |
if (WiFi.status() == WL_NO_SHIELD) { | |
Serial.println("FAIL"); | |
// If there's no WiFi shield, stop here | |
while (true); | |
} | |
Serial.println("OK"); | |
// Try to connect to the local WiFi network | |
while (wifiStatus != WL_CONNECTED) { | |
Serial.print("WiFi:"); | |
wifiStatus = WiFi.begin(WIFI_SSID, WPA_PASSWORD); | |
if (wifiStatus == WL_CONNECTED) { | |
Serial.println("OK"); | |
} else { | |
Serial.println("FAIL"); | |
} | |
delay(5000); | |
} | |
printer.begin(); | |
Serial.println("Setup complete.\n"); | |
} | |
void loop() { | |
if (calls <= maxCalls) { | |
Serial.println("Running LatestTweet - Run #" + String(calls++)); | |
TembooChoreoSSL LatestTweetChoreo(client); | |
// Invoke the Temboo client | |
LatestTweetChoreo.begin(); | |
// Set Temboo account credentials | |
LatestTweetChoreo.setAccountName(TEMBOO_ACCOUNT); | |
LatestTweetChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME); | |
LatestTweetChoreo.setAppKey(TEMBOO_APP_KEY); | |
LatestTweetChoreo.setDeviceType(TEMBOO_DEVICE_TYPE); | |
// Set Choreo inputs | |
String QueryValue = "#makeamericagreatagain"; | |
LatestTweetChoreo.addInput("Query", QueryValue); | |
String AccessTokenValue = "842998343328387075-58ujmNvoFHmAoB5hR3XlGFXMBB0xttt"; | |
LatestTweetChoreo.addInput("AccessToken", AccessTokenValue); | |
String ConsumerKeyValue = "1A84tG1LrpiBZWcfsGfbqUTDs"; | |
LatestTweetChoreo.addInput("ConsumerKey", ConsumerKeyValue); | |
String ConsumerSecretValue = "62E5pADkflEqw7cXNFWXrRWkLsJb7wNUm1YuvgR8Zb4PWwykru"; | |
LatestTweetChoreo.addInput("ConsumerSecret", ConsumerSecretValue); | |
String AccessTokenSecretValue = "AIPQeVm2GJFMzeTUzhk5hg5ok57uooLXkQZXzrfgTEBi8"; | |
LatestTweetChoreo.addInput("AccessTokenSecret", AccessTokenSecretValue); | |
// Identify the Choreo to run | |
LatestTweetChoreo.setChoreo("/Library/Twitter/Search/LatestTweet"); | |
// Run the Choreo; when results are available, print them to serial | |
LatestTweetChoreo.run(); | |
while (fake_connection == true) { | |
if (inputString.indexOf("text") > -1) { | |
// Serial.println(inputString.indexOf("text")); | |
// Serial.println(inputString) | |
for (int i = inputString.indexOf("text") + 7; i < int(inputString.indexOf("text")) + 147; i++) { | |
Serial.print(inputString[i]); | |
outString += inputString[i]; | |
} | |
printer.println(outString); | |
printer.println("\n"); | |
printer.println("\n"); | |
printer.sleep(); // Tell printer to sleep | |
printer.wake(); // MUST wake() before printing again, even if reset | |
printer.setDefault(); // Restore printer to defaults | |
outString = ""; | |
delay(15000); | |
} | |
} | |
} | |
// while(LatestTweetChoreo.available()) { | |
// char c = LatestTweetChoreo.read(); | |
// inputString += c; | |
// if (inputString.indexOf("text") > -1){ | |
// Serial.println("found"); | |
// } | |
// Serial.print(c); | |
// } | |
// if (inputString.indexOf("text") > -1) { | |
// // Serial.println(inputString.indexOf("text")); | |
// // Serial.println(inputString) | |
// for (int i = inputString.indexOf("text") + 7; i < int(inputString.indexOf("text")) + 147; i++) { | |
// Serial.print(inputString[i]); | |
// outString += inputString[i]; | |
// } | |
// printer.println(outString); | |
// printer.println("\n"); | |
// printer.println("\n"); | |
// printer.sleep(); // Tell printer to sleep | |
// printer.wake(); // MUST wake() before printing again, even if reset | |
// printer.setDefault(); // Restore printer to defaults | |
// outString = ""; | |
// delay(15000); | |
// LatestTweetChoreo.close(); | |
Serial.println("\nWaiting...\n"); | |
delay(5000); // wait 5 seconds between LatestTweet calls | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment