Temperature measurement

Yes, that is an AT command

ok, give several min

I don’t know whats happened, but now it doesn’t react on AT command

Remember to to set Both NL & CR in the serial monitor.
Ready

AT

OK
AT+CIOBAUD=9600

OK

This is serial monitor with this code:
//AT+CIOBAUD=9600
#include <SoftwareSerial.h>
SoftwareSerial ESPserial(2, 3);
// RX | TXAT+CIOBAUD=9600

void setup()
{
Serial.begin(9600); // communication with the host computer
//while (!Serial) { ; }

// Start the software serial for communication with the ESP8266
ESPserial.begin(9600);  

Serial.println("");
Serial.println("Remember to to set Both NL & CR in the serial monitor.");
Serial.println("Ready");
Serial.println("");    

}

void loop()
{
// listen for communication from the ESP8266 and then write it to the serial monitor
if ( ESPserial.available() ) { Serial.write( ESPserial.read() ); }

// listen for user input and send it to the ESP8266
if ( Serial.available() )       {  ESPserial.write( Serial.read() );  }

}

Once you have the baud rate rate to 9600 , change it in the code from this post.

Hi. I’ve done, thats what I get in serial monitor:

[1533] ESP is not responding
[6423] Connected to WiFi
[6423] Connecting to mqtt.mydevices.com:1883
[7670] Connected
[8461] Publish: topic 4, channel 65534, value Arduino Uno, subkey , key
[13498] Publish: topic 6, channel 65534, value ATmega328P, subkey , key
[18535] Publish: topic 7, channel 65534, value 16000000, subkey , key
[23570] Publish: topic 5, channel 65534, value 1.3.0, subkey , key
[28602] Publish: topic 8, channel 65534, value ESP8266Shield, subkey , key
[28674] Publish: topic 1, channel 0, value 28674, subkey , key
[38664] Connection ok
[43693] Publish: topic 1, channel 0, value 43693, subkey , key
[48690] Connection ok
[58720] Publish: topic 1, channel 0, value 58720, subkey , key
[64225] Connection ok

that means it is working.

Yep, I understand, but why it doesn’t work when I start to use it?)))

what do you mean by that? it is connected and it is publishing data to cayenne.

Now if I start to put the sensors in to the code and make widgets, its working like 5-10 seconds and disconnected, then in 1-2-3 min its connecting again and work for 5-10 seconds and disconnecting again

You know what, yesterday I upload this code:

define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space
#include <CayenneMQTTESP8266Shield.h>
#include <DHT.h>
// WiFi network info.
char ssid[] = "";
char wifiPassword[] = "";

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "";
char password[] = "";
char clientID[] = "3";

// Set ESP8266 Serial object. In this example we use the Serial1 hardware serial which is available on boards like the Arduino Mega.
#define EspSerial Serial
#define SENSOR_PIN1 A0
#define VIRTUAL_CHANNEL1 1
#define SENSOR_PIN2 A1
#define VIRTUAL_CHANNEL2 2
#define DHTPIN 2     // Digital pin connected to the DHT sensor
#define RELEY_VIRTUAL_CHANNEL 9
#define ACTUATOR_PIN 4
// Uncomment whatever type you're using!
//#define DHTTYPE DHT11   // DHT 11
//#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321
#define DHTTYPE DHT21   // DHT 21 (AM2301)

#define TEMPERATURE_VIRTUAL_CHANNEL 7
#define HUMIDITY_VIRTUAL_CHANNEL 8


DHT dht(DHTPIN, DHTTYPE); // Initialize DHT sensor.
ESP8266 wifi(&EspSerial);

void setup()
{
  pinMode(ACTUATOR_PIN, OUTPUT);


  Serial.begin(9600);
  delay(10);

  // Set ESP8266 baud rate
  EspSerial.begin(115200);
  delay(10);

  Cayenne.begin(username, password, clientID, wifi, ssid, wifiPassword);
  dht.begin();
}

void loop()
{
  Cayenne.loop();
}
CAYENNE_IN(RELEY_VIRTUAL_CHANNEL)
{
  // Write value to turn the relay switch on or off. This code assumes you wire your relay as normally open.
  if (getValue.asInt() == 0) {
    digitalWrite(ACTUATOR_PIN, LOW);
  }
  else {
    digitalWrite(ACTUATOR_PIN, HIGH);
  }
} 
CAYENNE_OUT(TEMPERATURE_VIRTUAL_CHANNEL)
{
  Cayenne.virtualWrite(TEMPERATURE_VIRTUAL_CHANNEL, dht.readTemperature(), "temp", "c");
}

