Friday,29-September-2017

MIT App Inventor 2: sniffing 433Mghz commands

EN

Hi folks,

That is one study/project that dare to share in my small web space. It`s based on that remarkable RCSwitch arduino library and MIT App inventor website. So, what`s the story? I have few plip remote units left, working on that 433Mhz frequency. And said: hey, why not to control something with them using arduino..

For that purpose I need to know what code each one send and to code it into the atmel chip. Simple test: press button - LED on, second button LED off. Bought myself few RXB6 433Mhz receivers, and simple senders from ebay. After that use the ready example sketch provided with that library and arduino`s serial terminal to see what come. Then only add my code into and presto - ON / OFF. That was attempt one. And here is attempt 2:

Arduino read incoming code, and send it to my phone app. There I see posted code, and if wish can repeat it back.

Test stage was build with two arduinos(one for main device and one only to bring it LED on and off if I manage to repeat right code)

stage433mghz.jpg

Arduino code used is that:


#include <RCSwitch.h>

#define DATA_PIN 3   // incoming data

#define SEND_PIN 10  // output codes

RCSwitch mySwitch = RCSwitch();

long int dataBuffer; //temp storage 

void setup() {

  Serial.begin(38400); //as is BT set

  mySwitch.enableTransmit(SEND_PIN); // Transmitter is connected to Arduino Pin #10  

  mySwitch.setRepeatTransmit(5);   // Optional set number of transmission repetitions.

  // mySwitch.setPulseLength(320); //Optional set pulse length.If you need to change

  

  pinMode(DATA_PIN, INPUT);

  mySwitch.enableReceive(1);  // Receiver on interrupt 1 => that is pin D3

   

  pinMode(13,OUTPUT);  //that is for debug purposes

  digitalWrite(13,LOW);

  

}

void loop() {

      while (Serial.available() > 0) {

                 // 1234,24,1#  < example command send, in that case code:1234, 24bit , 1 protocol , #-end of command

                 long int command = Serial.parseInt();

                         int bits = Serial.parseInt();

                        int proto = Serial.parseInt();

                 if (Serial.read() == '#') {

                        // Optional set protocol (default is 1, will work for most outlets)

                        mySwitch.setProtocol(proto);

                        mySwitch.send(command, bits);

                 }

      }

      if (mySwitch.available()) {

          long int tmpValue  = mySwitch.getReceivedValue();

               int bitLenght = mySwitch.getReceivedBitlength();

          long int protocol  = mySwitch.getReceivedProtocol();

          

		       // the LED will flash if command is received.

			   // but if command is same but repeated, will be sent to BT dongle once

               digitalWrite(13,HIGH);  

               delay(40);

               digitalWrite(13,LOW);

               delay(40);

      

          

          if (tmpValue == 0) {

                      Serial.print(0);

          } else {

                  

                  if (dataBuffer != tmpValue) {

                             dataBuffer = tmpValue; 

                      Serial.print( tmpValue, DEC);

                      Serial.print( "*" );

                      Serial.print( bitLenght );

                      Serial.print( "*" );  

                      Serial.print( protocol );

                 }

         }

                mySwitch.resetAvailable();

      }

}

MIT app inventor AIA file can be downloaded here or ready app here. Please, be advised that I`m not responsible for any damage or data lost to your equipment due testing my project on your device!

AIA blocks as follow:

mit_sniff.jpg

mit_block_1.jpg

mit_block_2.jpg

mit_block_3.jpg

And how application work:

you press Connect and select your BT donbgle

phone1.jpg

Once selected and connected you get green “light”. After first code arrive, will appear drop list

phone2.jpg

Then just select desired code to repeat and it will be stored in sending area. Then just push.. SEND ?! 019.gif

phone3.jpg