-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(waypoint): Waypoint creation/deletion
Add methods to send (create or move), delete waypoint. Add an example script to create, move, delete waypoint.
- Loading branch information
1 parent
7c89e23
commit 9284a84
Showing
2 changed files
with
150 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
"""Program to create and delete waypoint | ||
To run: | ||
python3 examples/waypoint.py --port /dev/ttyUSB0 create 45 test the_desc_2 '2024-12-18T23:05:23' 48.74 7.35 | ||
python examples/waypoint.py delete 45 | ||
""" | ||
|
||
import argparse | ||
import datetime | ||
import sys | ||
import time | ||
|
||
import meshtastic | ||
import meshtastic.serial_interface | ||
|
||
parser = argparse.ArgumentParser( | ||
prog='waypoint', | ||
description='Create and delete Meshtastic waypoint') | ||
parser.add_argument('--port', default=None) | ||
parser.add_argument('--debug', default=False, action='store_true') | ||
|
||
subparsers = parser.add_subparsers(dest='cmd') | ||
parser_delete = subparsers.add_parser('delete', help='Delete a waypoint') | ||
parser_delete.add_argument('id', help="id of the waypoint") | ||
|
||
parser_create = subparsers.add_parser('create', help='Create a new waypoint') | ||
parser_create.add_argument('id', help="id of the waypoint") | ||
parser_create.add_argument('name', help="name of the waypoint") | ||
parser_create.add_argument('description', help="description of the waypoint") | ||
parser_create.add_argument('expire', help="expiration date of the waypoint as interpreted by datetime.fromisoformat") | ||
parser_create.add_argument('latitude', help="latitude of the waypoint") | ||
parser_create.add_argument('longitude', help="longitude of the waypoint") | ||
|
||
args = parser.parse_args() | ||
print(args) | ||
|
||
# By default will try to find a meshtastic device, | ||
# otherwise provide a device path like /dev/ttyUSB0 | ||
if args.debug: | ||
d = sys.stderr | ||
else: | ||
d = None | ||
with meshtastic.serial_interface.SerialInterface(args.port, debugOut=d) as iface: | ||
if args.cmd == 'create': | ||
p = iface.sendWaypoint( | ||
id=int(args.id), | ||
name=args.name, | ||
description=args.description, | ||
expire=int(datetime.datetime.fromisoformat(args.expire).timestamp()), | ||
latitude=float(args.latitude), | ||
longitude=float(args.longitude), | ||
) | ||
else: | ||
p = iface.deleteWaypoint(int(args.id)) | ||
print(p) | ||
|
||
# iface.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters