Hi guys, im having some issues with cayenne and getting sensors going - this code (or very close to it) was going fine, then i changed some things unrelated to the onewire sensors and they’re just coming up with -127 degrees.
If i comment out the cayenne.begin part the serial monitor fills with the data i would expect.
Is there some stuff going on in the cayenne libraries that could stop this working? very confused, not a coder; strange to me that it was working then it just stopped.
Cheers
#define CAYENNE_PRINT Serial
#include <OneWire.h>
#include <DallasTemperature.h>
#include <CayenneMQTTEthernet.h>
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username = “x”;
char password = “x”;
char clientID = “x”;
#define ONEWIRESENSOR_PIN 10 // Do not use digital pins 0 or 1 since those conflict with the use of Serial.
#define OUTSIDE_NUMERIC 5
#define CEILING_NUMERIC 6
#define ROOM_NUMERIC 7
#define OUTSIDE_GRAPH 8
#define CEILING_GRAPH 9
#define ROOM_GRAPH 10
#define MOISTURE_VALUE 11
#define LIGHT_VALUE 15
const float AsensorPin = A0; // select the input pin for the potentiometer
const int relayPin = 2; // select the pin for the relay
float moisture = 0; // variable to store the value coming from the sensor
const int fanPin = 4; // fan output pin
const float LightPin = A1; // light pin
float light = 0; // light variable
OneWire oneWire(ONEWIRESENSOR_PIN);
DallasTemperature sensors(&oneWire);
void setup()
{
pinMode(relayPin, OUTPUT);
pinMode(fanPin, OUTPUT);
pinMode(AsensorPin, INPUT);
pinMode(LightPin, INPUT);
Serial.begin(9600);
Cayenne.begin(username, password, clientID);
sensors.begin();
}
void loop()
{
// Cayenne.loop();
//}
// This function is called at intervals to send sensor data to Cayenne.
CAYENNE_OUT(OUTSIDE_NUMERIC)
//{
// Send the command to get temperatures.
sensors.requestTemperatures();
light = analogRead(LightPin);
moisture = analogRead(AsensorPin);
moisture = (moisture / 700) * 100;
sensors.requestTemperatures();
// This command writes the temperature in Celsius to the Virtual Channel.
Serial.println(“”);
Serial.println(“Temperatures in house”);
Serial.println(“=====================”);
// OUTSIDE SENSOR TEMP
Cayenne.celsiusWrite(OUTSIDE_NUMERIC, sensors.getTempCByIndex(0));
Cayenne.celsiusWrite(OUTSIDE_GRAPH, sensors.getTempCByIndex(0));
Serial.print("Temperature OUTSIDE is: ");
Serial.println(sensors.getTempCByIndex(0));
// CEILING SENSOR TEMP
Cayenne.celsiusWrite(CEILING_NUMERIC, sensors.getTempCByIndex(1));
Cayenne.celsiusWrite(CEILING_GRAPH, sensors.getTempCByIndex(1));
Serial.print("Temperature CEILING is: ");
Serial.println(sensors.getTempCByIndex(1));
// ROOM SENSOR TEMP
Cayenne.celsiusWrite(ROOM_NUMERIC, sensors.getTempCByIndex(2));
Cayenne.celsiusWrite(ROOM_GRAPH, sensors.getTempCByIndex(2));
Serial.print("Temperature ROOM is: ");
Serial.println(sensors.getTempCByIndex(2));
// MOISTURE PRINT
Cayenne.virtualWrite(MOISTURE_VALUE, moisture, UNIT_PERCENT);
Serial.print(“Soil Moisture Percentage is: “);
Serial.print(moisture);
Serial.print(” %”);
Serial.println(" ");
// LIGHT PRINT
Cayenne.virtualWrite(LIGHT_VALUE, light, UNIT_PERCENT);
Serial.print("Light Level is: “);
Serial.print(light);
Serial.println(” ");
////////////////////////////////// HRV SYSTEM ///////////////////////////////////////
if (sensors.getTempCByIndex(1) < sensors.getTempCByIndex(2))
{
Serial.println(“high temp”);
digitalWrite(fanPin, HIGH);
}
else
{
Serial.println(“low temp”);
digitalWrite(fanPin, LOW);
}
////////////////////////////////// WATERING SYSTEM ///////////////////////////////////////
if (moisture < 30 and light < 300)
{
Serial.println(“Soil Moisture low, too bright to water”);
digitalWrite(relayPin, LOW);
}
else
if (moisture < 30 and light > 300)
{
Serial.println(“Soil Moisture low, Light level low - watering”);
digitalWrite(relayPin, HIGH);
}
else
{
Serial.println(“soil OK”);
digitalWrite(relayPin, LOW);
}
Serial.println(“end of loop”);
}