1

I want to send tweets with flame sensor and ESP8266. My flame sensor is digital. I think everything is good but it doesn't send.

This is my code:

#define ag_ismi "SSID"
#define ag_sifresi "PASSWORD"
#define IP "184.106.153.149" //thingspeak.com IP address

int sensorPin = 8;
int smoke_level = HIGH;

void setup() {
  pinMode(sensorPin, INPUT);
  Serial.begin(115200);
  Serial.println("AT");
  delay(3000);
  if (Serial.find("OK")) {
    Serial.println("AT+CWMODE=1");
    delay(2000);
    String baglantiKomutu = String("AT+CWJAP=\"") + ag_ismi + "\",\"" + ag_sifresi + "\"";
    Serial.println(baglantiKomutu);
    delay(5000);
  }
}

void loop() {
  smoke_level = digitalRead(sensorPin); // Arduino reads the value from the smoke sensor
  Serial.println(smoke_level);// prints just for debugging purposes, to see what values the sensor is picking up
  if (smoke_level == HIGH) {
    // if smoke level is greater than 500, the buzzer will go off
    sicaklik_yolla();
  }
  delay(20000);
}
void sicaklik_yolla() {
  Serial.println(String("AT+CIPSTART=\"TCP\",\"") + IP + "\",80");
  delay(1500);
  String tweet = "POST /apps/thingtweet/1/statuses/update HTTP/1.1\n";
  tweet += "Host: api.thingspeak.com\n";
  tweet += "Connection: close\n";
  tweet += "Content-Type: application/x-www-form-urlencoded\n";
  tweet += "Content-Length:67\r\n\r\napi_key=";
  tweet += String("MY API KEY");
  tweet += String("&status=");
  tweet += String("MY TWEET TEXT");
  Serial.print("AT+CIPSEND=");
  delay(100);
  Serial.println(tweet.length());
  if (Serial.find(">")) {
    Serial.println(tweet);
    Serial.println("AT+CIPCLOSE=0");
    delay(100);
  } else {
    Serial.println("AT+CIPCLOSE=0");
  }
}

This schema is old. Sensor connected to pin 8.

old connection

0

I guess your baud rate and network connection with the wifi module is working fine. Have to say that it is a bit difficult to get the data sent to ThingSpeak with ESP8266. I actually did some experiments to get the data sent. The problem is actually with the delay. Adding a delay of 5000 ms between sending the tweet length and the tweet content sorts it out. You can use GET format. Check out this Instructable.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.