Temperature measurement

can you try with a basic code again (with no sensor code). and try removing all print statement. Also comment Serial.begin(9600);

I copy paste my other code. It’s working now. I don’t know why, the code is almost the same, any way is working now. Thanks. Have a good one.

Hi again. It is again start to goes offline. It could work for 5-15 min and goes offline. What I noticed, I think it have a conflict when I use analog inputs for soil moisture sensor, when I disconnect it, everything works fine, but when I connecting it, after 5-10 min its goes offline. My be we need to add some code to avoid this conflict with analog input?

#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[] = "291ec8";
char password[] = "";
char clientID[] = "7d";

// 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 SENSOR_PIN3 A2
#define VIRTUAL_CHANNEL3 3
#define SENSOR_PIN4 A3
#define VIRTUAL_CHANNEL4 4
#define SENSOR_PIN5 A4
#define VIRTUAL_CHANNEL5 5
#define SENSOR_PIN6 A5
#define VIRTUAL_CHANNEL6 6
#define DHTPIN 2     // Digital pin connected to the DHT sensor

// 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
#define RELEY_VIRTUAL_CHANNEL 9
#define ACTUATOR_PIN 4

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

void setup()
{
  //Serial.begin(9600);
  //delay(10);
  pinMode(ACTUATOR_PIN, OUTPUT);

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

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

void loop()
{
  Cayenne.loop();
}
// This function is called at intervals to send temperature sensor data to Cayenne in Celsius.
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");
}
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);
  }
}
// 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));

Cayenne.virtualWrite(VIRTUAL_CHANNEL3, analogRead(SENSOR_PIN3));

Cayenne.virtualWrite(VIRTUAL_CHANNEL4, analogRead(SENSOR_PIN4));

Cayenne.virtualWrite(VIRTUAL_CHANNEL5, analogRead(SENSOR_PIN5));

Cayenne.virtualWrite(VIRTUAL_CHANNEL6, analogRead(SENSOR_PIN6));
  // 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");
}

output

AT
ATE0
AT+CIPMUX=1
AT+CWMODE?
AT+CWJAP="Nikolskaia33","89859248161"
[5571] Connected to WiFi
[5571] Connecting to mqtt.mydevices.com:1883
AT+CIPSTART=1,"TCP","mqtt.mydevices.com",1883
AT+CIPSEND=1,40
⸮MQIsdp⸮<$7d254820-7256-11e9-beb3AT+CIPSEND=1,40
-736c9e4bf7d0$291ec810-488a-11e8-bf56-dAT+CIPSEND=1,40
b14f0c2b326(0e737ffa31e6de40bdc7958fd08AT+CIPSEND=1,13
2af113f3c1a4f[6402] Connected
AT+CIPSEND=1,40
⸮^Yv1/291ec810-488a-11e8-bf56-db14f0cAT+CIPSEND=1,40
2b326/things/7d254820-7256-11e9-beb3-736AT+CIPSEND=1,16
c9e4bf7d0/cmd/+[6946] Publish: topic 4, channel 65534, value Arduino Uno, subkey , key 
AT+CIPSEND=1,40
1j]v1/291ec810-488a-11e8-bf56-db14f0c2b[16975] Publish: topic 6, channel 65534, value ATmega328P, subkey , key 
AT+CIPSEND=1,40
1mav1/291ec810-488a-11e8-bf56-db14f0c2b[27005] Publish: topic 7, channel 65534, value 16000000, subkey , key 
AT+CIPSEND=1,40
1kav1/291ec810-488a-11e8-bf56-db14f0c2bAT+CIPSEND=1,40
[32228] Publish: topic 5, channel 65534, value 1.3.0, subkey , key 
AT+CIPSEND=1,40
[37245] Publish: topic 8, channel 65534, value ESP8266Shield, subkey , key 
[37316] Publish: topic 1, channel 7, value 26.500, subkey c, key temp
AT+CIPSEND=1,40
[42337] Publish: topic 1, channel 8, value 47.700, subkey p, key rel_hum
AT+CIPSEND=1,40
[47354] Publish: topic 1, channel 1, value 432, subkey , key 
AT+CIPSEND=1,40
[52371] Publish: topic 1, channel 2, value 302, subkey , key 
AT+CIPSEND=1,40
[57387] Publish: topic 1, channel 3, value 296, subkey , key 
AT+CIPSEND=1,40
[62403] Publish: topic 1, channel 4, value 308, subkey , key 
AT+CIPSEND=1,40
[67419] Publish: topic 1, channel 5, value 385, subkey , key 
AT+CIPSEND=1,40
[72435] Publish: topic 1, channel 6, value 391, subkey , key 
AT+CIPSEND=1,40
[77451] Connection ok
AT+CIPSEND=1,2
[82497] Publish: topic 1, channel 7, value 26.200, subkey c, key temp
[82499] Publish: topic 1, channel 8, value 49.100, subkey p, key rel_hum
[82504] Publish: topic 1, channel 1, value 327, subkey , key 
[82510] Publish: topic 1, channel 2, value 310, subkey , key 
[82515] Publish: topic 1, channel 3, value 315, subkey , key 
[82521] Publish: topic 1, channel 4, value 312, subkey , key 
[82526] Publish: topic 1, channel 5, value 375, subkey , key 
[82532] Publish: topic 1, channel 6, value 361, subkey , key 
AT+CIPSEND=1,2
AT+CIPCLOSE=1
[92563] Disconnected
[92563] Connecting to mqtt.mydevices.com:1883
AT+CIPSTART=1,"TCP","mqtt.mydevices.com",1883
AT+CIPSEND=1,40
⸮MQIsdp⸮<$7d254820-7256-11e9-beb3AT+CIPSEND=1,40
-736c9e4bf7d0$291ec810-488a-11e8-bf56-dAT+CIPSEND=1,40
b14f0c2b326(0e737ffa31e6de40bdc7958fd08AT+CIPSEND=1,13
2af113f3c1a4f[93729] Connected
AT+CIPSEND=1,40
⸮^Yv1/291ec810-488a-11e8-bf56-db14f0cAT+CIPSEND=1,40
2b326/things/7d254820-7256-11e9-beb3-736AT+CIPSEND=1,16
c9e4bf7d0/cmd/+[94446] Publish: topic 4, channel 65534, value Arduino Uno, subkey , key 
AT+CIPSEND=1,40
1j]v1/291ec810-488a-11e8-bf56-db14f0c2b[104476] Publish: topic 6, channel 65534, value ATmega328P, subkey , key 
AT+CIPSEND=1,40
1mav1/291ec810-488a-11e8-bf56-db14f0c2b[114505] Publish: topic 7, channel 65534, value 16000000, subkey , key 
AT+CIPSEND=1,40
1kav1/291ec810-488a-11e8-bf56-db14f0c2bAT+CIPSEND=1,40
[119774] Publish: topic 5, channel 65534, value 1.3.0, subkey , key 
AT+CIPSEND=1,40
[124791] Publish: topic 8, channel 65534, value ESP8266Shield, subkey , key 
[124831] Publish: topic 1, channel 7, value 26.100, subkey c, key temp
AT+CIPSEND=1,40

