mirror of
https://github.com/meshtastic/python.git
synced 2025-12-30 03:17:54 -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:
8
.vscode/launch.json
vendored
8
.vscode/launch.json
vendored
@@ -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",
|
||||
|
||||
@@ -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):
|
||||
<ul class="hlist">
|
||||
<li><code><a title="meshtastic.MeshInterface.sendData" href="#meshtastic.MeshInterface.sendData">sendData</a></code></li>
|
||||
<li><code><a title="meshtastic.MeshInterface.sendPacket" href="#meshtastic.MeshInterface.sendPacket">sendPacket</a></code></li>
|
||||
<li><code><a title="meshtastic.MeshInterface.sendPosition" href="#meshtastic.MeshInterface.sendPosition">sendPosition</a></code></li>
|
||||
<li><code><a title="meshtastic.MeshInterface.sendText" href="#meshtastic.MeshInterface.sendText">sendText</a></code></li>
|
||||
<li><code><a title="meshtastic.MeshInterface.writeConfig" href="#meshtastic.MeshInterface.writeConfig">writeConfig</a></code></li>
|
||||
</ul>
|
||||
@@ -682,6 +710,32 @@ debugOut</p>
|
||||
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.</p></div>
|
||||
self._sendToRadio(toRadio)</code></pre>
|
||||
</details>
|
||||
</dd>
|
||||
<dt id="meshtastic.MeshInterface.sendPosition"><code class="name flex">
|
||||
<span>def <span class="ident">sendPosition</span></span>(<span>self, latitude=0.0, longitude=0.0, altitude=0, timeSec=0, destinationId='^all', wantAck=False, wantResponse=False)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<div class="desc"><p>Send a position packet to some other node (normally a broadcast)</p>
|
||||
<p>Also, the device software will notice this packet and use it to automatically set its notion of
|
||||
the local position.</p>
|
||||
<p>If timeSec is not specified (recommended), we will use the local machine time.</p></div>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">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)</code></pre>
|
||||
</details>
|
||||
</dd>
|
||||
<dt id="meshtastic.MeshInterface.sendText"><code class="name flex">
|
||||
<span>def <span class="ident">sendText</span></span>(<span>self, text, destinationId='^all', wantAck=False, wantResponse=False)</span>
|
||||
</code></dt>
|
||||
@@ -1119,6 +1212,7 @@ debugOut {stream} – If a stream is provided, any debug serial output from
|
||||
<ul class="hlist">
|
||||
<li><code><a title="meshtastic.MeshInterface.sendData" href="#meshtastic.MeshInterface.sendData">sendData</a></code></li>
|
||||
<li><code><a title="meshtastic.MeshInterface.sendPacket" href="#meshtastic.MeshInterface.sendPacket">sendPacket</a></code></li>
|
||||
<li><code><a title="meshtastic.MeshInterface.sendPosition" href="#meshtastic.MeshInterface.sendPosition">sendPosition</a></code></li>
|
||||
<li><code><a title="meshtastic.MeshInterface.sendText" href="#meshtastic.MeshInterface.sendText">sendText</a></code></li>
|
||||
<li><code><a title="meshtastic.MeshInterface.writeConfig" href="#meshtastic.MeshInterface.writeConfig">writeConfig</a></code></li>
|
||||
</ul>
|
||||
@@ -1164,6 +1258,7 @@ debugOut {stream} – If a stream is provided, any debug serial output from
|
||||
<ul class="">
|
||||
<li><code><a title="meshtastic.MeshInterface.sendData" href="#meshtastic.MeshInterface.sendData">sendData</a></code></li>
|
||||
<li><code><a title="meshtastic.MeshInterface.sendPacket" href="#meshtastic.MeshInterface.sendPacket">sendPacket</a></code></li>
|
||||
<li><code><a title="meshtastic.MeshInterface.sendPosition" href="#meshtastic.MeshInterface.sendPosition">sendPosition</a></code></li>
|
||||
<li><code><a title="meshtastic.MeshInterface.sendText" href="#meshtastic.MeshInterface.sendText">sendText</a></code></li>
|
||||
<li><code><a title="meshtastic.MeshInterface.writeConfig" href="#meshtastic.MeshInterface.writeConfig">writeConfig</a></code></li>
|
||||
</ul>
|
||||
|
||||
@@ -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")
|
||||
|
||||
|
||||
2
proto
2
proto
Submodule proto updated: 9d083d5d4f...ab281311c4
2
setup.py
2
setup.py
@@ -10,7 +10,7 @@ with open("README.md", "r") as fh:
|
||||
# This call to setup() does all the work
|
||||
setup(
|
||||
name="meshtastic",
|
||||
version="0.7.8",
|
||||
version="0.7.9",
|
||||
description="Python API & client shell for talking to Meshtastic devices",
|
||||
long_description=long_description,
|
||||
long_description_content_type="text/markdown",
|
||||
|
||||
Reference in New Issue
Block a user