Hi all,
I'm not sure where to start this, Ill give a quick simple description of my setup.
I have an pi4 running with domoticz as thermostat primarily.
First I had 4x DS18B20 temperature sensors hooked up to gpio4 on the pi without the resistor, this worked fine for some time till this gave some issues, I figured out quickly what went wrong here, so I hooked those sensors up to an arduino mega 2560. After some playing around and not getting the results in to domoticz like i would like to I was pointed to MySensors and use the serial sketch, I added some lines from an DS18B20 sketch in there and uploaded this.. straight away this worked awesome!
Till last night where it all came to an hold, the temperature data was not updating any more to domoticz and this just kept going. resulting in a kitchen floor of about 60°c
My question, can someone check for me if the scetch I'm running is any good or does it have any flaws? I'm totally not in to programming and I'm just getting slowly in to this.
My sketch:
// Enable debug prints to serial monitor
#define MY_DEBUG
// Enable RS485 transport layer
#define MY_RS485
// Define this to enables DE-pin management on defined pin
#define MY_RS485_DE_PIN 7
// Set RS485 baud rate to use
#define MY_RS485_BAUD_RATE 9600
// Enable this if RS485 is connected to a hardware serial port
//#define MY_RS485_HWSERIAL Serial1
// Enable serial gateway
#define MY_GATEWAY_SERIAL
// Enable inclusion mode
#define MY_INCLUSION_MODE_FEATURE
// Enable Inclusion mode button on gateway
#define MY_INCLUSION_BUTTON_FEATURE
// 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
// Set blinking period
#define MY_DEFAULT_LED_BLINK_PERIOD 300
// Flash leds on rx/tx/err
#define MY_DEFAULT_ERR_LED_PIN 4 // Error led pin
#define MY_DEFAULT_RX_LED_PIN 5 // Receive led pin
#define MY_DEFAULT_TX_LED_PIN 6 // the PCB, on board LED
#include <MySensors.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define COMPARE_TEMP 1 // Send temperature only if changed? 1 = Yes 0 = No
#define ONE_WIRE_BUS 2 // Pin where dallase sensor is connected
#define MAX_ATTACHED_DS18B20 16
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.
float lastTemperature[MAX_ATTACHED_DS18B20];
int numSensors=0;
bool receivedConfig = false;
bool metric = true;
// 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);
}
void presentation() {
// Send the sketch version information to the gateway and Controller
sendSketchInfo("Temp Sensor", "1");
// 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()
{
// 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);
wait(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;
}
}
}
Thanks in advance Olaf,