mirror of
https://github.com/meshtastic/python.git
synced 2026-02-25 11:10:14 -05:00
0.7.9 add sendPosition(lat, lng, alt) method also...
Use this method for the --settime command line flag - which sets the device
time to be the same as the local computers time (in UTC)
def sendPosition(self, latitude=0.0, longitude=0.0, altitude=0, timeSec=0, destinationId=BROADCAST_ADDR, wantAck=False, wantResponse=False):
"""
Send a position packet to some other node (normally a broadcast)
Also, the device software will notice this packet and use it to automatically set its notion of
the local position.
If timeSec is not specified (recommended), we will use the local machine time.
"""
This commit is contained in:
@@ -55,6 +55,7 @@ import logging
|
||||
import time
|
||||
import sys
|
||||
import traceback
|
||||
import time
|
||||
from . import mesh_pb2
|
||||
from . import util
|
||||
from pubsub import pub
|
||||
@@ -114,6 +115,32 @@ class MeshInterface:
|
||||
meshPacket.decoded.want_response = wantResponse
|
||||
self.sendPacket(meshPacket, destinationId, wantAck=wantAck)
|
||||
|
||||
def sendPosition(self, latitude=0.0, longitude=0.0, altitude=0, timeSec=0, destinationId=BROADCAST_ADDR, wantAck=False, wantResponse=False):
|
||||
"""
|
||||
Send a position packet to some other node (normally a broadcast)
|
||||
|
||||
Also, the device software will notice this packet and use it to automatically set its notion of
|
||||
the local position.
|
||||
|
||||
If timeSec is not specified (recommended), we will use the local machine time.
|
||||
"""
|
||||
meshPacket = mesh_pb2.MeshPacket()
|
||||
if(latitude != 0.0):
|
||||
meshPacket.decoded.position.latitude_i = int(latitude / 1e-7)
|
||||
|
||||
if(longitude != 0.0):
|
||||
meshPacket.decoded.position.longitude_i = int(longitude / 1e-7)
|
||||
|
||||
if(altitude != 0):
|
||||
meshPacket.decoded.position.altitude = int(altitude)
|
||||
|
||||
if timeSec == 0:
|
||||
timeSec = time.time() # returns unix timestamp in seconds
|
||||
meshPacket.decoded.position.time = int(timeSec)
|
||||
|
||||
meshPacket.decoded.want_response = wantResponse
|
||||
self.sendPacket(meshPacket, destinationId, wantAck=wantAck)
|
||||
|
||||
def sendPacket(self, meshPacket, destinationId=BROADCAST_ADDR, wantAck=False):
|
||||
"""Send a MeshPacket to the specified node (or if unspecified, broadcast).
|
||||
You probably don't want this - use sendData instead."""
|
||||
|
||||
@@ -30,6 +30,10 @@ def onConnected(interface):
|
||||
global args
|
||||
print("Connected to radio")
|
||||
try:
|
||||
if args.settime:
|
||||
print("Setting device RTC time")
|
||||
interface.sendPosition() # can include lat/long/alt etc: latitude = 37.5, longitude = -122.1
|
||||
|
||||
if args.sendtext:
|
||||
print(f"Sending text message {args.sendtext} to {args.dest}")
|
||||
interface.sendText(args.sendtext, args.dest,
|
||||
@@ -100,6 +104,9 @@ def main():
|
||||
parser.add_argument(
|
||||
"--sendtext", help="Send a text message")
|
||||
|
||||
parser.add_argument(
|
||||
"--settime", help="Set the real time clock on the device", action="store_true")
|
||||
|
||||
parser.add_argument("--debug", help="Show API library debug log messages",
|
||||
action="store_true")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user