RF::HC12 - Interface to the 433 MHz HC-12 Radio Frequency serial trancievers
Interfaces with the HC-12 433MHz Radio Frequency serial data transceivers.
NOTE: Currently, this distribution can only be used to configure the devices, in the future, I'll incorporate the ability to use it to actually communicate between them.
NOTE: The HC-12 transceivers are designed to operate in pairs. The settings on one device must match the other device or communication will fail.
HC-12
use RF::HC12; my $rf = RF::HC12->new('/dev/ttyUSB0'); $rf->sleep; $rf->wake; print $rf->baud; print $rf->power; print $rf->mode; print $rf->channel; print $rf->config;
Instantiates a new RF::HC12 module over the serial interface, and returns it.
Parameters:
$device
Mandatory, String: The path and file name of your UART serial TTY device. (eg: /dev/ttyUSB0).
/dev/ttyUSB0
Sends a test command to the HC-12 transceiver. If everything is configured correctly, this method will return the string OK.
OK
Returns all of the various configuration settings as they are currently set. Here's an example containing the configuration of a unit set to factory defaults:
OK+B9600 # 9600 baud OK+RC001 # RF channel 001 (this is the min) OK+RP:+20dBm # +20dBm power (this is the max) OK+FU3 # transmission mode
Resets the HC-12 unit to factory defaults. See "config" for details on what the defaults are.
Return, String: OK+DEFAULT on success.
OK+DEFAULT
Set/get the baud rate of the HC-12.
$baud
Optional, Integer: The baud rate that the HC-12 will communicate over. Valid values:
1200 2400 4800 9600 19200 38400 57600 115200
Return, String: The current baud rate, eg. OK+B9600.
OK+B9600
Sets/gets the channel the device operates on.
$ch
Optional, Integer: The channel to operate under. Valid values are 1 (default) through 127. All channels above channel 100 are likely to be flaky, so unless you're testing or having communication problems using lower channels, don't use them.
1
127
100
Return, String: The current operating channel, eg. OK+RC001.
OK+RC001
Sets/gets the transmission power (dB) of the HC-12.
$tp
Optional, Integer: The associated mapping to the value to set. Valid values (1-8):
Param Value (dB) 1 -1 2 2 3 5 4 8 5 11 6 14 7 17 8 20
Return, String: The current value, eg. OK+RP:+20dBm.
OK+RP:+20dBm
Sets/gets the transmission mode of the HC-12. This setting is transparent for the most part, and relies on other settings. I'd recomment reading the datasheet for the device before modifying this setting.
$mode
Optional, Integer: The mode to set the device to. Valid values are 1-3.
1-3
Return, String: The current mode, eg. OK+FU3.
OK+FU3
Puts the HC-12 into a sleep mode. In this mode, no RF communication is possible, and the device will operate at 0.22 micro Amp working current.
0.22 micro Amp
The opposite of "sleep". Wakes the device back up for wireless communication.
Returns the current version information from the HC-12's firmware.
Example: www.hc01.com HC-12_V2.4.
www.hc01.com HC-12_V2.4
Steve Bertrand, <steveb at cpan.org>
<steveb at cpan.org>
Copyright 2019 Steve Bertrand.
This program is free software; you can redistribute it and/or modify it under the terms of the the Artistic License (2.0). You may obtain a copy of the full license at:
http://www.perlfoundation.org/artistic_license_2_0
To install RF::HC12, copy and paste the appropriate command in to your terminal.
cpanm
cpanm RF::HC12
CPAN shell
perl -MCPAN -e shell install RF::HC12
For more information on module installation, please visit the detailed CPAN module installation guide.