2022-12-22 14:02:16 +01:00
2022-12-22 14:02:12 +01:00
2022-12-22 14:02:16 +01:00

Coldbox/Tessie Python Library via MQTT

This is a python library to controll the Coldbox/Tessie via the MQTT protol

Installation

Please install the paho-mqtt library: pip install paho-mqtt

usage

either you import the library into another script and use it there or you use it via the interactove shell. like this ->

python

from coldbox import *

box = Coldbox()

then use all functions... example: box.tecall.getTemp() -> return all temperature

Classes

Tessie

Tessie is a class that represents a client that communicates with a MQTT broker. It has several methods for interacting with the broker, including get, set, and cmd.

  • The __init__ method is the class constructor, which is called when a new Tessie object is created. It initializes several instance variables, including the MQTT broker's hostname and port, the topic to which the client will subscribe, and a paho.mqtt.client.Client object that will be used for communication with the broker. The __init__ method also sets up a connection to the MQTT broker and subscribes to the specified topic.

  • The on_connect method is a static method that is called when the client successfully connects to the MQTT broker. It simply prints a message to the console indicating that the connection was successful.

  • The _connect_mqtt method is a private method that sets up a connection to the MQTT broker. It sets the on_connect callback to the on_connect static method and then calls the connect and loop_start methods on the paho.mqtt.client.Client object.

  • The decode_msg method is a static method that processes incoming messages from the MQTT broker and stores them in the found list if they match a variable that is being waited for.

  • The on_message method is a static method that is called when the client receives a message from the MQTT broker. It filters out certain types of messages and calls the decode_msg method on the remaining messages.

  • The _subscribe method is a private method that subscribes the client to the specified topic and sets the on_message callback to the on_message static method.

  • The _wait_for_var method is a private static method that waits for a specified variable to be received from the MQTT broker. If the variable is not received within a certain timeout period, the method returns None.

  • The get method sends a message to the MQTT broker requesting the value of a specified variable and waits for a response. If a response is received, it is returned to the caller. If no response is received, the method returns False.

  • The set method sends a message to the MQTT broker setting the value of a specified variable.

  • The cmd method sends a command to the MQTT broker and, if specified, waits for a response. If a response is received, it is returned to the caller. If no response is received, the method returns None.

Valve

Valve is a class that represents a valve that can be controlled through a Tessie object. It has two methods: set and get.

  • The __init__ method is the class constructor, which is called when a new Valve object is created. It takes a Tessie object and an integer as arguments and initializes the name instance variable to "valve" followed by the integer. It also stores the Tessie object in the _tessie instance variable.

  • The set method sets the value of the valve. It takes an integer as an argument and sends a message to the Tessie object to set the valve to "on" if the integer is 1 or "off" if it is 0.

  • The get method gets the value of the valve. It sends a message to the Tessie object requesting the value of the valve and returns 1 if the value is "on" or 0 if it is "off".

Env(ironement)

Env is a class that represents an environment and provides methods for accessing environmental data through a Tessie object. It has four methods: getRH, getDP, getTempAir, and getTempWater.

  • The __init__ method is the class constructor, which is called when a new Env object is created. It takes a Tessie object as an argument and stores it in the _tessie instance variable.

  • The getRH method gets the relative humidity of the environment. It sends a message to the Tessie object requesting the value of the "RH" variable and returns it as a float.

  • The getDP method gets the dew point of the environment. It sends a message to the Tessie object requesting the value of the "DP" variable and returns it as a float.

  • The getTempAir method gets the air temperature of the environment. It sends a message to the Tessie object requesting the value of the "Temp" variable and returns it as a float.

  • The getTempWater method gets the water temperature of the environment. It sends a message to the Tessie object requesting the value of the "Temp_W" variable from TEC 8 and returns it as a float.

TEC

The TEC class has several methods that allow you to interact with a TEC (thermoelectric cooler) device:

  • pon(): This method sends a "Power_On" command to the TEC device, which turns the device on.

  • poff(): This method sends a "Power_Off" command to the TEC device, which turns the device off.

  • getState(): This method retrieves the power state of the TEC device, which indicates whether the device is currently on or off. The method returns the power state as a list of booleans.

  • getTemp(): This method retrieves the temperature of the TEC device. The method returns the temperature as a list of floats.

  • getUI(): This method retrieves various voltage and current measurements from the TEC device, including the supply voltage and current, and the Peltier voltage and current. The method returns the measurements as a list of lists of floats.

  • setTemp(temp: float): This method sets the target temperature of the TEC device. The target temperature is passed as a float parameter.

  • setVoltage(u: float): This method sets the control voltage of the TEC device. The control voltage is passed as a float parameter.

  • getVoltage(): This method retrieves the control voltage of the TEC device. The method returns the control voltage as a list of floats.

  • reset(): This method sends a "Reboot" command to the TEC device, which causes the device to reboot.

  • loadFromFlash(): This method sends a "LoadVariables" command to the TEC device, which causes the device to load variables from flash memory.

  • getSWVersion(): This method sends a "GetSWVersion" command to the TEC device, which retrieves the software version of the device.

Conftec

ConfTEC is a class that represents the configuration of a TEC (thermoelectric cooler) and provides methods for interacting with that configuration through a Tessie object. It has several methods for getting and setting various TEC configuration parameters, such as the PID control constants, reference temperature, and operating mode.

  • The __init__ method is the class constructor, which is called when a new ConfTEC object is created. It takes a Tessie object and an integer as arguments and stores the Tessie object in the _tessie instance variable. It also initializes the name instance variable to " tec " followed by the integer.

  • The saveToFlash method sends a message to the Tessie object to save the TEC configuration to flash memory. It returns the response from the Tessie object.

  • The getPID method gets the PID control constants for the TEC. It sends messages to the Tessie object requesting the values of the "PID_kp", "PID_ki", and "PID_kd" variables and returns them as lists of floats.

  • The setPID method sets the PID control constants for the TEC. It takes three floats as arguments and sends messages to the Tessie object to set the values of the "PID_kp", "PID_ki", and "PID_kd" variables.

  • The getPIDMinMax method gets the minimum and maximum values for the PID control output. It sends messages to the Tessie object requesting the values of the "PID_Min" and "PID_Max" variables and returns them as lists of floats.

  • The setPIDMinMax method sets the minimum and maximum values for the PID control output. It takes two floats as arguments and sends messages to the Tessie object to set the values of the "PID_Min" and "PID_Max" variables.

  • The setRef method sets the reference temperature for the TEC. It takes a float as an argument and sends a message to the Tessie object to set the value of the "Ref_U" variable.

  • The getRef method gets the reference temperature for the TEC. It sends a message to the Tessie object requesting the value of the "Ref_U" variable and returns it as a list of floats.

  • The setMode method sets the operating mode for the TEC. It takes an integer as an argument and sends a message to the Tessie object to set the value of the "Mode" variable.

  • The getMode method gets the operating mode for the TEC. It sends a message to the Tessie object requesting the value of the "Mode" variable and returns it as a list of integers.

  • The clearError method sends a message to the Tessie object to clear any errors on the TEC.

  • The getError method gets the error codes for the TEC. It sends a message to the Tessie object requesting the value of the "Error" variable and returns it as a list of hexadecimal strings.

Description
No description provided
Readme 37 KiB
Languages
Python 100%