meshtastic

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidPacket signals the source buffer does not contain a valid packet.
	ErrInvalidPacket = errors.New("meshtastic: invalid packet")
)

Functions

This section is empty.

Types

type NodeID

type NodeID uint32
const (
	// BroadcastNodeID is the special NodeID used when broadcasting a packet to a channel.
	BroadcastNodeID NodeID = math.MaxUint32

	// BroadcastNodeIDNoLora is a special broadcast address that excludes LoRa transmission.
	// Used for MQTT-only broadcasts. This is ^all with the NO_LORA flag (0x40) cleared.
	BroadcastNodeIDNoLora NodeID = math.MaxUint32 ^ 0x40
)

func ParseNodeID

func ParseNodeID(s string) (NodeID, error)

ParseNodeID parses a NodeID from various string formats:

  • "!abcd1234" (Meshtastic format with ! prefix)
  • "0xabcd1234" (hex with 0x prefix)
  • "abcd1234" (plain hex)
  • "12345678" (decimal)

func RandomNodeID

func RandomNodeID() (NodeID, error)

RandomNodeID returns a randomised NodeID. It's recommended to call this the first time a node is started and persist the result.

Hardware meshtastic nodes first try a NodeID of the last four bytes of the BLE MAC address. If that ID is already in use or invalid, a random NodeID is generated. Source: https://github.com/meshtastic/firmware/blob/d1ea58975755e146457a8345065e4ca357555275/src/mesh/NodeDB.cpp#L466

func (NodeID) Bytes

func (n NodeID) Bytes() []byte

Bytes converts the NodeID to a byte slice

func (NodeID) DefaultLongName

func (n NodeID) DefaultLongName() string

DefaultLongName returns the default long node name based on the NodeID. Source: https://github.com/meshtastic/firmware/blob/d1ea58975755e146457a8345065e4ca357555275/src/mesh/NodeDB.cpp#L382

func (NodeID) DefaultShortName

func (n NodeID) DefaultShortName() string

DefaultShortName returns the default short node name based on the NodeID. Last two bytes of the NodeID represented in hex. Source: https://github.com/meshtastic/firmware/blob/d1ea58975755e146457a8345065e4ca357555275/src/mesh/NodeDB.cpp#L382

func (NodeID) IsBroadcast

func (n NodeID) IsBroadcast() bool

IsBroadcast returns true if this is any form of broadcast address.

func (NodeID) IsReservedID

func (n NodeID) IsReservedID() bool

IsReservedID returns true if this is a reserved or broadcast NodeID.

func (NodeID) MarshalText

func (n NodeID) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (NodeID) String

func (n NodeID) String() string

String converts the NodeID to a hex formatted string. This is typically how NodeIDs are displayed in Meshtastic UIs.

func (NodeID) ToMacAddress

func (n NodeID) ToMacAddress() string

ToMacAddress returns a MAC address string derived from the NodeID. This creates a locally administered unicast MAC address.

func (NodeID) Uint32

func (n NodeID) Uint32() uint32

Uint32 returns the underlying uint32 value of the NodeID.

func (*NodeID) UnmarshalText

func (n *NodeID) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler for use with config parsers like Viper.

type Packet

type Packet struct {
	Destination    NodeID               `json:"destination"`
	Source         NodeID               `json:"source"`
	ID             uint32               `json:"id"`
	Flags          uint8                `json:"flags"`
	ChannelHash    uint8                `json:"channelHash"`
	NextHop        uint8                `json:"nextHop"`
	RelayNode      uint8                `json:"relayNode"`
	PayloadLength  int                  `json:"-"`
	Payload        [maxPayloadSize]byte `json:"-"`
	Data           *meshtasticpb.Data   `json:"data,omitempty"`
	DecodedPayload proto.Message        `json:"decodedPayload,omitempty"`
	TextPayload    string               `json:"textPayload,omitempty"`
}

func (*Packet) Decode

func (packet *Packet) Decode(data []byte) error

func (*Packet) HopLimit

func (packet *Packet) HopLimit() int

func (*Packet) MarshalJSON

func (packet *Packet) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling for Packet.

func (*Packet) PayloadBytes

func (packet *Packet) PayloadBytes() []byte

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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