Temboo Twitter Problems

Hello Arduino Forum,
I am trying to create a sketch that tweets 29 different tweets in secession and then starts from the beginning again and keeps doing this. I took Temboo's statusupdate_sketch example and modified it a bit so it looked like this:

#include <Bridge.h>
#include <Temboo.h>
#include "TembooAccount.h" // contains Temboo account information, as described below

int quoteCounter = 1;   // Execution count, so this doesn't run forever
int maxRuns = 26;   // Maximum number of times the Choreo should be executed


#define tweet1 "1949 - Mao becomes Chairman"
#define tweet2 "1949 - Mao convinces Stalin to sign a treaty for economic aid"
#define tweet3 "1956 -  Mao encourages 'a hundred flowers to bloom', telling intellectuals to speak out"
#define tweet4 "Mao then targeted the intellectuals who spoke out for improvement"
#define tweet5 "1958 - Mao launches Great Leap Forward"
#define tweet6 "He encouraged people to set up 'people's communes' - dissolving private property"
#define tweet7 "People did not have resources or administration to manage such large social units"
#define tweet8 "In an effort to please Mao party officials left very little grain for people, most of it sent to the government"
#define tweet9 "'Backyard steel' created in an attempt to rapidly industrialize China was useless and consumed resources."
#define tweet10 "30 million starved"
#define tweet11 "1959 - Mao realises change is needed."
#define tweet12 "1966 - The Great Proletariat Cultural Revolution is begun"
#define tweet14 "Called for students to become 'Red Guards', a group of Mao followers dedicated to his idea for China"
#define tweet15 "Red Guards rampaged through cities to destroy Four Olds 四舊"
#define tweet16 "Four Olds - Old Customs, Old Culture, Old Habits, and Old Ideas"
#define tweet17 "Red Guards attacked and humiliated people from 'bad class status' - intellectuals or wealthy"
#define tweet18 "Private property was invaded by Red Guards and trashed"
#define tweet19 "This created great chaos, violence, injury and death #unsuccessful"
#define tweet20 "1966 - Mao Zhuxi Yulu, often known as the #Little_Red_Book, was published"
#define tweet21 "Mao’s quotes were the unchallenged rules the by which Chinese lived"
#define tweet22 ""
#define tweet23 "August 1966 - Culture - Lao She, a famous playwright is beaten to death by Red Guards"
#define tweet24 "Culture - All art supposed to be #propaganda for Mao"
#define tweet25 "1972 - Nixon Visits China"
#define tweet26 "Despite differences Mao can negotiate with US to China’s advantage"
#define tweet27 "US agrees to aid China if Taiwan tries to take power"
#define tweet28 "US used to support Taiwan, Mao made China a more valuable ally"
#define tweet29 "The end result: 1.5 million murdered, a million more tortured, imprisoned, humiliated or robbed of property."

void setup() {
  Serial.begin(9600);
  
  // For debugging, wait until the serial console is connected.
  delay(4000);
  while(!Serial);
  Bridge.begin();
}

void loop() {
  String tweets[] = {tweet1, tweet2, tweet3, tweet4, tweet5, tweet6, tweet7, tweet8, tweet9, tweet10, tweet11, tweet12, tweet14, tweet15, tweet16, tweet17, tweet18, tweet19, tweet20, tweet21, tweet22, tweet23, tweet24, tweet26};
  if (quoteCounter <= maxRuns) {
  
    Serial.println("Running StatusesUpdate - Run #" + String(quoteCounter));
    
    TembooChoreo StatusesUpdateChoreo;

    // Invoke the Temboo client
    StatusesUpdateChoreo.begin();
    
    // Set Temboo account credentials
    StatusesUpdateChoreo.setAccountName(TEMBOO_ACCOUNT);
    StatusesUpdateChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
    StatusesUpdateChoreo.setAppKey(TEMBOO_APP_KEY);
    
    // Set Choreo inputs
    StatusesUpdateChoreo.addInput("AccessToken", ACCESS_TOKEN);
    StatusesUpdateChoreo.addInput(ACESS_TOKEN_SECRET);
    StatusesUpdateChoreo.addInput(CONSUMER_SECRET);
    StatusesUpdateChoreo.addInput("StatusUpdate", tweets[quoteCounter]); //tweet the tweet 
    StatusesUpdateChoreo.addInput("ConsumerKey", CONSUMER_KEY);
    
    // Identify the Choreo to run
    StatusesUpdateChoreo.setChoreo("/Library/Twitter/Tweets/StatusesUpdate");
    
    // Run the Choreo; when results are available, print them to serial
    StatusesUpdateChoreo.run();
    
    while(StatusesUpdateChoreo.available()) {
      char c = StatusesUpdateChoreo.read();
      Serial.print(c);
    }
    StatusesUpdateChoreo.close();
    quoteCounter++;
  }

  Serial.println("Waiting...");
  delay(30000); // wait 30 seconds between StatusesUpdate calls
}

