Thanks @TheoL, I will give it a try.
Hilltan
@Hilltan
Best posts made by Hilltan
-
RE: 💬 AC-DC double solid state relay module
The link to to DirtyPCBs is broken, got a new one?
Latest posts made by Hilltan
-
RE: Domotiocz + Rain gauge
I need could need some help/advice to get my rain gauge to show correct values, as per today my rain gauge shows to low values. The rain gauge that I use is this one: Rain gauge
I use Domoticz V 3.8153 with Mysensors V2.1.1 and have bucket size 0,3. Anyone that have experience with this rain gauge and what bucket size to use for correct values or is there something with my code that creates problems?This it my sketch that I am usning:
// Enable and select radio type attached #define MY_RADIO_NRF24 #define MY_NODE_ID 5 #include "ThresholdUtil.h" #include <math.h> #include <Time.h> #include <MySensors.h> #include "DHT.h" #include <Wire.h> DHT dht; #define DHT 0 #define BUCKET_PIN 3 // The Arduino pin to which the bucket is attached. We need an interrupt pin (2 or 3 on the Uno and the Pro Mini) #define SKETCH_INFO "Rain,Temp&Hum" // The name of the sketch as presented to the gateway #define SKETCH_VERSION "1.0" // The version of the sketch as presented to the gateway #define CHILD_ID_RAIN_LOG 4 // The child id of the rain gauge #define MS_WAIT 100 // short delay used to give the NRF24L01+ antenna some time to recover from the last data sending #define bucketSize 0.3 // I've used a MI-SOL Rain Guage which has a bucket size of 0.3 mm #define CHILD_ID_TEMP 5 #define DHT_TEMP 6 #define CHILD_ID_HUMIDITY 7 #define DHT_HUM 9 #define DHT_DATA_PIN 5 MyMessage msgHum( CHILD_ID_HUMIDITY, V_HUM ); MyMessage msgTemp( CHILD_ID_TEMP, V_TEMP ); MyMessage msgRain( CHILD_ID_RAIN_LOG, V_RAIN ); MyMessage lastCounterMsg( CHILD_ID_RAIN_LOG, V_VAR1 ); float hwRainVolume = 0; // Current rainvolume calculated in hardware. unsigned long hwPulseCounter = 0; // Pulsecount recieved from GW boolean pcReceived = false; // If we have recieved the pulscount from GW or not unsigned long lastTipTime = millis(); // TS of when the bucket tip has been detected for the last time volatile unsigned long wasTippedCounter; // Queue for storing the tipped counter as been set by the interrupt handler. byte lastHour; // Stores the hour used for checking if time needs to be synchronized void presentation() { // Send the sketch version information to the gateway sendSketchInfo( SKETCH_INFO, SKETCH_VERSION ); wait( MS_WAIT ); present( CHILD_ID_HUMIDITY, S_HUM, "Outside Humidity" ); wait( MS_WAIT ); present( CHILD_ID_TEMP, S_TEMP, "Outside Temperature" ); wait( MS_WAIT ); present( CHILD_ID_RAIN_LOG, S_RAIN, "Rain fall" ); wait( MS_WAIT ); unsigned long functionTimeout = millis(); while ( pcReceived == false && millis() - functionTimeout < 30000UL ) { request( CHILD_ID_RAIN_LOG, V_VAR1); Serial.println(F("Getting pulse count")); Serial.println(F(".")); wait( 1000 ); } attachInterrupt( digitalPinToInterrupt( BUCKET_PIN ), sensorTipped, LOW ); //FALLING ); // depending on location of the hall effect sensor may need CHANGE, LOW or HIGE } void setup() { Serial.begin( 115200 ); pinMode( BUCKET_PIN, INPUT_PULLUP ); registerThresholdedSensor( CHILD_ID_TEMP, DHT_TEMP, TEMPERATURE_SENSOR, 0.5, 60, 8 ); // Change of value +/-0,5 , every 60 seconds report, and force report every 8 minutes registerThresholdedSensor( CHILD_ID_HUMIDITY, DHT_HUM, HUMIDTY_SENSOR, 1.0, 60, 8 ); // Change of value +/- 1, every 60 seconds report, and force report every 8 minutes dht.setup( DHT_DATA_PIN ); // data pin 8 delay( dht.getMinimumSamplingPeriod() ); unsigned long functionTimeout = millis(); while ( timeStatus() == timeNotSet && millis() - functionTimeout < 30000UL ) { requestTime(); Serial.println(F("Getting Time")); Serial.println(F(".")); wait( 1000 ); } lastHour = hour(); } /** Sends the value of the rain gauge to the Gateway. */ void sendRainVolumeData() { float hwRainVolume = hwPulseCounter * bucketSize; Serial.print( "Tipped " ); Serial.print( hwPulseCounter ); Serial.println( " times." ); Serial.print( "Rain fall is " ); Serial.print( hwRainVolume, 1 ); Serial.println( " mm." ); send( msgRain.set( (float)hwRainVolume, 1 ) ); wait( MS_WAIT ); send( lastCounterMsg.set( hwPulseCounter ) ); wait( MS_WAIT ); } void loop() { if ( wasTippedCounter != hwPulseCounter ) { hwPulseCounter = wasTippedCounter; sendRainVolumeData(); } byte currentHour = hour(); if (currentHour != lastHour) { Serial.println( "Resyncing hour" ); requestTime(); // sync the time every hour wait( MS_WAIT ); lastHour = currentHour; sendRainVolumeData(); // Send heart beat } checkThresholdedSensors( readSensorValue, updatedSensorValue ); } void sensorTipped() { unsigned long thisTipTime = millis(); if (thisTipTime - lastTipTime > 100UL) { wasTippedCounter++; } lastTipTime = thisTipTime; } float dhtHumidity; void readSensorValue( uint8_t aSensorId, ThreshHoldedSensorType aType, float *value ) { switch ( aSensorId ) { case DHT_TEMP: if ( aType == TEMPERATURE_SENSOR ) { *value = dht.getTemperature(); } break; case DHT_HUM: if ( aType == HUMIDTY_SENSOR ) { *value = dht.getHumidity(); } break; } } void updatedSensorValue( uint8_t child_id, uint8_t sensor_id, ThreshHoldedSensorType sensor_type, float value ) { switch ( child_id ) { case CHILD_ID_TEMP: Serial.print( "Temperatur " ); Serial.print( value, 0 ); Serial.print( "C" ); send( msgTemp.set( value, 1 ) ); wait( MS_WAIT ); break; case CHILD_ID_HUMIDITY: Serial.print( "HUMIDITY " ); Serial.print( value, 0 ); Serial.print( "%" ); send( msgHum.set( value, 1 ) ); wait( MS_WAIT ); break; } } void receiveTime(unsigned long time) { Serial.println( F("Time received...")); setTime(time); char theTime[6]; sprintf(theTime, "%d:%2d", hour(), minute()); Serial.println(theTime); } void receive(const MyMessage &message) { if ( message.sensor == CHILD_ID_RAIN_LOG && message.type == V_VAR1) { // We only expect pulse count values from the gateway hwPulseCounter = message.getULong(); wasTippedCounter = hwPulseCounter; pcReceived = true; Serial.print("Received last pulse count from gw: "); Serial.println(hwPulseCounter); } }
-
RE: 💬 AC-DC double solid state relay module
The link to to DirtyPCBs is broken, got a new one?
-
RE: Domotiocz + Rain gauge
Finally I get it to run with a light sensor (BH1750), temp/hum sensor (DHT22), and the rain tipping sensor. But there are some problems:
Domoticz seems not to want to divide the DHT sensor in to two, one humidity and one temperature. What I get in Domoticz is one WTGR800 (temp/hum) and one LaCrosse TX3 (temp). Have played around with the code a little bit, just ending up with one WTGT800 (temp/hum) and one LaCrosse TX3 (temp or humidity).
The rain sensor gets fault impulse from time to time, the sensor got trigged without that the sensor have been set off?
Overall your @TheoL Threshhold util is a very nice tool to work with, but the DHT sensor is not that easy to deal with I think…// Enable and select radio type attached #define MY_RADIO_NRF24 /* Include libraries used by the sketch */ #include "ThresholdUtil.h" #include <math.h> #include <Time.h> #include <MySensors.h> #include <BH1750.h> #include "DHT.h" #include <Wire.h> DHT dht; #define DHT 0 #define BUCKET_PIN 3 // The Arduino pin to which the bucket is attached. We need an interrupt pin (2 or 3 on the Uno and the Pro Mini) #define SKETCH_INFO "Outside weather" // The name of the sketch as presented to the gateway #define SKETCH_VERSION "1.0" // The version of the sketch as presented to the gateway #define CHILD_ID_RAIN_LOG 4 // The child id of the rain gauge #define MS_WAIT 100 // short delay used to give the NRF24L01+ antenna some time to recover from the last data sending #define bucketSize 0.3 // I've used a MI-SOL Rain Guage which has a bucket size of 0.3 mm #define LIGHTLEVEL_SENSOR_CHILD_ID 0 #define LIGHTLEVEL_SENSOR_ID 3 #define CHILD_ID_TEMP 5 #define DHT_TEMP 6 #define CHILD_ID_HUMIDITY 7 #define DHT_HUM 9 #define DHT_DATA_PIN 8 MyMessage lightLevelMsg(LIGHTLEVEL_SENSOR_CHILD_ID, V_LIGHT_LEVEL); MyMessage msgHum( CHILD_ID_HUMIDITY, V_HUM ); MyMessage msgTemp( CHILD_ID_TEMP, V_TEMP ); MyMessage msgRain( CHILD_ID_RAIN_LOG, V_RAIN ); MyMessage lastCounterMsg( CHILD_ID_RAIN_LOG, V_VAR1 ); BH1750 lightSensor; float hwRainVolume = 0; // Current rainvolume calculated in hardware. unsigned long hwPulseCounter = 0; // Pulsecount recieved from GW boolean pcReceived = false; // If we have recieved the pulscount from GW or not unsigned long lastTipTime = millis(); // TS of when the bucket tip has been detected for the last time volatile unsigned long wasTippedCounter; // Queue for storing the tipped counter as been set by the interrupt handler. byte lastHour; // Stores the hour used for checking if time needs to be synchronized void presentation() { // Send the sketch version information to the gateway sendSketchInfo( SKETCH_INFO, SKETCH_VERSION ); wait( MS_WAIT ); present(LIGHTLEVEL_SENSOR_CHILD_ID, S_LIGHT_LEVEL, "Light level" ); wait( MS_WAIT ); present( CHILD_ID_HUMIDITY, S_HUM, "Outside Humidity" ); wait( MS_WAIT ); present( CHILD_ID_TEMP, S_TEMP, "Outside Temperature" ); wait( MS_WAIT ); present( CHILD_ID_RAIN_LOG, S_RAIN, "Rain fall" ); wait( MS_WAIT ); unsigned long functionTimeout = millis(); while ( pcReceived == false && millis() - functionTimeout < 30000UL ) { request( CHILD_ID_RAIN_LOG, V_VAR1); Serial.println(F("Getting pulse count")); Serial.println(F(".")); wait( 1000 ); } attachInterrupt( digitalPinToInterrupt( BUCKET_PIN ), sensorTipped, LOW ); //FALLING ); // depending on location of the hall effect sensor may need CHANGE } void setup() { Serial.begin( 115200 ); pinMode( BUCKET_PIN, INPUT_PULLUP ); lightSensor.begin(); registerThresholdedSensor( LIGHTLEVEL_SENSOR_CHILD_ID, LIGHTLEVEL_SENSOR_ID, LIGHTLEVEL_SENSOR, 20, 30, 20 ); // read every 5 sec and report at least every 5 minute ändrat 300 till 20 registerThresholdedSensor( CHILD_ID_TEMP, DHT_TEMP, TEMPERATURE_SENSOR, 0.5, 30, 20 ); // every 30 seconds report at least every 10 minutes registerThresholdedSensor( CHILD_ID_HUMIDITY, DHT_HUM, HUMIDTY_SENSOR, 1.0, 60, 10 ); // every 60 seconds dht.setup( DHT_DATA_PIN ); // data pin 8 delay( dht.getMinimumSamplingPeriod() ); unsigned long functionTimeout = millis(); while ( timeStatus() == timeNotSet && millis() - functionTimeout < 30000UL ) { requestTime(); Serial.println(F("Getting Time")); Serial.println(F(".")); wait( 1000 ); } lastHour = hour(); } /** Sends the value of the rain gauge to the Gateway. */ void sendRainVolumeData() { float hwRainVolume = hwPulseCounter * bucketSize; Serial.print( "Tipped " ); Serial.print( hwPulseCounter ); Serial.println( " times." ); Serial.print( "Rain fall is " ); Serial.print( hwRainVolume, 1 ); Serial.println( " mm." ); send( msgRain.set( (float)hwRainVolume, 1 ) ); wait( MS_WAIT ); send( lastCounterMsg.set( hwPulseCounter ) ); wait( MS_WAIT ); } void loop() { if ( wasTippedCounter != hwPulseCounter ) { hwPulseCounter = wasTippedCounter; sendRainVolumeData(); } byte currentHour = hour(); if (currentHour != lastHour) { Serial.println( "Resyncing hour" ); requestTime(); // sync the time every hour wait( MS_WAIT ); lastHour = currentHour; sendRainVolumeData(); // Send heart beat } checkThresholdedSensors( readSensorValue, updatedSensorValue ); } void sensorTipped() { unsigned long thisTipTime = millis(); if (thisTipTime - lastTipTime > 100UL) { wasTippedCounter++; } lastTipTime = thisTipTime; } float dhtHumidity; void readSensorValue( uint8_t aSensorId, ThreshHoldedSensorType aType, float *value ) { switch ( aSensorId ) { case LIGHTLEVEL_SENSOR_ID: if ( aType == LIGHTLEVEL_SENSOR ) { *value = lightSensor.readLightLevel(); } break; case DHT_TEMP: if ( aType == TEMPERATURE_SENSOR ) { *value = dht.getTemperature(); } break; case DHT_HUM: if ( aType == HUMIDTY_SENSOR ) { *value = dht.getHumidity(); } break; } } void updatedSensorValue( uint8_t child_id, uint8_t sensor_id, ThreshHoldedSensorType sensor_type, float value ) { switch ( child_id ) { case LIGHTLEVEL_SENSOR_CHILD_ID: Serial.print( "Light level " ); Serial.print( value, 0 ); Serial.println( "%" ); send( lightLevelMsg.set( value, 5 ) ); wait( MS_WAIT ); break; case CHILD_ID_TEMP: Serial.print( "Temperatur " ); Serial.print( value, 0 ); Serial.print( "C" ); send( msgTemp.set( value, 1 ) ); wait( MS_WAIT ); break; case CHILD_ID_HUMIDITY: Serial.print( "HUMIDITY " ); Serial.print( value, 0 ); Serial.print( "%" ); send( msgHum.set( value, 1 ) ); wait( MS_WAIT ); break; } } void receiveTime(unsigned long time) { Serial.println( F("Time received...")); setTime(time); char theTime[6]; sprintf(theTime, "%d:%2d", hour(), minute()); Serial.println(theTime); } void receive(const MyMessage &message) { if ( message.sensor == CHILD_ID_RAIN_LOG && message.type == V_VAR1) { // We only expect pulse count values from the gateway hwPulseCounter = message.getULong(); wasTippedCounter = hwPulseCounter; pcReceived = true; Serial.print("Received last pulse count from gw: "); Serial.println(hwPulseCounter); } }
There are probably strange things in the sketch, I am new to this
-
RE: Domotiocz + Rain gauge
How will the numbers affect the Thresholds reading and reporting of the sensor?
registerThresholdedSensor( CHILD_ID_TEMP, 1, TEMPERATURE_SENSOR, 0.5, 30, 20 );
0.5 //What will this do?
30 //What will this do?
20 //That one I assume is how often the value will be sent to the gateway?void updatedTHSensorValue( uint8_t child_id, uint8_t sensor_id, ThreshHoldedSensorType sensor_type, float value ) {
switch ( child_id ) {
case CHILD_ID_TEMP:
Serial.print( "Sending temp " );
Serial.println( value, 1 ); //What will this do?
send( msgTemp.set( value, 1 ) ); //What will this do?
break;I don’t have the SI7021 sensor yet so therefore my questions
And a problem with the DHT sensor is correct me if I am wrong, is that the DHT sensor does not like to be “read” to often. How will I do this? Or maybe the answer to my question is in the registerThresholdedSensor code ;).
-
RE: Domotiocz + Rain gauge
Maybe a stupid question, but it is possible to replace the SI7021 sensor with a DHT-22 sensor (the code has to be changed offsourse)? And get everything to work with ThresholdUtil? I have all parts, but not the SI7021 sensor to build the rain gauge.
-
RE: A beginners question
Thanks for a replay. I change sleep to wait then. What I was concerned about was to “read” to often from the DHT sensor. But I believe "static const uint64_t UPDATE_INTERVAL = 60000; " in the beginning will regulate this, so my gateway will not over read the DHT sensor?
-
A beginners question
I have put a DHT22 sensor to my serial gateway, and in the sketch code for the DHT22 sensor there is sleeping “code”, static const uint64_t UPDATE_INTERVAL = 60000; and on the end sleep(UPDATE_INTERVAL); . Will this affect the gateway forcing it to sleep or will this only affect the DHT sensor? My sketch:
// Enable debug prints to serial monitor #define MY_DEBUG // Enable and select radio type attached #define MY_RADIO_NRF24 //#define MY_RADIO_RFM69 // Set LOW transmit power level as default, if you have an amplified NRF-module and // power your radio separately with a good regulator you can turn up PA level. #define MY_RF24_PA_LEVEL RF24_PA_LOW // Enable serial gateway #define MY_GATEWAY_SERIAL // Define a lower baud rate for Arduino's running on 8 MHz (Arduino Pro Mini 3.3V & SenseBender) #if F_CPU == 8000000L #define MY_BAUD_RATE 38400 #endif // Flash leds on rx/tx/err #define MY_LEDS_BLINKING_FEATURE // Set blinking period #define MY_DEFAULT_LED_BLINK_PERIOD 300 // Inverses the behavior of leds //#define MY_WITH_LEDS_BLINKING_INVERSE // Enable inclusion mode #define MY_INCLUSION_MODE_FEATURE // Enable Inclusion mode button on gateway #define MY_INCLUSION_BUTTON_FEATURE // Inverses behavior of inclusion button (if using external pullup) //#define MY_INCLUSION_BUTTON_EXTERNAL_PULLUP // Set inclusion mode duration (in seconds) #define MY_INCLUSION_MODE_DURATION 60 // Digital pin used for inclusion mode button #define MY_INCLUSION_MODE_BUTTON_PIN 3 // Uncomment to override default HW configurations //#define MY_DEFAULT_ERR_LED_PIN 4 // Error led pin //#define MY_DEFAULT_RX_LED_PIN 6 // Receive led pin //#define MY_DEFAULT_TX_LED_PIN 5 // the PCB, on board LED #include <DHT.h> #include <SPI.h> #include <MySensors.h> //DHT Begin // Set this to the pin you connected the DHT's data pin to #define DHT_DATA_PIN 8 // Set this offset if the sensor has a permanent small offset to the real temperatures #define SENSOR_TEMP_OFFSET 0 // Sleep time between sensor updates (in milliseconds) // Must be >1000ms for DHT22 and >2000ms for DHT11 static const uint64_t UPDATE_INTERVAL = 60000; // Force sending an update of the temperature after n sensor reads, so a controller showing the // timestamp of the last update doesn't show something like 3 hours in the unlikely case, that // the value didn't change since; // i.e. the sensor would force sending an update every UPDATE_INTERVAL*FORCE_UPDATE_N_READS [ms] static const uint8_t FORCE_UPDATE_N_READS = 10; #define CHILD_ID_HUM 10 #define CHILD_ID_TEMP 11 float lastTemp; float lastHum; uint8_t nNoUpdatesTemp; uint8_t nNoUpdatesHum; bool metric = true; MyMessage msgHum(CHILD_ID_HUM, V_HUM); MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP); DHT dht; void setup() { dht.setup(DHT_DATA_PIN); // set data pin of DHT sensor if (UPDATE_INTERVAL <= dht.getMinimumSamplingPeriod()) { Serial.println("Warning: UPDATE_INTERVAL is smaller than supported by the sensor!"); } // Sleep for the time of the minimum sampling period to give the sensor time to power up // (otherwise, timeout errors might occure for the first reading) sleep(dht.getMinimumSamplingPeriod()); } void presentation() { // Send the sketch version information to the gateway sendSketchInfo("Getway+DHT", "1.1"); // Register all sensors to gw (they will be created as child devices) present(CHILD_ID_HUM, S_HUM); present(CHILD_ID_TEMP, S_TEMP); metric = getConfig().isMetric; } void loop() { // Force reading sensor, so it works also after sleep() dht.readSensor(true); // Get temperature from DHT library float temperature = dht.getTemperature(); if (isnan(temperature)) { Serial.println("Failed reading temperature from DHT!"); } else if (temperature != lastTemp || nNoUpdatesTemp == FORCE_UPDATE_N_READS) { // Only send temperature if it changed since the last measurement or if we didn't send an update for n times lastTemp = temperature; if (!metric) { temperature = dht.toFahrenheit(temperature); } // Reset no updates counter nNoUpdatesTemp = 0; temperature += SENSOR_TEMP_OFFSET; send(msgTemp.set(temperature, 1)); #ifdef MY_DEBUG Serial.print("T: "); Serial.println(temperature); #endif } else { // Increase no update counter if the temperature stayed the same nNoUpdatesTemp++; } // Get humidity from DHT library float humidity = dht.getHumidity(); if (isnan(humidity)) { Serial.println("Failed reading humidity from DHT"); } else if (humidity != lastHum || nNoUpdatesHum == FORCE_UPDATE_N_READS) { // Only send humidity if it changed since the last measurement or if we didn't send an update for n times lastHum = humidity; // Reset no updates counter nNoUpdatesHum = 0; send(msgHum.set(humidity, 1)); #ifdef MY_DEBUG Serial.print("H: "); Serial.println(humidity); #endif } else { // Increase no update counter if the humidity stayed the same nNoUpdatesHum++; } // Sleep for a while to save energy sleep(UPDATE_INTERVAL); }