Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

Commit

Permalink
Merge pull request #3 from hapi-robo/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
r-oung authored Aug 30, 2021
2 parents 1e6c730 + 996657b commit 8d413e2
Show file tree
Hide file tree
Showing 11 changed files with 524 additions and 137 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
pytemi/__pycache__/
pytemi.egg-info/
venv/
test.py
_test/
test.py
*.pyc
*.csv
*.env
22 changes: 4 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
# pytemi
Control temi using Python scripts over MQTT.


## Prerequisites
* [Python 3](https://www.python.org/downloads/)
* [Connect app](https://github.com/hapi-robo/connect/releases) installed on temi
* MQTT broker. Free brokers for testing:
* [Eclipse](http://test.mosquitto.org/)
* [Mosquitto](http://mqtt.eclipse.org)
* [HiveMQ](http://broker.hivemq.com)
A Python package for controlling temi over MQTT. To be used with [temi-mqtt-client](https://github.com/hapi-robo/temi-mqtt-client/). For prototyping/development only.


## Setup
Expand All @@ -24,15 +15,10 @@ For Linux users, there's a script that will create a Python virtual environment


## Usage
Make sure the robot is connected to an MQTT broker via the [Connect app](https://github.com/hapi-robo/connect/releases).

Edit the `sample.py` script and adjust the `parameters` appropriately, then run:
```
python sample.py
```
Make sure the robot is connected to an MQTT broker via the [temi-mqtt-client](https://github.com/hapi-robo/temi-mqtt-client/) app.


## Sample Script
### Sample Script
```
import pytemi as temi
Expand All @@ -53,4 +39,4 @@ robot.tts("Going to the Entrance")
robot.goto("entrance")
```

See `sample.py` for more details.
See `./sample.py` for more details. Other examples can be found in the `scripts/` folder.
24 changes: 24 additions & 0 deletions pytemi/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# MQTT Topics
The following is a summary of MQTT topics used by this package.

## Publish
```
temi/{id}/command/move/turn_by
temi/{id}/command/move/joystick
temi/{id}/command/move/tilt
temi/{id}/command/move/tilt_by
temi/{id}/command/move/stop
temi/{id}/command/follow/unconstrained
temi/{id}/command/waypoint/goto
temi/{id}/command/tts
temi/{id}/command/media/video
temi/{id}/command/media/webview
```

## Subscribe
```
temi/{id}/status/info
temi/{id}/status/utils/battery
temi/{id}/event/waypoint/goto
temi/{id}/event/user/detection
```
20 changes: 13 additions & 7 deletions pytemi/connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@


def _on_connect(client, userdata, flags, rc):
"""Connect to MQTT broker and subscribe to topics
"""
"""Connect to MQTT broker and subscribe to topics"""
print(
"[STATUS] Connected to: {} (rc:{})".format(
client._client_id.decode("ascii"), str(rc)
)
)

# subscribing in on_connect() means that if we lose the connection and
# reconnect, then subscriptions will be renewed
client.subscribe("temi/#")

def _on_disconnect(client, userdata, rc):
"""Disconnect from MQTT broker

"""
def _on_disconnect(client, userdata, rc):
"""Disconnect from MQTT broker"""
print(
"[STATUS] Disconnected from: {} (rc:{})".format(
client._client_id.decode("ascii"), str(rc)
Expand All @@ -34,13 +34,19 @@ def _on_disconnect(client, userdata, rc):
client.loop_stop()


def _on_message(client, userdata, msg):
"""Print out any topics that have no callbacks"""
print("[{}][SUB] {} {}".format(now(), msg.topic, str(msg.payload)))


def connect(host, port, username=None, password=None):
"""Connect to MQTT broker"""
client_id = socket.gethostname() + "-" + datetime.now().strftime("%Y%m%d%H%M%S")

# create a new MQTT client instance
client = mqtt.Client(client_id=client_id)

# attach callbacks
# attach general callbacks
client.on_connect = _on_connect
client.on_disconnect = _on_disconnect

Expand Down
Loading

0 comments on commit 8d413e2

Please sign in to comment.