Hi,
I replaced the thermostat of my old fridge by an sensor made of arduino nano + nrf24l01+ DS18B20 temp sensor + relay.
And it works great. Except that after a few hours, and although the temperature control works ok, the sensor stops emitting to the controller.
If I reset the arduino the radio communication is good again, and then a few hours later, same thing, it does't send anything (no messages appear in the log of the controller).
In the meantime I added a 47µF capacitor on the radio, but it didn't help.
The arduino is not on battery..
Today when I saw the radio didn't send data anymore I plugged the serial, and here's what I read (the T:X.XX comp:1 are the temperature and the boolean indicating if the compressor is on or off):
T:6.70 comp:1
!TSP:SEND:TNR
!TSP:SEND:TNR
T:6.70 comp:1
!TSP:SEND:TNR
!TSP:SEND:TNR
T:6.70 comp:1
!TSP:SEND:TNR
!TSP:SEND:TNR
T:6.70 comp:1
!TSP:SEND:TNR
!TSP:SEND:TNR
T:6.60 comp:1
!TSP:SEND:TNR
!TSP:SEND:TNR
T:6.60 comp:1
!TSP:SEND:TNR
!TSP:SEND:TNR
T:6.60 comp:1
!TSP:SEND:TNR
!TSP:SEND:TNR
T:6.50 comp:1
TSM:FPAR
TSP:MSG:SEND 142-142-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
!TSP:SEND:TNR
!TSP:SEND:TNR
T:6.50 comp:1
!TSP:SEND:TNR
!TSP:SEND:TNR
Reading a bit of the MySensors source code I understood that TNR means "Transport Not Ready", but... why ?
In any case, here's the sketch I'm using:
// Enable debug prints to serial monitor
#define MY_DEBUG
// Enable and select radio type attached
#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69
#include <SPI.h>
#include <MySensors.h>
#include <DallasTemperature.h>
#include <OneWire.h>
#include "FridgeThermostat.h"
#define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected
#define MAX_ATTACHED_DS18B20 16
#define SLEEP_TIME 30000 // Sleep time between reads (in milliseconds)
#define GPIO_THERMOSTAT 8
#define TEMP_LOW 5.0
#define TEMP_HIGH 6.0
#define NB_HOT_READS_NO_ACTION 1
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.
// Initialize temperature message
MyMessage msg(0, V_TEMP);
MyMessage msgCompressorStatus(1, V_STATUS);
FridgeThermostat thermostat(GPIO_THERMOSTAT, TEMP_LOW, TEMP_HIGH, NB_HOT_READS_NO_ACTION);
// query conversion time and sleep until conversion completed
int16_t conversionTime;
void presentation() {
// Send the sketch version information to the gateway and Controller
sendSketchInfo("Fridge thermostat", "0.4");
// Register all sensors to gateway (they will be created as child devices)
present(0, S_TEMP, "Temperature");
present(1, S_BINARY, "Compressor on/off");
}
void setup() {
// Startup up the OneWire library
sensors.begin();
// query conversion time
conversionTime = sensors.millisToWaitForConversion(sensors.getResolution());
// requestTemperatures() will not block current thread
sensors.setWaitForConversion(false);
}
void loop()
{
// Fetch temperatures from Dallas sensors
sensors.requestTemperatures();
// sleep until conversion completed
// 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
// Fetch and round temperature to one decimal
float temperature = static_cast<float>(static_cast<int>((getConfig().isMetric?sensors.getTempCByIndex(0):sensors.getTempFByIndex(0)) * 10.)) / 10.;
// Send in the temperature to the controller even if error, to have a clue
// something goes wrong:
send(msg.set(temperature,1));
boolean compressorIsOn;
// Only tell the thermostat if no error:
if (temperature != -127.00 && temperature != 85.00) {
compressorIsOn = thermostat.act(temperature);
send(msgCompressorStatus.set(compressorIsOn));
}
Serial.print("T:");
Serial.print(temperature);
Serial.print(" comp:");
Serial.println(compressorIsOn);
sleep(SLEEP_TIME);
}
Any help appreciated !
Thanks,
Yann