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