Documentation
¶
Overview ¶
Example (BasicUsage) ¶
Example_basicUsage demonstrates basic library usage
// configure the radio
address := uint16(1)
networkID := uint8(5)
band := BandUSA
config := Configuration{
Address: &address,
NetworkID: &networkID,
Band: &band,
}
// create connection
lora, err := CreateConnectionDEBUG(testSerialPort, UartBaudRate_115200, config, 10, "r1", func(name, msg string) {
log.Printf("[DEBUG][%s] %s", name, msg)
})
if err != nil {
fmt.Printf("Error: %v\n", err.Err)
return
}
defer lora.CloseConnection()
// send a message
targetAddress := uint16(2)
message := []byte("Hello!")
if sendErr := lora.SendMessage(targetAddress, message); sendErr != nil {
fmt.Printf("Send error: %v\n", sendErr.Err)
return
}
// listen for incoming messages
go func() {
for {
select {
case msg := <-lora.RecievedData:
fmt.Printf("Received: %s from %d\n",
string(msg.Data[:msg.Length]),
msg.Address)
case errEvent := <-lora.Errors:
if errEvent.Err != nil {
fmt.Printf("Error: %v\n", errEvent.Err)
}
}
}
}()
// keep running
time.Sleep(60 * time.Second)
Index ¶
Examples ¶
Constants ¶
View Source
const ( Bandwidth7_8KHz uint8 = 0 // NOT RECCOMENDED Bandwidth10_4KHz uint8 = 1 // NOT RECCOMENDED Bandwidth15_6KHz uint8 = 2 Bandwidth20_8KHz uint8 = 3 Bandwidth31_25KHz uint8 = 4 Bandwidth41_7KHz uint8 = 5 Bandwidth62_5KHz uint8 = 6 Bandwidth125KHz uint8 = 7 Bandwidth250KHz uint8 = 8 Bandwidth500KHz uint8 = 9 )
bandwidth constants
View Source
const ( BandUSA uint32 = 915000000 BandEUROPE1 uint32 = 868000000 BandEUROPE2 uint32 = 433000000 BandCHINA uint32 = 470000000 BandASIA uint32 = 470000000 BandAUSTRALIA uint32 = 923000000 BandINDIA uint32 = 865000000 BandKOREA uint32 = 920000000 BandBRAZIL uint32 = 915000000 BandJAPAN uint32 = 920000000 )
band constants, HZ
View Source
const ( MODE_TRX uint8 = 0 // transmit and recieve MODE_SLEEP uint8 = 1 // sleep )
mode constants
View Source
const ( UartBaudRate_300 int = 300 UartBaudRate_1200 int = 1200 UartBaudRate_4800 int = 4800 UartBaudRate_9600 int = 9600 UartBaudRate_28800 int = 19200 UartBaudRate_38400 int = 38400 UartBaudRate_57600 int = 57600 UartBaudRate_115200 int = 115200 // default )
UART baud rate constants
View Source
const ( OK = 0 // OK NO_ENTER = 1 // missing "\r\n" after command NO_AT = 2 // head of command is not AT NO_EQ = 3 // missing "=" in AT command UNK_CMD = 4 // unknown command TX_OT = 10 // transmit over time RX_OT = 11 // receive over time CRC_ERR = 12 // CRC error TX_OR = 13 // transmit over run(over 240 bytes) UNK_ERR = 15 // unknown error )
result code constants
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Command ¶
type Command struct {
Text string
ResponseChan chan CommandResponse // channel to receive response on
}
type CommandResponse ¶
type CommandResponse struct {
Response string
Error *ErrorEvent // nil if no error
}
type Configuration ¶
type Configuration struct {
Address *uint16 // ADDRESS, 0-65535, ident of the transciever
NetworkID *uint8 // NETWORKID, 0-16, must be the same for radios to communicate
Band *uint32 // BAND(Hz), 433000000-915000000, center freq of wireless band
Parameter *Parameters // PARAMETER, rf params
Mode *uint8 // MODE, 0-1, work mode
UartBaudRate *int // IPR, 300-115200, uart baud rate
EncryptionKey *[16]byte // CPIN, 00000000000000000000000000000000-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF, AES128 network password
RFOutputPower *uint8 // CRFOP(dBm), 0-15, RF output power
}
complete configuration
type ErrorEvent ¶
type ErrorEvent struct {
Code *int // LoRa error code (nil if not applicable)
Err error // Go error (nil if not applicable)
}
func CreateConnection ¶
func CreateConnection(serialInterfaceName string, baudRate int, config Configuration, buffLen int) (Lora *lora, errEvent *ErrorEvent)
CreateConnection attaches to a uart serial port, and a desired buffer length and returns a lora object
func CreateConnectionDEBUG ¶
func CreateConnectionDEBUG(serialInterfaceName string, baudRate int, config Configuration, buffLen int, debugName string, debugFunc func(string, string)) (Lora *lora, errEvent *ErrorEvent)
CreateConnectionDEBUG creates a connection with debug logging enabled
Click to show internal directories.
Click to hide internal directories.