在nodejs中执行RFSniffer和codeSend

execute RFSniffer and codeSend in nodejs

本文关键字:codeSend RFSniffer 执行 nodejs      更新时间:2023-10-16

这两个工具都可以在这里找到:https://github.com/ninjablocks/433Utils/tree/master/RPi_utils

我真的想要一个简单的接口来管理我的433mhz设备。但是我找不到一个好的。

所以我已经工作了一整天,现在试图使nodejs包装RCSwitch类。用两种简单的方法——发送(代码)——接收回调[准则]]

当我尝试创建RCSwitch类的新实例时,我得到这个错误。

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

它可以完美地编译node-gyp,但是当我执行node时,它失败了。

现在我使用exec执行sendCommand与代码。(UGLY I Know)

我试着让RFSniffer像这样工作:

  1. 。/RFSniffer> RFSniffer .log
  2. 。然后tail -f

但是RFSniffer不会给我任何数据。

所以我的问题是谁可以帮助我得到RFsniffer与尾-f工作或者更好的是,有人能帮我修复nodejs的c++插件:)

下面是包装器代码:
#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代码:

var addon = require('./build/Release/kaku');
console.log(addon.Send(1234));
addon.Recieve(1234, function (val) {
    console.log(val);
});

我有同样的问题比你和./RFSniffer > rfsniffer.log不工作的原因是RFSniffer代码中的printf()函数没有刷新。

试试这个源代码:

/*
  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 %in", mySwitch.getReceivedValue() );
        }
        fflush(stdout); // Add this line to flush the previous printf()
        mySwitch.resetAvailable();
      }
  }
  exit(0);
}

如果你以sudo权限运行RFSniffer工具,你可以执行:

sudo ./RFSniffer | sudo tee rfsniffer.log

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