// This function is called at intervals to send humidity sensor data to Cayenne.
CAYENNE_OUT(HUMIDITY_VIRTUAL_CHANNEL)
{
  Cayenne.virtualWrite(HUMIDITY_VIRTUAL_CHANNEL, dht.readHumidity(), "rel_hum", "p");
}
// Default function for sending sensor data at intervals to Cayenne.
// You can also use functions for specific channels, e.g CAYENNE_OUT(1) for sending channel 1 data.
CAYENNE_OUT_DEFAULT()
{
  Cayenne.virtualWrite(VIRTUAL_CHANNEL1, analogRead(SENSOR_PIN1));

Cayenne.virtualWrite(VIRTUAL_CHANNEL2, analogRead(SENSOR_PIN2));
  // Write data to Cayenne here. This example just sends the current uptime in milliseconds on virtual channel 0.
  Cayenne.virtualWrite(0, millis());
  // Some examples of other functions you can use to send data.
  //Cayenne.celsiusWrite(1, 22.0);
  //Cayenne.luxWrite(2, 700);
  //Cayenne.virtualWrite(3, 50, TYPE_PROXIMITY, UNIT_CENTIMETER);
}

// Default function for processing actuator commands from the Cayenne Dashboard.
// You can also use functions for specific channels, e.g CAYENNE_IN(1) for channel 1 commands.
CAYENNE_IN_DEFAULT()
{
  CAYENNE_LOG("Channel %u, value %s", request.channel, getValue.asString());
  //Process message here. If there is an error set an error message using getValue.setError(), e.g getValue.setError("Error message");
}

to my chaines Arduino Nano and its still working without any disconnection, but my original Italian Arduino uno doesn’t

can you share the entire serial monitor output during the connect and disconnect event.

give me some time, cause my nano is in my country house, but I’am in town now, and I don’t have sensors with me, I will try without sensors

hold on, should I leave my rx and tx in 2 and 3 pins, or I need to move it to rx and tx?

you tried the software serial code on the arduino nano or uno? if on uno, try it on nano with rx and tx in 2 and 3.

On uno with 2 and 3:

