Remote controlled switches (433MHz) and temperature sensors
-
To be sure that the sensor works, you should download myscontroller from here : goo.gl/9DCWNo
(http://forum.mysensors.org/topic/838/windows-gui-controller-for-mysensors/33)Edit the ini file and enter the ip and port of your mysensors-gateway or com port which depends on the type of gateway you are using.
Start MysController and click the connect button.
Now power on your sensor and check if the sensor is sending values.If everything is ok then something is wrong with your vera integration. If the sensor does not show up then something is wrong with your sensor. You can also send messages to your sensor with myscontroller to check if your incomming function works.
-
Have a look at this lib
https://code.google.com/p/rc-switch/ -
Have a look at this lib
https://code.google.com/p/rc-switch/@Heinz I've used that lib in both my tries (it works with their sketch, but not with mine), but I will try the windows GUI and see how that goes.
LE: While bringing the serial gateway near my computer, I broke off the mini USB port (on the nano I was testing this), something dropped on it and all hell broke loose. I'll check it out tomorrow, but I would really appreciate if someone could take a look at my code. It has to be something I used incorrectly.
-
@CaptainZap I would start by trying to eliminate the st=fail: issue in your logs first. That is indicative of a wireless comm problem, at times indicating a message size failure. The root cause in my case was not due to software, but due to the circuit state which I corrected by power cycling, not hard resetting, to stabilize the current/radio.
-
@CaptainZap I would start by trying to eliminate the st=fail: issue in your logs first. That is indicative of a wireless comm problem, at times indicating a message size failure. The root cause in my case was not due to software, but due to the circuit state which I corrected by power cycling, not hard resetting, to stabilize the current/radio.
@blacey
Thanks for the feedback, today I started from scratch with a brand spanking new arduino nano ready for flashing. I ditched the temperature sensor part because yesterday I was being a bit too cocky, and rewrote the the sketch based on @Dwalt example combined with the TypeA_lightweight example from RC Switch and I can successfully say that I was able to control my switches !!!YAY! , now how do I add the temperature part as I need to monitor two temperature sensors from the device.
FYI, this is the sketch I have that works :
#include <MySensor.h> #include <SPI.h> #include <RF24.h> #define NUMBER_OF_OUTLETS 3 // Each outlet will have 2 OOK codes #define SEND_DATA 3 MySensor gw; int RCLpin = 3; void RCLswitch(uint16_t code) { for (int nRepeat=0; nRepeat<6; nRepeat++) { for (int i=4; i<16; i++) { RCLtransmit(1,3); if (((code << (i-4)) & 2048) > 0) { RCLtransmit(1,3); } else { RCLtransmit(3,1); } } RCLtransmit(1,31); } } void RCLtransmit(int nHighPulses, int nLowPulses) { digitalWrite(RCLpin, HIGH); delayMicroseconds( 350 * nHighPulses); digitalWrite(RCLpin, LOW); delayMicroseconds( 350 * nLowPulses); } void setup() { // The node is mains powered, so why not make it a repeater. gw.begin(incomingMessage, AUTO, true); // Send the sketch version information to gateway gw.sendSketchInfo("RF433", "0.1"); pinMode(RCLpin, OUTPUT); // Register outlets to gw (they will be created as child devices) for(int i=0; i<NUMBER_OF_OUTLETS;i++) { gw.present(i+1, S_LIGHT); } } void loop() { gw.process(); } void incomingMessage(const MyMessage &message) { if (message.type==V_LIGHT) { int incomingLightState = message.getBool(); int incomingOutlet = message.sensor; Serial.print("Outlet #: "); Serial.println(message.sensor); Serial.print("Command: "); Serial.println(message.getBool()); if (incomingOutlet==1) { if (incomingLightState==1) { // Turn on socket 1 Serial.println("Turn on Socket 1"); RCLswitch(0b101011000001);// These codes are unique to each outlet delay(50); } if (incomingLightState==0) { // Turn off socket 1 Serial.println("Turn off Socket 1"); RCLswitch(0b101011000010); delay(50); } } if (incomingOutlet==2) { if (incomingLightState==1) { // Turn on socket 2 Serial.println("Turn on Socket 2"); RCLswitch(0b101010100001); delay(50); } if (incomingLightState==0) { // Turn off socket 2 Serial.println("Turn off Socket 2"); RCLswitch(0b101010100010); delay(50); } } if (incomingOutlet==3) { if (incomingLightState==1) { // Turn on socket 3 Serial.println("Turn on Socket 3"); RCLswitch(0b101010010001); delay(50); } if (incomingLightState==0) { // Turn off socket 3 Serial.println("Turn off Socket 3"); RCLswitch(0b101010010010); delay(50); } } } delay(50); } -
Just an update on this, I've spent several hours today but I was able to get the sketch to show up 1 temperature sensor, and then two temperature sensors. Now the problem I have is that the two temperature sensors display the same value. They are connected to different pins on the arduino, 4 and 5, and are not wired in parallel. This is the temperature sensor part :
OneWire oneWire(ONE_WIRE_BUS); DallasTemperature DallasSensors(&oneWire); float lastTemperature ; float lastTemperature1 ; #define CHILD_ID_T1 4 //CHILD ID for temperature sensor1 #define CHILD_ID_T2 5 //CHILD ID for temperature sensor2 MyMessage tempMsg(CHILD_ID_T1,V_TEMP); MyMessage tempMsg2(CHILD_ID_T2,V_TEMP); void setup() { {...} // the lights part gw.present(CHILD_ID_T1, S_TEMP); gw.present(CHILD_ID_T2, S_TEMP); } void loop() { gw.process(); // Fetch temperatures from Dallas sensors DallasSensors.requestTemperatures(); float tempC = DallasSensors.getTempCByIndex(1); float tempD = DallasSensors.getTempCByIndex(2); // Only send data if temperature has changed and no error if (lastTemperature != tempC && tempC != -127.00) { // Send in the new temperature gw.send(tempMsg.set(tempC,1)); lastTemperature=tempC; } // Only send data if temperature has changed and no error if (lastTemperature1 != tempD && tempD != -127.00) { // Send in the new temperature gw.send(tempMsg2.set(tempD,1)); lastTemperature1=tempD; } }Anyone got any hints ? I'm so close on finalizing this ! I've learned a lot over the last couple of days :D
LE: After writing this here I realized I didn't declare the second pin in the code and thus was using the same one. I've corrected that and this WAS IT !
-
Why did you connect the two sensors to two different pins on the arduino? Onewire bus is exactly what it says, only a single wire, and a bus (meaning that it supports multiple devices)
you have
OneWire onewire(ONE_WIRE_BUS)ONE_WIRE_BUS is the pin that all your DS1820 sensors are connected to..
-
Why did you connect the two sensors to two different pins on the arduino? Onewire bus is exactly what it says, only a single wire, and a bus (meaning that it supports multiple devices)
you have
OneWire onewire(ONE_WIRE_BUS)ONE_WIRE_BUS is the pin that all your DS1820 sensors are connected to..
@tbowmo Because I don't know how to use the library correctly. I don't know how to display two sensors connected to the same port so I've done it how I knew. I am a beginner at coding and I know it can be simplified but this is as much as I know. I would like to see how you would do it :)
This is my last code for the temperature part:
#define ONE_WIRE_BUS 4 // Pin where dallas sensor is connected - on Rboard this is A0(D14) #define ONE_WIRE_BUS2 5 OneWire oneWire(ONE_WIRE_BUS); DallasTemperature DallasSensors(&oneWire); OneWire oneWire2(ONE_WIRE_BUS2); DallasTemperature DallasSensors2(&oneWire2); float lastTemperature ; float lastTemperature1 ; #define CHILD_ID_T1 4 //CHILD ID for temperature sensor1 #define CHILD_ID_T2 5 //CHILD ID for temperature sensor2 MyMessage tempMsg(CHILD_ID_T1,V_TEMP); MyMessage tempMsg2(CHILD_ID_T2,V_TEMP); void setup() { {...} // the lights part gw.present(CHILD_ID_T1, S_TEMP); gw.present(CHILD_ID_T2, S_TEMP); } void loop() { gw.process(); // Fetch temperatures from Dallas sensors DallasSensors.requestTemperatures(); float tempC = DallasSensors.getTempCByIndex(1); DallasSensors2.requestTemperatures(); float tempD = DallasSensors2.getTempCByIndex(1); // Only send data if temperature has changed and no error if (lastTemperature != tempC && tempC != -127.00) { // Send in the new temperature gw.send(tempMsg.set(tempC,1)); lastTemperature=tempC; } // Only send data if temperature has changed and no error if (lastTemperature1 != tempD && tempD != -127.00) { // Send in the new temperature gw.send(tempMsg2.set(tempD,1)); lastTemperature1=tempD; } } -
Indexes usually start at 0 not at 1
try getTempCByIndex(0); -
As per @Heinz suggestion I was able to use only one pin to get both temperature values, now I'm looking at lowering the refresh rate interval, now happens very fast. He suggested using millis(), but didn't help much.
Also I have one other question, I've noticed that when the node is on my desk (about 5 meters and 1 wall) from the gateway the RF switches no longer work, but the sensors do keep updating without any issues. I don't understand exactly why would this be the case.
LE: Seems that the issue with the RF is related to the power output from my USB port, I changed to a different one and it works without issue. Weird anyway.
-
@tbowmo Because I don't know how to use the library correctly. I don't know how to display two sensors connected to the same port so I've done it how I knew. I am a beginner at coding and I know it can be simplified but this is as much as I know. I would like to see how you would do it :)
This is my last code for the temperature part:
#define ONE_WIRE_BUS 4 // Pin where dallas sensor is connected - on Rboard this is A0(D14) #define ONE_WIRE_BUS2 5 OneWire oneWire(ONE_WIRE_BUS); DallasTemperature DallasSensors(&oneWire); OneWire oneWire2(ONE_WIRE_BUS2); DallasTemperature DallasSensors2(&oneWire2); float lastTemperature ; float lastTemperature1 ; #define CHILD_ID_T1 4 //CHILD ID for temperature sensor1 #define CHILD_ID_T2 5 //CHILD ID for temperature sensor2 MyMessage tempMsg(CHILD_ID_T1,V_TEMP); MyMessage tempMsg2(CHILD_ID_T2,V_TEMP); void setup() { {...} // the lights part gw.present(CHILD_ID_T1, S_TEMP); gw.present(CHILD_ID_T2, S_TEMP); } void loop() { gw.process(); // Fetch temperatures from Dallas sensors DallasSensors.requestTemperatures(); float tempC = DallasSensors.getTempCByIndex(1); DallasSensors2.requestTemperatures(); float tempD = DallasSensors2.getTempCByIndex(1); // Only send data if temperature has changed and no error if (lastTemperature != tempC && tempC != -127.00) { // Send in the new temperature gw.send(tempMsg.set(tempC,1)); lastTemperature=tempC; } // Only send data if temperature has changed and no error if (lastTemperature1 != tempD && tempD != -127.00) { // Send in the new temperature gw.send(tempMsg2.set(tempD,1)); lastTemperature1=tempD; } }@CaptainZap said:
@tbowmo Because I don't know how to use the library correctly. I don't know how to display two sensors connected to the same port so I've done it how I knew. I am a beginner at coding and I know it can be simplified but this is as much as I know. I would like to see how you would do it :)
Take a look at the dallas example that comes with the mysensors library it supports multiple ds1820s.
http://www.mysensors.org/build/temp
Think that everything you need is there.
-
@CaptainZap I had the same problem with the range.
The sensor is able to send data to the gateway but the gateway fails to send commands to the sensor.
I found out that the maximum power level of the gateway sender is not set to maximum by default, but the
level of the sensor is. I simply changed the value before compiling the gateway in
MyConfig.h
#define RF24_PA_LEVEL_GW RF24_PA_MAX -
@CaptainZap I had the same problem with the range.
The sensor is able to send data to the gateway but the gateway fails to send commands to the sensor.
I found out that the maximum power level of the gateway sender is not set to maximum by default, but the
level of the sensor is. I simply changed the value before compiling the gateway in
MyConfig.h
#define RF24_PA_LEVEL_GW RF24_PA_MAX@Heinz Thanks for pointing that out, since I plan to have most if not all my sensors ac powered I'll change that.