WHAT IS GOING ON? In the Temboo example the Serial Monitor says "Running StatusesUpdate...." but in this nothing happens. PLEASE RESPOND QUICKLY! :cold_sweat: :fearful:

UPDATE: the 26 as maxRuns is a typo it should be 29

UPDATE: I got it to work, sort of, not really... I was trying with just the three first tweets and strangly enough It tweets the third tweet and then bugs out. This is the Serial monitor. When it says Sucess it just sent to third tweet, not the first.

Running SendATweet - Run #1...
Success! Tweet sent!
Waiting...
Running SendATweet - Run #2...

500����������
���
�

�
�JeehEE�WWFaa

1Sjklmnopqrstuvwxyz{|}~�������������������������������������������������������������������������������������������������������������������������������
500����������
���
�

Here is the code

/*
  SendATweet

  Demonstrates sending a tweet via a Twitter account using the Temboo Arduino Yun SDK.
  
  This example code is in the public domain.
*/

#include <Bridge.h>
#include <Temboo.h>
#include "TembooAccount.h" // contains Temboo account information


#define tweet1 "1949 - Mao becomes Chairman"
#define tweet2 "1949 - Mao convinces Stalin to sign a treaty for economic aid #sucess"
#define tweet3 "1956 -  Mao encourages 'a hundred flowers to bloom', telling intellectuals to speak out"
#define tweet4 "Mao then imprisoned the intellectuals who spoke out for improvement"
#define tweet5 "1958 - Mao launches Great Leap Forward"
#define tweet6 "He encouraged people to set up 'people's communes' - dissolving private property"
#define tweet7 "People did not have resources or administration to manage such large social units"
#define tweet8 "In an effort to please Mao party officials left very little grain for people, most of it sent to the government"
#define tweet9 "'Backyard steel' created in an attempt to rapidly industrialize China was useless and consumed resources."
#define tweet10 "30 million starved"
#define tweet11 "1959 - Mao realizes change is needed."
#define tweet12 "1966 - The Great Proletariat Cultural Revolution"
#define tweet14 "Called for students to become 'Red Guards', a group of Mao followers dedicated to his idea for China"
#define tweet15 "Red Guards rampaged through cities to destroy Four Olds"
#define tweet16 "Four Olds - Old Customs, Old Culture, Old Habits, and Old Ideas"
#define tweet17 "Red Guards attacked and humiliated people from 'bad class status' - intellectuals or wealthy"
#define tweet18 "Private property was invaded by Red Guards and trashed"
#define tweet19 "This created great chaos, violence, injury and death #unsuccessful"
#define tweet20 "1966 - Mao Zhuxi Yulu, often known as the #Little_Red_Book, was published"
#define tweet21 "Mao’s quotes were the unchallenged rules the by which Chinese lived"
#define tweet23 "August 1966 - Culture - Lao She, a famous playwright, is beaten to death by Red Guards"
#define tweet24 "Culture - All art supposed to be #propaganda for Mao"
#define tweet25 "1972 - Nixon Visits China"
#define tweet26 "Despite differences Mao can negotiate with US to China’s advantage"
#define tweet27 "US agrees to aid China if Taiwan tries to take power"
#define tweet28 "US used to support Taiwan, Mao made China a more valuable ally"
#define tweet29 "The end result: 1.5 million murdered, a million more tortured, imprisoned, humiliated or robbed of property."


int numRuns = 1;   // execution count, so this sketch doesn't run forever
int maxRuns = 3;  // the max number of times the Twitter Update Choreo should run



void setup() {
  Serial.begin(9600);

  // for debugging, wait until a serial console is connected
  delay(4000);
  while(!Serial);

  Bridge.begin();
}

void loop()
{
  String tweets[] = {tweet1, tweet2, tweet3}; 
 
  if (numRuns <= maxRuns) {

    Serial.println("Running SendATweet - Run #" + String(numRuns++) + "...");
  
    // define the text of the tweet we want to send
    String tweetText(tweets[numRuns]);

    
    TembooChoreo StatusesUpdateChoreo;

    // invoke the Temboo client
    // NOTE that the client must be reinvoked, and repopulated with
    // appropriate arguments, each time its run() method is called.
    StatusesUpdateChoreo.begin();
    
    // set Temboo account credentials
    StatusesUpdateChoreo.setAccountName(TEMBOO_ACCOUNT);
    StatusesUpdateChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
    StatusesUpdateChoreo.setAppKey(TEMBOO_APP_KEY);

    // identify the Temboo Library choreo to run (Twitter > Tweets > StatusesUpdate)
    StatusesUpdateChoreo.setChoreo("/Library/Twitter/Tweets/StatusesUpdate");

    // set the required choreo inputs
    // see https://www.temboo.com/library/Library/Twitter/Tweets/StatusesUpdate/ 
    // for complete details about the inputs for this Choreo
 
    // add the Twitter account information
    StatusesUpdateChoreo.addInput("AccessToken", AccessToken);
    StatusesUpdateChoreo.addInput("AccessTokenSecret", AccessTokenSecret);
    StatusesUpdateChoreo.addInput("ConsumerKey", ConsumerKey);    
    StatusesUpdateChoreo.addInput("ConsumerSecret", ConsumerSecret);

    // and the tweet we want to send
    StatusesUpdateChoreo.addInput("StatusUpdate", tweetText);

    // tell the Process to run and wait for the results. The 
    // return code (returnCode) will tell us whether the Temboo client 
    // was able to send our request to the Temboo servers
    unsigned int returnCode = StatusesUpdateChoreo.run();

    // a return code of zero (0) means everything worked
    if (returnCode == 0) {
        Serial.println("Success! Tweet sent!");
    } else {
      // a non-zero return code means there was an error
      // read and print the error message
      while (StatusesUpdateChoreo.available()) {
        char c = StatusesUpdateChoreo.read();
        Serial.print(c);
      }
    } 
    //StatusesUpdateChoreo.close();

    // do nothing for the next 90 seconds
    Serial.println("Waiting...");
    delay(5000);
  }
  else{
   numRuns = 1; 
  }
}

