DS18B20 Temp sensor/Cayenne dashboard problems


#21

You might be polling the temp sensor too fast. Try this:

CAYENNE_OUT(VIRTUAL_PIN6)                                  
{
  delay(5000);
   sensors1.requestTemperatures();
   Cayenne.celsiusWrite(VIRTUAL_PIN6, sensors1.getTempCByIndex(0));
//  Cayenne.virtualWrite(V6, temperature1);
}
CAYENNE_OUT(VIRTUAL_PIN7)                                  
{
  delay(5000);
  sensors2.requestTemperatures();
  Cayenne.celsiusWrite(VIRTUAL_PIN7, sensors2.getTempCByIndex(0));
//  Cayenne.virtualWrite(V7, temperature2);
}
CAYENNE_OUT(VIRTUAL_PIN8)                                  
{
  delay(5000);
  sensors3.requestTemperatures();
  Cayenne.celsiusWrite(VIRTUAL_PIN7, sensors3.getTempCByIndex(0));
//  Cayenne.virtualWrite(V8, temperature3);
}

#22

Hi from today I have the sample problem!
I have only one DS18B20 connected on my pi that worked fine but now since today it does not work anymore and my dashboard is full of sensors that I can not remove and they block my dashboard (I can not do anything my page is frozen)!
What can I do?


#23

Can you check your wiring and possibly switch our for another temp senor if possible? Kind of sounds like the sensor is bad or loose connection.


#24

Hey gianfryn,

I have been experiencing a similar problem over the last few days. I have an Arduino Uno accessing Cayenne through my Raspberry Pi3 through a USB-serial port. Over the weekend my sensors were working great and the widgets were updating without issue. After about 20 minutes, the whole dashboard froze. I am also unable to remove widgets. I know my sensors are working fine as I have tested them using my Serial Monitor when not connected to the the Pi or Cayenne. Please advise.


#25

I have the same problem!!
I disconnected the sensor but I can not remove the 1000 sensors on my bashboard! I managed to remove them from the app on my phone but this did not applied to the web one!!
I am disperate…
I do not know what to do!


#26

Dear Adam,
I can try with another sensor but my feeling is that the problem is not the sensor because for instance my dashboard is frozen and I can not remove all the sensors or doing other stuff!!
it should be a bug !


#27

I had a similar problem last year and I had to reset dashboard several times and start over fresh. Seems I remember a system problem that @bestes or @rsiegel or maybe @adam helped me solve.
This maybe jog memories.


#28

This is the code I am running on the UNO R3 that is attached to my (Raspberry Pi 3 via Serial-USB) running Raspbian Jessie using my home’s wifi. The issue I was experiencing was when viewing the dashboard via the web over the Raspberry Pi. I noticed the app values were no longer changing as well on my iPhone. Please forgive my coding skills as I am a science teacher trying to teach myself to use Arduinos and Raspberry Pis to help automate a hydroponic system I am building with my students. Everything I have learned has come in the last 2 months by reading tutorials, community forums, and reverse engineering the code of others.

//Libraries
#include <OneWire.h>
#include <DallasTemperature.h>
#include "DHT.h"
#include <CayenneSerial.h>
#include "CayenneDefines.h"

//DHT11 Air Temp and Humidity Sensor Type and Pin
#define DHTPIN 2
#define DHTTYPE DHT11

//DS18b20 Water Temp Sensor Pin
#define ONE_WIRE_BUS 3

//LED Outputs Pins
#define greenPin 4
#define yellowPin 5
#define redPin 6

//FanControl Pin
#define fanRelay 7

//Cayenne Virtual Pins
#define hum_VIRTUAL_PIN V0
#define aTemp_VIRTUAL_PIN V1
#define wTemp_VIRTUAL_PIN V2

//Setup a oneWire instance to communicate with DS18b20
OneWire oneWire(ONE_WIRE_BUS);

//Pass oneWire reference to Dallas Temperature
DallasTemperature sensors(&oneWire);

//Initialize DHT11 Sensor
DHT dht(DHTPIN, DHTTYPE);

//Set Variables to hold Sensor Readings
float aTemp;
float hum;
float wTemp;