60972] Publish: topic 1, channel 8, value   NAN, subkey p, key rel_hum
[66008] Publish: topic 1, channel 0, value 66008, subkey , key 
[71036] Connection ok
[76096] Publish: topic 1, channel 7, value   NAN, subkey c, key temp
[76102] Publish: topic 1, channel 8, value   NAN, subkey p, key rel_hum
[76179] Publish: topic 1, channel 0, value 76178, subkey , key 
[86297] Disconnected
[86297] Connecting to mqtt.mydevices.com:1883
[87605] Connected
[88740] Publish: topic 4, channel 65534, value Arduino Uno, subkey , key 
[93778] Publish: topic 6, channel 65534, value ATmega328P, subkey , key 
[98816] Publish: topic 7, channel 65534, value 16000000, subkey , key 
[103851] Publish: topic 5, channel 65534, value 1.3.0, subkey , key 
[108883] Publish: topic 8, channel 65534, value ESP8266Shield, subkey , key 
[108931] Publish: topic 1, channel 7, value   NAN, subkey c, key temp
[109717] Publish: topic 1, channel 8, value   NAN, subkey p, key rel_hum
[110435] Publish: topic 1, channel 0, value 110435, subkey , key 
[111142] Connection ok
[121171] Connection ok
[123945] Publish: topic 1, channel 7, value   NAN, subkey c, key temp
[124665] Publish: topic 1, channel 8, value   NAN, subkey p, key rel_hum
[129705] Publish: topic 1, channel 0, value 129705, subkey , key 
[134735] Connection ok
[138953] Publish: topic 1, channel 7, value   NAN, subkey c, key temp
[143990] Publish: topic 1, channel 8, value   NAN, subkey p, key rel_hum
[149028] Publish: topic 1, channel 0, value 149028, subkey , key 
[154057] Connection ok
[159117] Publish: topic 1, channel 7, value   NAN, subkey c, key temp
[159124] Publish: topic 1, channel 8, value   NAN, subkey p, key rel_hum
[159202] Publish: topic 1, channel 0, value 159201, subkey , key 
[169322] Disconnected
[169322] Connecting to mqtt.mydevices.com:1883
[170584] Connected
[171417] Publish: topic 4, channel 65534, value Arduino Uno, subkey , key 
[176455] Publish: topic 6, channel 65534, value ATmega328P, subkey , key 
[181492] Publish: topic 7, channel 65534, value 16000000, subkey , key 
[186527] Publish: topic 5, channel 65534, value 1.3.0, subkey , key 
[191559] Publish: topic 8, channel 65534, value ESP8266Shield, subkey , key 
[191605] Publish: topic 1, channel 7, value   NAN, subkey c, key temp
[192394] Publish: topic 1, channel 8, value   NAN, subkey p, key rel_hum
[193105] Publish: topic 1, channel 0, value 193105, subkey , key 
[193805] Connection ok
[203834] Connection ok
[206607] Publish: topic 1, channel 7, value   NAN, subkey c, key temp
[207318] Publish: topic 1, channel 8, value   NAN, subkey p, key rel_hum
[212358] Publish: topic 1, channel 0, value 212358, subkey , key 
[217387] Connection ok
[221636] Publish: topic 1, channel 7, value   NAN, subkey c, key temp
[226674] Publish: topic 1, channel 8, value   NAN, subkey p, key rel_hum
[231711] Publish: topic 1, channel 0, value 231711, subkey , key 
[236740] Connection ok
[241799] Publish: topic 1, channel 7, value   NAN, subkey c, key temp
[241806] Publish: topic 1, channel 8, value   NAN, subkey p, key rel_hum
[241884] Publish: topic 1, channel 0, value 241883, subkey , key 
[252005] Disconnected
[252005] Connecting to mqtt.mydevices.com:1883
[253245] Connected
[254093] Publish: topic 4, channel 65534, value Arduino Uno, subkey , key 
[259132] Publish: topic 6, channel 65534, value ATmega328P, subkey , key 
[264170] Publish: topic 7, channel 65534, value 16000000, subkey , key 
[269206] Publish: topic 5, channel 65534, value 1.3.0, subkey , key 
[274239] Publish: topic 8, channel 65534, value ESP8266Shield, subkey , key 
[274285] Publish: topic 1, channel 7, value   NAN, subkey c, key temp
[275290] Publish: topic 1, channel 8, value   NAN, subkey p, key rel_hum
[276302] Publish: topic 1, channel 0, value 276302, subkey , key 
[277195] Connection ok
[287224] Connection ok
[289305] Publish: topic 1, channel 7, value   NAN, subkey c, key temp
[290251] Publish: topic 1, channel 8, value   NAN, subkey p, key rel_hum
[295291] Publish: topic 1, channel 0, value 295291, subkey , key 
[300320] Connection ok
[304329] Publish: topic 1, channel 7, value   NAN, subkey c, key temp
[309366] Publish: topic 1, channel 8, value   NAN, subkey p, key rel_hum
[314404] Publish: topic 1, channel 0, value 314404, subkey , key 
[319433] Connection ok
[324493] Publish: topic 1, channel 7, value   NAN, subkey c, key temp
[324500] Publish: topic 1, channel 8, value   NAN, subkey p, key rel_hum
[324578] Publish: topic 1, channel 0, value 324577, subkey , key 
[334698] Disconnected
[334698] Connecting to mqtt.mydevices.com:1883
[335913] Connected
[336760] Publish: topic 4, channel 65534, value Arduino Uno, subkey , key 
[341799] Publish: topic 6, channel 65534, value ATmega328P, subkey , key 
[346838] Publish: topic 7, channel 65534, value 16000000, subkey , key 
[351873] Publish: topic 5, channel 65534, value 1.3.0, subkey , key 
[356905] Publish: topic 8, channel 65534, value ESP8266Shield, subkey , key 
[356953] Publish: topic 1, channel 7, value   NAN, subkey c, key temp
[357662] Publish: topic 1, channel 8, value   NAN, subkey p, key rel_hum
[358341] Publish: topic 1, channel 0, value 358340, subkey , key 
[359005] Connection ok
[369034] Connection ok
[371959] Publish: topic 1, channel 7, value   NAN, subkey c, key temp
[372933] Publish: topic 1, channel 8, value   NAN, subkey p, key rel_hum
[377972] Publish: topic 1, channel 0, value 377972, subkey , key 
[383001] Connection ok
[386979] Publish: topic 1, channel 7, value   NAN, subkey c, key temp
[392017] Publish: topic 1, channel 8, value   NAN, subkey p, key rel_hum
[397056] Publish: topic 1, channel 0, value 397056, subkey , key 
[402085] Connection ok
[407145] Publish: topic 1, channel 7, value   NAN, subkey c, key temp
[407152] Publish: topic 1, channel 8, value   NAN, subkey p, key rel_hum
[407230] Publish: topic 1, channel 0, value 407229, subkey , key 
[417350] Disconnected
[417350] Connecting to mqtt.mydevices.com:1883
[419010] Connected
[420046] Publish: topic 4, channel 65534, value Arduino Uno, subkey , key 
[425085] Publish: topic 6, channel 65534, value ATmega328P, subkey , key 
[430123] Publish: topic 7, channel 65534, value 16000000, subkey , key 

