help to build a RF315 transmitter with NRF and mysensors



  • hi friend,
    i want send a command with domoticz and mysensors and receive in one node so node send a command with RF315 trasmitter(sorry for english)
    in pic :
    0_1493586027373_NRF24l01_Arduino_433.png

    I thought this code will be ok but dont work. every body can i help me for this?

    #define MY_DEBUG
    #define MY_RADIO_NRF24
    #define MY_RF24_CHANNEL 0
    #define MY_REPEATER_FEATURE
    #define MY_NODE_ID 6
    #define MY_RF24_PA_LEVEL RF24_PA_MAX
    
    #include <SPI.h>
    #include <MySensors.h>
    #include <VirtualWire.h>
    
    int tx = 3;
    
    bool stateA;
    
    #define CHILD_IDA 1
    
    MyMessage msgA(CHILD_IDA, V_STATUS );
    
    void setup() {
      vw_set_tx_pin(tx);
      vw_set_ptt_inverted(true);
       vw_setup(2000);
    }
    
    
    void presentation()
    {
      sendSketchInfo("RF315", "1.0");
      present(CHILD_IDA, S_LIGHT);
    }
    
    void loop() {
    }
    void receive(const MyMessage &message) {
      if (message.type == V_STATUS) {
            stateA = message.getBool();
            if ( stateA == true) {
              const char *msg = "1A";
              vw_send((uint8_t *)msg, strlen(msg));
              vw_wait_tx();
              delay(500);
            }
            if (stateA == false) {
              const char *msg = "2A";
              vw_send((uint8_t *)msg, strlen(msg));
              vw_wait_tx();
              delay(500);
            }
        }
      }
    


  • first i have this error :

    0 MCO:BGN:INIT REPEATER,CP=RNNRA--,VER=2.1.0
    3 TSM:INIT
    4 TSF:WUR:MS=0
    11 TSM:INIT:TSP OK
    13 TSM:INIT:STATID=6
    15 TSF:SID:OK,ID=6
    17 TSM:FPAR
    53 TSF:MSG:SEND,6-6-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    921 TSF:MSG:READ,0-0-6,s=255,c=3,t=8,pt=1,l=1,sg=0:0
    926 TSF:MSG:FPAR OK,ID=0,D=1
    939 TSF:MSG:READ,2-2-6,s=255,c=3,t=8,pt=1,l=1,sg=0:1
    2060 TSM:FPAR:OK
    2061 TSM:ID
    2062 TSM:ID:OK
    2064 TSM:UPL
    2067 TSF:MSG:SEND,6-6-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1
    2073 TSF:MSG:READ,0-0-6,s=255,c=3,t=25,pt=1,l=1,sg=0:1
    2078 TSF:MSG:PONG RECV,HP=1
    2081 TSM:UPL:OK
    2082 TSM:READY:ID=6,PAR=0,DIS=1
    2089 TSF:MSG:SEND,6-6-0-0,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100
    2096 TSF:MSG:READ,0-0-6,s=255,c=3,t=15,pt=6,l=2,sg=0:0100
    2108 TSF:MSG:SEND,6-6-0-0,s=255,c=0,t=18,pt=0,l=5,sg=0,ft=0,st=OK:2.1.0
    2116 TSF:MSG:SEND,6-6-0-0,s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=OK:0
    2137 TSF:MSG:READ,0-0-6,s=255,c=3,t=6,pt=0,l=1,sg=0:M
    2155 TSF:MSG:SEND,6-6-0-0,s=255,c=3,t=11,pt=0,l=5,sg=0,ft=0,st=OK:RF315
    2170 TSF:MSG:SEND,6-6-0-0,s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=OK:1.0
    2183 TSF:MSG:SEND,6-6-0-0,s=1,c=0,t=3,pt=0,l=0,sg=0,ft=0,st=OK:
    2189 MCO:REG:REQ
    2193 TSF:MSG:SEND,6-6-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=OK:2
    2202 TSF:MSG:READ,0-0-6,s=255,c=3,t=27,pt=1,l=1,sg=0:1
    2207 MCO:PIM:NODE REG=1
    2209 MCO:BGN:STP
    2211 MCO:BGN:INIT OK,TSP=1
    2214 TSF:MSG:READ,0-0-6,s=255,c=3,t=27,pt=1,l=1,sg=0:1
    2220 !TSF:MSG:LEN,0!=8
    2222 TSF:MSG:READ,0-0-6,s=255,c=3,t=27,pt=1,l=1,sg=0:1
    2227 !TSF:MSG:LEN,0!=8
    2230 TSF:MSG:READ,0-0-6,s=255,c=3,t=27,pt=1,l=1,sg=0:1
    2235 !TSF:MSG:LEN,0!=8
    2237 TSF:MSG:READ,0-0-6,s=255,c=3,t=27,pt=1,l=1,sg=0:1
    2242 !TSF:MSG:LEN,0!=8
    2253 TSF:MSG:READ,0-0-6,s=255,c=3,t=27,pt=1,l=1,sg=0:1
    2258 !TSF:MSG:LEN,0!=8
    2260 TSF:MSG:READ,0-0-6,s=255,c=3,t=27,pt=1,l=1,sg=0:1
    2266 !TSF:MSG:LEN,0!=8
    2273 TSF:MSG:READ,0-0-6,s=255,c=3,t=27,pt=1,l=1,sg=0:1
    2278 !TSF:MSG:LEN,0!=8
    2281 TSF:MSG:READ,0-0-6,s=255,c=3,t=27,pt=1,l=1,sg=0:1
    2286 !TSF:MSG:LEN,0!=8
    2293 TSF:MSG:READ,0-0-6,s=255,c=3,t=27,pt=1,l=1,sg=0:1
    2298 !TSF:MSG:LEN,0!=8
    2300 TSF:MSG:READ,0-0-6,s=255,c=3,t=27,pt=1,l=1,sg=0:1
    2306 !TSF:MSG:LEN,0!=8
    2314 TSF:MSG:READ,0-0-6,s=255,c=3,t=27,pt=1,l=1,sg=0:1
    2319 !TSF:MSG:LEN,0!=8
    2321 TSF:MSG:READ,0-0-6,s=255,c=3,t=27,pt=1,l=1,sg=0:1
    2326 !TSF:MSG:LEN,0!=8
    2333 TSF:MSG:READ,0-0-6,s=255,c=3,t=27,pt=1,l=1,sg=0:1
    2338 !TSF:MSG:LEN,0!=8
    2340 TSF:MSG:READ,0-0-6,s=255,c=3,t=27,pt=1,l=1,sg=0:1
    2345 !TSF:MSG:LEN,0!=8
    2354 TSF:MSG:READ,0-0-6,s=255,c=3,t=27,pt=1,l=1,sg=0:1
    2359 !TSF:MSG:LEN,0!=8
    2361 TSF:MSG:READ,0-0-6,s=255,c=3,t=27,pt=1,l=1,sg=0:1
    2366 !TSF:MSG:LEN,0!=8
    2373 TSF:MSG:READ,0-0-6,s=255,c=3,t=27,pt=1,l=1,sg=0:1
    2378 !TSF:MSG:LEN,0!=8
    2381 TSF:MSG:READ,0-0-6,s=255,c=3,t=27,pt=1,l=1,sg=0:1
    2386 !TSF:MSG:LEN,0!=8
    2394 TSF:MSG:READ,0-0-6,s=255,c=3,t=27,pt=1,l=1,sg=0:1
    2399 !TSF:MSG:LEN,0!=8
    2401 TSF:MSG:READ,0-0-6,s=255,c=3,t=27,pt=1,l=1,sg=0:1
    2406 !TSF:MSG:LEN,0!=8
    2413 TSF:MSG:READ,0-0-6,s=255,c=3,t=27,pt=1,l=1,sg=0:1
    2418 !TSF:MSG:LEN,0!=8
    2421 TSF:MSG:READ,0-0-6,s=255,c=3,t=27,pt=1,l=1,sg=0:1
    2426 !TSF:MSG:LEN,0!=8
    2434 TSF:MSG:READ,0-0-6,s=255,c=3,t=27,pt=1,l=1,sg=0:1
    2439 !TSF:MSG:LEN,0!=8
    2441 TSF:MSG:READ,0-0-6,s=255,c=3,t=27,pt=1,l=1,sg=0:1
    2446 !TSF:MSG:LEN,0!=8
    2453 TSF:MSG:READ,0-0-6,s=255,c=3,t=27,pt=1,l=1,sg=0:1
    2458 !TSF:MSG:LEN,0!=8
    2461 TSF:MSG:READ,0-0-6,s=255,c=3,t=27,pt=1,l=1,sg=0:1
    2466 !TSF:MSG:LEN,0!=8
    2473 TSF:MSG:READ,0-0-6,s=255,c=3,t=27,pt=1,l=1,sg=0:1
    2479 !TSF:MSG:LEN,0!=8
    2481 TSF:MSG:READ,0-0-6,s=255,c=3,t=27,pt=1,l=1,sg=0:1
    2486 !TSF:MSG:LEN,0!=8
    2493 TSF:MSG:READ,0-0-6,s=255,c=3,t=27,pt=1,l=1,sg=0:1
    2498 !TSF:MSG:LEN,0!=8
    2501 TSF:MSG:READ,0-0-6,s=255,c=3,t=27,pt=1,l=1,sg=0:1
    2506 !TSF:MSG:LEN,0!=8
    2513 TSF:MSG:READ,0-0-6,s=255,c=3,t=27,pt=1,l=1,sg=0:1
    2519 !TSF:MSG:LEN,0!=8
    2521 TSF:MSG:READ,0-0-6,s=255,c=3,t=27,pt=1,l=1,sg=0:1
    2526 !TSF:MSG:LEN,0!=8
    2534 TSF:MSG:READ,0-0-6,s=255,c=3,t=27,pt=1,l=1,sg=0:1
    2539 !TSF:MSG:LEN,0!=8
    2541 TSF:MSG:READ,0-0-6,s=255,c=3,t=27,pt=1,l=1,sg=0:1
    2546 !TSF:MSG:LEN,0!=8
    2553 TSF:MSG:READ,0-0-6,s=255,c=3,t=27,pt=1,l=1,sg=0:1
    2558 !TSF:MSG:LEN,0!=8
    2561 TSF:MSG:READ,0-0-6,s=255,c=3,t=27,pt=1,l=1,sg=0:1
    2566 !TSF:MSG:LEN,0!=8
    2574 TSF:MSG:READ,0-0-6,s=255,c=3,t=27,pt=1,l=1,sg=0:1
    2579 !TSF:MSG:LEN,0!=8
    2581 TSF:MSG:READ,0-0-6,s=255,c=3,t=27,pt=1,l=1,sg=0:1
    2586 !TSF:MSG:LEN,0!=8
    2593 TSF:MSG:READ,0-0-6,s=255,c=3,t=27,pt=1,l=1,sg=0:1
    2598 !TSF:MSG:LEN,0!=8
    2600 TSF:MSG:READ,0-0-6,s=255,c=3,t=27,pt=1,l=1,sg=0:1
    2606 !TSF:MSG:LEN,0!=8
    2614 TSF:MSG:READ,0-0-6,s=255,c=3,t=27,pt=1,l=1,sg=0:1
    

    for this line :

    vw_setup(2000);
    

    but i remove this line and solve this error. but node dont work...



  • no body can not help me ? 😞
    i need a device for send code in RF315 Mhz.


  • Hero Member

    I don't know how to use a RF315 module but usually it is a bad idea to use "delay()", please try to use "wait()" instead.



  • @korttoma hi thank you for answer . i think problem is related to ack....
    i change sketch... and i see some code send and some code dont send. some time ok and sometime is fail for always...



  • this is sketch of nrf node :

    #define MY_DEBUG
    #define MY_RADIO_NRF24
    #define MY_RF24_CHANNEL 0
    #define MY_REPEATER_FEATURE
    #define MY_NODE_ID 6
    #define MY_RF24_PA_LEVEL RF24_PA_MAX
    #define MY_TRANSPORT_WAIT_READY_MS 10000
    
    #include <SPI.h>
    #include <MySensors.h>
    #include <VirtualWire.h>
    
    int rx = 3;
    int tx = 4;
    
    bool stateA = false;
    bool stateB = false;
    
    #define CHILD_IDA 1
    #define CHILD_IDB 2
    
    MyMessage msgA(CHILD_IDA, V_STATUS );
    MyMessage msgB(CHILD_IDB, V_STATUS );
    
    void setup()
    {
      vw_set_rx_pin(rx);
      vw_set_tx_pin(tx);
      vw_set_ptt_inverted(true);
      vw_setup(2000);
      vw_rx_start();
      send(msgA.set(false));
      send(msgB.set(false));
    }
    
    void presentation()
    {
      sendSketchInfo("RF315", "1.0");
      present(CHILD_IDA, S_LIGHT);
      present(CHILD_IDB, S_LIGHT);
    }
    
    void loop()
    {
      uint8_t buf[VW_MAX_MESSAGE_LEN];
      uint8_t buflen = VW_MAX_MESSAGE_LEN;
    
      if (vw_get_message(buf, &buflen))
      {
        if ((buf[0] == '1') && (buf[1] == '0') && (buf[2] == '1')) {
          send(msgA.set(true));
        }
        if ((buf[0] == '1') && (buf[1] == '0') && (buf[2] == '3') ) {
          send(msgA.set(false));
        }
        if ((buf[0] == '1') && (buf[1] == '0') && (buf[2] == '5') ) {
          send(msgB.set(true));
        }
        if ((buf[0] == '1') && (buf[1] == '0') && (buf[2] == '7') ) {
          send(msgB.set(false));
        }
        else {
          for (int i = 0; i < 10; i++)
            buf [i] = ' ' ;
        }
      }
    }
    
    void receive(const MyMessage &message) {
      if (message.type == V_STATUS) {
        switch (message.sensor) {
          case 1:
            stateA = message.getBool();
            if ( stateA == true) {
              send(msgA.set(false));
              const char *msg = "100";
              vw_send((uint8_t *)msg, strlen(msg));
              vw_wait_tx();
            }
            if (stateA == false) {
              send(msgA.set(true));
              const char *msg = "102";
              vw_send((uint8_t *)msg, strlen(msg));
              vw_wait_tx();
            }
            break;
          case 2:
            stateB = message.getBool();
            if ( stateB == true) {
              send(msgB.set(false));
              const char *msg = "104";
              vw_send((uint8_t *)msg, strlen(msg));
              vw_wait_tx();
            }
            if (stateB == false) {
              send(msgB.set(true));
              const char *msg = "106";
              vw_send((uint8_t *)msg, strlen(msg));
              vw_wait_tx();
            }
            break;
        }
      }
    
    }
    

    and this is for receiver:

    #include <VirtualWire.h>
    
    int rx = 3;
    int tx = 4;
    
    int relay1 = 5;
    int relay2 = 6;
    int key1 = 7;
    int key2 = 8;
    
    void setup()
    {
      Serial.begin(115200);
      Serial.println("setup");
    
      vw_set_rx_pin(rx);
      vw_set_tx_pin(tx);
      vw_set_ptt_inverted(true);
      vw_setup(2000);
      vw_rx_start();
    
      pinMode(key1, INPUT_PULLUP);
      pinMode(key2, INPUT_PULLUP);
    
      pinMode(relay1, OUTPUT);
      pinMode(relay2, OUTPUT);
    
    
      digitalWrite(relay1, HIGH);
      digitalWrite(relay2, HIGH);
    }
    
    void loop()
    {
        uint8_t buf[VW_MAX_MESSAGE_LEN];
        uint8_t buflen = VW_MAX_MESSAGE_LEN;
    
        if (vw_get_message(buf, &buflen))
        {
          if ((buf[0] == '1') && (buf[1] == '0') && (buf[2] == '0') )
          {
            digitalWrite(relay1, LOW);
            delay(100);
            const char *msg = "101";
            vw_send((uint8_t *)msg, strlen(msg));
            vw_wait_tx();
            delay(100);
          }
    
          if ((buf[0] == '1') && (buf[1] == '0') && (buf[2] == '2'))
          {
            digitalWrite(relay1, HIGH);
            delay(100);
            const char *msg = "103";
            vw_send((uint8_t *)msg, strlen(msg));
            vw_wait_tx();
            delay(100);
          }
          if ((buf[0] == '1') && (buf[1] == '0') && (buf[2] == '4'))
          {
            digitalWrite(relay2, LOW);
            delay(100);
            const char *msg = "105";
            vw_send((uint8_t *)msg, strlen(msg));
            vw_wait_tx();
            delay(100);
          }
                if ((buf[0] == '1') && (buf[1] == '0') && (buf[2] == '6'))
          {
            digitalWrite(relay2, HIGH);
            delay(100);
            const char *msg = "107";
            vw_send((uint8_t *)msg, strlen(msg));
            vw_wait_tx();
            delay(100);
          }
          else {
            for (int i = 0; i < 10; i++)
              buf [i] = ' ' ;
          }
        }
      }
    

    this code was worked. but there is some problem that i can not found ! some code sent and some dont send. also some time for many time can not work just with reset or power off/on. @hek please tag some members and programmer here that they can repair this code. this code is very efficient...
    then you can use this sketch in site for RF 315 and 433 mhz device...

    this code can solve some problem about short range of NRF. we can define many child id that every child can control many device with RF315 or RF433. for example for more distance we can use this node. with 315mhz and long distance...


Log in to reply
 

Suggested Topics

  • 1
  • 6
  • 5
  • 1
  • 1
  • 3

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts