correct, it makes sense. I will correct this error.
However Domoticz reads correctly the temperature and links correctly the CHILD ID's, so...
Posts made by lekeb
-
RE: 💬 Relay
-
RE: 💬 Relay
Sur,
my node controls two relays, one water pressure sensor and three DS18b20
/** code pour controle cave a vin, temp et pression */ // Enable debug prints to serial monitor //#define MY_DEBUG // Enable and select radio type attached #define MY_RADIO_NRF24 // Enable repeater functionality for this node #define MY_REPEATER_FEATURE #define MY_NODE_ID 15 #include <SPI.h> #include <MySensors.h> #include <DallasTemperature.h> #include <OneWire.h> #define BARO_CHILD 0 //Child ID for pressure sensor #define BAR_SENSOR_ANALOG_PIN 0 // pin for pressure sensor #define COMPARE_TEMP 1 // Send temperature only if changed? 1 = Yes 0 = No #define ONE_WIRE_BUS 5 // Pin where dallase sensor is connected #define MAX_ATTACHED_DS18B20 16 #define RELAY_PIN 3 //pin for first relay #define NUMBER_OF_RELAYS 2 #define RELAY_ON 1 // GPIO value to write to turn on attached relay #define RELAY_OFF 0 // GPIO value to write to turn off attached relay 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; float lastpression; uint8_t DS_First_Child_ID = 4; //First Child-ID to be used by Dallas Bus MyMessage pressureMsg(BARO_CHILD, V_PRESSURE); MyMessage msg(0,V_TEMP); void before() { for (int sensor=1, pin=RELAY_PIN; sensor<=NUMBER_OF_RELAYS; sensor++, pin++) { // Then set relay pins in output mode pinMode(pin, OUTPUT); // Set relay to last known state (using eeprom storage) digitalWrite(pin, loadState(sensor)?RELAY_ON:RELAY_OFF); } // 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("Buanderie node", "1.0"); //present pressure sensor present(BARO_CHILD, S_BARO); for (int sensor=1, pin=RELAY_PIN; sensor<=NUMBER_OF_RELAYS; sensor++, pin++) { // Register all sensors to gw (they will be created as child devices) present(sensor, S_BINARY); } // 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 + DS_First_Child_ID, S_TEMP); } } void loop() { //read water pressure int lecture_adc = analogRead(BAR_SENSOR_ANALOG_PIN); float pression = ((lecture_adc*5/1024.0)-0.50)/1.7; if(pression != lastpression) { send(pressureMsg.set(pression, 2)); lastpression = pression; } // 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); // 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 + DS_First_Child_ID).set(temperature,1)); // Save new temperatures for next compare lastTemperature[i]=temperature; } } } void receive(const MyMessage &message) { // We only expect one type of message from controller. But we better check anyway. if (message.type==V_STATUS) { // Change relay state digitalWrite(message.sensor-1+RELAY_PIN, message.getBool()?RELAY_ON:RELAY_OFF); // Store state in eeprom saveState(message.sensor, message.getBool()); // Write some debug info Serial.print("Incoming change for sensor:"); Serial.print(message.sensor); Serial.print(", New status: "); Serial.println(message.getBool()); } }
-
RE: 💬 Relay
perfect it works great. I started my temperature sensor at CHILD ID 4 and let relays from 1 to 2. I had to add also "DS_First_Child_ID" in the sent message to gateway.
thanks -
RE: 💬 Relay
hello.
I am building a node with several kind of sensors and two relays.
My sensors use CHILD ID from 0 to 3. I would like to start child ID of relay from 4.
How I can't do that with this sketch?
I guess I have to change this part of sketch :
"for (int sensor=1, pin=RELAY_PIN; sensor<=NUMBER_OF_RELAYS; sensor++, pin++) {
// Register all sensors to gw (they will be created as child devices)
present(sensor, S_BINARY);"correct?
thanks
-
RE: Water pressure sensor
Thanks a lot, It works!!!
Here my code updated
// Enable debug prints to serial monitor //#define MY_DEBUG // Enable and select radio type attached #define MY_RADIO_NRF24 //#define MY_NODE_ID 7 #include <MySensors.h> #define BARO_CHILD 0 #define BAR_SENSOR_ANALOG_PIN 0 unsigned long SLEEP_TIME = 60000; MyMessage pressureMsg(BARO_CHILD, V_PRESSURE); void setup(){ } void presentation() { sendSketchInfo("pressure Sensor", "1.0"); present(BARO_CHILD, S_BARO); } void loop() { int lecture_adc = analogRead(BAR_SENSOR_ANALOG_PIN); float pression = ((lecture_adc*5/1024.0)-0.50)/1.7; Serial.println(pression); send(pressureMsg.set(pression, 2)); sleep(SLEEP_TIME); }
-
RE: Water pressure sensor
Makes sense! My value didn't change over time
But what means this ligne#define BAR_SENSOR_ANALOG_PIN 0
I guessed it was to declare AnalogRead on pin 0?
-
RE: Water pressure sensor
Thanks for your answer.
Exactly, I don't get the same value
Here my full debug
0 MCO:BGN:INIT NODE,CP=RNNNA--,VER=2.1.1 3 TSM:INIT 4 TSF:WUR:MS=0 11 TSM:INIT:TSP OK 12 TSM:INIT:STATID=7 14 TSF:SID:OK,ID=7 16 TSM:FPAR 35 TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK: 2042 !TSM:FPAR:NO REPLY 2044 TSM:FPAR 2063 TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK: 2071 TSF:MSG:READ,0-0-7,s=255,c=3,t=8,pt=1,l=1,sg=0:0 2076 TSF:MSG:FPAR OK,ID=0,D=1 4071 TSM:FPAR:OK 4072 TSM:ID 4073 TSM:ID:OK 4075 TSM:UPL 4077 TSF:MSG:SEND,7-7-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1 4083 TSF:MSG:READ,0-0-7,s=255,c=3,t=25,pt=1,l=1,sg=0:1 4088 TSF:MSG:PONG RECV,HP=1 4091 TSM:UPL:OK 4092 TSM:READY:ID=7,PAR=0,DIS=1 4097 TSF:MSG:SEND,7-7-0-0,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100 4104 TSF:MSG:READ,0-0-7,s=255,c=3,t=15,pt=6,l=2,sg=0:0100 4110 TSF:MSG:SEND,7-7-0-0,s=255,c=0,t=17,pt=0,l=5,sg=0,ft=0,st=OK:2.1.1 4118 TSF:MSG:SEND,7-7-0-0,s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=OK:0 4128 TSF:MSG:READ,0-0-7,s=255,c=3,t=6,pt=0,l=1,sg=0:M 4134 TSF:MSG:SEND,7-7-0-0,s=255,c=3,t=11,pt=0,l=15,sg=0,ft=0,st=OK:pressure Sensor 4144 TSF:MSG:SEND,7-7-0-0,s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=OK:1.0 4151 TSF:MSG:SEND,7-7-0-0,s=0,c=0,t=8,pt=0,l=0,sg=0,ft=0,st=OK: 4157 MCO:REG:REQ 4160 TSF:MSG:SEND,7-7-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=OK:2 4166 TSF:MSG:READ,0-0-7,s=255,c=3,t=27,pt=1,l=1,sg=0:1 4171 MCO:PIM:NODE REG=1 4173 MCO:BGN:STP 4175 MCO:BGN:INIT OK,TSP=1 -0.29 4178 TSF:MSG:SEND,7-7-0-0,s=0,c=1,t=4,pt=7,l=5,sg=0,ft=0,st=OK:-0.29 4186 MCO:SLP:MS=60000,SMS=0,I1=255,M1=255,I2=255,M2=255 4191 MCO:SLP:TPD 4192 MCO:SLP:WUP=-1 -0.29 4196 TSF:MSG:SEND,7-7-0-0,s=0,c=1,t=4,pt=7,l=5,sg=0,ft=0,st=OK:-0.29 4202 MCO:SLP:MS=60000,SMS=0,I1=255,M1=255,I2=255,M2=255 4207 MCO:SLP:TPD```
-
Water pressure sensor
Hello,
I need your help to write my first "My sensor" sketch.
I use this 5V sensor (link below) and pro-mini arduino to mesure water pressure inside my home water pipe.
https://fr.aliexpress.com/item/0-0-5-Mpa-Water-Gas-Pressure-Sensor-G1-4-DC-5V-Air-Compressor-Pressure-Transmitter/32660132491.html?spm=a2g0s.9042311.0.0.KxZ6lvI used this simple sketch to read water pressure in Bar. I can read a pressure around 2.20 Bar
void setup() { Serial.begin(9600); } void loop() { int lecture_adc; float pression; lecture_adc = analogRead(A0); Serial.print("Sensor Value: "); Serial.println(lecture_adc); pression = (((lecture_adc*5/1024.0)-0.52)/1.7); //read pressure in Bar, remove 1.7 to read Voltage, divide 0.17 to read in MPa Serial.print("Pression: "); Serial.println(pression); delay(1000);
Now, I tried to monitore my water pressure with my sensor and domoticz, that's why I wrote this sketch
// Enable debug prints to serial monitor #define MY_DEBUG // Enable and select radio type attached #define MY_RADIO_NRF24 #define MY_NODE_ID 7 #include <MySensors.h> #define BARO_CHILD 0 #define BAR_SENSOR_ANALOG_PIN 0 unsigned long SLEEP_TIME = 60000; MyMessage pressureMsg(BARO_CHILD, V_PRESSURE); void setup(){ } void presentation() { sendSketchInfo("pressure Sensor", "1.0"); present(BARO_CHILD, S_BARO); } void loop() { int lecture_adc; float pression; lecture_adc = BAR_SENSOR_ANALOG_PIN; pression = ((lecture_adc*5/1024.0)-0.52)/1.7; Serial.println(pression); send(pressureMsg.set(pression, 2)); sleep(SLEEP_TIME); }
But with this code, my node send as value -0.21 (check in DEBUG). I don't understand why.
Could you help me to understand what is wrong?Thanks