forked from trackuino/trackuino
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6eedc19
commit 052dde0
Showing
5 changed files
with
106 additions
and
30 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
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
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
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,24 @@ | ||
from redis import Redis | ||
from rq import Queue | ||
import paho.mqtt.client as mqtt | ||
from paho.mqtt.packettypes import PacketTypes | ||
from paho.mqtt.properties import Properties | ||
import json | ||
|
||
def add_data_task(data_type, data): | ||
client = mqtt.Client() | ||
client.connect("localhost", 1883, 60) | ||
properties=Properties(PacketTypes.PUBLISH) | ||
properties.MessageExpiryInterval=60 # retain messages for x seconds | ||
|
||
if data_type == "position": | ||
client.publish("POSITION/" + data["name"], json.dumps(data), retain=True, qos=0, properties=properties) | ||
elif data_type == "telemetry": | ||
client.publish("TELEMETRY/" + data["name"], json.dumps(data), retain=True, qos=0, properties=properties) | ||
|
||
client.disconnect() | ||
|
||
|
||
def add_data(data_type, data): | ||
q = Queue(connection=Redis()) | ||
q.enqueue(add_data, data_type, data) |
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