Using 433 MHZ Reciver and Sender

Moderator: leecollings

Post Reply
Smartie
Posts: 21
Joined: Monday 14 December 2015 15:12
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Using 433 MHZ Reciver and Sender

Post by Smartie »

Hello now i have Played with the 433 MHZ Reciver on GPIO from Amazon.
http://www.amazon.de/Aukru-Superregener ... +raspberry

The Switches from Bennstuhl has a Remote Control but nobody can use it with Domoticz.

Now i have Playes with Wiringpi and 433Utils.

A Script to recive Actions from Remote Control is the RFSniffer. But he has no Actions.

So Modify the RFSniffer.cpp before using Make.

Code: Select all

/*
  RFSniffer
  Usage: ./RFSniffer [<pulseLength>]
  [] = optional
  Hacked from http://code.google.com/p/rc-switch/
  by @justy to provide a handy RF code sniffer
*/

#include "RCSwitch.h"
#include <stdlib.h>
#include <stdio.h>
#define CURL_STATICLIB
#include <curl/curl.h>

RCSwitch mySwitch;



int main(int argc, char *argv[]) {

     // This pin is not the first pin on the RPi GPIO header!
     // Consult https://projects.drogon.net/raspberry-pi/wiringpi/pins/
     // for more information.
     int PIN = 2;

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

     int pulseLength = 0;
     if (argv[1] != NULL) pulseLength = atoi(argv[1]);
     mySwitch = RCSwitch();
         if (pulseLength != 0) mySwitch.setPulseLength(pulseLength);
     mySwitch.enableReceive(PIN);  // Receiver on interrupt 0 => that is pin #2


     while(1) {

      if (mySwitch.available()) {

        int value = mySwitch.getReceivedValue();

        if (value == 0) {
          printf("Unknown encoding\n");
        } else {

         if (mySwitch.getReceivedValue() == 1394001) {
 printf("Switch A ON");
FILE * pFile;
    pFile = fopen ("test.txt","w");
    if (pFile!=NULL)
    {
            fputs ("AON",pFile);
            fclose (pFile);
}

}

         if (mySwitch.getReceivedValue() == 1394004) {
 printf("Switch A OFF");
FILE * pFile;
    pFile = fopen ("test.txt","w");

            fputs ("AOFF",pFile);
            fclose (pFile);
}
}
         if (mySwitch.getReceivedValue() == 1397073) {
 printf("Switch B ON");
FILE * pFile;
    pFile = fopen ("test.txt","w");
    if (pFile!=NULL)
    {
            fputs ("BON",pFile);
            fclose (pFile);
}

}
         if (mySwitch.getReceivedValue() == 1397076) {
 printf("Switch B OFF");
FILE * pFile;
    pFile = fopen ("test.txt","w");
    if (pFile!=NULL)
    {
            fputs ("BOFF",pFile);
            fclose (pFile);
}
}
         if (mySwitch.getReceivedValue() == 1397841) {
 printf("Switch C ON");
FILE * pFile;
    pFile = fopen ("test.txt","w");
    if (pFile!=NULL)
    {
            fputs ("CON",pFile);
            fclose (pFile);
}
}
         if (mySwitch.getReceivedValue() == 1397844) {
 printf("Switch C OFF");
FILE * pFile;
    pFile = fopen ("test.txt","w");
    if (pFile!=NULL)
    {
            fputs ("COFF",pFile);
            fclose (pFile);
}
}
         if (mySwitch.getReceivedValue() == 1398033) {
 printf("Switch D ON");
FILE * pFile;
    pFile = fopen ("test.txt","w");
            fclose (pFile);
}
}
         if (mySwitch.getReceivedValue() == 1398036) {
 printf("Switch D OFF");
FILE * pFile;
    pFile = fopen ("test.txt","w");
    if (pFile!=NULL)
    {
            fputs ("DOFF",pFile);
            fclose (pFile);
}
}

printf("\n" );
        }

        mySwitch.resetAvailable();

      }


  }

  exit(0);


}



now Save it and using make.

Then make a read.sh
sudo nano read.sh
then add

Code: Select all

#!/bin/sh

# Domoticz server
SERVER="127.0.0.1:8080"

sleep  1
#sudo sh ./home/pi/wiringPi/433Utils/RPi_utils/RFSniffer

