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_connectmethod 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_mqttmethod is a private method that sets up a connection to the MQTT broker. It sets theon_connectcallback to theon_connectstatic method and then calls the connect and loop_start methods on the paho.mqtt.client.Client object. -
The
decode_msgmethod 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_messagemethod 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 thedecode_msgmethod on the remaining messages. -
The
_subscribemethod is a private method that subscribes the client to the specified topic and sets theon_messagecallback to theon_messagestatic method. -
The
_wait_for_varmethod 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
getmethod 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
setmethod sends a message to the MQTT broker setting the value of a specified variable. -
The
cmdmethod 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
setmethod 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
getmethod 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
getRHmethod 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
getDPmethod 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
getTempAirmethod 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
getTempWatermethod 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
saveToFlashmethod sends a message to the Tessie object to save the TEC configuration to flash memory. It returns the response from the Tessie object. -
The
getPIDmethod 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
setPIDmethod 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
getPIDMinMaxmethod 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
setPIDMinMaxmethod 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
setRefmethod 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
getRefmethod 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
setModemethod 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
getModemethod 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
clearErrormethod sends a message to the Tessie object to clear any errors on the TEC. -
The
getErrormethod 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.