Beispiel #1
0
    def __init__(self, board, network, scheduler):
        self.board = board
        self.scheduler = scheduler
        self.parts_initialized = False
        self.mac = network.mac
        self.data = {}
        self.mine = None
        self.version = "0.8.0"
        self.listeners = []
        self.read_cache()
        #        if (type(self.mine) is dict and "parts" in self.mine):
        #            ct.print_heading("initializing from cache")
        #            Part.init_parts(board, scheduler, self.mine["parts"])

        Component.setup_services(board, scheduler)
        if (type(self.mine) is dict and "components" in self.mine):
            ct.print_heading("initializing from cache")
            Component.netlist_from_config(self.mine["components"])
            Component.print_netlist()
        MQTT.subscribe(config_topic_base + self.mac + "/config", self.on_mqtt)
Beispiel #2
0
            file.write("\n")
            file.close()
    elif msg.topic == "pressure":
    	with open("pressure.txt", "a") as file:
            print("Writing into pressure.txt")
            file.write(msg.payload)
            file.write("\n")
            file.close()
    else:
    	print("Not a valid topic")

# Publish a message - Client is connected
mqttc.publish(user, "Getting started ...")
mqttc.on_receive(on_message)
localtime = time.asctime(time.localtime(time.time()))

for topic in topic_list:
    mqttc.subscribe(topic)
    # Continue the network loop, exit when an error occurs
    with open(topic + ".txt", "a") as file:
        header = "-------------- Data for " + topic + ": " + localtime + " --------------"
        file.write(header)
        file.write("\n")

mqttc.loop()

# rc = 0
# while rc == 0:
#     print(str(rc))
#    rc = mqttc.loop()
#print("rc: " + str(rc))
Beispiel #3
0
 def init_param(cls, value, component, param_name):
     assert param_name == "input", "the only parameter of an input_pin must be named 'input'"
     MQTT.subscribe(value, component.callback, True)
Beispiel #4
0
            t_control.pid.Ki = float(msg)
            print(msg)
        elif "FAN" in topic:
            if msg.decode() == "OFF":
                t_control.cooler.fanOff()
            else:
                t_control.cooler.fanOn()
        elif "target_temp" in topic:
            t_control.pid.target = float(msg) 
        else:
            print("Unknown topic received")

    # setup subscriptions
    
    broker.setCallback(subCB)
    broker.subscribe("FAN")
    broker.subscribe("PID_P")
    broker.subscribe("PID_I")
    sleep(0.1)
    broker.subscribe("PID_I_SetValue")
    broker.subscribe("target_temp")
    count = 50
    # main loop
    print("reached main loop")
    while True:
        
        print(od.measure(200))
        # all repeating actions
        broker.publish("exp1.temperature",t_control.thermometer.read()) #testing
        disp.write("temperature: " + str(int(t_control.thermometer.read())),0,0)
        disp.write("Algae: " + "derp/mL",1,0)