Very comprehensive and prompt reply !!! I will follow your steps today and update you on the outcome.
Thank you so much for your help.
mehrdad.silatani
@mehrdad.silatani
Best posts made by mehrdad.silatani
-
RE: Error compiling - ATSHA204.h not Found
-
RE: DHT sensor for Mysensors V2
@sundberg84 Fantastic ! It worked very well ! Thanks for quick response !
-
RE: Error compiling - ATSHA204.h not Found
Ok, I tired the steps as explained and everything seems to be working.
[Some Observations]:
-
Strangely, I had Arduino version 1.7 which did not have "Manage Libraries" button in the sketch tab at all. So I uninstalled it and installed the 1.6.11 version and then I found the "Manage Libraries" and successfully installed the "mysensors" library. I also compiled and uploaded some example sketches to my Arduino nano!
-
In the video of the demonstration of how to start with my sensors (made by petewill), it says to locate an example named "SerialGateway", but in my library it is named "GatewaySerial", are they the same thing ?
-
I would really appreciate if I can have some sort of tutorials on how to start using the wifi modules, or put simple, how to get the best out of mysensors.org ? At the moment, I have all the components but yet to find out how I can really utilise the "mysensors.org" capability.
Again, thank you so much for all your help !
Cheers,
Mehrdad -
-
RE: Error compiling - ATSHA204.h not Found
Thank you so much for your elaborate explanations ! It really cleared up some questions I had in mind, especially about the Arduino versions !
Also, I did not know that "Mysensors" is run entirely by volunteers! I will try to become one of those useful volunteers that helps others (like you ) rather than coming up with questions all the time
-
RE: DHT + Relay Sketch
@mfalkvidd Thank you so much for your comment. I already checked the link you send me and it is very insightful but I guess I am still too beginner to find my solution from those explanations.
Since you asked about missing functions, I couldn't find any description on " C_SET".
Also if you don't mind I would like to ask for your help to understand some of the functions used in my code. These are the functions I am not fully understanding;
-
"send(msgHum.set(humidity, 1))"
What is the action of that number "1" after the payload (i.e. humidity)? can it be any number ? -
"send(msgRlay.set(state?RELAY_ON:RELAY_OFF),2)"
I fully understand up to the part of "send(msgRlay.set" but what happens in "state?RELAY_ON:RELAY_OFF" and also again what is that number "2" at the end doing ?( I randomly typed 2) .... I suspect, in "state?RELAY_ON:RELAY_OFF" it asks the Arduino that which state is true and use that, is that correct? -
"send(msgRlay.set(state?RELAY_ON:RELAY_OFF), true)"
What is the "true" at the end of the line doing? -
"wait(2000, C_SET, V_STATUS)"
This is where I came across the "C_SET" -
"state = (bool)message.getInt()"
I can guess that this line is trying to extract the information of the relay state from the received msg, but I really don't know what is the breakdown of the logic in it (e.g. does adding (bool) at the front of the message.getInt() means only accept boolean type data ? .... ) -
"debouncer.update()"
I really dont quite get what happens in this line ...
Sorry for asking too many questions .. I am really loving to work with "mysensors" and I am trying to make sure I understand what happens in my codes
-
-
RE: DHT + Relay Sketch
@mfalkvidd WOW ! I am blown away by your detailed answers !!! Nothing is more satisfying than plain answers to puzzling questions Thank you so so much !!!
Meanwhile, by using my "MYSController". I figured out that the sketch is reporting right values as you pointed out before;
So what I did was to check my "mysensors.json" ... I noticed there are traces of my old sensor node still embedded in the "mysensors.json". So I deleted the file and let the HA to create a new one from scratch ! and then Volla ! HA started to recognise the sensors and switch separately !
I know everyone here are helping and volunteers, but I thought I will just share my suggestion with you wonderful people, I think it would be invaluable to mysensors users to be able to refer to a language reference page similar to the arduino's website; "https://www.arduino.cc/en/Reference/HomePage"
Again, THANK YOU so much for your elaborated answers !
Cheers,
Mehrdad -
RE: Should I modifymy IDE once I am changing from Arduino Nano to ProMini ?
@sundberg84 The whole system is currently working on 5V adapter which is fed to the RAW port of Promini and then I am powering the sensor from "Vcc" port.
Anyway, I checked the voltage across the DHT11 sensor and my voltmeter shows 4.98 V. So I dont think the power is the problem ...I think this has been flagged before by other people as well, See-> (https://forum.mysensors.org/topic/1894/pro-mini-is-giving-a-frequent-time-out-on-dth11-read-out/9)
I even tried two different Pro mini boards ! still no luck !
Latest posts made by mehrdad.silatani
-
RE: Should I modifymy IDE once I am changing from Arduino Nano to ProMini ?
Ok out of curiosity, i changed my processor from "5V 16Mhz" to "3.3V 8Mhz" and then everything started to work all of a sudden !
How can you tell what processor is used on your board ? I checked my order, and I am confident that I ordered the 5V 16MHz version ... so I guess I've been sent the wrong devices !
-
RE: Should I modifymy IDE once I am changing from Arduino Nano to ProMini ?
@sundberg84 The whole system is currently working on 5V adapter which is fed to the RAW port of Promini and then I am powering the sensor from "Vcc" port.
Anyway, I checked the voltage across the DHT11 sensor and my voltmeter shows 4.98 V. So I dont think the power is the problem ...I think this has been flagged before by other people as well, See-> (https://forum.mysensors.org/topic/1894/pro-mini-is-giving-a-frequent-time-out-on-dth11-read-out/9)
I even tried two different Pro mini boards ! still no luck !
-
RE: Should I modifymy IDE once I am changing from Arduino Nano to ProMini ?
@scalz Thank you for your reply.
Not a chance that it is the bad quality wire, cause Nano works on the very same wiring.
Following your suggestion, I tested the Pro mini with the example sketch of dht lib. I get a weired outputs on my serial port (baud rate is matching to the defined rate on sketch, I even tried all other baud rates anyway ...)
-
Should I modifymy IDE once I am changing from Arduino Nano to ProMini ?
Hi,
I ran into a confusing problem. So the story is;
I made an IDE which combines the DHT, LDR and a RELAY "mysensor" libraries together in one single code. Then I uploaded it to my Arduino Nano for testing, everything went smoothly and fine and I got all the readings on my HA.
The problem started once I uploaded the same code to my Arduino Pro mini (I changed the board and port before uploading), and then for some reason, it keeps telling "It failed to read temp/hum from DHT". Believe me I doubled checked pin numbers, wires, and everything I still get the same error. Even when I changed to another Promini, I got the same error. And to add to my confusion, without changing anything, once I put the Nano back on, everything started to work and it could read data from DHT !
So now I have two questions in my head;
- Is it possible that some "mysensors" libraries are incompatible with certain boards ?
- Simply, is there any difference between pin D3 on a Promini and a Nano ? (maybe ProMini can't provide the current required by DHT ... ?)
Would really appreciate any suggestion,
Cheers,
Mehrdad -
RE: DHT + Relay Sketch
One last question !!!
Now that I opened up my "mysensors.json", it made me curious about some of the information in it. Currently it shows;
{"0": {"sketch_name": null, "sensor_id": 0, "children": {}, "battery_level": 0, "sketch_version": null, "protocol_version": "2.0.0", "type": 18}, "1": {"sketch_name": "TempHumidRelay", "sensor_id": 1, "children": {"0": {"id": 0, "description": "", "values": {"1": "51.0"}, "type": 7}, "1": {"id": 1, "description": "", "values": {"0": "21.0"}, "type": 6}, "2": {"id": 2, "description": "", "values": {"2": "0"}, "type": 3}}, "battery_level": 0, "sketch_version": "1.1", "protocol_version": "2.0.0", "type": 18}}
Inside the "values" brackets, I know the second numbers are the reported values (i.e. payload), but what is the first number in the bracket ? {"0": "21.0"} , {"1": "51.0"} or {"2": "0"}
And finally what are the definition of "type": 18 , "type": 3 , "type": 7 and "type":6 ?
Cheers,
Mehrdad -
RE: DHT + Relay Sketch
@mfalkvidd WOW ! I am blown away by your detailed answers !!! Nothing is more satisfying than plain answers to puzzling questions Thank you so so much !!!
Meanwhile, by using my "MYSController". I figured out that the sketch is reporting right values as you pointed out before;
So what I did was to check my "mysensors.json" ... I noticed there are traces of my old sensor node still embedded in the "mysensors.json". So I deleted the file and let the HA to create a new one from scratch ! and then Volla ! HA started to recognise the sensors and switch separately !
I know everyone here are helping and volunteers, but I thought I will just share my suggestion with you wonderful people, I think it would be invaluable to mysensors users to be able to refer to a language reference page similar to the arduino's website; "https://www.arduino.cc/en/Reference/HomePage"
Again, THANK YOU so much for your elaborated answers !
Cheers,
Mehrdad -
RE: DHT + Relay Sketch
@mfalkvidd Thank you so much for your comment. I already checked the link you send me and it is very insightful but I guess I am still too beginner to find my solution from those explanations.
Since you asked about missing functions, I couldn't find any description on " C_SET".
Also if you don't mind I would like to ask for your help to understand some of the functions used in my code. These are the functions I am not fully understanding;
-
"send(msgHum.set(humidity, 1))"
What is the action of that number "1" after the payload (i.e. humidity)? can it be any number ? -
"send(msgRlay.set(state?RELAY_ON:RELAY_OFF),2)"
I fully understand up to the part of "send(msgRlay.set" but what happens in "state?RELAY_ON:RELAY_OFF" and also again what is that number "2" at the end doing ?( I randomly typed 2) .... I suspect, in "state?RELAY_ON:RELAY_OFF" it asks the Arduino that which state is true and use that, is that correct? -
"send(msgRlay.set(state?RELAY_ON:RELAY_OFF), true)"
What is the "true" at the end of the line doing? -
"wait(2000, C_SET, V_STATUS)"
This is where I came across the "C_SET" -
"state = (bool)message.getInt()"
I can guess that this line is trying to extract the information of the relay state from the received msg, but I really don't know what is the breakdown of the logic in it (e.g. does adding (bool) at the front of the message.getInt() means only accept boolean type data ? .... ) -
"debouncer.update()"
I really dont quite get what happens in this line ...
Sorry for asking too many questions .. I am really loving to work with "mysensors" and I am trying to make sure I understand what happens in my codes
-
-
RE: DHT + Relay Sketch
Ok, I made one step forward. Now the two sketches are combined and I managed to get the HA to recognise the attributes. However, in HA, the temperature sensor keeps appear as a switch !
This is my sketch:
#define MY_DEBUG #define MY_RADIO_NRF24 #define MY_REPEATER_FEATURE #define MY_NODE_ID 1 #include <SPI.h> #include <MySensors.h> #include <Bounce2.h> #include <DHT.h> // Set this to the pin you connected the DHT's data pin to #define DHT_DATA_PIN 3 // Set this offset if the sensor has a permanent small offset to the real temperatures #define SENSOR_TEMP_OFFSET 0 // Sleep time between sensor updates (in milliseconds) // Must be >1000ms for DHT22 and >2000ms for DHT11 static const uint64_t UPDATE_INTERVAL = 60000; // Force sending an update of the temperature after n sensor reads, so a controller showing the // timestamp of the last update doesn't show something like 3 hours in the unlikely case, that // the value didn't change since; // i.e. the sensor would force sending an update every UPDATE_INTERVAL*FORCE_UPDATE_N_READS [ms] static const uint8_t FORCE_UPDATE_N_READS = 10; #define CHILD_ID_HUM 0 #define CHILD_ID_TEMP 1 #define CHILD_ID_RLAY 2 #define RELAY_PIN 4 #define RELAY_ON 1 #define RELAY_OFF 0 Bounce debouncer = Bounce(); bool state = false; bool initialValueSent = false; float lastTemp; float lastHum; uint8_t nNoUpdatesTemp; uint8_t nNoUpdatesHum; bool metric = true; MyMessage msgHum(CHILD_ID_HUM, V_HUM); MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP); MyMessage msgRlay(CHILD_ID_RLAY, V_STATUS); DHT dht; void presentation() { // Send the sketch version information to the gateway sendSketchInfo("TempHumidRelay", "1.1"); // Register all sensors to gw (they will be created as child devices) present(CHILD_ID_HUM, S_HUM); present(CHILD_ID_TEMP, S_TEMP); present(CHILD_ID_RLAY, S_BINARY); metric = getConfig().isMetric; } void setup() { dht.setup(DHT_DATA_PIN); // set data pin of DHT sensor if (UPDATE_INTERVAL <= dht.getMinimumSamplingPeriod()) { Serial.println("Warning: UPDATE_INTERVAL is smaller than supported by the sensor!"); } // Sleep for the time of the minimum sampling period to give the sensor time to power up // (otherwise, timeout errors might occure for the first reading) //sleep(dht.getMinimumSamplingPeriod()); // Make sure relays are off when starting up digitalWrite(RELAY_PIN, RELAY_OFF); pinMode(RELAY_PIN, OUTPUT); } void loop() { if (!initialValueSent) { Serial.println("Sending initial value"); send(msgRlay.set(state?RELAY_ON:RELAY_OFF),2); Serial.println("Requesting initial value from controller"); request(CHILD_ID_RLAY, V_STATUS); wait(2000, C_SET, V_STATUS); } if (debouncer.update()) { if (debouncer.read()==LOW) { state = !state; // Send new state and request ack back send(msgRlay.set(state?RELAY_ON:RELAY_OFF), true); } } dht.readSensor(true); float temperature = dht.getTemperature(); if (isnan(temperature)) { Serial.println("Failed reading temperature from DHT!"); } else if (temperature != lastTemp || nNoUpdatesTemp == FORCE_UPDATE_N_READS) { // Only send temperature if it changed since the last measurement or if we didn't send an update for n times lastTemp = temperature; if (!metric) { temperature = dht.toFahrenheit(temperature); } nNoUpdatesTemp = 0; temperature += SENSOR_TEMP_OFFSET; send(msgTemp.set(temperature, 1)); #ifdef MY_DEBUG Serial.print("T: "); Serial.println(temperature); #endif } else { // Increase no update counter if the temperature stayed the same nNoUpdatesTemp++; } // Get humidity from DHT library float humidity = dht.getHumidity(); if (isnan(humidity)) { Serial.println("Failed reading humidity from DHT"); } else if (humidity != lastHum || nNoUpdatesHum == FORCE_UPDATE_N_READS) { // Only send humidity if it changed since the last measurement or if we didn't send an update for n times lastHum = humidity; // Reset no updates counter nNoUpdatesHum = 0; send(msgHum.set(humidity, 1)); #ifdef MY_DEBUG Serial.print("H: "); Serial.println(humidity); #endif } else { // Increase no update counter if the humidity stayed the same nNoUpdatesHum++; } wait(2000); } void receive(const MyMessage &message) { if (message.isAck()) { Serial.println("This is an ack from gateway"); } if (message.type == V_STATUS) { if (!initialValueSent) { Serial.println("Receiving initial value from controller"); initialValueSent = true; } // Change relay state state = (bool)message.getInt(); digitalWrite(RELAY_PIN, state?RELAY_ON:RELAY_OFF); send(msgRlay.set(state?RELAY_ON:RELAY_OFF,2)); } }
I would really sincerely appreciate if someone can shed some light on what I am doing wrong !
Plus, I read mysensors website millions time but still I can't find clear description of some of the functions that are being used in V2 of the library, any idea where I can look up functions used in mysensors examples ?
Cheers
-
RE: DHT + Relay Sketch
@TheoL THank you for your reply, I already have 47uF capacitor connected to the radio module, and its already running on an external power supply.
All being said, I suspect, I am missing something in the sketch.
Cheers,
Mehrdad -
DHT + Relay Sketch
Hi,
I am trying to combine a DHT sensor with a Relay module in one sketch. I already looked up the example of how to combine two IDEs together and used some of its information. However, once I combine the sketches and upload it to Arduino, I can see an error in my SerialPort:
Also when I am running the sketch and let it to communicate with GW, my HA (controller) doesnt recognise any entity for my relay !
Any help would be much appreciated!
This is the current sketch:// Enable debug prints #define MY_DEBUG // Enable and select radio type attached #define MY_RADIO_NRF24 //#define MY_RADIO_RFM69 //#define MY_RS485 #include <SPI.h> #include <MySensors.h> #include <DHT.h> // Set this to the pin you connected the DHT's data pin to #define DHT_DATA_PIN 3 // Set this offset if the sensor has a permanent small offset to the real temperatures #define SENSOR_TEMP_OFFSET 0 // Sleep time between sensor updates (in milliseconds) // Must be >1000ms for DHT22 and >2000ms for DHT11 static const uint64_t UPDATE_INTERVAL = 60000; // Force sending an update of the temperature after n sensor reads, so a controller showing the // timestamp of the last update doesn't show something like 3 hours in the unlikely case, that // the value didn't change since; // i.e. the sensor would force sending an update every UPDATE_INTERVAL*FORCE_UPDATE_N_READS [ms] static const uint8_t FORCE_UPDATE_N_READS = 10; #define CHILD_ID_HUM 0 #define CHILD_ID_TEMP 1 #define CHILD_ID_RLAY 2 #define RELAY_1 4 // Arduino Digital I/O pin number for first relay (second on pin+1 etc) #define NUMBER_OF_RELAYS 1 // Total number of attached relays #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 float lastTemp; float lastHum; uint8_t nNoUpdatesTemp; uint8_t nNoUpdatesHum; bool metric = true; MyMessage msgHum(CHILD_ID_HUM, V_HUM); MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP); DHT dht; void before() { for (int sensor=1, pin=RELAY_1; 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); } } void presentation() { // Send the sketch version information to the gateway sendSketchInfo("TempHumidRelay", "1.1"); // Register all sensors to gw (they will be created as child devices) present(CHILD_ID_RLAY, S_LIGHT); present(CHILD_ID_HUM, S_HUM); present(CHILD_ID_TEMP, S_TEMP); metric = getConfig().isMetric; } void setup() { dht.setup(DHT_DATA_PIN); // set data pin of DHT sensor if (UPDATE_INTERVAL <= dht.getMinimumSamplingPeriod()) { Serial.println("Warning: UPDATE_INTERVAL is smaller than supported by the sensor!"); } // Sleep for the time of the minimum sampling period to give the sensor time to power up // (otherwise, timeout errors might occure for the first reading) sleep(dht.getMinimumSamplingPeriod()); } void receive(const MyMessage &message) { // We only expect one type of message from controller. But we better check anyway. if (message.type==V_LIGHT) { // Change relay state digitalWrite(message.sensor-1+RELAY_1, 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()); } } void loop() { // Force reading sensor, so it works also after sleep() dht.readSensor(true); // Get temperature from DHT library float temperature = dht.getTemperature(); if (isnan(temperature)) { Serial.println("Failed reading temperature from DHT!"); } else if (temperature != lastTemp || nNoUpdatesTemp == FORCE_UPDATE_N_READS) { // Only send temperature if it changed since the last measurement or if we didn't send an update for n times lastTemp = temperature; if (!metric) { temperature = dht.toFahrenheit(temperature); } // Reset no updates counter nNoUpdatesTemp = 0; temperature += SENSOR_TEMP_OFFSET; send(msgTemp.set(temperature, 1)); #ifdef MY_DEBUG Serial.print("T: "); Serial.println(temperature); #endif } else { // Increase no update counter if the temperature stayed the same nNoUpdatesTemp++; } // Get humidity from DHT library float humidity = dht.getHumidity(); if (isnan(humidity)) { Serial.println("Failed reading humidity from DHT"); } else if (humidity != lastHum || nNoUpdatesHum == FORCE_UPDATE_N_READS) { // Only send humidity if it changed since the last measurement or if we didn't send an update for n times lastHum = humidity; // Reset no updates counter nNoUpdatesHum = 0; send(msgHum.set(humidity, 1)); #ifdef MY_DEBUG Serial.print("H: "); Serial.println(humidity); #endif } else { // Increase no update counter if the humidity stayed the same nNoUpdatesHum++; } // Sleep for a while to save energy sleep(UPDATE_INTERVAL); }