- firmware/firmware.ino, compilé identique à l'original - boitier : boîtier pour Pro Mini de sluebbert (Thingiverse 4015203, Creative Commons), copie des STL et de la source OpenSCAD - docs : adresses des sondes DS18B20, rendu du boîtier - README, .gitignore Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
345 lines
9.6 KiB
Arduino
345 lines
9.6 KiB
Arduino
// #define MY_DEBUG
|
|
// Enable and select radio type attached
|
|
#define MY_RADIO_RF24
|
|
// #define MY_RF24_PA_LEVEL RF24_PA_MIN
|
|
// #define MY_RF24_PA_LEVEL RF24_PA_LOW
|
|
#define MY_RF24_PA_LEVEL RF24_PA_HIGH
|
|
//#define MY_RF24_PA_LEVEL RF24_PA_MAX
|
|
|
|
#define MY_RF24_CHANNEL 14
|
|
|
|
// INFO coincell optimization
|
|
// https://www.openhardware.io/view/398/NModule-Temperature-Humidity-Light-Door-sensor-shield#tabs-source
|
|
#define MY_TRANSPORT_UPLINK_CHECK_DISABLED
|
|
|
|
// Timeout for transport to be ready during initialization, after this duration, even if it didn't manage to enable transport the node will enter the loop() method
|
|
// For battery powered nodes, I set this to 5000 so after 5 seconds it will stop eating the battery
|
|
// 5s is long enough to connect to gateway so you should connect your node back to your computer and check the log if your node cannot connect
|
|
#define MY_TRANSPORT_WAIT_READY_MS 5000 // no more than 5 seconds of waiting for transport to be ready
|
|
|
|
// Reduce maximum delay before going to sleep, as we do not want to kill the battery if gateway is not available
|
|
// Before going to sleep MySensors will make sure we don't have a connection problem to MySensors network
|
|
// If this value is too high and you have connection problem, MySensors will never go to sleep and bye bye battery ...
|
|
// If using AA/AAA batteries you can set a longer duration like 5000ms
|
|
#define MY_SLEEP_TRANSPORT_RECONNECT_TIMEOUT_MS 2000
|
|
|
|
// #define MY_SIGNING_SIMPLE_PASSWD "C@KptBi1L@5op?8!"
|
|
// #define MY_SECURITY_SIMPLE_PASSWD "C@KptBi1L@5op?8!"
|
|
|
|
#include <SPI.h>
|
|
#include <MySensors.h>
|
|
|
|
|
|
// https://lastminuteengineers.com/multiple-ds18b20-arduino-tutorial/
|
|
#include <OneWire.h>
|
|
#include <DallasTemperature.h>
|
|
|
|
// Data wire is plugged into port 3 on the Arduino
|
|
#define ONE_WIRE_BUS 3
|
|
|
|
// Setup a oneWire instance to communicate with any OneWire devices
|
|
OneWire oneWire(ONE_WIRE_BUS);
|
|
|
|
// Pass our oneWire reference to Dallas Temperature.
|
|
DallasTemperature sensors(&oneWire);
|
|
|
|
// Addresses of 3 DS18B20s
|
|
uint8_t sensor1[8] = { 0x28, 0xEA, 0x4F, 0x96, 0xF0, 0x01, 0x3C, 0xC2 };
|
|
uint8_t sensor2[8] = { 0x28, 0xDE, 0x8D, 0x96, 0xF0, 0x01, 0x3C, 0x52 };
|
|
uint8_t sensor3[8] = { 0x28, 0xCC, 0x0B, 0x81, 0xE3, 0xE1, 0x3C, 0x55 };
|
|
uint8_t sensor4[8] = { 0x28, 0x77, 0xCD, 0x96, 0xF0, 0x01, 0x3C, 0x71 };
|
|
uint8_t sensor5[8] = { 0x28, 0x6E, 0x54, 0x48, 0xF6, 0xA4, 0x3C, 0x2C };
|
|
uint8_t sensor6[8] = { 0x28, 0x57, 0x2C, 0x49, 0xF6, 0x0D, 0x3C, 0xD7 };
|
|
uint8_t sensor7[8] = { 0x28, 0x17, 0xA8, 0x96, 0xF0, 0x01, 0x3C, 0x71 };
|
|
uint8_t sensor8[8] = { 0x28, 0x72, 0x9C, 0x96, 0xF0, 0x01, 0x3C, 0xC2 };
|
|
uint8_t sensor9[8] = { 0x28, 0x9D, 0xC7, 0x49, 0xF6, 0x91, 0x3C, 0xA3 };
|
|
uint8_t sensor10[8] = { 0x28, 0x70, 0xCB, 0x96, 0xF0, 0x01, 0x3C, 0x68 };
|
|
|
|
static const uint64_t UPDATE_INTERVAL = 600000; // (5min * 60 seconds * 1000 milliseconds)
|
|
|
|
#define CHILD_ID_TEMP1 1
|
|
#define CHILD_ID_TEMP2 2
|
|
#define CHILD_ID_TEMP3 3
|
|
#define CHILD_ID_TEMP4 4
|
|
#define CHILD_ID_TEMP5 5
|
|
#define CHILD_ID_TEMP6 6
|
|
#define CHILD_ID_TEMP7 7
|
|
#define CHILD_ID_TEMP8 8
|
|
#define CHILD_ID_TEMP9 9
|
|
#define CHILD_ID_TEMP10 10
|
|
#define CHILD_ID_BAT 11
|
|
#define CHILD_ID_BATV 12
|
|
|
|
bool metric = true;
|
|
float DTemp1;
|
|
float DTemp2;
|
|
float DTemp3;
|
|
float DTemp4;
|
|
float DTemp5;
|
|
float DTemp6;
|
|
float DTemp7;
|
|
float DTemp8;
|
|
float DTemp9;
|
|
float DTemp10;
|
|
|
|
float old_DTemp1;
|
|
float old_DTemp2;
|
|
float old_DTemp3;
|
|
float old_DTemp4;
|
|
float old_DTemp5;
|
|
float old_DTemp6;
|
|
float old_DTemp7;
|
|
float old_DTemp8;
|
|
float old_DTemp9;
|
|
float old_DTemp10;
|
|
|
|
int oldBatteryPcnt = 0;
|
|
#define FULL_BATTERY 3 // 3V for 2xAA alkaline. Adjust if you use a different battery setup.
|
|
|
|
MyMessage msgTemp1(CHILD_ID_TEMP1, V_TEMP);
|
|
MyMessage msgTemp2(CHILD_ID_TEMP2, V_TEMP);
|
|
MyMessage msgTemp3(CHILD_ID_TEMP3, V_TEMP);
|
|
MyMessage msgTemp4(CHILD_ID_TEMP4, V_TEMP);
|
|
MyMessage msgTemp5(CHILD_ID_TEMP5, V_TEMP);
|
|
MyMessage msgTemp6(CHILD_ID_TEMP6, V_TEMP);
|
|
MyMessage msgTemp7(CHILD_ID_TEMP7, V_TEMP);
|
|
MyMessage msgTemp8(CHILD_ID_TEMP8, V_TEMP);
|
|
MyMessage msgTemp9(CHILD_ID_TEMP9, V_TEMP);
|
|
MyMessage msgTemp10(CHILD_ID_TEMP10, V_TEMP);
|
|
MyMessage msgBat(CHILD_ID_BAT, V_VAR1);
|
|
MyMessage msgBatPrefix(CHILD_ID_BAT, V_UNIT_PREFIX); // Custom unit message.
|
|
MyMessage msgBatV(CHILD_ID_BATV, V_VAR2);
|
|
MyMessage msgBatVPrefix(CHILD_ID_BATV, V_UNIT_PREFIX); // Custom unit message.
|
|
|
|
|
|
// Sleep between sendings to preserve coin cell
|
|
void sleepForCoinCell() {
|
|
sleep(400);
|
|
}
|
|
|
|
void presentation()
|
|
{
|
|
#ifdef MY_DEBUG
|
|
Serial.println("- - - - - presentation - - - - -");
|
|
#endif
|
|
|
|
// Send the sketch version information to the gateway
|
|
sendSketchInfo("Cumulus DS18B20x10", "0.2");
|
|
sleepForCoinCell();
|
|
|
|
// Register all sensors to gw (they will be created as child devices)
|
|
present(CHILD_ID_TEMP1, S_TEMP, "Temperature Cumulus 1");
|
|
sleepForCoinCell();
|
|
present(CHILD_ID_TEMP2, S_TEMP, "Temperature Cumulus 2");
|
|
sleepForCoinCell();
|
|
present(CHILD_ID_TEMP3, S_TEMP, "Temperature Cumulus 3");
|
|
sleepForCoinCell();
|
|
present(CHILD_ID_TEMP4, S_TEMP, "Temperature Cumulus 4");
|
|
sleepForCoinCell();
|
|
present(CHILD_ID_TEMP5, S_TEMP, "Temperature Cumulus 5");
|
|
sleepForCoinCell();
|
|
present(CHILD_ID_TEMP6, S_TEMP, "Temperature Cumulus 6");
|
|
sleepForCoinCell();
|
|
present(CHILD_ID_TEMP7, S_TEMP, "Temperature Cumulus 7");
|
|
sleepForCoinCell();
|
|
present(CHILD_ID_TEMP8, S_TEMP, "Temperature Cumulus 8");
|
|
sleepForCoinCell();
|
|
present(CHILD_ID_TEMP9, S_TEMP, "Temperature Cumulus 9");
|
|
sleepForCoinCell();
|
|
present(CHILD_ID_TEMP10, S_TEMP, "Temperature Cumulus 10");
|
|
sleepForCoinCell();
|
|
present(CHILD_ID_BAT, S_CUSTOM, "Battery Percent");
|
|
sleepForCoinCell();
|
|
present(CHILD_ID_BATV, S_CUSTOM, "Battery Voltage");
|
|
sleepForCoinCell();
|
|
|
|
metric = getControllerConfig().isMetric;
|
|
sleepForCoinCell();
|
|
|
|
}
|
|
|
|
void setup(void)
|
|
{
|
|
sensors.begin();
|
|
}
|
|
|
|
void loop(void)
|
|
{
|
|
sensors.requestTemperatures();
|
|
|
|
old_DTemp1 = DTemp1;
|
|
DTemp1 = sensors.getTempC(sensor1);
|
|
#ifdef MY_DEBUG
|
|
Serial.print(F("Sensor 1: "));
|
|
Serial.print(DTemp1);
|
|
Serial.println(F("C"));
|
|
#endif
|
|
if (DTemp1 != old_DTemp1)
|
|
{
|
|
send(msgTemp1.set(DTemp1, 1));
|
|
old_DTemp1 = DTemp1;
|
|
}
|
|
sleep(2000);
|
|
|
|
old_DTemp2 = DTemp2;
|
|
DTemp2 = sensors.getTempC(sensor2);
|
|
#ifdef MY_DEBUG
|
|
Serial.print(F("Sensor 2: "));
|
|
Serial.print(DTemp2);
|
|
Serial.println(F("C"));
|
|
#endif
|
|
if (DTemp2 != old_DTemp2)
|
|
{
|
|
send(msgTemp2.set(DTemp2, 1));
|
|
old_DTemp2 = DTemp2;
|
|
}
|
|
sleep(2000);
|
|
|
|
old_DTemp3 = DTemp3;
|
|
DTemp3 = sensors.getTempC(sensor3);
|
|
#ifdef MY_DEBUG
|
|
Serial.print(F("Sensor 3: "));
|
|
Serial.print(DTemp3);
|
|
Serial.println(F("C"));
|
|
#endif
|
|
if (DTemp3 != old_DTemp3)
|
|
{
|
|
send(msgTemp3.set(DTemp3, 1));
|
|
old_DTemp3 = DTemp3;
|
|
}
|
|
sleep(2000);
|
|
|
|
old_DTemp4 = DTemp4;
|
|
DTemp4 = sensors.getTempC(sensor4);
|
|
#ifdef MY_DEBUG
|
|
Serial.print(F("Sensor 4: "));
|
|
Serial.print(DTemp4);
|
|
Serial.println(F("C"));
|
|
#endif
|
|
if (DTemp4 != old_DTemp4)
|
|
{
|
|
send(msgTemp4.set(DTemp4, 1));
|
|
old_DTemp4 = DTemp4;
|
|
}
|
|
sleep(2000);
|
|
|
|
old_DTemp5 = DTemp5;
|
|
DTemp5 = sensors.getTempC(sensor5);
|
|
#ifdef MY_DEBUG
|
|
Serial.print(F("Sensor 5: "));
|
|
Serial.print(DTemp5);
|
|
Serial.println(F("C"));
|
|
#endif
|
|
if (DTemp5 != old_DTemp5)
|
|
{
|
|
send(msgTemp5.set(DTemp5, 1));
|
|
old_DTemp5 = DTemp5;
|
|
}
|
|
sleep(2000);
|
|
|
|
old_DTemp6 = DTemp6;
|
|
DTemp6 = sensors.getTempC(sensor6);
|
|
#ifdef MY_DEBUG
|
|
Serial.print(F("Sensor 6: "));
|
|
Serial.print(DTemp6);
|
|
Serial.println(F("C"));
|
|
#endif
|
|
if (DTemp6 != old_DTemp6)
|
|
{
|
|
send(msgTemp6.set(DTemp6, 1));
|
|
old_DTemp6 = DTemp6;
|
|
}
|
|
sleep(2000);
|
|
|
|
old_DTemp7 = DTemp7;
|
|
DTemp7 = sensors.getTempC(sensor7);
|
|
#ifdef MY_DEBUG
|
|
Serial.print(F("Sensor 7: "));
|
|
Serial.print(DTemp7);
|
|
Serial.println(F("C"));
|
|
#endif
|
|
if (DTemp7 != old_DTemp7)
|
|
{
|
|
send(msgTemp7.set(DTemp7, 1));
|
|
old_DTemp7 = DTemp7;
|
|
}
|
|
sleep(2000);
|
|
|
|
old_DTemp8 = DTemp8;
|
|
DTemp8 = sensors.getTempC(sensor8);
|
|
#ifdef MY_DEBUG
|
|
Serial.print(F("Sensor 8: "));
|
|
Serial.print(DTemp8);
|
|
Serial.println(F("C"));
|
|
#endif
|
|
if (DTemp8 != old_DTemp8)
|
|
{
|
|
send(msgTemp8.set(DTemp8, 1));
|
|
old_DTemp8 = DTemp8;
|
|
}
|
|
sleep(2000);
|
|
|
|
old_DTemp9 = DTemp9;
|
|
DTemp9 = sensors.getTempC(sensor9);
|
|
#ifdef MY_DEBUG
|
|
Serial.print(F("Sensor 9: "));
|
|
Serial.print(DTemp9);
|
|
Serial.println(F("C"));
|
|
#endif
|
|
if (DTemp9 != old_DTemp9)
|
|
{
|
|
send(msgTemp9.set(DTemp9, 1));
|
|
old_DTemp9 = DTemp9;
|
|
}
|
|
sleep(2000);
|
|
|
|
old_DTemp10 = DTemp10;
|
|
DTemp10 = sensors.getTempC(sensor10);
|
|
#ifdef MY_DEBUG
|
|
Serial.print(F("Sensor 10: "));
|
|
Serial.print(DTemp10);
|
|
Serial.println(F("C"));
|
|
#endif
|
|
if (DTemp10 != old_DTemp10)
|
|
{
|
|
send(msgTemp10.set(DTemp10, 1));
|
|
old_DTemp10 = DTemp10;
|
|
}
|
|
sleep(2000);
|
|
|
|
// get the battery Voltage
|
|
long batteryMillivolts = hwCPUVoltage();
|
|
float batteryVolts = batteryMillivolts / 1000.0;
|
|
int batteryPcnt = batteryMillivolts / FULL_BATTERY / 1000.0 * 100 + 0.5;
|
|
#ifdef MY_DEBUG
|
|
Serial.print("Battery voltage: ");
|
|
Serial.print(batteryVolts);
|
|
Serial.println("V");
|
|
Serial.print("Battery percent: ");
|
|
Serial.print(batteryPcnt);
|
|
Serial.println(" %");
|
|
#endif
|
|
|
|
if (oldBatteryPcnt != batteryPcnt) {
|
|
sendBatteryLevel(batteryPcnt);
|
|
oldBatteryPcnt = batteryPcnt;
|
|
send(msgBatPrefix.set("%")); // Set custom unit.
|
|
send(msgBat.set(batteryPcnt, 1));
|
|
send(msgBatVPrefix.set("V")); // Set custom unit.
|
|
send(msgBatV.set(batteryVolts, 1));
|
|
}
|
|
|
|
// Sleep for a while to save energy
|
|
sleep(UPDATE_INTERVAL);
|
|
}
|
|
|
|
void printTemperature(DeviceAddress deviceAddress)
|
|
{
|
|
float tempC = sensors.getTempC(deviceAddress);
|
|
Serial.print(tempC);
|
|
Serial.print((char)176);
|
|
Serial.println("C");
|
|
// Serial.print(DallasTemperature::toFahrenheit(tempC));
|
|
// Serial.print((char)176);
|
|
// Serial.println("F");
|
|
} |