Commit 6847bbee authored by Guilhem Saurel's avatar Guilhem Saurel
Browse files

publish temperature & throttle

parent 2535b2ee
......@@ -36,6 +36,8 @@ yarn parce src/index.html
/odri/current
/odri/energy
/odri/status
/odri/temperature
/odri/throttled
/odri/joystick
```
......
......@@ -10,6 +10,8 @@ const app = Vue.createApp({
current: '-',
energy: '-',
status: '-',
temperature: '-',
throttled: '-',
joystick: '-'
}
},
......@@ -19,7 +21,8 @@ const app = Vue.createApp({
},
onConnect() {
this.client.subscribe(['/odri/voltage', '/odri/current',
'/odri/energy', '/odri/joystick', '/odri/status']);
'/odri/energy', '/odri/joystick', '/odri/status',
'/odri/temperature', '/odri/throttled']);
},
onMessage(topic, message) {
if (topic == '/odri/voltage') {
......@@ -30,6 +33,10 @@ const app = Vue.createApp({
this.energy = message.toString();
} else if (topic == '/odri/status') {
this.status = message.toString();
} else if (topic == '/odri/temperature') {
this.temperature = message.toString();
} else if (topic == '/odri/throttled') {
this.throttled = message.toString();
} else if (topic == '/odri/joystick') {
this.joystick = message.toString();
} else {
......
......@@ -15,6 +15,8 @@
<dt class="col-sm-3">Voltage</dt><dd class="col-sm-9">{{ voltage }}</dd>
<dt class="col-sm-3">Current</dt><dd class="col-sm-9">{{ current }}</dd>
<dt class="col-sm-3">Energy</dt><dd class="col-sm-9">{{ energy }}</dd>
<dt class="col-sm-3">Temperature</dt><dd class="col-sm-9">{{ temperature }}</dd>
<dt class="col-sm-3">Throttled</dt><dd class="col-sm-9">{{ throttled }}</dd>
<dt class="col-sm-3">Joystick</dt><dd class="col-sm-9">{{ joystick }}</dd>
</dl>
<button type="button" class="btn btn-warning" v-on:click="onCommand('calibrate')">Calibrate</button>
......
#!/usr/bin/env python3
"""Export Temperature & Throttle to MQTT"""
from subprocess import check_output
from time import sleep
from paho.mqtt import client as mqtt
def temp_throt():
client = mqtt.Client()
client.connect("localhost", 1883, 60)
while True:
temperature = check_output(['vcgencmd', 'measure_temp'], text=True).split('=')[1].strip()
client.publish('/odri/temperature', temperature)
throttled = check_output(['vcgencmd', 'get_throttled'], text=True).split('=')[1].strip()
client.publish('/odri/throttled', throttled)
sleep(15)
if __name__ == '__main__':
temp_throt()
[Unit]
Description=Export Temperature and Throttling to MQTT
StartLimitIntervalSec=2
[Service]
Type=simple
Restart=always
RestartSec=5
WorkingDirectory=/home/pi/src/web-operator
ExecStart=/home/pi/src/web-operator/temp-throt.py
[Install]
WantedBy=multi-user.target
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment