everything worked fine (the ds1820 was connecter on my hot water pipe. but since a few weeks I do not get new values.
is something changed so my sketch isn't compatible? who can help me with controlling the sketch?
Not knowing if it's a bug or something on the script.
Code: Select all
#include <SPI.h>
#include <MySensor.h>
#include <DHT.h>
#include <BH1750.h>
#include <Wire.h>
#include <DallasTemperature.h>
#include <OneWire.h>
#define COMPARE_TEMP 1 // Send temperature only if changed? 1 = Yes 0 = No
#define ONE_WIRE_BUS 5
#define MAX_ATTACHED_DS18B20 1
#define CHILD_ID_LIGHT 0
#define CHILD_ID_TEMP2 1
#define CHILD_ID_HUM 2
#define CHILD_ID_TEMP 2
#define CHILD_ID_MOT 3 // Id of the sensor child
#define HUMIDITY_SENSOR_DIGITAL_PIN 4
#define DIGITAL_INPUT_SENSOR 3 // The digital input you attached your motion sensor. (Only 2 and 3 generates interrupt!)
#define INTERRUPT DIGITAL_INPUT_SENSOR-2 // Usually the interrupt = pin -2 (on uno/nano anyway)
unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
DallasTemperature sensors(&oneWire); // Pass the oneWire reference to Dallas Temperature.
MySensor gw;
DHT dht;
BH1750 lightSensor;
float lastTemperature[MAX_ATTACHED_DS18B20];
int numSensors=1;
boolean receivedConfig = false;
boolean metric = true;
float lastTemp;
float lastHum;
MyMessage msgHum(CHILD_ID_HUM, V_HUM);
MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
MyMessage msgMot(CHILD_ID_MOT, V_TRIPPED);
MyMessage msgLux(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
MyMessage msgTemperature(CHILD_ID_TEMP2,V_TEMP);
uint16_t lastlux;
void setup()
{
// Startup up the OneWire library
sensors.begin();
// requestTemperatures() will not block current thread
sensors.setWaitForConversion(false);
// Startup and initialize MySensors library. Set callback for incoming messages.
gw.begin();
dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN);
// Send the Sketch Version Information to the Gateway
gw.sendSketchInfo("Temp/Temp/Humidity/Motion/Lux", "1.0");
pinMode(DIGITAL_INPUT_SENSOR, INPUT); // sets the motion sensor digital pin as input
// Register all sensors to gw (they will be created as child devices)
gw.present(CHILD_ID_TEMP2, S_TEMP);
gw.present(CHILD_ID_HUM, S_HUM);
gw.present(CHILD_ID_TEMP, S_TEMP);
gw.present(CHILD_ID_MOT, S_MOTION);
gw.present(CHILD_ID_LIGHT, S_LIGHT_LEVEL);
metric = gw.getConfig().isMetric;
lightSensor.begin();
}
void loop()
{
// Process incoming messages (like config from server)
gw.process();
// Read digital motion value
boolean tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH;
Serial.print("Motion 1/0: ");
Serial.println(tripped);
gw.send(msgMot.set(tripped?"1":"0")); // Send tripped value to gw
delay(dht.getMinimumSamplingPeriod());
float temperature = dht.getTemperature();
if (isnan(temperature)) {
Serial.println("Failed reading temperature from DHT");
} else if (temperature != lastTemp) {
lastTemp = temperature;
if (!metric) {
temperature = dht.toFahrenheit(temperature);
}
gw.send(msgTemp.set(temperature, 1));
Serial.print("Temp: ");
Serial.println(temperature);
}
float humidity = dht.getHumidity();
if (isnan(humidity)) {
Serial.println("Failed reading humidity from DHT");
} else if (humidity != lastHum) {
lastHum = humidity;
gw.send(msgHum.set(humidity, 1));
Serial.print("Hum: ");
Serial.println(humidity);
}
uint16_t lux = lightSensor.readLightLevel();// Get Lux value
if (lux != lastlux) {
gw.send(msgLux.set(lux));
lastlux = lux;
Serial.print("lux: ");
Serial.println(lux);
}
// Ds1820
// Fetch temperatures from Dallas sensors
sensors.requestTemperatures();
// query conversion time and sleep until conversion completed
int16_t conversionTime = sensors.millisToWaitForConversion(sensors.getResolution());
// sleep() call can be replaced by wait() call if node need to process incoming messages (or if node is repeater)
gw.sleep(conversionTime);
// Read temperatures and send them to controller
for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {
// Fetch and round temperature to one decimal
float temperature1 = static_cast<float>(static_cast<int>((gw.getConfig().isMetric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.;
// Only send data if temperature has changed and no error
#if COMPARE_TEMP == 1
if (lastTemperature[i] != temperature1 && temperature1 != -127.00 && temperature1 != 85.00)
{
Serial.print("DS1820: ");
Serial.println(temperature1);
}
#else
if (temperature1 != -127.00 && temperature1 != 85.00) {
#endif
// Send in the new temperature
gw.send(msg.setSensor(i).set(temperature1,1));
// Save new temperatures for next compare
lastTemperature[i]=temperature1;
}
}
// Sleep until interrupt comes in on motion sensor. Send update every two minute.
gw.sleep(INTERRUPT,CHANGE, SLEEP_TIME);
}