Beispiel #1
0
def main():
    global mqclient
    mqclient = MQTTClient(board.location, board.mqtt_server, ssl=True,
            ssl_params={'psk_ident':board.mqtt_ident, 'psk_key':board.mqtt_key})
    print("Connect:", mqclient.connect())

    mqclient.set_callback(msg_in)
    mqclient.subscribe(REPL_IN)
    print("Subscribed to", REPL_IN)
Beispiel #2
0
# http("http://192.168.1.133:8000/configuration/room/setpoint/update", "POST", JSON.stringify({"sensor":currentSensorSelection, "setpoint":currentSetpointValue, "time":time}))

import requests, random, time, json
from mqtt_client import Receiver, MQTTClient


class OnReceive(Receiver):
    def on_message(self, client, userdata, message):
        msg = str(time.time()) + "," + str(message.payload.decode("utf-8"))
        print(msg)


receiver = OnReceive()
client = MQTTClient(receiver, 'latency_tester')
client.subscribe('latency/response')

try:
    client.start_loop()

    timer = time.time()
    update = 1 / 1000
    sender = 0
    while True:
        t1 = time.time()
        t0 = t1 - timer
        if t0 >= update:
            print(str(time.time()) + ",send," + str(sender))
            requests.post(
                'http://192.168.1.133:8000/configuration/room/setpoint/update',
                data=json.dumps({
                    "sensor": '30:AE:A4:DF:9A:6C',
Beispiel #3
0
from mqtt_client import MQTTClient
import ssl
import json
import paho.mqtt.client as mqtt

with open("config/config.json", "r") as load_f:
    parameter = json.load(load_f)

cli = MQTTClient(parameter["host"], parameter["port"])

cli.tls_set(parameter["ca_cert"], parameter["certfile"], parameter["keyfile"])

cli.on_log

cli.connect(parameter["username"], parameter["password"])

cli.on_connect

cli.subscribe(parameter["topic0"])

cli._on_message

cli.loop()
Beispiel #4
0
        msg = str(message.payload.decode("utf-8"))

        if message.topic == sensor_name + '/room/config':
            msg = json.loads(msg)
            room_name = msg['room']
            update_config(msg)
            print(msg)


# get_room_data()
receiver = OnReceive()
client = MQTTClient(receiver)

client.start_loop()

client.subscribe(sensor_name + '/room/config')

if room_name is None:
    client.publish('sensor/registration', sensor_name + '/temperature')
    client.publish('sensor/registration', sensor_name + '/humidity')
    client.publish('sensor/registration', sensor_name + '/lux')

try:
    while True:
        if room_name != None:

            temperature = str(get_temperature())
            humidity = str(get_humidity())
            lux = str(get_lux())
            client.publish(
                sensor_name + '/temperature',