//Establish delay period between readings return millis value
unsigned long waitTime=5000;
unsigned long previousMillis=0;

//Cayenne authentication token for Regini Arduino
char token[] = "mytoken"; //omitted for post but entered in code

void setup() 
{
  //Start Libraries
  Cayenne.begin(token, 9600);
  dht.begin();
  sensors.begin();

  //Assign Inputs and Outputs
  pinMode(greenPin, OUTPUT);
  pinMode(yellowPin, OUTPUT);
  pinMode(redPin, OUTPUT);
  pinMode(fanRelay, OUTPUT);
  
  //Start with Fan OFF (Relay OFF when HIGH)
  digitalWrite(fanRelay, HIGH);
}

void loop() 
{
  Cayenne.run();
  ReadSensors();
  TakeActions();
}

void ReadSensors()
{
  //Grab current time
  unsigned long currentMillis = millis();
    //Checks to ensure delay period has been met before reading senors again
    if ((unsigned long)(currentMillis - previousMillis) >= waitTime)
    {
      //Reads DHT11 Sensor for Air Temp in F and Humidity in %
      aTemp = dht.readTemperature(true);
      hum = dht.readHumidity();
      //Check if any reads failed and exit early (to try again)
      if (isnan(hum) || isnan(aTemp))
        {
          return;
        }
        
      //Issues temperature request to all oneWire sensors on the bus
      sensors.requestTemperatures();
      //Reads DS18b20 for water temperature. ByIndex(0) included if more sensors added later.
      wTemp = (sensors.getTempFByIndex(0));

      //Saves Current time
      previousMillis = millis();
     }
}
//Send Sensor Data to Cayenne Virtual Pins
CAYENNE_OUT(hum_VIRTUAL_PIN)
{
  Cayenne.virtualWrite(V0, hum);
}

CAYENNE_OUT(aTemp_VIRTUAL_PIN)
{
  Cayenne.virtualWrite(V1, aTemp);
}

CAYENNE_OUT(wTemp_VIRTUAL_PIN)
{
  Cayenne.virtualWrite(V2, wTemp);
}

void TakeActions()
{
  if (aTemp > 80)
  {
    digitalWrite(greenPin, LOW);
    digitalWrite(yellowPin, LOW);
    digitalWrite(redPin, HIGH);
    digitalWrite(fanRelay, LOW);
  }
  else if ((aTemp >= 75) && (aTemp <= 80))
  {
    digitalWrite(greenPin, LOW);
    digitalWrite(yellowPin, HIGH);
    digitalWrite(redPin, LOW);
    digitalWrite(fanRelay, HIGH);
  }
  else
  {
    digitalWrite(greenPin, HIGH);
    digitalWrite(yellowPin, LOW);
    digitalWrite(redPin, LOW);
    digitalWrite(fanRelay, HIGH);
  }
}

#29

apologies, for the continual posting, but the copy and pasting of my code created some crazy fonts and omitted three of my libraries as well as all the pound symbols:
OneWire.h
DallasTemperature.h
CayenneSerial.h


#30

It’s the markup taking over haha. I fixed it for you. In the future you select all the code and hit the </> to make it show up in the code block to disregard markup.

As far as the values not changing on your iPhone, I’m not sure what the problem would be there. Try connecting to WiFi on the same network if possible. This will connect to the Pi locally and will eliminate any network issues from your phone to the Cayenne server.


#31

Thanks! I guess you can tell I’m a rookie. The readings I was viewing were when the RPi and phone were on the same wifi network. Both the on screen widgets over the web using Chromium and the iOS widgets on my iPhone had frozen. I was testing the longevity of the connection as this system will eventually be monitoring our in school hydroponic garden full time. I was getting excellent results for a few minutes before it locked up.


#32

Even in my last post the markup ate some of my characters. It should say “In the future you select all the code and hit the </> to make it show up in the code block to disregard markup.”

The other suggestion I have is to check your power supplies to make sure they are all rated to handle your devices. For the Pi it should be at least 2A. I would use the same rating for the Arduino but 1A should be fine there.