💬 Temperature Sensor
-
@skywatch doing what you want is a bit hard since millis won't update while the node is in power save mode (sleeping). But this should do it:
set SLEEP_TIME = 2 * 60 * 1000 // 2 minutes
and changevoid loop() { // get the battery Voltage unsigned long currentMillis = millis(); if (currentMillis - previousMillis >= interval) { previousMillis = currentMillis; int sensorValue = analogRead(BATTERY_SENSE_PIN); batteryPcnt = sensorValue / 10; sendBatteryLevel(batteryPcnt); } ...to
unsigned int batteryReportFactor = 30*60*1000ul/SLEEP_TIME; // Only report battery every x SLEEP times (x=15 with current values) unsigned int timesSlept = 0; void loop() { if (timesSlept < batteryReportFactor) { timesSlept++; } else { // get the battery Voltage timesSlept = 0; int sensorValue = analogRead(BATTERY_SENSE_PIN); batteryPcnt = sensorValue / 10; sendBatteryLevel(batteryPcnt); } ...I don't understand why you're using interrupt to sleep though.
@mfalkvidd said in 💬 Temperature Sensor:
Thank you very much for helping out with this! - I will try it today if I can. I guess I could use the same principle to send sensor data every 2 minutes instead of every 1 minute and further reduce battery draw. I know the DS18B20 sensors are correctly going into sleep mode, but the node itself is still using too much juice.@skywatch doing what you want is a bit hard since millis won't update while the node is in power save mode (sleeping).
There is nothing in the API about this, would be nice if it were added as I don't think I will be the only person with such requirements. Also, what does sleep actually do and are there further things I could do to reduce the power use?
I don't understand why you're using interrupt to sleep though.
That is because I haven't finished this node yet.... I am working on it systematically and in future a water leak detector will be added. But only when this part is working correctly and I have good battery life from the node.
-
@mfalkvidd said in 💬 Temperature Sensor:
Thank you very much for helping out with this! - I will try it today if I can. I guess I could use the same principle to send sensor data every 2 minutes instead of every 1 minute and further reduce battery draw. I know the DS18B20 sensors are correctly going into sleep mode, but the node itself is still using too much juice.@skywatch doing what you want is a bit hard since millis won't update while the node is in power save mode (sleeping).
There is nothing in the API about this, would be nice if it were added as I don't think I will be the only person with such requirements. Also, what does sleep actually do and are there further things I could do to reduce the power use?
I don't understand why you're using interrupt to sleep though.
That is because I haven't finished this node yet.... I am working on it systematically and in future a water leak detector will be added. But only when this part is working correctly and I have good battery life from the node.
@skywatch said in 💬 Temperature Sensor:
There is nothing in the API about this, would be nice if it were added as I don't think I will be the only person with such requirements.
Good point. I have added a note on https://www.mysensors.org/download/sensor_api_20#sleeping
Also, what does sleep actually do and are there further things I could do to reduce the power use?
It does a lot of things, but basically it puts the radio and the Arduino in power save mode and uses the Arduino's watchdog timer to roughly keep track of time (exact timing is not possible because exact timing requires power, and power save mode is all about saving power).
https://www.mysensors.org/build/battery has the official MySensors recommendations on how to save power in battery-operated nodes.
If you want to dive deeper, start with https://www.gammon.com.au/power
-
I'd use the sleep time to 2 minutes and then simply set a counter that every 15 loops of the code sends battery status and resets the counter. Imho 2 minutes are quite often for battery life.
-
This can't be right, can it???
-
This can't be right, can it???
-
@mfalkvidd I'm on mobile, I didn't read the code 😇
-
Did you notice the time line on the bottom of the image. I thought it was supposed to send data once every 30 mins. Seems that something isn't right or I am looking at it from the wrong angle.....?
-
Did you notice the time line on the bottom of the image. I thought it was supposed to send data once every 30 mins. Seems that something isn't right or I am looking at it from the wrong angle.....?
-
Here is the sketch, debug will be later today I hope....
// Enable debug prints to serial monitor //#define MY_DEBUG // Enable and select radio type attached #define MY_RADIO_NRF24 //#define MY_RADIO_RFM69 #define COMPARE_TEMP 1 // Send temperature only if changed? 1 = Yes 0 = No #define MY_RF24_PA_LEVEL (RF24_PA_LOW) #define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected #define MAX_ATTACHED_DS18B20 3 #include <SPI.h> #include <MySensors.h> #include <DallasTemperature.h> #include <OneWire.h> int BATTERY_SENSE_PIN = A0; // select the input pin for the battery sense point int batteryPcnt = 0; unsigned long SLEEP_TIME = 2 * 60 * 1000; // 2 minutes Sleep time between reads. 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. float lastTemperature[MAX_ATTACHED_DS18B20]; int numSensors = 0; const long interval = 90000; unsigned long previousMillis = 0; bool receivedConfig = false; bool metric = true; unsigned int batteryReportFactor = 30*60*1000/SLEEP_TIME; // Only report battery every x SLEEP times (x=15 with current values) unsigned int timesSlept = 0; // Initialize temperature message MyMessage msg(0, V_TEMP); void before() { // Startup up the OneWire library sensors.begin(); } void setup() { // requestTemperatures() will not block current thread sensors.setWaitForConversion(false); analogReference(INTERNAL); } void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("HW/CH", "0.5"); // Fetch the number of attached temperature sensors numSensors = sensors.getDeviceCount(); // Present all sensors to controller for (int i = 0; i < numSensors && i < MAX_ATTACHED_DS18B20; i++) { present(i, S_TEMP); } } void loop() { // get the battery Voltage if (timesSlept < batteryReportFactor) { timesSlept++; } else { // get the battery Voltage timesSlept = 0; int sensorValue = analogRead(BATTERY_SENSE_PIN); batteryPcnt = sensorValue / 10; sendBatteryLevel(batteryPcnt); } // 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) 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 temperature = static_cast<float>(static_cast<int>((getControllerConfig().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] != temperature && temperature != -127.00 && temperature != 85.00) { #else if (temperature != -127.00 && temperature != 85.00) { #endif // Send in the new temperature send(msg.setSensor(i).set(temperature, 1)); // Save new temperatures for next compare lastTemperature[i] = temperature; } } int8_t sleep(1, FALLING, SLEEP_TIME); }``` Thanks! -
Here is the sketch, debug will be later today I hope....
// Enable debug prints to serial monitor //#define MY_DEBUG // Enable and select radio type attached #define MY_RADIO_NRF24 //#define MY_RADIO_RFM69 #define COMPARE_TEMP 1 // Send temperature only if changed? 1 = Yes 0 = No #define MY_RF24_PA_LEVEL (RF24_PA_LOW) #define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected #define MAX_ATTACHED_DS18B20 3 #include <SPI.h> #include <MySensors.h> #include <DallasTemperature.h> #include <OneWire.h> int BATTERY_SENSE_PIN = A0; // select the input pin for the battery sense point int batteryPcnt = 0; unsigned long SLEEP_TIME = 2 * 60 * 1000; // 2 minutes Sleep time between reads. 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. float lastTemperature[MAX_ATTACHED_DS18B20]; int numSensors = 0; const long interval = 90000; unsigned long previousMillis = 0; bool receivedConfig = false; bool metric = true; unsigned int batteryReportFactor = 30*60*1000/SLEEP_TIME; // Only report battery every x SLEEP times (x=15 with current values) unsigned int timesSlept = 0; // Initialize temperature message MyMessage msg(0, V_TEMP); void before() { // Startup up the OneWire library sensors.begin(); } void setup() { // requestTemperatures() will not block current thread sensors.setWaitForConversion(false); analogReference(INTERNAL); } void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("HW/CH", "0.5"); // Fetch the number of attached temperature sensors numSensors = sensors.getDeviceCount(); // Present all sensors to controller for (int i = 0; i < numSensors && i < MAX_ATTACHED_DS18B20; i++) { present(i, S_TEMP); } } void loop() { // get the battery Voltage if (timesSlept < batteryReportFactor) { timesSlept++; } else { // get the battery Voltage timesSlept = 0; int sensorValue = analogRead(BATTERY_SENSE_PIN); batteryPcnt = sensorValue / 10; sendBatteryLevel(batteryPcnt); } // 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) 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 temperature = static_cast<float>(static_cast<int>((getControllerConfig().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] != temperature && temperature != -127.00 && temperature != 85.00) { #else if (temperature != -127.00 && temperature != 85.00) { #endif // Send in the new temperature send(msg.setSensor(i).set(temperature, 1)); // Save new temperatures for next compare lastTemperature[i] = temperature; } } int8_t sleep(1, FALLING, SLEEP_TIME); }``` Thanks! -
I am using a pro mini 3.3v 8MHz. I would ideally like to get a 1MHZ bootloader onto it but the last try stopped the temperature sensors sending data (although battery levels were still sent!)..... Hope it helps.
-
Sorry for the dealy, I have had a week of plumbing problems at home - yuck! :(
So, I came back fresh to this and noticed that I had put the interrupt into the code ready for the water leak sensor (apt considering this weeks activities!) - BUT, I had not assigned the pin nor initialised it in the code. So maybe it was floating and giving random triggers?
I tested by changing from int8_t sleep(1, FALLING, SLEEP_TIME); to int8_t sleep(SLEEP_TIME); but now I get battery level sent every single second! - This is making me crazy......The log for the gateway has the following.....
Sep 3 07:00:37 HAAS rsyslogd-2007: action 'action 17' suspended, next retry is Sun Sep 3 07:02:07 2017 [try http://www.rsyslog.com/e/2007 ] Sep 3 06:26:28 HAAS rsyslogd0: action 'action 17' resumed (module 'builtin:ompipe') [try http://www.rsyslog.com/e/0 ] Sep 3 06:26:28 HAAS rsyslogd-2359: action 'action 17' resumed (module 'builtin:ompipe') [try http://www.rsyslog.com/e/2359 ]Not sure what the above is all about. Nor the below....
7:15:45 HAAS dhcpcd[474]: eth0: Router Advertisement from fe80::3291:8fff:fe06:64bcBut here is sending data every second.....
Sep 3 12:46:52 HAAS mysgw: TSF:MSG:READ,5-5-0,s=255,c=3,t=0,pt=1,l=1,sg=0:75 Sep 3 12:46:53 HAAS mysgw: TSF:MSG:READ,5-5-0,s=255,c=3,t=0,pt=1,l=1,sg=0:75 Sep 3 12:46:54 HAAS mysgw: TSF:MSG:READ,5-5-0,s=255,c=3,t=0,pt=1,l=1,sg=0:75 Sep 3 12:46:55 HAAS mysgw: TSF:MSG:READ,5-5-0,s=255,c=3,t=0,pt=1,l=1,sg=0:75 Sep 3 12:46:56 HAAS mysgw: TSF:MSG:READ,5-5-0,s=255,c=3,t=0,pt=1,l=1,sg=0:75 Sep 3 12:46:57 HAAS mysgw: TSF:MSG:READ,5-5-0,s=255,c=3,t=0,pt=1,l=1,sg=0:75 Sep 3 12:46:58 HAAS mysgw: TSF:MSG:READ,5-5-0,s=255,c=3,t=0,pt=1,l=1,sg=0:75 Sep 3 12:46:59 HAAS mysgw: TSF:MSG:READ,5-5-0,s=255,c=3,t=0,pt=1,l=1,sg=0:75 Sep 3 12:47:00 HAAS mysgw: TSF:MSG:READ,5-5-0,s=255,c=3,t=0,pt=1,l=1,sg=0:75Will try debug on node next....
-
Hi,
is there any known problem / bug with version 2.1.* and the Dallas temp sensor? (I found non in the bug tracker and/or forum)
I updated several nodes from 1.5 to 2.1.1 and now no temp sensor is working. No temp sensor DS18B20 is found by the node, therefore -127.0 is returned to the controller. I checked the wiring - as illustrated in this manual, everything seems right; incl. the pull-up with 4,7 k. I use the modified version of the Dallas-Library included in the examples package, as stated out in this manual.
Thanks,
Thomas -
I am not a programmer, but trying to learn by making small projects.
I am trying to build a arduino/ESP8266 with temp sensor so that at a particular set temp it sends a single to another arduino/ESP8266 with relay to turn on a cooler/heater. if there is a thread on this, please help me find it.