Exemplo n.º 1
0
def test_format_channel_link():
    tests = [
        {
            "channel": "test",
            "options": {Client.with_ttl(5)},
            "expected": "test/?ttl=5"
        },
    ]

    for test in tests:
        formatted = Client._format_channel_link(channel=test["channel"],
                                                options=test["options"])
        assert formatted == test["expected"]
Exemplo n.º 2
0
def message(retain=False):
    if retain:
        emitter.publish(channel_key.get(), channel.get(), text_message.get(),
                        {Client.with_retain()})
    else:
        emitter.publish(channel_key.get(), channel.get(), text_message.get(),
                        {})
    result_text.insert(
        "0.0", "Test message send through '" + channel.get() + "'.\n\n")
Exemplo n.º 3
0
def test_format_channel():
    tests = [
        {
            "key": "5xZjIQp6GA9fpxso1Kslqnv8d4XVWCha",
            "channel": "test",
            "options": None,
            "expected": "5xZjIQp6GA9fpxso1Kslqnv8d4XVWCha/test/"
        },
        {
            "key": "5xZjIQp6GA9fpxso1Kslqnv8d4XVWCha",
            "channel": "test/",
            "options": None,
            "expected": "5xZjIQp6GA9fpxso1Kslqnv8d4XVWCha/test/"
        },
        {
            "key": "5xZjIQp6GA9fpxso1Kslqnv8d4XVWCha/",
            "channel": "test",
            "options": None,
            "expected": "5xZjIQp6GA9fpxso1Kslqnv8d4XVWCha/test/"
        },
        {
            "key": "5xZjIQp6GA9fpxso1Kslqnv8d4XVWCha/",
            "channel": "test/",
            "options": None,
            "expected": "5xZjIQp6GA9fpxso1Kslqnv8d4XVWCha/test/"
        },
        # With options.
        {
            "key": "5xZjIQp6GA9fpxso1Kslqnv8d4XVWCha",
            "channel": "test",
            "options": {Client.with_ttl(5)},
            "expected": "5xZjIQp6GA9fpxso1Kslqnv8d4XVWCha/test/?ttl=5"
        },
        # The following test won't always work, since the enumeration of the options vary in order.
        #{"key": "5xZjIQp6GA9fpxso1Kslqnv8d4XVWCha", "channel": "test", "options": {Client.with_ttl(5), Client.without_echo()}, "expected": "5xZjIQp6GA9fpxso1Kslqnv8d4XVWCha/test/?ttl=5&me=0"}
    ]

    for test in tests:
        formatted = Client._format_channel(key=test["key"],
                                           channel=test["channel"],
                                           options=test["options"])
        assert formatted == test["expected"]
Exemplo n.º 4
0
    def mutate(self, info, testing_id, mqtt_host, mqtt_port):
        '''
            Function to get all objects on db and create a string to be sent
            to unbrake-local
        '''

        client = Client()

        client.connect(host=mqtt_host, port=mqtt_port, secure=False)

        testing = SubmitTesting._get_testing_info(testing_id)
        client.publish(get_secret('mqtt-writing-key'),
                       "unbrake/galpao/experiment", testing)

        return SubmitTesting(succes=testing)
Exemplo n.º 5
0
    def mutate(self, info, username, testing_id, mqtt_host, mqtt_port):
        '''
          Mutation to execute quiting
        '''
        client = Client()

        client.connect(host=mqtt_host, port=8080, secure=False)

        testing = Testing.objects.get(pk=testing_id)
        user = testing.create_by
        if user == username:
            client.publish(get_secret('mqtt-writing-key'),
                           "unbrake/galpao/quitExperiment", "VINTE MIL")

            return QuitExperiment(response="Success")
        return QuitExperiment(error="Permission denied")
Exemplo n.º 6
0
AXUDP_PORT = int(os.getenv('AXUDP_PORT') or 1234)
AXUDP_MODE = os.getenv('AXUDP_MODE') or "FM"

MQTT_SERVER = os.getenv('MQTT_SERVER') or "buildserver.hamfog.net"
MQTT_PORT = int(os.getenv('MQTT_PORT') or "44004")
MQTT_KEY = os.getenv('MQTT_KEY') or ""
MQTT_TOPIC = os.getenv('MQTT_TOPIC') or "aprs"

RECV_BUFFER_LENGTH = 1500

axudpsocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
axudpsocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

axudpsocket.bind((AXUDP_IP, AXUDP_PORT))

emitter = Client()

emitter.connect(host=MQTT_SERVER, port=MQTT_PORT, secure=False)

connected = False

