Exemplo n.º 1
0
def send(message, contact):
    data = config.my_data.find("data", "all")[0]
    target = config.nodes.find("nodes", {"address": contact})[0]
    address = data['address']
    stamp = time.time()
    config.cache.insert("sent", {
        "message": message,
        "contact": contact,
        "time": stamp
    })
    config.cache.save()
    public_key = filter(None, re.findall("[0-9]*", target['publickey'])
                        )  #Safe way of extracting the public key from a string
    public_key = PublicKey(int(public_key[0]),
                           int(public_key[1]))  # Re build public key
    key = uuid.uuid4().hex  # Generate AES key
    k = encrypt(
        key,
        public_key)  #Encrypt the key with the RSA public key of the target
    k = base64.b64encode(k)  #Encode the encrypted data
    message = base64.b64encode(aes.encryptData(
        key,
        message))  #Encrypt the message with the AES key and then encode it
    broadcast.send(
        {
            "cmd": "send_message",
            "message": message,
            "contact": contact,
            "address": address,
            "key": k,
            "time": stamp
        }, False)  #Broadcast the message
Exemplo n.º 2
0
def connected(client, userdata, flags, rc):
    # This function will be called when the client is connected
    # successfully to the broker.
    for item in subscribes:
        client.subscribe(subscribes[item])
        broadcast.send(
            "Connected to {0}! Listening for topic changes on {1}".format(
                secrets["mqtt_broker"], subscribes[item]))
Exemplo n.º 3
0
def stop():
    global countdown
    broadcast.send("stop")
    lspeed = 0.0
    rspeed = 0.0
    mleft.throttle = 0.0
    mright.throttle = 0.0
    countdown = 0
Exemplo n.º 4
0
def main():

	message_handler1 = MessageHandler()
	message_handler1.read_message(SLAVE_PORT)
	time.sleep(1)
	broadcast.send('hei, dette er heis1',SLAVE_PORT)
	broadcast.send('heis1 er sulten',SLAVE_PORT)
	time.sleep(1)
	print message_handler1.read_message(SLAVE_PORT)
	print message_handler1.read_message(SLAVE_PORT)
Exemplo n.º 5
0
def send():
    data = config.my_data.find("data", "all")[0]
    broadcast.send(
        {
            "cmd": "register",
            "publickey": data["publickey"],
            "port": config.port,
            "relay": config.relay,
            "address": data["address"]
        }, False)
Exemplo n.º 6
0
def main():

    message_handler1 = MessageHandler()
    message_handler1.read_message(SLAVE_PORT)
    time.sleep(1)
    broadcast.send('hei, dette er heis1', SLAVE_PORT)
    broadcast.send('heis1 er sulten', SLAVE_PORT)
    time.sleep(1)
    print message_handler1.read_message(SLAVE_PORT)
    print message_handler1.read_message(SLAVE_PORT)
Exemplo n.º 7
0
def send(message, contact):
    data = config.my_data.find("data", "all")[0]
    target = config.nodes.find("nodes", {"address":contact})[0]
    address = data['address']
    stamp = time.time()
    config.cache.insert("sent", {"message":message, "contact":contact, "time":stamp})
    config.cache.save()
    public_key = filter(None, re.findall("[0-9]*", target['publickey'])) #Safe way of extracting the public key from a string
    public_key = PublicKey(int(public_key[0]), int(public_key[1])) # Re build public key
    key = uuid.uuid4().hex  # Generate AES key
    k = encrypt(key, public_key) #Encrypt the key with the RSA public key of the target
    k = base64.b64encode(k) #Encode the encrypted data
    message = base64.b64encode(aes.encryptData(key, message)) #Encrypt the message with the AES key and then encode it
    broadcast.send({"cmd":"send_message", "message":message, "contact":contact, "address":address, "key":k, "time":stamp}, False) #Broadcast the message