let’s try the software serial. you need to connect esp to pin 2 and 3 of arduino.

#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>

#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

SoftwareSerial EspSerial(2,3);

ESP8266 wifi(&EspSerial);

void setup()
{
  Serial.begin(115200);   
  delay(10);

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


void loop()
{
  Cayenne.loop();
}

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

You mean connect RX and TX to 2 and 3 pin? Which one goes to pin 2, RX or TX?

Connection:
UNO------------------Esp8266
(2)Rx--------------------Tx
(3)Tx--------------------Rx

So, what’s next? I uploading code which you provide and copy paste the serial com port?

yes.

Which country you working? What time zone and working hours?

Timezone: GMT+5

[79250] Failed to set STA mode
[80798] Failed to set STA mode
[82347] Failed to set STA mode
[83895] Failed to set STA mode
[85443] Failed to set STA mode
[86992] Failed to set STA mode
[88541] Failed to set STA mode
[90089] Failed to set STA mode

What baud rate is set on your esp?

How could I check it?

This is the process i use to check the baud rate. currently the baud rate is set to 9600. If in the serial monitor i get response for AT then it is set to 9600. if not then change serial baud rate in the code to 115200:

// Basic serial communication with ESP8266
// Uses serial monitor for communication with ESP8266
//
//  Pins
//  Arduino pin 2 (RX) to ESP8266 TX
//  Arduino pin 3 to voltage divider then to ESP8266 RX
//  Connect GND from the Arduiono to GND on the ESP8266
//  Pull ESP8266 CH_PD HIGH
//
// When a command is entered in to the serial monitor on the computer 
// the Arduino will relay it to the ESP8266
//
 //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() );  }
}
1 Like

On 115200 it shows
Remember to to set Both NL & CR in the serial monitor.
Ready

AT

OK

May be I need to uncomment something in code?

once you get response OK try setting the baud rate to 9600 using AT+CIOBAUD=9600 and use the cayenne code with 9600 baud rate.

Hi. How are you? Sorry man, don’t have time on this week.
so I try to uncomment AT+CI0BAUD=9600 and have a problem

you have to add AT+CIOBAUD=9600 in your serial monitor.

So, I don’t need to uncomment this in the code? I Just need to put this in serial monitor?