emitter.on_connect = lambda: print("Connected\n\n")
connected = True
emitter.on_disconnect = lambda: print("Disconnected\n\n")
emitter.on_presence = lambda p: print("Presence message on channel: '" + str(p)
                                      + "'\n\n")
emitter.on_message = lambda m: print(
    "Message received on default handler, destined to " + m.channel + ": " + m.
    as_string() + "\n\n")
emitter.on_error = lambda e: print("Error received: " + str(e) + "\n\n")
emitter.on_me = lambda me: print("Information about Me received: " + str(me) +
Exemplo n.º 7
0
#!/usr/bin/python3
"""
For sending fake data to all unbrake/galpao subchannels,
for debugging
"""

from emitter import Client
from os import environ
from multiprocessing import Process
from random import randint
from time import sleep

PREFIX_CHANNEL = "unbrake/galpao"
FREQUENCY = 1

client = Client()

client.connect(
    host=environ.get("MQTT_HOST", default="unbrake.ml"),
    port=environ.get("MQTT_PORT", default=8080),
    secure=False
)
client.on_message = lambda m: print(str(m.channel) + m.as_string())
client.on_error = lambda m: print(e)

def publish_data(physical_quantity, subchannel, lower, upper):
    print("Sending", physical_quantity, "to", PREFIX_CHANNEL + '/' + subchannel + "...")

    while True:
        client.publish(
            environ.get("MQTT_KEY"),
Exemplo n.º 8
0
try:
    from .emitter import Client
except ImportError:
    from emitter import Client
import Tkinter
import json

emitter = Client()

root = Tkinter.Tk()

channel_key = tkinter.StringVar(root, value="8jMLP9F859oDyqmJ3aV4aqnmFZpxApvb")
#channel_key = tkinter.StringVar(root, value="aghbt67CuPawxQvoBfKZ8MpecpPoz7od")#local
channel = tkinter.StringVar(root, value="test/")
shortcut = tkinter.StringVar(root, value="a0")
text_message = tkinter.StringVar(root, value="Hello World")
share_group = tkinter.StringVar(root, value="sg")
share_group_key = tkinter.StringVar(root, value="b7FEsiGFQoSYA6qyeu1dDodFnO0ypp0f")
#share_group_key = tkinter.StringVar(root, value="Q_dM5ODuhWjaR_LNo886hVjoecvt5pMJ") #local

def connect():
	#emitter.connect(host="127.0.0.1", port=8080, secure=False)
	emitter.connect()

	emitter.on_connect = lambda: result_text.insert("0.0", "Connected\n\n")
	emitter.on_disconnect = lambda: result_text.insert("0.0", "Disconnected\n\n")
	emitter.on_presence = lambda p: result_text.insert("0.0", "Presence message: '" + p.as_string() + "'\n\n")
	emitter.on_message = lambda m: result_text.insert("0.0", "Message received on default handler, destined to " + m.channel + ": " + m.as_string() + "\n\n")
	emitter.on_error = lambda e: result_text.insert("0.0", "Error received: " + str(e) + "\n\n")
	emitter.on_me = lambda me: result_text.insert("0.0", "Information about Me received: " + str(me) +"\n\n")
	emitter.loop_start()
Exemplo n.º 9
0
#!/usr/bin/python3
"""
For getting data from all unbrake/galpao subchannels,
for debugging
"""

from emitter import Client
from os import environ
from time import sleep

FREQUENCY = 1

client = Client()

client.connect(host=environ.get("MQTT_HOST", default="unbrake.ml"),
               port=environ.get("MQTT_PORT", default=8080),
               secure=False)
client.on_message = lambda m: print(str(m.channel) + m.as_string())
client.on_error = lambda m: print(e)
client.subscribe(environ.get("MQTT_KEY"), "unbrake/galpao/a/")

while True:
    client.loop_start()
    sleep(1 / FREQUENCY)
Exemplo n.º 10
0
    from .emitter import Client
except ImportError:
    from emitter import Client


def on_connect():
    print("CONNECTED")


def on_keygen(key):
    print("KEYGEN", key)


# secret key: aPr4nH0j7tzdi-d6nMToQOb95D9roTKg
if __name__ == "__main__":
    emitter = Client()

    emitter.connect(host="127.0.0.1", port=8080, secure=False)
    emitter.on_connect = lambda: print("Connected\n\n")
    emitter.subscribe(
        "NgFv_zrSsRznDwjdngZ77wwsP3NEzQeX",
        "parking/occupancy/",
        optional_handler=lambda m: print(
            "Message received on handler for parking/occupancy/: " + m.
            as_string() + "\n\n"))

    emitter.loop_start()

    while True:
        time.sleep(1)