0

Both tools are available over here: https://github.com/ninjablocks/433Utils/tree/master/RPi_utils

I really want a simple interface to manage my 433mhz devices. but i can't find a good one.

So I have worked all day now trying to make a wrapper for nodejs to the RCSwitch class. with 2 simple methods - send[code] - recieve[callback[code]]

I get this error when i try to make a new instance of the RCSwitch class.

node: symbol lookup error:
/root/nodemodule/example/build/Release/kaku.node: 
undefined symbol: _ZN8RCSwitchC1Ev

It compiles perfectly with node-gyp but when I execute node it fails.

Now I use exec to execute sendCommand with the code. (UGLY I Know)

And I tried to make the RFSniffer work like this:

  1. ./RFSniffer > rfsniffer.log
  2. .Then tail -f the rfsniffer.log

But RFSniffer wont give me any data.

So my question is can anybody help me to get RFsniffer working with tail -f Or even beter can someone help me fix the c++ addon for nodejs:)

Here is the wrapper code:

#include "RCSwitch.h"
#include <node.h>
#include <v8.h>

using namespace v8;

Handle<Value> CodeSend(const Arguments& args) {
  HandleScope scope;

  int PIN = 0;
    RCSwitch mySwitch = RCSwitch();
    mySwitch.enableTransmit(PIN);

    mySwitch.send(args[0]->IntegerValue(), 24);

  return scope.Close(True());
}

Handle<Value> CodeRecieve(const Arguments& args) {
    HandleScope scope;
    // Entry check
    if (args.Length() != 2) {
        ThrowException(Exception::TypeError(String::New("Wrong number of arguments")));
        return scope.Close(Undefined());
    }

    Local<String> name= args[0]->ToString();
    Local<String> msg = name;
    Local<Function> cb = Local<Function>::Cast(args[1]);

    const unsigned argc = 1;
    Local<Value> argv[argc] = { Local<Value>::New(msg) };
    cb->Call(Context::GetCurrent()->Global(), argc, argv);

    return scope.Close(Undefined());
}

extern "C" {
  static void init(Handle<Object> target) {
    if( wiringPiSetup() == -1 ) {
        ThrowException( Exception::TypeError( String::New( "rcswitch: GPIO initialization failed" ) ) );
        return;
    }

    NODE_SET_METHOD(target, "Send", CodeSend);
    NODE_SET_METHOD(target, "Recieve", CodeRecieve);


  }
  NODE_MODULE(kaku, init);
}

nodejs code:

var addon = require('./build/Release/kaku');

console.log(addon.Send(1234));

addon.Recieve(1234, function (val) {
    console.log(val);
});
  • It works NOS i had tot include The c++ file in The gyp file. I will share the node addon on github;) – Sjaak Hijmering May 24 '15 at 08:19
  • 1
    Sorry.. It was a long time ago. Now I don't have the code anymore also I was getting another problem back than I couldn't snif and send at the same time... – Sjaak Hijmering Jun 21 '17 at 09:29

1 Answers1

0

I had the same problem than you and the reason why ./RFSniffer > rfsniffer.log doesn't work is that printf() function in RFSniffer code is not flushed.

Try with this source code :

/*
  RF_Sniffer

  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>

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)
       return 0;

     mySwitch = RCSwitch();
     mySwitch.enableReceive(PIN);  // Receiver on inerrupt 0 => that is pin #2

     while(1) {

      if (mySwitch.available()) {

        int value = mySwitch.getReceivedValue();

        if (value == 0) {
          printf("Unknown encoding");
        } else {
          printf("Received %i\n", mySwitch.getReceivedValue() );
        }

        fflush(stdout); // Add this line to flush the previous printf()
        mySwitch.resetAvailable();

      }

  }

  exit(0);

}

And if you run the RFSniffer tool with sudo permission, you can execute with :

sudo ./RFSniffer | sudo tee rfsniffer.log

OR

sudo sh -c './RFSniffer >> rfsniffer.log'

eroak
  • 1,017
  • 10
  • 17