gomesh

package module
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2024 License: MIT Imports: 14 Imported by: 1

README

Go Mesh

Go Mesh (goMesh) is a package that provides prebuilt methods and tools for interacting with meshtastic radios and is compatible with Windows, Linux and Mac. The only requirements for this tool are the ESP32 drivers if not already installed.

Initialization

All communications with meshtastic radios can be done through the Radio struct. Below is an example that shows the setup:

radio := Radio{}
radio.Init("/dev/cu.SLAB_USBtoUART")
defer radio.Close()

This example uses the Mac port name from the ESP32 drivers (cu.SLAB_USBtoUART) but this will change depending on the OS and the drivers used. It is possible to communicate with meshtastic radios over TCP as well. Passing in an IP address will automatically have the Radio client choose TCP communications.

Remember to defer radio.Close() to close the port that's being used to communicate with the device.

Usage

There are multiple available functions to interact with the radios and perform different functions.

r := gomesh.Radio{}
responses, err := r.GetRadioInfo()
if err != nil {
  return err
})

In this example the responses could then be read and processed by type to process the data.

for _, response := range responses {
  if info, ok := response.GetPayloadVariant().(*pb.FromRadio_MyInfo); ok {
    // Do something with the response
  }
}

Tests

Tests for each major radio function are provided in radio_test.go. The full test suite should be run while the machine running the tests is plugged into a meshtastic radio. The test require a command line argument that specifies the port a Meshtastic radio is connected to. To run all test use:

go test -args -port=/dev/cu.usbserial-0200674E

To run a single test specify the test to run and use the command:

go test -run TestSetChannelURL -args -port=/dev/cu.usbserial-0200674E

Feedback

This package is still under development. Any issues or feedback can be submitted to the issues page.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Radio

type Radio struct {
	// contains filtered or unexported fields
}

Radio holds the port and serial io.ReadWriteCloser struct to maintain one serial connection

func (*Radio) AddChannel

func (r *Radio) AddChannel(name string, cIndex int) error

AddChannel adds a new channel to the radio

func (*Radio) Close

func (r *Radio) Close()

Close closes the serial port. Added so users can defer the close after opening

func (*Radio) DeleteChannel

func (r *Radio) DeleteChannel(cIndex int) error

Delete a channel from the radio

func (*Radio) FactoryRest added in v0.1.8

func (r *Radio) FactoryRest() error

Send a factory reset command to the radio

func (*Radio) GetChannelInfo

func (r *Radio) GetChannelInfo(index int) (channelSettings *pb.Channel, err error)

GetChannelInfo returns the current chanels settings for the radio

func (*Radio) GetChannels added in v0.1.8

func (r *Radio) GetChannels() (channels []*pb.Channel, err error)

GetChannelInfo returns the current chanels settings for the radio

func (*Radio) GetRadioConfig added in v0.1.8

func (r *Radio) GetRadioConfig() (configPackets []*pb.FromRadio_Config, modulePackets []*pb.FromRadio_ModuleConfig, err error)

GetRadioConfig returns a filtered list of raiod and module config settings

func (*Radio) GetRadioInfo

func (r *Radio) GetRadioInfo() (radioResponses []*pb.FromRadio, err error)

GetRadioInfo retrieves information from the radio including config and adjacent Node information

func (*Radio) Init

func (r *Radio) Init(port string) error

Init initializes the Serial connection for the radio

func (*Radio) ReadResponse added in v0.1.3

func (r *Radio) ReadResponse(timeout bool) (FromRadioPackets []*pb.FromRadio, err error)

ReadResponse reads any responses in the serial port, convert them to a FromRadio protobuf and return

func (*Radio) SendTextMessage

func (r *Radio) SendTextMessage(message string, to int64) error

SendTextMessage sends a free form text message to other radios

func (*Radio) SetChannel

func (r *Radio) SetChannel(chIndex int, key string, value string) error

SetChannel sets a channel value

func (*Radio) SetChannelURL

func (r *Radio) SetChannelURL(url string) error

SetChannelURL sets the channel for the radio. The incoming channel should match the meshtastic URL format of a URL ending with /#{base_64_encoded_radio_params}

func (*Radio) SetLocation

func (r *Radio) SetLocation(lat float64, long float64, alt int32) error

SetLocation sets a fixed location for the radio

func (*Radio) SetModemMode

func (r *Radio) SetModemMode(mode string) error

SetModemMode sets the channel modem setting to be fast or slow

func (*Radio) SetRadioConfig added in v0.1.8

func (r *Radio) SetRadioConfig(key string, value string) error

SetRadioConfig allows an freeform setting of values in the RadioConfig_UserPreferences struct

func (*Radio) SetRadioOwner

func (r *Radio) SetRadioOwner(name string) error

SetRadioOwner sets the owner of the radio visible on the public mesh

Directories

Path Synopsis
github.com

Jump to

Keyboard shortcuts

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