Files
bachirandClaude Opus 5.5 b5d5b5057a rangement : premier commit de l'appareil
- 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>
2026-11-29 23:10:11 +01:00

164 lines
4.9 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 };
static const uint64_t UPDATE_INTERVAL = 600000; // (5min * 60 seconds * 1000 milliseconds)
#define CHILD_ID_TEMP1 1
#define CHILD_ID_BAT 11
#define CHILD_ID_BATV 12
int numSensors=0;
bool metric = true;
float DTemp1;
float old_DTemp1;
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 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("DS18B20x1", "0.2");
sleepForCoinCell();
// Fetch the number of attached temperature sensors
numSensors = sensors.getDeviceCount();
#ifdef MY_DEBUG
Serial.print(F("Sensor 1: "));
Serial.print(DTemp1);
Serial.println(F("C"));
#endif
// Register all sensors to gw (they will be created as child devices)
present(CHILD_ID_TEMP1, S_TEMP, "Temperature");
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)
{
#ifdef MY_DEBUG
Serial.println("- - - - - setup - - - - -");
#endif
sensors.begin();
}
void loop(void)
{
#ifdef MY_DEBUG
Serial.println("- - - - - loop - - - - -");
#endif
sensors.requestTemperatures();
old_DTemp1 = DTemp1;
// DTemp1 = sensors.getTempC(sensor1);
DTemp1 = sensors.getTempCByIndex(0);
#ifdef MY_DEBUG
Serial.print(F("Sensor 1: "));
Serial.print(DTemp1);
Serial.println(F("C"));
#endif
if (DTemp1 != old_DTemp1 && DTemp1 != -127)
{
send(msgTemp1.set(DTemp1, 1));
old_DTemp1 = DTemp1;
}
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);
}