ESP8266 + Arduino Uno connection problem

Hi everyone,
I have a problem while connecting my esp8266 to wifi using arduino.
It worked once and then it never did it again.
I basically want my esp to connect and then send some data to my thingspeak channel.
This is my code, my temperature calculation is correct, I guess the problem is in the connection function

#define SSID "Stanza_tesisti"
#define PASS "********"

#include <SoftwareSerial.h>
#include <stdlib.h>

// LED
int ledPin = 13;
// LM35 analog input
int lm35Pin = A0;

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

// 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");
delay(3000);
connectWiFi();
}
// 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;
 int reading = analogRead(lm35Pin);  

 float voltage = reading * 5.0;
 voltage /= 1024.0; 
 
 float temp = (voltage - 0.5) * 100 ;
// 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 += "\r\n\r\n";

// 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);
}



boolean connectWiFi(){
  //set ESP8266 mode with AT commands
  
    ser.println("AT+CWMODE=1");
  delay(2000);

  //build connection command
  String cmd="AT+CWJAP=\"";
  cmd+=SSID;
  cmd+="\",\"";
  cmd+=PASS;
  cmd+="\"";
  
  //connect to WiFi network and wait 5 seconds
  ser.println(cmd);
  delay(5000);
  
  //if connected return true, else false
  if(ser.find("OK")){
   
    return true;
  }else{

    return false;
  }
}

This is the output I get

22.8
AT+CIPCLOSE
23.7
AT+CIPCLOSE
23.7
AT+CIPCLOSE

Thanks for your help

getStr += String(strTemp);

strTemp is ALREADY a String. Wrapping a String in a String does NOT make sense.

You should Serial.print() all the Strings that you are sending to the ESP. You should print ALL the responses from the ESP.

Thanks for the advice but this is not my problem: I have some issues with AT+CWJAP command that does not work and I don't know why. I tried to build a temperature server that displays in a webpage my current temperature and it works so every AT command work except the CWJAP one and I can't figure out why

I can't figure out why

I have no idea what the AT+CWJAP command is supposed to do, or what the ESP response is when you issue the command. You don't know, either. So, any attempt to change the code to make the AT+CWJAP command work is going to involve guesswork, magic, and a lot of luck. Wouldn't you know it. You need magic just after I broke my magic wand. Damn the luck. I guess I can't help you.

There, I managed to work all three in my response. 8)