Skip to content
Snippets Groups Projects
Commit e4b2cfe7 authored by ft-Demo's avatar ft-Demo
Browse files

commit by robo pro coding

parents
Branches master
No related tags found
No related merge requests found
{"name":"IoT_MQTT_Barometer","mode":"ADVANCED","uuid":"70df319e-8306-f6c2-1be5-df84a2ba4b08"}
\ No newline at end of file
This diff is collapsed.
import json
import math
import time
from datetime import datetime
from fischertechnik.mqtt.Client import Client as MqttClient
from fischertechnik.mqtt.Constants import CONTROLLER_ID
from lib.controller import *
from lib.display import *
h = None
ts = None
pressure = None
temperature = None
humidity = None
p0 = None
def datetimestamp():
global h, ts, pressure, temperature, humidity, p0
ts = datetime.now().strftime("%Y-%m-%dT%H:%M:%S.%f")[:-3] + "Z"
return ts
h = 125
MqttClient.getInstance().connect()
while True:
if (MqttClient.getInstance().is_connected()):
break
time.sleep(0.010)
while True:
pressure = TXT_M_I2C_1_environment_sensor.get_pressure()
temperature = TXT_M_I2C_1_environment_sensor.get_temperature()
humidity = TXT_M_I2C_1_environment_sensor.get_humidity()
display.set_attr("humidity.text", str(''.join([str(x) for x in ['Humidity: ', round(humidity, 1), ' %']])))
display.set_attr("temperature.text", str(''.join([str(x2) for x2 in ['Temperature: ', round(temperature, 1), ' °C']])))
p0 = (((temperature + 273.15) + 0.0065 * h) / (temperature + 273.15)) ** 5.255 * pressure
display.set_attr("pressure.text", str(''.join([str(x3) for x3 in ['Pressure: ', round(pressure, 1), ' hPa (', round(p0, 1), ' hPa to NN)']])))
if p0 < 980:
display.set_attr("forecast.text", str('Forecast: Rain'))
elif p0 > 1020:
display.set_attr("forecast.text", str('Forecast: Fair'))
else:
display.set_attr("forecast.text", str('Forecast: Change'))
MqttClient.getInstance().publish("/j1/txt/" + str(CONTROLLER_ID) +"/i/bme680", '{{"ts":"{}","t":{},"h":{},"p":{}}}'.format(datetimestamp(), TXT_M_I2C_1_environment_sensor.get_temperature(), TXT_M_I2C_1_environment_sensor.get_humidity(), TXT_M_I2C_1_environment_sensor.get_pressure()))
time.sleep(1)
<xml xmlns="https://developers.google.com/blockly/xml" version="12">
<block type="txt4_controller" id="bx`~@dS+oeG-#2C{_P6k" x="0" y="0">
<mutation>
<arg type="Input" name="Input-0" value="-"/>
<arg type="Output" name="Output-0" value="-"/>
<arg type="Motor" name="Motor-0" value="-"/>
<arg type="Servomotor" name="Servomotor-0" value="-"/>
<arg type="Counter" name="Counter-0" value="-"/>
<arg type="I2C" name="I2C-0" value="I2C_1"/>
<arg type="I2C" name="I2C-1" value="-"/>
<arg type="USB" name="USB-0" value="-"/>
</mutation>
<field name="mode">0</field>
<field name="controller_name">TXT</field>
<field name="Input-0">-</field>
<field name="Output-0">-</field>
<field name="Motor-0">-</field>
<field name="Servomotor-0">-</field>
<field name="Counter-0">-</field>
<field name="I2C-0">I2C_1</field>
<field name="I2C-1">-</field>
<field name="USB-0">-</field>
<value name="I2C-0">
<block type="environment_sensor" id="^[+fFmp-$M]:Q@3|$^i]"/>
</value>
</block>
</xml>
\ No newline at end of file
import fischertechnik.factories as txt_factory
txt_factory.init()
txt_factory.init_i2c_factory()
TXT_M = txt_factory.controller_factory.create_graphical_controller()
TXT_M_I2C_1_environment_sensor = txt_factory.i2c_factory.create_environment_sensor(TXT_M, 1)
txt_factory.initialized()
\ No newline at end of file
import os
import time
import threading
import signal
import ftgui
display = ftgui.fttxt2_gui_connector("app")
display.open()
def display_monitoring():
while display.is_open():
time.sleep(1)
os.kill(os.getpid(), signal.SIGTERM)
exit()
threading.Thread(target=display_monitoring, daemon=True).start()
// auto generated content from display configuration
import QtQuick 2.2
import QtQuick.Window 2.0
import QtQuick.Controls 1.1
import QtQuick.Controls.Styles 1.1
import QtQuick.Extras 1.4
TXTWindow {
Rectangle {
id: rect
color: "grey"
anchors.fill: parent
}
TXTLabel {
id: txt_label
text: "Meteorological Station"
font.pixelSize: 16
elide: Text.ElideRight
x: 20
y: 20
width: 200
height: 20
}
TXTLabel {
id: humidity
text: "Humidity: - %"
font.pixelSize: 16
elide: Text.ElideRight
x: 20
y: 60
width: 200
height: 20
}
TXTLabel {
id: temperature
text: "Temperature: - °C"
font.pixelSize: 16
elide: Text.ElideRight
x: 20
y: 100
width: 200
height: 20
}
TXTLabel {
id: pressure
text: "Pressure: - hPa"
font.pixelSize: 16
elide: Text.ElideRight
x: 20
y: 140
width: 200
height: 20
}
TXTLabel {
id: forecast
text: "Forecast: -"
font.pixelSize: 16
elide: Text.ElideRight
x: 20
y: 180
width: 200
height: 20
}
}
<xml type="display" version="2"><item id="2" class="TXTLabel"><name>txt_label</name><text>Meteorological Station</text><geometry><x>20</x><y>20</y><width>200</width><height>20</height></geometry></item><item id="3" class="TXTLabel"><name>humidity</name><text>Humidity: - %</text><geometry><x>20</x><y>60</y><width>200</width><height>20</height></geometry></item><item id="4" class="TXTLabel"><name>temperature</name><text>Temperature: - °C</text><geometry><x>20</x><y>100</y><width>200</width><height>20</height></geometry></item><item id="5" class="TXTLabel"><name>pressure</name><text>Pressure: - hPa</text><geometry><x>20</x><y>140</y><width>200</width><height>20</height></geometry></item><item id="6" class="TXTLabel"><name>forecast</name><text>Forecast: -</text><geometry><x>20</x><y>180</y><width>200</width><height>20</height></geometry></item></xml>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment