RF 433 MHz sensor to control RF sockets.
-
Thank You for response.
This is actual code: http://wklej.org/id/1365746/
I noticed that, the problem occurs when node receiving code from RF433 remote. After start arduino program works good (diode connected to pin 13 lights up). When I push button on RF433 remote several times diode turns off and then I can't send codes from gateway to node. When I push buttons on RF433 remote diode blinks and codes are transmitted to gateway correctly. After a few more pushes of the button on remote diode connected to pin 13 turns on and then I can't send codes to node from gateway and get codes from node to gateway. -
Hek, thank for your response. I have to send two information to node (and from node): RF433 code and period. I would like to avoid sending this information in two messages (e.g. as V_VAR1 and V_VAR2), so I joined this informations in one by using class String. Maybe do You have idea how to avoid String class in this program?
-
Hek, thank for your response. I have to send two information to node (and from node): RF433 code and period. I would like to avoid sending this information in two messages (e.g. as V_VAR1 and V_VAR2), so I joined this informations in one by using class String. Maybe do You have idea how to avoid String class in this program?
-
OK, I stopped using String Class, but program works in the same way.On start Arduino, program works well and I can get and send RF433 codes. After some pushes a button on RF433 remote, LED on Arduino (pin 13) turns off and then I can't send messages from gateway to node, but I can still get codes of buttons on gateway from node. I think that, maybe this problem is connected with interrupts because NRF24 and receiver RF433 modules are using interrupts. IRQ pin from NRF24 module is connected to pin 2 (int.0) in Arduino Pro Mini and data pin from receiver RF433 module is connected to pin 3 (int.1) in Arduino.
@hek Do You have any idea why this program doesn't work properly?#include <Relay.h> #include <SPI.h> #include <EEPROM.h> #include <RF24.h> #include <RemoteReceiver.h> #include <RemoteTransmitter.h> #define TRANSMITTER_PIN 8 #define RECEIVER_INTERRUPT 1 #define RF433_CHILD_ID 0 Sensor gw; void setup() { gw.begin(28); gw.sendSketchInfo("RF433", "1.0"); gw.sendSensorPresentation(RF433_CHILD_ID, S_IR); RemoteReceiver::init(RECEIVER_INTERRUPT, 3, getRfMessage); } void loop() { if (gw.messageAvailable()) { message_s message = gw.getMessage(); sendRfMessage(message); } } void sendRfMessage(message_s message) { if (message.header.messageType==M_SET_VARIABLE && message.header.type==V_IR_SEND) { char sendingRfCode[7]; char sendingRfPeriod[4]; strncpy(sendingRfCode, message.data, 6); strncpy(sendingRfPeriod, message.data+6, 3); sendingRfCode[6] = 0; sendingRfPeriod[3] = 0; Serial.println(atol(sendingRfCode)); Serial.println(atol(sendingRfPeriod)); RemoteReceiver::disable(); interrupts(); delay(200); RemoteTransmitter::sendCode(TRANSMITTER_PIN, atol(sendingRfCode), atol(sendingRfPeriod), 3); RemoteReceiver::enable(); } } void getRfMessage(unsigned long incomingRfCode, unsigned int incomingRfPeriod){ char gettingRfMessage[10]; sprintf(gettingRfMessage, "%lu%u", incomingRfCode, incomingRfPeriod); Serial.println(incomingRfCode); Serial.println(incomingRfPeriod); Serial.println(gettingRfMessage); gw.sendVariable(RF433_CHILD_ID, V_IR_RECEIVE, gettingRfMessage); delay(200); } -
If I understand the RemoteReceiver code correctly your callback will be called in an interrupt. This means you should do as little as possible there. Definetly not serial print or send any data over radio.
I propose you just save the incoming values and a new flag like this:
setup() { RemoteReceiver::init(RECEIVER_INTERRUPT, 3, newRf); } volatile bool receivedNew = false; volatile unsigned long incomingRfCode; volatile unsigned int incomingRfPeriod; void newRf(unsigned long _incomingRfCode, unsigned int _incomingRfPeriod){ incomingRfCode = _incomingRfCode; incomingRfPeriod = _incomingRfPeriod; receivedNew=true; }And in you main loop check if received new is true.
loop() { if(receivedNew) { getRfMessage(incomingRfCode, incomingRfPeriod); receivedNew = false; } }Note this is not tested and should just give you an hint how to handle it without doing lots of stuff when executing inside an interrupt.
-
@hek
Wow it's working :+1:. Hek thank you very much, you are the master :D
This is working code:
#include <Relay.h>
#include <SPI.h>
#include <EEPROM.h>
#include <RF24.h>#include <RemoteReceiver.h> #include <RemoteTransmitter.h> #define TRANSMITTER_PIN 8 #define RECEIVER_INTERRUPT 1 #define RF433_CHILD_ID 0 Sensor gw; volatile bool receivedNew = false; volatile unsigned long incomingRfCode; volatile unsigned int incomingRfPeriod; void setup() { gw.begin(28); gw.sendSketchInfo("RF433", "1.0"); gw.sendSensorPresentation(RF433_CHILD_ID, S_IR); delay(200); RemoteReceiver::init(RECEIVER_INTERRUPT, 3, newRf); } void loop() { if (gw.messageAvailable()) { message_s message = gw.getMessage(); sendRfMessage(message); } if(receivedNew) { getRfMessage(incomingRfCode, incomingRfPeriod); receivedNew = false; } } void sendRfMessage(message_s message) { if (message.header.messageType==M_SET_VARIABLE && message.header.type==V_IR_SEND) { char sendingRfCode[7]; char sendingRfPeriod[4]; strncpy(sendingRfCode, message.data, 6); strncpy(sendingRfPeriod, message.data+6, 3); sendingRfCode[6] = 0; sendingRfPeriod[3] = 0; Serial.println(atol(sendingRfCode)); Serial.println(atol(sendingRfPeriod)); RemoteReceiver::disable(); interrupts(); delay(200); RemoteTransmitter::sendCode(TRANSMITTER_PIN, atol(sendingRfCode), atol(sendingRfPeriod), 3); RemoteReceiver::enable(); } } void newRf(unsigned long _incomingRfCode, unsigned int _incomingRfPeriod){ incomingRfCode = _incomingRfCode; incomingRfPeriod = _incomingRfPeriod; receivedNew=true; } void getRfMessage(unsigned long incomingRfCode, unsigned int incomingRfPeriod){ char gettingRfMessage[10]; sprintf(gettingRfMessage, "%lu%u", incomingRfCode, incomingRfPeriod); Serial.println(incomingRfCode); Serial.println(incomingRfPeriod); Serial.println(gettingRfMessage); gw.sendVariable(RF433_CHILD_ID, V_IR_RECEIVE, gettingRfMessage); } -
@lasso Are you learning the codes with the receiver inorder to know what to send to them ? I would really like to react on my 433mhz sensors i have for doors and i am interested how to do that and i found your post and i am trying to figure out if i could use some of this code for that purpose, what's your take on that ?
-
Did you ever get this working?
What pins did you attache the transmitter to and what pin did you attach the receiver to?
Is that the latest code?
-
Hello,
this is my version "Home Easy Plug-in switch (HE877)". scatch.
Arduino emulates remote control Elro AB440
AVI, thanks for the inspiration. -
@hek
Wow it's working :+1:. Hek thank you very much, you are the master :D
This is working code:
#include <Relay.h>
#include <SPI.h>
#include <EEPROM.h>
#include <RF24.h>#include <RemoteReceiver.h> #include <RemoteTransmitter.h> #define TRANSMITTER_PIN 8 #define RECEIVER_INTERRUPT 1 #define RF433_CHILD_ID 0 Sensor gw; volatile bool receivedNew = false; volatile unsigned long incomingRfCode; volatile unsigned int incomingRfPeriod; void setup() { gw.begin(28); gw.sendSketchInfo("RF433", "1.0"); gw.sendSensorPresentation(RF433_CHILD_ID, S_IR); delay(200); RemoteReceiver::init(RECEIVER_INTERRUPT, 3, newRf); } void loop() { if (gw.messageAvailable()) { message_s message = gw.getMessage(); sendRfMessage(message); } if(receivedNew) { getRfMessage(incomingRfCode, incomingRfPeriod); receivedNew = false; } } void sendRfMessage(message_s message) { if (message.header.messageType==M_SET_VARIABLE && message.header.type==V_IR_SEND) { char sendingRfCode[7]; char sendingRfPeriod[4]; strncpy(sendingRfCode, message.data, 6); strncpy(sendingRfPeriod, message.data+6, 3); sendingRfCode[6] = 0; sendingRfPeriod[3] = 0; Serial.println(atol(sendingRfCode)); Serial.println(atol(sendingRfPeriod)); RemoteReceiver::disable(); interrupts(); delay(200); RemoteTransmitter::sendCode(TRANSMITTER_PIN, atol(sendingRfCode), atol(sendingRfPeriod), 3); RemoteReceiver::enable(); } } void newRf(unsigned long _incomingRfCode, unsigned int _incomingRfPeriod){ incomingRfCode = _incomingRfCode; incomingRfPeriod = _incomingRfPeriod; receivedNew=true; } void getRfMessage(unsigned long incomingRfCode, unsigned int incomingRfPeriod){ char gettingRfMessage[10]; sprintf(gettingRfMessage, "%lu%u", incomingRfCode, incomingRfPeriod); Serial.println(incomingRfCode); Serial.println(incomingRfPeriod); Serial.println(gettingRfMessage); gw.sendVariable(RF433_CHILD_ID, V_IR_RECEIVE, gettingRfMessage); } -
"can't find a working instance od Relay.h."
Having the same issue here, perhaps it's for version 1.3 of mysensors?
-
Does anyone have a working version of this for 2.x?