Steve Bertrand

NAME

RF::HC12 - Interface to the 433 MHz HC-12 Radio Frequency serial trancievers

DESCRIPTION

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.

SYNOPSIS

    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;

METHODS

new($device)

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).

test

Sends a test command to the HC-12 transceiver. If everything is configured correctly, this method will return the string OK.

config

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

reset

Resets the HC-12 unit to factory defaults. See "config" for details on what the defaults are.

Return, String: OK+DEFAULT on success.

baud($baud)

Set/get the baud rate of the HC-12.

Parameters:

    $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.

channel($ch)

Sets/gets the channel the device operates on.

Parameters:

    $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.

Return, String: The current operating channel, eg. OK+RC001.

power($tp)

Sets/gets the transmission power (dB) of the HC-12.

Parameters:

    $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.

mode($mode)

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.

Parameters:

    $mode

Optional, Integer: The mode to set the device to. Valid values are 1-3.

Return, String: The current mode, eg. OK+FU3.

sleep

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.

wake

The opposite of "sleep". Wakes the device back up for wireless communication.

version

Returns the current version information from the HC-12's firmware.

Example: www.hc01.com HC-12_V2.4.

AUTHOR

Steve Bertrand, <steveb at cpan.org>

LICENSE AND COPYRIGHT

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