ThinSpeak Unreachable ! | ESP Wi-Fi | Forum

Avatar

Please consider registering
Guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —






— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed sp_TopicIcon
ThinSpeak Unreachable !
No permission to create posts
June 4, 2016
8:03 am
Avatar
aissam
New Member
Members
Forum Posts: 3
Member Since:
April 5, 2016
sp_UserOfflineSmall Offline
Hello,

I use an Arduino Uno linked to a LM35 temperature sensor, to ESP8266 01 and to my laptop, and I intend to send the data collected by the sensor to the ThingSpeak platform, and to do that I use the following code.
---------------------------------------------------------------------------------------------------------------------------------------------------------
int ledPin = 13;
// LM35 analog input
int lm35Pin = 0;

// replace with your channel's thingspeak API key
String apiKey = "T2RJXWQAVXG4ZV39";

// connect 10 to TX of Serial USB
// connect 11 to RX of serial USB
SoftwareSerial ser(10, 11); // RX, TX

// this runs once
void setup() {                
  // initialize the digital pin as an output.
  pinMode(ledPin, OUTPUT);    

  // enable debug serial
  Serial.begin(9600); 
  // enable software serial
  ser.begin(9600);
  
  // reset ESP8266
  ser.println("AT+RST");
}


// the loop 
void loop() {
  
  // blink LED on board
  digitalWrite(ledPin, HIGH);   
  delay(200);               
  digitalWrite(ledPin, LOW);

  // read the value from LM35.
  // read 10 values for averaging.
  int val = 0;
  for(int i = 0; i < 10; i++) {
      val += analogRead(lm35Pin);   
      delay(500);
  }

  // convert to temp:
  // temp value is in 0-1023 range
  // LM35 outputs 10mV/degree C. ie, 1 Volt => 100 degrees C
  // So Temp = (avg_val/1023)*5 Volts * 100 degrees/Volt
  float temp = val*50.0f/1023.0f;

  // convert to string
  char buf[16];
  String strTemp = dtostrf(temp, 4, 1, buf);
  
  Serial.println(strTemp);
  
  // TCP connection
  String cmd = "AT+CIPSTART=\"TCP\",\"";
  cmd += "184.106.153.149"; // api.thingspeak.com
  cmd += "\",80";
  ser.println(cmd);
   
  if(ser.find("Error")){
    Serial.println("AT+CIPSTART error");
    return;
  }
  
  // prepare GET string
  String getStr = "GET /update?api_key=";
  getStr += apiKey;
  getStr +="&field1=";
  getStr += String(strTemp);
  getStr += "

";

  // send data length
  cmd = "AT+CIPSEND=";
  cmd += String(getStr.length());
  ser.println(cmd);

  if(ser.find(">")){
    ser.print(getStr);
  }
  else{
    ser.println("AT+CIPCLOSE");
    // alert user
    Serial.println("AT+CIPCLOSE");
  }
    
  // thingspeak needs 15 sec delay between updates
  delay(16000);  
}
----------------------------------------------------------------------------------------------------------------------------------------------------------
When I upload the code the ESP8266 connects to my WiFi network and I get an IP address, I can PING it .. in brief, no connection problems.
But the upload of my data to ThingSpeak does not work, I can not visualize anything in the platform and the serial monitor shows the temperature value and "AT + CIPCLOSE" (which means, I think, that after "AT + = CIPSEND data_length" I do not get a ">")
If you can see my error(s) and how to correct it: D

Thank you.
Forum Timezone: America/New_York

Most Users Ever Online: 166

Currently Online:
29 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 272

Vinod: 240

piajola: 95

turgo: 70

vespapierre: 63

Adarsh_Murthy: 62

Member Stats:

Guest Posters: 1

Members: 8665

Moderators: 1

Admins: 2

Forum Stats:

Groups: 3

Forums: 14

Topics: 1600

Posts: 5760

Newest Members:

aaceitunog01, AlinaCutle, MARTO, simplicity1, jango6954, LDN001

Moderators: cstapels: 460

Administrators: Hans: 405, lee: 457