Exemplo n.º 8
0
def main():
    message_handler = MessageHandler()
    old_message = "this message will never be sent"
    while True:
        (floor, button) = message_handler.read_message(SLAVE_TO_MASTER_PORT)

        time.sleep(0.01)
        '''
		Do some massive shit and calculations

		'''

        if (floor and button) is not None:
            message = "%s,%s" % (floor, button)
            if message != old_message:
                broadcast.send(message, MASTER_TO_SLAVE_PORT)
Exemplo n.º 9
0
def main():
	message_handler = MessageHandler()
	old_message = "this message will never be sent"
	while True:
		(floor,button) = message_handler.read_message(SLAVE_TO_MASTER_PORT)

		time.sleep(0.01) 
		'''
		Do some massive shit and calculations

		'''

		if (floor and button) is not None:
			message = "%s,%s" % (floor,button) 
			if message != old_message:
				broadcast.send(message,MASTER_TO_SLAVE_PORT)
Exemplo n.º 10
0
def main():
    message_handler = MessageHandler()
    elevator_driver = ElevatorDriver()
    elevator_driver.start()
    old_message = 12345678
    while True:

        (master_floor, master_button) = elevator_driver.pop_button_queue()
        if (master_floor and master_button) is not None:
            message = "%i,%i" % (master_floor, master_button)
            if message != old_message:
                broadcast.send(message, SLAVE_TO_MASTER_PORT)
            time.sleep(0.001)

        (floor, button) = message_handler.read_message(MASTER_TO_SLAVE_PORT)
        if (floor and button) is not None:
            floor = int(floor)
            button = int(button)
            elevator_driver.queue_floor_button_run(floor, button)
Exemplo n.º 11
0
def main():
	message_handler = MessageHandler()
	elevator_driver = ElevatorDriver()
	elevator_driver.start()
	old_message = 12345678
	while True:

		(master_floor, master_button) = elevator_driver.pop_button_queue()
		if (master_floor and master_button) is not None:
			message = "%i,%i" % (master_floor,master_button)
			if message != old_message:
				broadcast.send(message,SLAVE_TO_MASTER_PORT)
			time.sleep(0.001)

		(floor, button) = message_handler.read_message(MASTER_TO_SLAVE_PORT)
		if (floor and button) is not None:
			floor = int(floor)
			button = int(button)
			elevator_driver.queue_floor_button_run(floor, button)
Exemplo n.º 12
0
def send(address):
    out = broadcast.send({
        "cmd": "is_online",
        "address": address
    },
                         False,
                         output_as_array=True)
    if out:
        return True
    else:
        return False
Exemplo n.º 13
0
def move(left=0.0, right=0.0, duration=COUNTDOWN):
    if MOTORS:
        global countdown
        global lspeed
        global rspeed
        broadcast.send("Move: {:.2f}.{:.2f}".format(left, right))
        if left > MAX_SPEED:
            lspeed = MAX_SPEED
        elif left < (MAX_SPEED * -1):
            lspeed = MAX_SPEED * -1
        else:
            lspeed = left
        if right > MAX_SPEED:
            rspeed = MAX_SPEED
        elif right < (MAX_SPEED * -1):
            rspeed = MAX_SPEED * -1
        else:
            rspeed = right

        countdown = duration
Exemplo n.º 14
0
def main():
	#floorDestination = int(raw_input("->"))

	panel1 = Panel()
	message_handler1 = MessageHandler()
	order_list = []

	panel1.read_button()
	message_handler1.read_message()

	time.sleep(1)


	broadcast.send('hei, dette er heis1')
	broadcast.send('heis1 er sulten')

	

	time.sleep(1)
	Pukk = 1
	while Pukk < 100:
		message = message_handler1.read_message()
		button = panel1.read_button()
		if message is not None:
			order_list.append(message)
		if button is not None:
			order_list.append(button)
			broadcast.send(button)
		Pukk += 1



	
	print order_list	