with this code:

#define CAYENNE_DEBUG       // Uncomment to show debug messages
#define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space
#include <CayenneMQTTESP8266Shield.h>
#include <SoftwareSerial.h>
#include <DHT.h>
#define VIRTUAL_CHANNEL 1


// WiFi network info.
char ssid[] = "";
char wifiPassword[] = "";

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "";
char password[] = "";
char clientID[] = "";


// Set ESP8266 Serial object. In this example we use the Serial1 hardware serial which is available on boards like the Arduino Mega.
//#define EspSerial Serial
#define DHTPIN 5     // Digital pin connected to the DHT sensor
SoftwareSerial EspSerial(2,3);
#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321
ESP8266 wifi(&EspSerial);
#define TEMPERATURE_VIRTUAL_CHANNEL 7
#define HUMIDITY_VIRTUAL_CHANNEL 8


DHT dht(DHTPIN, DHTTYPE); // Initialize DHT sensor.
void setup()
{
  Serial.begin(9600);   
  delay(10);

  // Set ESP8266 baud rate
  EspSerial.begin(9600);
  delay(10);
  Cayenne.begin(username, password, clientID, wifi, ssid, wifiPassword);
 
}


void loop()
{
  Cayenne.loop();
}
CAYENNE_OUT(TEMPERATURE_VIRTUAL_CHANNEL)
{
  Cayenne.virtualWrite(TEMPERATURE_VIRTUAL_CHANNEL, dht.readTemperature(), "temp", "c");
}

// This function is called at intervals to send humidity sensor data to Cayenne.
CAYENNE_OUT(HUMIDITY_VIRTUAL_CHANNEL)
{
  Cayenne.virtualWrite(HUMIDITY_VIRTUAL_CHANNEL, dht.readHumidity(), "rel_hum", "p");
}
// Default function for sending sensor data at intervals to Cayenne.
// You can also use functions for specific channels, e.g CAYENNE_OUT(1) for sending channel 1 data.
CAYENNE_OUT_DEFAULT()
{
  // Write data to Cayenne here. This example just sends the current uptime in milliseconds on virtual channel 0.
  Cayenne.virtualWrite(0, millis());
  // Some examples of other functions you can use to send data.
  //Cayenne.celsiusWrite(1, 22.0);
  //Cayenne.luxWrite(2, 700);
  //Cayenne.virtualWrite(3, 50, TYPE_PROXIMITY, UNIT_CENTIMETER);
}

// Default function for processing actuator commands from the Cayenne Dashboard.
// You can also use functions for specific channels, e.g CAYENNE_IN(1) for channel 1 commands.
CAYENNE_IN_DEFAULT()
{
  CAYENNE_LOG("Channel %u, value %s", request.channel, getValue.asString());
  //Process message here. If there is an error set an error message using getValue.setError(), e.g getValue.setError("Error message");
}

but it doesn’t show the temperature

for temperature issue, you are missing dht.begin(); in the void setup.
the disconnect issue maybe due to various reason, one maybe a faulty uno, other maybe power supply issue. Did you use a voltage divide between uno and esp?

my mistake

now I use this code:
/*
This sketch connects to the Cayenne server using an ESP8266 WiFi module as a shield connected via a hardware serial to an Arduino.

The CayenneMQTT Library is required to run this sketch. If you have not already done so you can install it from the Arduino IDE Library Manager.

Steps:
1. Install the ESP8266SerialLibrary.zip library via the Arduino IDE (Sketch->Include Library->Add .ZIP Library) from the Cayenne extras/libraries
   folder (e.g. My Documents\Arduino\libraries\CayenneMQTT\extras\libraries) to compile this example.
2. Connect the ESP8266 as a shield to your Arduino. This example uses the Serial1 hardware serial pins available on the Mega. You can also try 
   using a software serial, though it may be less stable.
3. Set the Cayenne authentication info to match the authentication info from the Dashboard.
4. Set the network name and password.
5. Compile and upload the sketch.
6. A temporary widget will be automatically generated in the Cayenne Dashboard. To make the widget permanent click the plus sign on the widget.

NOTE: This code requires ESP8266 firmware version 1.0.0 (AT v0.22) or later.
*/

