Using DS18B20 as input for 2 state trigger

Having a problem changing from an analog input to a DS18B20 as the input in this example. The temp always reads 24 Degrees. Not sure where that is coming from. Reads correctly when used with other programs. Any suggestions?
Thanks,
John

#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h> // Change this to use a different communication device. See Communications examples.
#include <OneWire.h>
#include <DallasTemperature.h>

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

#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
DeviceAddress tempSensorA = { 0x28, 0xFF, 0xC7, 0xA8, 0x60, 0x17, 0x05, 0x96 };  

#define DATA_CHANNEL 0 //Virtual channel for publishing sensor data.
#define TRIGGER_CHANNEL 1 //Virtual channel for publishing the trigger value.
#define THRESHOLD 60 //Threshold for the trigger.
bool sendBelowThreshold = true; //Set to true if the trigger should happen when the data value is below the threshold, 
                                //false if it should happen when the data value is above or equal to the threshold.
bool crossedThreshold = false;

void setup() {
  Serial.begin(9600);
  Cayenne.begin(username, password, clientID, ssid, wifiPassword);
   //set the resolution to 10 bit
  sensors.setResolution(tempSensorA, 10);
}


void sendTriggerValue(int channel, int value, int threshold, bool sendBelowThreshold) {
  if (((value >= threshold) && !sendBelowThreshold) || ((value < threshold) && sendBelowThreshold)) {
    if (!crossedThreshold) {
      Cayenne.virtualWrite(channel, 1, "digital_sensor", "d"); //set trigger two-state widget to 1 
      crossedThreshold = true;
    }
  }
  else
  {
    Cayenne.virtualWrite(channel, 0, "digital_sensor", "d"); //set trigger two-state widget to 0
    crossedThreshold = false;
  }
}

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

CAYENNE_OUT_DEFAULT()
{
// int sensor_value = analogRead(A0);
 
   int sensor_value = sensors.getTempF(tempSensorA);
   sendTriggerValue(TRIGGER_CHANNEL, sensor_value, THRESHOLD, sendBelowThreshold);
   
// Cayenne.virtualWrite(DATA_CHANNEL, sensor_value , "analog_sensor", "null"); //widget to display sensor data.

   Cayenne.virtualWrite(DATA_CHANNEL, sensor_value , "temp", "f"); //widget to display sensor data.
}

As I read my posted problem I saw the answer, needed:
sensors.requestTemperatures();

Have a good weekend!!
John

2 Likes