Temperature measurement

follow this guide and get your esp connected to cayenne Cayenne MQTT and Standalone ESP8266 ESP-01 - myDevices and then add the code to control the relay.

Thanks so much!

1 Like

Hi again. Could you help me with the soil moisture sensor, I mean with the code. Thanks.

which soil moisture sensor are you using?

I’m using this ones.
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>

// 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 SENSOR_PIN1 A0
#define VIRTUAL_CHANNEL1 1
#define SENSOR_PIN2 A2
#define VIRTUAL_CHANNEL2 2

ESP8266 wifi(&EspSerial);

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

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

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

void loop()
{
  Cayenne.loop();
}
CAYENNE_OUT(VIRTUAL_CHANNEL)
{
  Cayenne.virtualWrite(VIRTUAL_CHANNEL1, analogRead(SENSOR_PIN1));


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

for the first time everything was working, but on the next day, after I play a little bit with widgets, its stop working. I delete an Arduino and add it again, done everything from the very beginning, but it doesn’t help.

can you uncomment this line in your code #define CAYENNE_DEBUG and check the issue in your serial monitor.

AT
[1529] ESP is not responding
AT
ATE0
AT+CIPMUX=1
AT+CWMODE?
AT+CWJAP=“BEIREL 6354”,“75288437kh”
[8094] Connected to WiFi
[8095] Connecting to mqtt.mydevices.com:1883
AT+CIPSTART=1,“TCP”,“mqtt.mydevices.com”,1883
AT+CIPSEND=1,40
⸮MQIsdp⸮<$d06efc20-6116-11e9-9dd7AT+CIPSEND=1,40
-93e53f1934d3$291ec810-488a-11e8-bf56-dAT+CIPSEND=1,40
b14f0c2b326(0e737ffa31e6de40bdc7958fd08AT+CIPSEND=1,13
2af113f3c1a4f[8951] Connected
AT+CIPSEND=1,40
⸮^Yv1/291ec810-488a-11e8-bf56-db14f0cAT+CIPSEND=1,40
2b326/things/d06efc20-6116-11e9-9dd7-93eAT+CIPSEND=1,16
53f1934d3/cmd/+[9529] Publish: topic 4, channel 65534, value Arduino Uno, subkey , key
AT+CIPSEND=1,40
1j]v1/291ec810-488a-11e8-bf56-db14f0c2bAT+CIPSEND=1,40
326/things/d06efc20-6116-11e9-9dd7-93e53AT+CIPSEND=1,28
f1934d3/sys/modelArduino Uno[10061] Publish: topic 6, channel 65534, value ATmega328P, subkey , key
AT+CIPSEND=1,40
1mav1/291ec810-488a-11e8-bf56-db14f0c2bAT+CIPSEND=1,40
326/things/d06efc20-6116-11e9-9dd7-93e53AT+CIPSEND=1,31
f1934d3/sys/cpu/modelATmega328P[10544] Publish: topic 7, channel 65534, value 16000000, subkey , key
AT+CIPSEND=1,40
1kav1/291ec810-488a-11e8-bf56-db14f0c2bAT+CIPSEND=1,40
326/things/d06efc20-6116-11e9-9dd7-93e53AT+CIPSEND=1,29
f1934d3/sys/cpu/speed16000000[11027] Publish: topic 5, channel 65534, value 1.3.0, subkey , key
AT+CIPSEND=1,40
1f_v1/291ec810-488a-11e8-bf56-db14f0c2bAT+CIPSEND=1,40
326/things/d06efc20-6116-11e9-9dd7-93e53AT+CIPSEND=1,24
f1934d3/sys/version1.3.0[11508] Publish: topic 8, channel 65534, value ESP8266Shield, subkey , key
[11575] Publish: topic 1, channel 0, value 11575, subkey , key
AT+CIPSEND=1,40
1aZv1/291ec810-488a-11e8-bf56-db14f0c2bAT+CIPSEND=1,40
326/things/d06efc20-6116-11e9-9dd7-93e53AT+CIPSEND=1,19
f1934d3/data/011575[21547] Connection ok
[26579] Publish: topic 1, channel 0, value 26579, subkey , key
AT+CIPSEND=1,40
1aZv1/291ec810-488a-11e8-bf56-db14f0c2bAT+CIPSEND=1,40
326/things/d06efc20-6116-11e9-9dd7-93e53AT+CIPSEND=1,19
f1934d3/data/026579[31551] Connection ok
[41552] Connection ok
[41585] Publish: topic 1, channel 0, value 41585, subkey , key
AT+CIPSEND=1,40
1aZv1/291ec810-488a-11e8-bf56-db14f0c2bAT+CIPSEND=1,40
326/things/d06efc20-6116-11e9-9dd7-93e53AT+CIPSEND=1,19
f1934d3/data/041585

this one?

are you using this board?

No

I’m using Arduino Uno and ESP8266 module

the arduino UNO and esp8266 shield code is quite unstable as there is only one serial on uno. while this code is made for arduino mega.
from the serial monitor it looks like connecting but sending data on only channel 1. so can you try making this small change:

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

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());
Cayenne.virtualWrite(VIRTUAL_CHANNEL1, analogRead(SENSOR_PIN1));

Cayenne.virtualWrite(VIRTUAL_CHANNEL2, analogRead(SENSOR_PIN2));
}

wow it’s working
but why?

you were calling the CAYENNE_OUT function wrongly.

Ok.
Next problem: when I reboot the page, sensor shows value until the “0” and “2” channels pop up, but on my phone it shows all the time

what do mean by this. can you provide a screenshot of this.

you need to add the widgets to the dashboard by clicking on the + on the widgets.