simple library to control 433 Mhz target devices using a Raspberry Pi and a 433 Mhz transmitter module using the excellent rppal crate
An example with a command line interface can be found here:
https://github.com/elkasztano/sparkypi
[dependencies]
rppal = "0.14.1"
libsparkypi = "0.2.0"
```rust use libsparkypi::{Transmission, ProtocolProperties}; use libsparkypi::*; use rppal::gpio::Gpio; use std::error::Error; use std::{thread, time};
fn main() -> Result<(), Box
// gpio setup
let gpio = Gpio::new()?;
let mut output_pin = gpio.get(17)?.into_output();
// transmission with predefined protocol
let mut my_transmission = Transmission::new();
my_transmission.sequence.push_str("s000000010101000101011001");
my_transmission.pulse_length = 170;
my_transmission.repeats = 5;
my_transmission.protocol = P1;
println!("{:?}", &my_transmission);
my_transmission.send_to(&mut output_pin);
thread::sleep(time::Duration::from_millis(500));
// transmission with custom protocol
let my_protocol = ProtocolProperties {
short: 1,
long: 2,
sync_bit: 1,
sync_gap: 11,
};
let custom_transmission = Transmission {
sequence: String::from("s10100110001100100001001100000000"),
pulse_length: 570,
repeats: 10,
protocol: my_protocol,
};
println!("{:?}", &custom_transmission);
custom_transmission.send_to(&mut output_pin);
Ok(())
} ``` The above example will transmit the binary sequence '000000010101000101011001' (24 bit) with a leading sync bit and a pulse length of 170 microseconds 5 times using the predefined protocol 1 ('P1').
After a short pause of 500 milliseconds a 32 bit binary sequence will be transmitted 10 times using a custom protocol.
In the above example the data pin of the transmitter module is connected to GPIO pin 17 on the Raspberry Pi.
```rust let myprotocol = ProtocolProperties { short: 1, // short pulse is 1 * pulselength ( = 570 microseconds in the transmission below) long: 2, // long pulse is 2 * pulselength ( = 1140 microseconds) syncbit: 1, // syncbit is 1 * pulselength ( = 570 microseconds) syncgap: 11, // syncgap (pause) is 11 * pulse_length ( = 6270 microseconds) };
let my_transmission = Transmission {
// Binary sequence. The 's' at the beginning stands for the required sync bit.
sequence: String::from("s10100110001100100001001100000000"),
// The pulse length is the smallest time unit of the transmission.
// It will be multiplied by the factors defined in the ProtocolProperties struct above.
pulse_length: 570,
// Usually the sequence must be repeated several times. This number should be as low as possible.
repeats: 10,
// Setting the desired protocol. Can be predefined or custom.
protocol: my_protocol,
}; ```