Use Arduino to send tweets

Use Arduino to send tweets

Una de las cosas más útiles que veo yo en el hardware libre es la posibilidad de obtener soluciones para problemas cotidianos sin tener que desembolsar una gran cantidad de dinero. En una búsqueda de soluciones para mis problemas cotidianos he visto este curioso tutorial que me ha sorprendido ya que no esperaba que arduino pudiese funcionar directamente con Twitter ya que entre otras cosas, Arduino no es una placa SBC. Con este tutorial podremos obtener un sistema de publicación automática de tweets y lo que es mejor, un código útil para insertar en cualquier programa y que publique un tweet por cada acción correcta que haga nuestra placa arduino.

For this we will need an arduino board with Ethernet shield or, failing that, an arduino Yún. Through these boards, we will be able to connect our board with the internet and with our Twitter account to be able to send tweets.

In order to make operate this tweet posting system, we will need an internet connection and in the case of using an ethernet board, we will need a network cable to connect our board to the internet.

With Arduino Yún we will have an automatic tweet system

Once all this is achieved, now we will need a token or code so that our arduino board can work with our Twitter account, something like an authorization for our account. This token or permission can be obtained through this link, popping up something like that.

Twitter Token

Once we have the token, we copy the code it offers us and save it as it will be more useful later. Now we have to work with the Arduino IDE. We go to the ide and create a file that we will upload to our arduino board. But before we get off this bookstore and we will load it previously with the Arduino IDE. Now we create a file with the following code:

#include // Necesario en Arduino 0019 o posterior
#include
#include

// Configuracion de la Ethernet Shield
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

// Si no se especifica la IP, se utiliza DHCP (solo para Arduino 1.0 o superior).
byte ip[] = { 192, 168, 0, 250 };

Twitter twitter("INTRODUCIR TOKEN AQUI");

// Mensaje
char msg[] = "¡Publicando en Twitter desde #Arduino gracias a este tweet";

void setup()
{
delay(1000);
Ethernet.begin(mac, ip);
// Si usamos DHCP no hace falta incluir la IP.
// Ethernet.begin(mac);
Serial.begin(9600);

Serial.println("Estableciendo conexion con Twitter ...");
if (twitter.post(msg)) { // Publicamos el mensaje en Twitter. Devuelve true o false.
int status = twitter.wait(&Serial);
if (status == 200) { // Conexion exitosa
Serial.println("OK.");
} else { // Error en la conexion
Serial.print("Error : code ");
Serial.println(status);
}
} else {
Serial.println("Conexion fallida.");
}
}

void loop()
{
}

Once we have loaded this file, without it working we will see how tweets appear in our account with the message that we have marked in the code. Even if beforehand It may not seem very useful, it can always be used as a robot to program a tweet or simply be part of a more complex code.


3 comments, leave yours

Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   rehmmaster said

    Do not copy. not knowing. include are missing. Clown

    1.    John Louis Groves said

      Hello Rehmaster,

      There are many ways to comment on this news and better yet, to help our community continue to grow than to use insults.

      As the entry says, you have the library to download and in any high-level compiler, for example Eclipse, all you have to do is attach it to the project so that it is available and the program itself automatically gives you the option to import it. when you are going to use a library's own function.

      As you can see, it is not necessary to specify this type of thing since, understanding what the program does, what we want to achieve, surely you know this type of thing beforehand and you do not need to be told how to enter an import specific.

      regards

  2.   Gustavo said

    Hi, I have not been able to implement this code to do it wirelessly using a wifi network. with a WiFly.
    apparently the library does not allow it.
    Do you have any idea how to solve this?
    I have seen some projects on the internet but they only do searches or twitter counts, but not publish a tweet.
    Thank you!