Ds18b20 issue MQTT

Hi community, I need some support on my project MQTT migration.
The project is very simple, 2 relay and 1 ds18b20. Before everythings worked fine. Now I’m not able to manage the ds18b20. I was able to reinstall the 2 relays and they work, but once I try to implement the sketch to manage the sensor it stops to work and I’m not able to manage the project via web or mobile. I attach the sketch just to verify but it’s very simple. The sensor is attached to arduino pin 7.
Arduino UNO and esp8266
I installed of course the MQTT libraries and tryed dozen of sketch combination but I’m not able to go forward
Thanks in advance

#define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space
#include <CayenneMQTTESP8266Shield.h>
#include <OneWire.h>
#include <DallasTemperature.h>

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

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

#define ACTUATOR_PIN8 8// Do not use digital pins 0 or 1 since those conflict with the use of Serial.
#define ACTUATOR_PIN9 9 // Do not use digital pins 0 or 1 since those conflict with the use of Serial.
#define VIRTUAL_CHANNEL 3
#define sensorpin 7 // Do not use digital pins 0 or 1 since those conflict with the use of Serial.


OneWire oneWire(sensorpin);
DallasTemperature sensors(&oneWire);

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

ESP8266 wifi(&EspSerial);

void setup()
{
  Serial.begin(9600);
  pinMode(ACTUATOR_PIN8, OUTPUT);
  pinMode(ACTUATOR_PIN9, OUTPUT);
  delay(10);

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

  Cayenne.begin(username, password, clientID, wifi, ssid, wifiPassword);
  digitalWrite(ACTUATOR_PIN8, HIGH);
  digitalWrite(ACTUATOR_PIN9, HIGH);
}

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


CAYENNE_IN(1)
{
  // 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_PIN8, HIGH);
  }
  else {
    digitalWrite(ACTUATOR_PIN8, LOW);
  }
}
CAYENNE_IN(2)
{
  // 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_PIN9, HIGH);
  }
  else {
    digitalWrite(ACTUATOR_PIN9, LOW);
  }
}


CAYENNE_IN(3)
{
  // Send the command to get temperatures.
//sensors.requestTemperatures();
  // This command writes the temperature in Celsius to the Virtual Channel.
//Cayenne.celsiusWrite(VIRTUAL_CHANNEL, sensors.getTempCByIndex(0));
  // To send the temperature in Fahrenheit use the corresponding code below.
//Cayenne.fahrenheitWrite(VIRTUAL_CHANNEL, sensors.getTempFByIndex(0));
}

change to

CAYENNE_OUT(3)

{

// Send the command to get temperatures.

sensors.requestTemperatures();

// This command writes the temperature in Celsius to the Virtual Channel.

Cayenne.celsiusWrite(VIRTUAL_CHANNEL, sensors.getTempCByIndex(0));

// To send the temperature in Fahrenheit use the corresponding code below.

//Cayenne.fahrenheitWrite(VIRTUAL_CHANNEL, sensors.getTempFByIndex(0));

}

Thanks shramiksalgaonkar is one of the combination I have tryed but once I load the sketch the system is not able to connect to cayenne, it remain offline

esp8266 as shield for uno is not stable and is recomended for mega and i have not tried it with uno. what error your getting in your serial monitor. maybe @jcruz and @bestes can help you out with this

@shramik_salgaonkar may be you are right but before the MQTT migration it worked fine and still now if I comment the 2 sketch linees to read the temperature I’m able to manage the system via web and mobile.

but MQTT for other devices is very stable and i am loving it. it just that it require a bit more time to make it all perfect.

Just for information, I discovered that any instruction written inside void loop() do not permit the connection with cayenne.
To solve I changed arduino UNO in Mega. Now it works as expected.

Thanks anyway for the support

1 Like