BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

How to get past (Twitter doesn't allow identical subsequent messages. )

am i into something here?

define BLYNK_PRINT Serial


#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

long randomNumber;

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "MYCHAR";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "MYNET";
char pass[] = "MYPASS";

BlynkTimer timer;

void tweetUptime()
{
  long uptime = millis() / 60000L;
  Serial.println("Tweeting every 10 minutes ;)");

  // Actually send the message.
  // Note:
  //   We allow 1 tweet per 15 seconds for now.
  //   Twitter doesn't allow identical subsequent messages.
  Blynk.tweet(String("been up high for ") + uptime + " minutes.");
}

void TweetwhenHIGH()
{
  // Invert state, since button is "Active LOW"
  //int isButtonPressed = !digitalRead(2);
  //if (isButtonPressed) {
if (digitalRead(2) == HIGH)  {
    timer.setInterval(500L, TweetwhenHIGH);
    Serial.println("Button is pressed.");
    randomNumber = random(300);
    Blynk.tweet(String("Testing ") + randomNumber + " HIGH");
    Serial.println("Button is pressed.");
    Blynk.tweet(" Pin Went from Low to HIGH, doing tweet");
  }
}

void setup()
{
  // Debug console
  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);

  // Tweet immediately on startup
  Blynk.tweet("My Arduino project is tweeting again");

  // Reading analogRead to create a random Number
  randomSeed(analogRead(0));
  // Setup a function to be called every 2 minutes
  timer.setInterval(2L * 60000L, tweetUptime);

  // Setup twitter button on pin 2
  pinMode(2, INPUT_PULLUP);
  // Attach pin 2 interrupt to our handler
  //attachInterrupt(digitalPinToInterrupt(2), tweetOnButtonPress, CHANGE);
  timer.setInterval(500L, TweetwhenHIGH);
}

void loop()
{
  Blynk.run();
  timer.run();
}

Let me know when your code is forum formatted. P.S. looks ok but I’m not going to try and read it with the format you have at the moment.

define BLYNK_PRINT Serial


#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

long randomNumber;

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "MYCHAR";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "mynet";
char pass[] = "mypw";

BlynkTimer timer;

void tweetUptime()
{
  long uptime = millis() / 60000L;
  Serial.println("Tweeting every 10 minutes ;)");

  // Actually send the message.
  // Note:
  //   We allow 1 tweet per 15 seconds for now.
  //   Twitter doesn't allow identical subsequent messages.
  Blynk.tweet(String("been up high for ") + uptime + " minutes.");
}

void TweetwhenHIGH()
{
  // Invert state, since button is "Active LOW"
  //int isButtonPressed = !digitalRead(2);
  //if (isButtonPressed) {
if (digitalRead(2) == HIGH)  {
    timer.setInterval(500L, TweetwhenHIGH);
    Serial.println("PIN IS HIGH.");
    randomNumber = random(300);
    Blynk.tweet(String("Testing pin ") + randomNumber + " HIGH");
    Blynk.tweet(" Pin Went from Low to HIGH, doing tweet");
  }
}

void setup()
{
  // Debug console
  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);

  // Tweet immediately on startup
  Blynk.tweet("My Arduino project is tweeting again");

  // Reading analogRead to create a random Number
  randomSeed(analogRead(0));
  // Setup a function to be called every 2 minutes
  timer.setInterval(2L * 60000L, tweetUptime);

  // Setup twitter button on pin 2
  pinMode(2, INPUT_PULLUP);
  // Attach pin 2 interrupt to our handler
  //attachInterrupt(digitalPinToInterrupt(2), tweetOnButtonPress, CHANGE);
  timer.setInterval(500L, TweetwhenHIGH);
}

void loop()
{
  Blynk.run();
  timer.run();
}

here we go.

Since your first cod dump was unformatted… as REQUIRED in the Welcome Topic… I fixed it for you… Thank you for formatting the rest :slight_smile:

@Sondre_Wold remove timer.setInterval(500L, TweetwhenHIGH); from TweetwhenHIGH() function as you only need it in setup().

Change baud from 9600 to 115200, 9600 is for super slow Arduino’s not super fast ESP’s.

Consider using a “safe” pin like 4 and 5 not an ESP “special” pin like 2.

I FINALY got it to work :smiley: Thanks so much for you help Costas!!! I hope you are getting some good karma now :smiley: thanks again.

1 Like