Exemplo n.º 15
0
def main():
    #floorDestination = int(raw_input("->"))

    panel1 = Panel()
    message_handler1 = MessageHandler()
    order_list = []

    panel1.read_button()
    message_handler1.read_message()

    time.sleep(1)

    broadcast.send('hei, dette er heis1')
    broadcast.send('heis1 er sulten')

    time.sleep(1)
    Pukk = 1
    while Pukk < 100:
        message = message_handler1.read_message()
        button = panel1.read_button()
        if message is not None:
            order_list.append(message)
        if button is not None:
            order_list.append(button)
            broadcast.send(button)
        Pukk += 1

    print order_list
Exemplo n.º 16
0
def send():
    try:
        check = len(config.nodes.find("nodes", "all"))
    except TypeError:
        config.nodes.insert("nodes", {})
        config.nodes.save()
        check = len(config.nodes.find("nodes", "all"))
    
    output = broadcast.send({"cmd":"get_nodes_count"}, True) #(to_send, output wanted)
    try:
        data = json.loads(output)
    except:
        print "Something went wrong with get_nodes_count send"
        return
    else:
        if data != "null" and data["response"] > check:
            get_nodes.send()
Exemplo n.º 17
0
def send():
    try:
        check = len(config.nodes.find("nodes", "all"))
    except TypeError:
        config.nodes.insert("nodes", {})
        config.nodes.save()
        check = len(config.nodes.find("nodes", "all"))

    output = broadcast.send({"cmd": "get_nodes_count"},
                            True)  #(to_send, output wanted)
    try:
        data = json.loads(output)
    except:
        print "Something went wrong with get_nodes_count send"
        return
    else:
        if data != "null" and data["response"] > check:
            get_nodes.send()
Exemplo n.º 18
0
def send():
    data = broadcast.send({"cmd":"get_nodes"}, True)
    with open("nodes.db", 'wb') as file:
        file.write(data)
Exemplo n.º 19
0
def message_send(master, alive):
	while True:
		if master.value == 1:
			broadcast.send('1')
		time.sleep(0.01)
Exemplo n.º 20
0
import time
import broadcast
import sys

try:
    from adafruit_crickit import crickit
    MOTORS = True
    broadcast.send("Motors initialized")
except ValueError:
    MOTORS = False
    broadcast.send("Motors not found")

MAX_SPEED = 2.0
COUNTDOWN = 60

# make two variables for the motors to make code shorter to type
if MOTORS:
    mleft = crickit.dc_motor_1
    mright = crickit.dc_motor_2

lspeed = 0.0  # speed values ->  -2 to 2
rspeed = 0.0

countdown = 0


def tick():
    if MOTORS:
        global countdown
        global mleft
        global mright
Exemplo n.º 21
0
def mkdir(path):
    folder = os.path.exists(path)
    if not folder:
        os.makedirs(path)


def get_pic(resp, path):
    pics = resp.xpath('//*[@id="content"]/div[2]/script[1]/text()')[0]
    pics = str(pics)
    pics_url = re.findall(r'src: \'(.+?\.(JPG|jpeg|jpg))\'', pics)
    for i in pics_url:
        url = base_url + i[0]
        img = requests.get(url)
        with open(path + '\\' + str(pics_url.index(i)) + '.jpg', 'wb') as f:
            f.write(img.content)


if __name__ == '__main__':
    old_listing = read()
    new_listing = get_list()
    print(set(old_listing))
    print(set(new_listing))
    new_post = list(set(new_listing).difference(set(old_listing)))
    print(new_post)
    posted(new_listing)
    for i in new_post:
        print(i)
        get_detail(i)
        broadcast.send(i)
Exemplo n.º 22
0
def message_send():
	global master
	while True:
		if master == 'True':
			broadcast.send('True')
		time.sleep(0.01)
Exemplo n.º 23
0
import time
import broadcast
import wifimqtt as mqtt
import motors

# import servos
import sensors
# import motion

# Setup
mqtt.initialize("Percy", motors.mqttReceiveCommand)

broadcast.send("Setup complete.")
# mqtt.publishMessage("roger/status/feather", "Susan has connected to Roger")


