-
Notifications
You must be signed in to change notification settings - Fork 0
RC Switch module
This module contains functions for sending and receiving control signals using inexpensive XY-FST 433mhz transmitter resp. reciever modules.
These are widely used in different remote controlable power socket adapters and also in many led-strip controllers.
All you need is your existing sender+receiver that you want to be able to control via the Lua-RTOS device and a transmitter/receiver kit. Hook up the transmitter and receiver to 5v power and connect each one's data line with a GPIO on your Lua-RTOS device. If you don't want to control existing equipment, then you can also hook up the transmitter to one Lua-RTOS device and the receiver to a second Lua-RTOS device.
Sends the given Code with the given Protocol and Bitlength in the given Pulse time on the given PIN.
Arguments:
- code: the code to send
- pin (optional): the pin that the transmitter is connected to, defaults to GPIO12
- pulse (optional): the pulse width to use when sending the data, defaults to 330
- protocol (optional): the protocol to use when sending the data, defaults to 1
- bitlength (optional): the bitlength to use when sending the data, defaults to 24
Returns: nothing.
rcswitch.send(5703472, 12, 170, 1, 24)
Listens on the given PIN for the given milliseconds and returns the received code, if any. Calling receive this way will block the calling process for the time given. Make sure the time given is longer than the expected pulse length or you will never receive anything.
Arguments:
- pin (optional): the pin that the receiver is connected to, defaults to GPIO14
- millis (optional): the maximum time to wait for receiving, defaults to 500ms
Returns: nothing or the received code and attributes.
- code: the code received
- bitlength: the bitlength that the received code was sent with
- protocol: the protocol received that the received code with
- delay: the pulse width that the code was received in
rcswitch.receive(14, 5000)
Listens on the given PIN by starting a separate thread. Any code received will be passed to the callback function.
Arguments:
- pin: the pin that the receiver is connected to, defaults to GPIO14
- millis: must be zero
- callback: a user-provided lua function that is called with the received code as parameter
Returns: nothing
The lua callback function will receive the following parameters in the given order:
- code: the code received
- bitlength: the bitlength that the received code was sent with
- protocol: the protocol received that the received code with
- delay: the pulse width that the code was received in
function cb_received(value, bits, proto, delay) -- all 4 are integers
print("val: "..value.." bits:"..bits.." proto:"..proto.." delay:"..delay)
end
rcswitch.receive(14, 0, cb_received)
Stops a receive-thread running in the background that has been started with rcswitch.receive(...) and frees all allocated resources.
Arguments: none
Returns: nothing
rcswitch.stop()