B4R Question IRremote - how to send

derez

Expert
Licensed User
Longtime User
I have successfully decoded a remote signal - NEC (1) with value 551489775.
Now I want to send it by the ESP instead of the remote. How do I tell the application what to send ? I use sendNEC but what is m built of ?

I have another remote (the AC control !) which gives an unknown result and the values are inconsistent, so it needs a raw data to be logged and then sent. How can I do that ?
 

derez

Expert
Licensed User
Longtime User
I don't understand.
B4X:
Sub Timer1_Tick
   Dim m As UInt = Bit.And(Millis, 0xffffffff) 'get 32 bits
   Log("sending: ", m)
   irsend.SendNEC(m, 32)
End Sub

How do I tell the code to send this value 551489775 (which is what I have decoded for a specific signal) ?
 
Upvote 0

miker2069

Active Member
Licensed User
Longtime User
We should be able to use external C code for the IR RAW sending/reading correct? Until you implement IR RAW features?
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
I EREL, How do we use the new raw data feature?

When I try

Log("result: ", Result.RawBuffer)

I get "type not supported(type=Uint, Rank=1, RemoteObject=True)"

Can we have an example on how to read and send raw data!?
 
Upvote 0

derez

Expert
Licensed User
Longtime User
I get a softreset when copying the result.rawbuffer to a global buffer.
It goes OK when I send the result buffer after it is recorded, but I have to record the result buffer for later use, not send it immediately...
Just by direct allocation I get this error msg:
Error description: Cannot set a Const variable (global non-primitive variables are always constants).
Occurred on line: 31
recbuffer = Result.RawBuffer
When I copy the contents one by one in a loop I still get the reset.
It happens with two remote-controls.

This is the code:
B4X:
Sub Process_Globals
   Public Serial1 As Serial
   Private ir As IrReceive
   Private irsend As IrSend
   Private d1 As  D1Pins
   Private pinbtn As Pin
   Private recbuffer(100) As UInt
End Sub

Private Sub AppStart
   Serial1.Initialize(115200)
   Log("AppStart")
   ir.Initialize(d1.D6, "ir_Decoded") 'receiver is connected to pin 6, GND and 5v (or 3.3v on ESP8266)
   ir.Enable
   pinbtn.Initialize(d1.D1, pinbtn.MODE_INPUT_PULLUP)   ' pin 3
   pinbtn.AddListener("StateChangedSub")
   irsend.Enable(d1.D2, 38) 'frequency = 38khz  pin 4
End Sub

Private Sub ir_Decoded (Result As IrResult)
   Log("result: ", Result.DecodeType, ", ", Result.Value)
    For i = 0 To Result.RawBuffer.Length - 1
         recbuffer(i) = Result.RawBuffer(i)
        Log(i, "  " , recbuffer(i))
    Next
End Sub

Sub StateChangedSub(state As Boolean)
    Log(state)
    If state = False Then
        irsend.SendRaw(recbuffer, 38)
    End If
End Sub

The log is:
...
94 20
95 0
96 20
97 0
98 21
99 0
0
Soft WDT reset
ctx: cont
sp: 3ffef690 end: 3ffef8f0 offset: 01b0
>>>stack>>>
3ffef840: 3ffef870 3ffef850 00000004 40202169
3ffef850: 3ffee6f4 00000038 3ffee6e8 402021fb
3ffef860: 00000129 00000000 3ffee6f0 3ffee8bc
3ffef870: 00000000 00000000 3ffee420 402031c4
3ffef880: 00000000 00000000 3ffee420 40202f94
3ffef890: 3fffdad0 00000000 3ffee6dc 40201c20
3ffef8a0: 00000000 3fff0d54 3ffee5f4 40202db0
3ffef8b0: 00000000 3ffee5fc 00000000 40202e1b
3ffef8c0: 3fffdad0 00000000 3ffee8b4 402031ef
3ffef8d0: feefeffe feefeffe feefeffe 40203a9c
3ffef8e0: feefeffe feefeffe 3ffee8d0 40100718
<<<stack<<<
ets Jan 8 2013,rst cause:2, boot mode:(3,6)
load 0x4010f000, len 1384, room 16
tail 8
chksum 0x2d
csum 0x2d
v09f0c112
~ld

AppStart

Edit:
I made a global of "Private myresult As IrResult" and it was accepted by this line
B4X:
Private Sub ir_Decoded (Result As IrResult)
   Log("result: ", Result.DecodeType, ", ", Result.Value)
     myresult.RawBuffer = Result.RawBuffer
 
    Delay(1000)
    irsend.SendRaw(myresult.RawBuffer, 38)
    Log("sent")
End Sub
but when sent by the button event it also crashes.
 
Last edited:
Upvote 0

derez

Expert
Licensed User
Longtime User
Length is according to the recorded result buffer length.
I use this and it does not work (crash):
B4X:
  ...
Private recbuffer(136) As Byte
Private first As Boolean = True
...

Private Sub ir_Decoded (Result As IrResult)
   If first Then
       Log("result: ", Result.DecodeType, ", ", Result.Value, " size ",Result.RawBuffer.Length)
       bc.ArrayCopy(bc.UIntsToBytes(Result.RawBuffer),recbuffer)
        Log(recbuffer.Length)
        first = False
    End If
End Sub

Sub StateChangedSub(state As Boolean)
    Log(state)
    If state = False Then
        Log("size ", recbuffer.Length)
        irsend.SendRaw( bc.UIntsFromBytes(recbuffer), 38)
    End If
End Sub
 
Upvote 0

derez

Expert
Licensed User
Longtime User
Sorry for not making myself clear, the crash is in this:
B4X:
irsend.SendRaw( bc.UIntsFromBytes(recbuffer), 38)
no matter if it is in the recording sub or the transmit sub.
Sending the recorded Result.RawBuffer succeeds.
 
Last edited:
Upvote 0

derez

Expert
Licensed User
Longtime User
I guess that it is in SendRaw call, right?
I have tested with delays and log and the answer is Yes (it comes from the SendRaw method).
B4X:
Dim temp() As UInt = bc.UIntsFromBytes(recbuffer)
Log("OK")
Delay(2000)
irsend.SendRaw(temp , 38)
 
Upvote 0
Top