B4R Question about 315Mhz mode

bagazhou

Member
Licensed User
Longtime User
HI

i want to use 315Mhz mode.
i can use RCSwitch to send data in arduino ide , but How can i send and recive data in b4r ?

thanks
 

bagazhou

Member
Licensed User
Longtime User
my arduino c code:

#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();

void setup() {
Serial.begin(9600);
mySwitch.enableTransmit(10);
mySwitch.setPulseLength(163);
}

void loop() {
mySwitch.send(1004883, 24);
delay(2000);
}
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You will need to use inline c:
B4X:
Sub Process_Globals
   Public Serial1 As Serial
   Private Param1, Param2 As ULong 'ignore
   Private timer1 As Timer
End Sub

Private Sub AppStart
   Serial1.Initialize(115200)
   Log("AppStart")
   RunNative("Setup", Null)
   timer1.Initialize("timer1_Tick", 2000)
   timer1.Enabled = True
End Sub

Sub Timer1_Tick
   Param1 = 1004883
   Param2 = 24
   RunNative("Send", Null)
End Sub

#if C
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
void Setup(B4R::Object* o) {
   mySwitch.enableTransmit(10);
   mySwitch.setPulseLength(163);
}
void Send(B4R::Object* o) {
   mySwitch.send(b4r_main::_param1, b4r_main::_param2);
}
#End if
 
Upvote 0

vali khandangoll

Active Member
You will need to use inline c:
B4X:
Sub Process_Globals
   Public Serial1 As Serial
   Private Param1, Param2 As ULong 'ignore
   Private timer1 As Timer
End Sub

Private Sub AppStart
   Serial1.Initialize(115200)
   Log("AppStart")
   RunNative("Setup", Null)
   timer1.Initialize("timer1_Tick", 2000)
   timer1.Enabled = True
End Sub

Sub Timer1_Tick
   Param1 = 1004883
   Param2 = 24
   RunNative("Send", Null)
End Sub

#if C
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
void Setup(B4R::Object* o) {
   mySwitch.enableTransmit(10);
   mySwitch.setPulseLength(163);
}
void Send(B4R::Object* o) {
   mySwitch.send(b4r_main::_param1, b4r_main::_param2);
}
#End if
hi

At first I used your program and shown this error.
Verifying...
b4r_main.cpp:11:11: fatal error: RCSwitch.h: No such file or directory
#include <RCSwitch.h>
^~~~~~~~~~~~
compilation terminated.

secondly please send Recide code.

thanks
 
Upvote 0

vali khandangoll

Active Member
You will need to use inline c:
B4X:
Sub Process_Globals
   Public Serial1 As Serial
   Private Param1, Param2 As ULong 'ignore
   Private timer1 As Timer
End Sub

Private Sub AppStart
   Serial1.Initialize(115200)
   Log("AppStart")
   RunNative("Setup", Null)
   timer1.Initialize("timer1_Tick", 2000)
   timer1.Enabled = True
End Sub

Sub Timer1_Tick
   Param1 = 1004883
   Param2 = 24
   RunNative("Send", Null)
End Sub

#if C
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
void Setup(B4R::Object* o) {
   mySwitch.enableTransmit(10);
   mySwitch.setPulseLength(163);
}
void Send(B4R::Object* o) {
   mySwitch.send(b4r_main::_param1, b4r_main::_param2);
}
#End if
hi again
my first error about rcswith was solved.

how can send a text in your program ?
 
Upvote 0

candide

Active Member
Licensed User
i don't think rcswitch can send text.
you can receive /send a code like a swicth ON / switch OFF or a code from a remote control using fixe code
 
Upvote 0

candide

Active Member
Licensed User
in fact you can find a way to send/receive char one by one with rcswitch:
using protocol 1 with 32bits messages ,
- 16 bits can be used like Key message, a byte like char code and a byte to indicate char number
- or if several senders/receivers: 8 bits=Key message, 4 byte=sender, 4 bytes=receiver, 8bits=char number, 8bits=char
(char number is needed due to repetition of each messages sent by rcswitch)

here you can find more :

several protocols are available in rcswitch but i didn't use others
 
Last edited:
Upvote 0

candide

Active Member
Licensed User
you can find rcswitch2 library, including all functions of original rcswitch library.

B4R project added is using this library to send and receive codes, it is working examples
Also in this project, serial link is used to make provisioning, it is a good example of provisioning by serial with a save in eeprom
 

Attachments

  • rRCSwitch2.zip
    12.6 KB · Views: 71
  • ESP_RF433mhz_Repeater2.zip
    4 KB · Views: 61
Upvote 0
Top