server_fan script¶
Central IoT server, fan manageer, and MQTT coordinator.
Script provides following functionalities:
- Script manages a fan attached to a GPIO pin for cooling the system on the basis of the system temperature provided by the SoC.
- Script acts as a MQTT coordinator utilizing local MQTT broker
mosquittofor data exchange within the script as well as with outside environment. - Script communicates with cloud services
ThingSpeakandBlynk. - Script publishes system temperature and fan status (running, idle) to all
three platforms:
local MQTT broker,ThingSpeak cloud,Blynk mobile application. - Script can receive commands from local MQTT broker and from Blynk mobile app in order to change its behaviour during runnig, e.g., turn on or off the fan, change fan trigger temperatures, etc.
-
server_fan.action_fan(command, value=None)[source]¶ Perform command for the fan.
Parameters: - command (str) – Action name to be realized.
- value – Any value that the action should be realized with.
-
server_fan.action_script(command)[source]¶ Perform command for this script itself.
Parameters: command (str) – Received command to be realized: {"EXIT"}.
-
server_fan.blynk_publish_fan_limits()[source]¶ Publish fan temperature percentages to Blynk mobile application.
-
server_fan.blynk_publish_fan_percoff()[source]¶ Publish fan temperature percentage OFF to Blynk mobile application.
-
server_fan.blynk_publish_fan_percon()[source]¶ Publish fan temperature percentage ON to Blynk mobile application.
-
server_fan.cbBlynk_on_connect()[source]¶ Process actions when the script is connected to Blynk cloud.
-
server_fan.cbMqtt_on_connect(client, userdata, flags, rc)[source]¶ Process actions when the broker responds to a connection request.
Parameters: - client (object) – MQTT client instance for this callback.
- userdata – The private user data.
- flags (dict) – Response flags sent by the MQTT broker.
- rc (int) – The connection result (result code).
See also
gbj_pythonlib_sw.mqtt._on_connect()- Description of callback arguments for proper utilizing.
-
server_fan.cbMqtt_on_disconnect(client, userdata, rc)[source]¶ Process actions when the client disconnects from the broker.
Parameters: - client (object) – MQTT client instance for this callback.
- userdata – The private user data.
- rc (int) – The connection result (result code).
See also
gbj_pythonlib_sw.mqtt._on_connect()- Description of callback arguments for proper utilizing.
-
server_fan.cbMqtt_on_message(client, userdata, message)[source]¶ Process actions when a non-filtered message has been received.
Parameters: - client (object) – MQTT client instance for this callback.
- userdata – The private user data.
- message (object) – An instance of
MQTTMessage. This is a class with members topic, payload, qos, retain.
Notes
- The topic that the client subscribes to and the message does not match an existing topic filter callback.
- Use message_callback_add() to define a callback that will be called for specific topic filters. This function serves as fallback when none topic filter matched.
-
server_fan.cbMqtt_on_message_command(client, userdata, message)[source]¶ Process server command at receiving a message from the command topic(s).
Parameters: - client (object) – MQTT client instance for this callback.
- userdata – The private user data.
- message (object) – An instance of
MQTTMessage. This is a class with members topic, payload, qos, retain.
Notes
- The topic that the client subscribes to and the message match the topic filter for server commands.
-
server_fan.cbMqtt_on_message_data(client, userdata, message)[source]¶ Process server data send through a MQTT topic(s).
Parameters: - client (object) – MQTT client instance for this callback.
- userdata – The private user data.
- message (object) – An instance of
MQTTMessage. This is a class with members topic, payload, qos, retain.
-
server_fan.cbMqtt_on_subscribe(client, userdata, mid, granted_qos)[source]¶ Process actions when the broker responds to a subscribe request.
Parameters: - client (object) – MQTT client instance for this callback.
- userdata – The private user data.
- mid (int) – The message ID from the subscribe request.
- granted_qos (int) – The list of integers that give the QoS level the broker has granted for each of the different subscription requests.
-
server_fan.mqtt_message_log(message)[source]¶ Log receiving from a MQTT topic.
Parameters: message (str) – An instance of MQTTMessage. This is a class with members topic, payload, qos, retain.Returns: Flag about present message payload. Return type: bool See also
gbj_pythonlib_sw.mqtt()- Module for MQTT processing.
-
server_fan.mqtt_publish_fan_limits()[source]¶ Publish fan temperature percentages to the MQTT status topic.
-
server_fan.mqtt_publish_fan_percoff()[source]¶ Publish fan temperature percentage OFF to the MQTT status topic.
-
server_fan.mqtt_publish_fan_percon()[source]¶ Publish fan temperature percentage ON to the MQTT status topic.
-
server_fan.setup_mqtt_filters()[source]¶ Define MQTT topic filters and subscribe to them.
Notes
- The function is called in on_connect callback function after successful connection to a MQTT broker.
-
server_fan.setup_pi()[source]¶ Define GPIO control.
Notes
- Operational pin names are stored in the object as attributes.
- Default fan percentage limits are stored in the object as attributes.