Twitter & Arduino


I’m trying to build a arduino that twitters if my tomatoes need watering, just like botanicalls. So far I was able to send a single twitter, but after that one twitter has been send I keep getting "connection failed"errors. If I want to send another twitter I need to reset the board.

Any hints/ideas are very appreciated :slight_smile:

This is the Code

#include <Ethernet.h>
#include <PString.h>
int moistureSensor1 = 0;
int moisture_val1;
int Relais1 =  8;

//////////// EINSTELUNGEN ///////////////////
// Etherneteinstellungen für das Arduino Board //
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 178, 5 };
byte gateway[] = { 192, 168, 178, 1 };
byte subnet[] = { 255, 255, 255, 0 };
// Twitter Settings //
byte server[] = { 168, 143, 171, 180 };   // IP von Twitter (default:
#define TWITTERURL "/statuses/update.xml"  // URL zum Update Script
#define TWITTERUSERNAMEPW "dG9tYXRlbnBxxxxxxxxxxxxxxxxxxxxx"  // Base64 enkodet USERNAME:PASSWORT
Client client(server, 80);
char buffer[141];
PString mystring(buffer, sizeof(buffer));

void setup()
  Ethernet.begin(mac, ip, gateway, subnet);  // Ethernet initalisieren
  pinMode(Relais1, OUTPUT);
  Serial.begin(9600);   // Serielle Verbindung für Statusmeldungen
  delay(1000);  // Kurz warten, um serielle Verbindung zu starten
void loop()
   mystring.print("Actual resistance = ");  // start building tweet
/// Functions ////
void sendTwitterUpdate(char* tweet)        // Nachricht an Twitter übermitteln
  if (client.connect()) {
    client.print("POST ");
    client.println(" HTTP/1.1");
    client.print("Authorization: Basic ");
    client.print("Content-Length: ");
    Serial.println("twitter message send");
  } else {
    Serial.println("connection failed");
void fetchTwitterUpdate()     // Rückmeldung von Twitter auslesen
    if (client.available()) {
    char c =;
  if (!client.connected()) {

Twitter doesn't allow you to post the same message over and over. The moisture level is not going to change significantly in one second, so you are trying to post the same message over and over.

Either don't post unless the moisture level has changed, or time-stamp each message so that it IS unique.

thanks for your hints,

I added a random number to the tweets just to make sure they differ enough but the problem is still the same. Even if I pull the plug of the moisture sensor and the value goes down to 0 I keep getting the "connection failed" errors.

#include <PString.h>

Are you using the (older) version that has a memory leak?