How do I get them to tweet in secession??? PLEASE HELP IMMEDIATELY! :astonished: :cry:

Things "bugging out" like that after a few passes is generally a sighn of memory issues. When you run out of memory, the stack collides with your static data, corrupting your static data and giving strange output. Then you update that static data which corrupts the stack, causing the program to crash.

PLEASE HELP IMMEDIATELY!

You're really in no position to get arrogant and shout demands for help. Especially when you seem to have ignored most of the memory savings suggestions that were given to you back in December. Or is that why you keep starting new threads: you don't like the help you're given, so you ignore it and start a new thread?

Face it: the 32u4 processor simply does not have enough RAM to keep all of those tweet strings in memory! You WILL have to use a different technique. Until you come to grips with that you will just be frustrating yourself and us.

@Shapeshifter
I didn't ignore your or anyone elses comments. Trust me I really do appreciate everyone on this forum for being really kind to help me. The reason why I didn't implement them is because I thought that the SD card space I added would nullify the memory. Clearly, it didn't so yes, I WILL make the tweets as short as possible. Also with the caps I didn't mean to sound demanding of anyone I was just very frustrated at myself.
Thanks for putting up with this,
ma7730

I'm sorry typo:

thought that the SD card space I added would nullify the memory

I meant "the memory issue"

Hello,
I reduced the number of tweets and the number of characters but there is still very low memory. If I look in the console and in the Console it said

Sketch uses 15,394 bytes (53%) of program storage space. Maximum is 28,672 bytes.
Global variables use 2,370 bytes (92%) of dynamic memory, leaving 190 bytes for local variables. Maximum is 2,560 bytes.Low memory available, stability problems may occur.

Since there is 13278 bytes still available(47%) how do I utilize this available (or maybe it's not available, I don't know) memory.
Thanks,
ma7730

ma7730:
Since there is 13278 bytes still available(47%) how do I utilize this available (or maybe it's not available, I don't know) memory.

Yes, you can move your strings out of RAM and into program memory.

How? That was given to you back in your December thread:

PCWorxLA:
One of the biggest tripwires for most people is that on the AVR chips, each and every string used in your sketch will take up precious RAM space! They are not (only) stored in code space, as in most other programming environments.

The #define statements itself won't take any space, but the assignments in the case statement will. Put them straight in the case statement, surrounded by the F() macro or check up on the use of PROGMEM. Those will leave those constant strings in code space (FlashROM) only, with a small internal overhead for the different way how those strings will be loaded...

One of the easiest answers was right there, but I see no evidence of you trying it. Did you try it? Did you do any research on the F() macro or on the PROGMEM directive? It doesn't appear so. That's what I was referring to when I made the comment about ignoring advice. I have lots of patience for people who want to learn. I start to lose my patience and get grumpy when they ignore advice or don't want to put in any effort. (My son was famous for that: if the fully formed answer didn't immediately fall into his lap, he gave up. It's very frustrating. Maybe that's why I can get annoyed so easily when it looks like someone isn't putting in the effort.)

ma7730:
Hello,
I reduced the number of tweets and the number of characters but there is still very low memory. If I look in the console and in the Console it said

Sketch uses 15,394 bytes (53%) of program storage space. Maximum is 28,672 bytes.

Global variables use 2,370 bytes (92%) of dynamic memory, leaving 190 bytes for local variables. Maximum is 2,560 bytes.Low memory available, stability problems may occur.



Since there is 13278 bytes still available(47%) how do I utilize this available (or maybe it's not available, I don't know) memory.
Thanks,
ma7730

By reading the replies you get that point you in the right direction. Not by shouting and demanding help!
:angry:

Ralf

The OP had several threads going on this topic. In the latest one, he's calmed down significantly and I think progress is being made. I think we have the duplicate thread issue solved, as well. Yún Memory Issues - Arduino Yún - Arduino Forum