rangement : premier commit de l'appareil
- firmware/firmware.ino (depuis congelo-DS18B20x2/pro-mini--congelo-DS18B20x2), compilé identique - boitier : boîtier FreeCAD et STL - docs : adresses des sondes DS18B20, rendu du boîtier - README, .gitignore Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,171 @@
|
||||
#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
|
||||
#define MAX_ATTACHED_DS18B20 16
|
||||
#define COMPARE_TEMP false
|
||||
|
||||
// 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);
|
||||
|
||||
static const uint64_t UPDATE_INTERVAL = 600000; // (5min * 60 seconds * 1000 milliseconds)
|
||||
|
||||
// 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 };;
|
||||
|
||||
// #define CHILD_ID_TEMP1 1
|
||||
// #define CHILD_ID_TEMP2 2
|
||||
|
||||
// float DTemp1;
|
||||
// float DTemp2;
|
||||
|
||||
// float old_DTemp1;
|
||||
// float old_DTemp2;
|
||||
|
||||
// Initialize temperature message
|
||||
// MyMessage msgTemp1(CHILD_ID_TEMP1, V_TEMP);
|
||||
// MyMessage msgTemp2(CHILD_ID_TEMP2, V_TEMP);
|
||||
MyMessage msg(0,V_TEMP);
|
||||
|
||||
bool metric = true;
|
||||
|
||||
float lastTemperature[MAX_ATTACHED_DS18B20];
|
||||
int numSensors=0;
|
||||
bool receivedConfig = false;
|
||||
|
||||
|
||||
void presentation()
|
||||
{
|
||||
#ifdef MY_DEBUG
|
||||
Serial.println("- - - - - presentation - - - - -");
|
||||
#endif
|
||||
|
||||
// Send the sketch version information to the gateway
|
||||
sendSketchInfo("Congelos DS18B20x2", "0.1");
|
||||
|
||||
// Register all sensors to gw (they will be created as child devices)
|
||||
// present(CHILD_ID_TEMP1, S_TEMP, "Temperature Cumulus 1");
|
||||
// present(CHILD_ID_TEMP2, S_TEMP, "Temperature Cumulus 2");
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
metric = getControllerConfig().isMetric;
|
||||
}
|
||||
void before()
|
||||
{
|
||||
// Startup up the OneWire library
|
||||
sensors.begin();
|
||||
}
|
||||
void setup(void)
|
||||
{
|
||||
// sensors.begin();
|
||||
// requestTemperatures() will not block current thread
|
||||
sensors.setWaitForConversion(false);
|
||||
}
|
||||
|
||||
void loop(void)
|
||||
{
|
||||
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.;
|
||||
#ifdef MY_DEBUG
|
||||
Serial.print("temperature ");
|
||||
Serial.println(i);
|
||||
Serial.println(temperature);
|
||||
#endif
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
// 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 for a while to save energy
|
||||
sleep(UPDATE_INTERVAL);
|
||||
}
|
||||
Reference in New Issue
Block a user