RF 433 MHz sensor to control RF sockets.
-
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?