while [ true ]; do
werta=$(awk ' /AON/ {print substr ($0,0)}' /home/pi/wiringPi/433Utils/RPi_utils/test.txt)
wertb=$(awk ' /BON/ {print substr ($0,0)}' /home/pi/wiringPi/433Utils/RPi_utils/test.txt)
wertc=$(awk ' /CON/ {print substr ($0,0)}' /home/pi/wiringPi/433Utils/RPi_utils/test.txt)
wertd=$(awk ' /DON/ {print substr ($0,0)}' /home/pi/wiringPi/433Utils/RPi_utils/test.txt)
wertao=$(awk ' /AOFF/ {print substr ($0,0)}' /home/pi/wiringPi/433Utils/RPi_utils/test.txt)
wertbo=$(awk ' /BOFF/ {print substr ($0,0)}' /home/pi/wiringPi/433Utils/RPi_utils/test.txt)
wertco=$(awk ' /COFF/ {print substr ($0,0)}' /home/pi/wiringPi/433Utils/RPi_utils/test.txt)
wertdo=$(awk ' /DOFF/ {print substr ($0,0)}' /home/pi/wiringPi/433Utils/RPi_utils/test.txt)

if [ "$werta" = "AON" ]
then
curl -s -i -H "Accept: application/json" "http://$SERVER/json.htm?type=command&param=switchscene&idx=9&switchcmd=On"
echo "AON"
sleep 1
reset=" " > /home/pi/wiringPi/433Utils/RPi_utils/test.txt
fi


if [ "$wertb" = "BON" ]
then
curl -s -i -H "Accept: application/json" "http://$SERVER/json.htm?type=command&param=switchscene&idx=3&switchcmd=On"
echo "BON"
sleep 1
reset=" " > /home/pi/wiringPi/433Utils/RPi_utils/test.txt
fi


if [ "$wertc" = "CON" ]
then
curl -s -i -H "Accept: application/json" "http://$SERVER/json.htm?type=command&param=switchscene&idx=7&switchcmd=On"
echo "CON"
sleep 1
reset=" " > /home/pi/wiringPi/433Utils/RPi_utils/test.txt
fi


if [ "$wertd" = "DON" ]
then
curl -s -i -H "Accept: application/json" "http://$SERVER/json.htm?type=command&param=switchscene&idx=11&switchcmd=On"
echo "DON"
sleep 1
reset=" " > /home/pi/wiringPi/433Utils/RPi_utils/test.txt
fi

if [ "$wertao" = "AOFF" ]
then
curl -s -i -H "Accept: application/json" "http://$SERVER/json.htm?type=command&param=switchscene&idx=10&switchcmd=On"
echo "AOFF"
sleep 1
reset=" " > /home/pi/wiringPi/433Utils/RPi_utils/test.txt
fi


if [ "$wertbo" = "BOFF" ]
then
curl -s -i -H "Accept: application/json" "http://$SERVER/json.htm?type=command&param=switchscene&idx=2&switchcmd=On"
echo "BOFF"
sleep 1
reset=" " > /home/pi/wiringPi/433Utils/RPi_utils/test.txt
fi

if [ "$wertco" = "COFF" ]
then
curl -s -i -H "Accept: application/json" "http://$SERVER/json.htm?type=command&param=switchscene&idx=6&switchcmd=On"
echo "COFF"
sleep 1
reset=" " > /home/pi/wiringPi/433Utils/RPi_utils/test.txt
fi


if [ "$wertdo" = "DOFF" ]
then
curl -s -i -H "Accept: application/json" "http://$SERVER/json.htm?type=command&param=switchscene&idx=8&switchcmd=On"
echo "DOFF"
sleep 1
reset=" " > /home/pi/wiringPi/433Utils/RPi_utils/test.txt
fi

done



exit 0

save with CTRL+O and EXIT with CTRL+X

then set the RW Rights
sudo chmod 0777 read.sh
sudo chown pi read.sh

sudo chmod 0777 RFSniffer
sudo chown pi RFSniffer

Start it to the next Restart with

cd /home/pi/domoticz/scripts
nice -n 19 nohup ./read.sh &

cd /home/pi/wiringPi/433Utils/RPi_utils/
nice -n 19 nohup ./RFSniffer &


and Revice from the Remote Contol.

HINT: Change the IDX for the Szenes its my IDX
regenschein71
Posts: 11
Joined: Wednesday 13 January 2016 13:45
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Using 433 MHZ Reciver and Sender

Post by regenschein71 »

Hi Smartie,

thanks for that post. I have also used on of these cheap 433MHz transmitter/receivers with a Brennenstuhl remote switch set, but was thinking about piping the output from RFSniffer into a script that forwards the information to Domoticz. So I'd just do

sudo ./RFSniffer | myScript.pl

This way I don't need to modify the RFSniffer code when the codes change. I'll post it here once I got it working.

But for my actual question: how near do you have to be to the receiver to successfully transmit from the remote control? For me, it's only working within 2 meters distance, even though I have attached an antenna to the receiver. This severely limits the usefulness of the receiver...

Best regards,
RS
Smartie
Posts: 21
Joined: Monday 14 December 2015 15:12
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Using 433 MHZ Reciver and Sender

Post by Smartie »

Hi,

I used a Antenna with ca 15cm so it worky for me at a Radius from 30m
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests