2

I'm trying to switch on a 433 MHz socket with my Raspberry Pi 3 B. I'm using a 433 MHz sender and 433Utils. Using the 433 MHz receiver and RFSniffer I validated the switch on code beeing -1900218880 (0x8ebcf600). I send my code using this C++ code:

#include "../../lib/433Utils/rc-switch/RCSwitch.h"
#include <stdlib.h>
#include <stdio.h>

// taken from https://tutorials-raspberrypi.de/raspberry-pi-funksteckdosen-433-mhz-steuern/

int main(int argc, char* argv[]) {
    int PIN = 0;  // see wiringpi-belegung
    int codeSocketDon  = 0x8ebcf600;
    int codeSocketDoff = 0x81bcf600;

    if (wiringPiSetup() == -1) {
        printf("wiringPiSetup failed.");
        return 1;
    }

    RCSwitch sw = RCSwitch();
    sw.enableTransmit(PIN);

    if (atoi(argv[1]) == 1)
        sw.send(codeSocketDon, 32);
    else
        sw.send(codeSocketDoff, 32);
    return 0;
}

The code compiles fine and sends the requested code (the RFSniffer receives it) but the socket will not switch on. The socket it only about 1 m away from the sender.

Any suggestions why my setup might fail? See update below that changed my question.

For the sake of completeness here are my used components:


UPDATE

I found a solution but it is quite odd and I do not really understand why this works and other solutions don't:

My code compiles to switch-socket (g++ -DRPI ../../lib/433Utils/rc-switch/RCSwitch.cpp switch-socket.cpp -o switch-socket -lwiringPi)

Running it twice such as switch-socket 1 && switch-socket 1 works! So I thought the transmitting time might be to short. However, setting longer values (RCSwitch.setRepeatTransmit(30)) doesn't work. I tried to send my code twice (didn't work). I even tried to put my whole code within a for loop to run it twice (didn't work).

Why the heck does it work to run the program twice and how to change my C++ code to get it work without running the program twice?

Spock
  • 260
  • 1
  • 13

0 Answers0