def quickLoop():
    motors.tick()
    # sensors.tick()


def slowLoop():
    mqtt.checkMessages()


def to_seconds(nanoseconds):
    return nanoseconds / nanosecsPerSec


# Main Loop
# Each loop iteration is 1 second
Exemplo n.º 24
0
def send():
    data = broadcast.send({"cmd": "get_nodes"}, True)
    with open("nodes.db", "wb") as file:
        file.write(data)
Exemplo n.º 25
0
def message(client, topic, message):
    # This method is called when a topic the client is subscribed to
    # has a new message.
    broadcast.send("New message on topic {0}: {1}".format(topic, message))
    subscribe_funcs[topic](message)
Exemplo n.º 26
0
def initialize(myName, motorFunc):

    robotName = myName
    esp32_cs = DigitalInOut(board.D13)
    esp32_ready = DigitalInOut(board.D11)
    esp32_reset = DigitalInOut(board.D12)

    spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
    esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready,
                                           esp32_reset)

    if esp.status == adafruit_esp32spi.WL_IDLE_STATUS:
        broadcast.send("ESP32 found")
    """Use below for Most Boards"""
    status_light = neopixel.NeoPixel(
        board.NEOPIXEL, 1, brightness=0.2)  # Uncomment for Most Boards

    wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(
        esp, secrets, status_light)

    ### Feeds ###
    publishes["status"] = "{}/status".format(robotName)
    subscribes["motor"] = "{}/cmd/motor".format(robotName)
    subscribe_funcs["{}/cmd/motor".format(robotName)] = motorFunc
    subscribes["beep"] = "{}/cmd/beep".format(robotName)
    subscribes["servo"] = "{}/cmd/servo".format(robotName)

    # Connect to WiFi
    broadcast.send("Connecting to WiFi...")
    try:
        wifi.connect()
        broadcast.send("Connected!")
    except:
        broadcast.send("Could not connect")
        raise

    # Initialize MQTT interface with the esp interface
    minimqtt.set_socket(socket, esp)

    # Set up a MiniMQTT Client
    global mqtt_client
    mqtt_client = minimqtt.MQTT(
        broker=secrets["mqtt_broker"],
        port=1883,
    )

    # Setup the callback methods above
    mqtt_client.on_connect = connected
    mqtt_client.on_disconnect = disconnected
    mqtt_client.on_message = message

    # Connect the client to the MQTT broker.
    broadcast.send("Connecting to MQTT Broker {}...".format(
        secrets["mqtt_broker_name"]))
    mqtt_client.connect()

    broadcast.send("MQTT initialized")
    global MQTT
    MQTT = True
Exemplo n.º 27
0
def disconnected(client, userdata, rc):
    # This method is called when the client is disconnected
    broadcast.send("Disconnected from {}!".format(secrets["mqtt_broker_name"]))
Exemplo n.º 28
0
def send():
    data = config.my_data.find("data", "all")[0]
    broadcast.send({"cmd":"register", "publickey":data["publickey"], "port":config.port, "relay":config.relay, "address":data["address"]}, False)
Exemplo n.º 29
0
import broadcast

message = raw_input("->")
while message != 'q':
	broadcast.send(message)
	message = raw_input("->")



Exemplo n.º 30
0
def send(address):
    out = broadcast.send({"cmd":"is_online", "address":address}, False, output_as_array=True)
    if out:
        return True
    else:
        return False
Exemplo n.º 31
0
import time
import broadcast
# import wifimqtt as mqtt
import motors
import WiFi

# import servos
import sensors
# import motion
import triggers

# Setup
# mqtt.initialize("Percy", motors.mqttReceiveCommand)
# WiFi.initialize(motors.receive_command)

broadcast.send("Setup complete.")
# mqtt.publishMessage("roger/status/feather", "Susan has connected to Roger")


def quickLoop():
    motors.tick()
    sensors.tick()
    triggers.tick()
    # pass


def slowLoop():
    # mqtt.checkMessages()
    WiFi.tick()
    # pass