diff --git a/.vscode/launch.json b/.vscode/launch.json index 83c15a3..c1aab52 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -44,6 +44,14 @@ "justMyCode": true, "args": ["--debug", "--test"] }, + { + "name": "meshtastic settime", + "type": "python", + "request": "launch", + "module": "meshtastic", + "justMyCode": true, + "args": ["--debug", "--settime"] + }, { "name": "meshtastic sendtext", "type": "python", diff --git a/docs/meshtastic/index.html b/docs/meshtastic/index.html index c66e4e8..fc29746 100644 --- a/docs/meshtastic/index.html +++ b/docs/meshtastic/index.html @@ -126,6 +126,7 @@ import logging import time import sys import traceback +import time from . import mesh_pb2 from . import util from pubsub import pub @@ -185,6 +186,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.""" @@ -623,6 +650,7 @@ class StreamInterface(MeshInterface):
@@ -682,6 +710,32 @@ debugOut 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.""" @@ -908,6 +962,45 @@ You probably don't want this - use sendData instead. self._sendToRadio(toRadio) +
+def sendPosition(self, latitude=0.0, longitude=0.0, altitude=0, timeSec=0, destinationId='^all', 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.
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 sendText(self, text, destinationId='^all', wantAck=False, wantResponse=False)