//#define CAYENNE_DEBUG       // Uncomment to show debug messages
#define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space
#include <CayenneMQTTESP8266Shield.h>
#include <DHT.h>
// WiFi network info.
char ssid[] = "";
char wifiPassword[] = "";

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "291";
char password[] = "";
char clientID[] = "9f\";

// Set ESP8266 Serial object. In this example we use the Serial1 hardware serial which is available on boards like the Arduino Mega.
#define EspSerial Serial
#define SENSOR_PIN1 A0
#define VIRTUAL_CHANNEL1 1
#define SENSOR_PIN2 A1
#define VIRTUAL_CHANNEL2 2
#define DHTPIN 5     // Digital pin connected to the DHT sensor
#define RELEY_VIRTUAL_CHANNEL 9
#define ACTUATOR_PIN 4
// Uncomment whatever type you're using!
//#define DHTTYPE DHT11   // DHT 11
#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321
//#define DHTTYPE DHT21   // DHT 21 (AM2301)

#define TEMPERATURE_VIRTUAL_CHANNEL 7
#define HUMIDITY_VIRTUAL_CHANNEL 8


DHT dht(DHTPIN, DHTTYPE); // Initialize DHT sensor.
ESP8266 wifi(&EspSerial);

void setup()
{
  pinMode(ACTUATOR_PIN, OUTPUT);


  Serial.begin(9600);
  delay(10);

  // Set ESP8266 baud rate
  EspSerial.begin(9600);
  delay(10);

  Cayenne.begin(username, password, clientID, wifi, ssid, wifiPassword);
  dht.begin();
}

void loop()
{
  Cayenne.loop();
}
CAYENNE_IN(RELEY_VIRTUAL_CHANNEL)
{
  // Write value to turn the relay switch on or off. This code assumes you wire your relay as normally open.
  if (getValue.asInt() == 0) {
    digitalWrite(ACTUATOR_PIN, LOW);
  }
  else {
    digitalWrite(ACTUATOR_PIN, HIGH);
  }
} 
CAYENNE_OUT(TEMPERATURE_VIRTUAL_CHANNEL)
{
  Cayenne.virtualWrite(TEMPERATURE_VIRTUAL_CHANNEL, dht.readTemperature(), "temp", "c");
}

// This function is called at intervals to send humidity sensor data to Cayenne.
CAYENNE_OUT(HUMIDITY_VIRTUAL_CHANNEL)
{
  Cayenne.virtualWrite(HUMIDITY_VIRTUAL_CHANNEL, dht.readHumidity(), "rel_hum", "p");
}
// Default function for sending sensor data at intervals to Cayenne.
// You can also use functions for specific channels, e.g CAYENNE_OUT(1) for sending channel 1 data.
CAYENNE_OUT_DEFAULT()
{
  Cayenne.virtualWrite(VIRTUAL_CHANNEL1, analogRead(SENSOR_PIN1));

Cayenne.virtualWrite(VIRTUAL_CHANNEL2, analogRead(SENSOR_PIN2));
  // Write data to Cayenne here. This example just sends the current uptime in milliseconds on virtual channel 0.
  Cayenne.virtualWrite(0, millis());
  // Some examples of other functions you can use to send data.
  //Cayenne.celsiusWrite(1, 22.0);
  //Cayenne.luxWrite(2, 700);
  //Cayenne.virtualWrite(3, 50, TYPE_PROXIMITY, UNIT_CENTIMETER);
}

// Default function for processing actuator commands from the Cayenne Dashboard.
// You can also use functions for specific channels, e.g CAYENNE_IN(1) for channel 1 commands.
CAYENNE_IN_DEFAULT()
{
  CAYENNE_LOG("Channel %u, value %s", request.channel, getValue.asString());
  //Process message here. If there is an error set an error message using getValue.setError(), e.g getValue.setError("Error message");
}

and every thing is working now, without any disconnection for already 10 minutes.
for my esp I use this thing:

May be different router settings?