GoStik

module
v0.0.0-...-7a80b81 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 31, 2021 License: LGPL-3.0

README

GoStik

GoStik is a Go(lang) package to send and receive data, (byte slices), utilizing the LoStik LoRa USB end node.

Purchase LoStik in the UK/EU.

Purchase LoStik in the US.

Status

Currently, point-to-point LoRa is implemented, LoRaWAN is WIP.

P2P usage example:

package main

import (
	"fmt"
	"log"

	"github.com/MatejLach/GoStik/lostik"
)

func main() {
	// Initialize sender
	stickTx, err := lostik.New("/dev/ttyUSB0", 57600)
	if err != nil {
		log.Fatalln(err)
	}

	err = stickTx.RadioInit()
	if err != nil {
		log.Fatalln(err)
	}

	// Initialize receiver
	stickRx, err := lostik.New("/dev/ttyUSB1", 57600)
	if err != nil {
		log.Fatalln(err)
	}

	err = stickRx.RadioInit()
	if err != nil {
		log.Fatalln(err)
	}

	// Send some data
	// Tx is non-blocking
	err = stickTx.Tx([]byte("golang.org"))
	if err != nil {
		log.Fatalln(err)
	}

	// Receive the data we just sent with another device
	resp, err := stickRx.Rx()
	if err != nil {
		log.Fatal(err)
	}

	if string(resp) != "golang.org" {
		log.Fatalln("unexpected response from receiver")
	} else {
		fmt.Printf("Received: %s", resp)
	}
}

Note that the receiving device has to be initialized and ready to receive at the same moment as data is being sent. It is generally NOT possible to receive 'past' data - that is data that was sent by someone prior to a device being ready to receive data.

Contributing

Bug reports and pull requests are welcome. Do not hesitate to open a PR / file an issue, or a feature request.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL