PartsPC: Difference between revisions

From NURDspace
mNo edit summary
No edit summary
Line 9: Line 9:
|Category=
|Category=
}}
}}
= What =
Workstation in Zaal 2. It has a barcode scanner which can be used for [[Parts|Partkeepr]].
Workstation in Zaal 2. It has a barcode scanner which can be used for [[Parts|Partkeepr]].
= Auto shutdown =
We want this machine to shutdown when space is closed. We check MQTT for this in a simple python script. We use paho, so let's install that:
<code>apt-get install python-paho-mqtt</code>
Normally the script would ask for a password to execute the shutdown command. We can avoid this with following line in /etc/sudoers (use visudo for this):
<code>hark harktv =NOPASSWD: /bin/systemctl poweroff</code>
Now we just run a cronjob every 5 minutes:
<code>*/5 * * * * ~/space_status_shutdown.py</code>
The script:
<code>
#!/usr/bin/env python
#2019 The_Niz
#checks space status and shuts machine down if space is closed
import paho.mqtt.client as mqtt
import os
# The callback for when the client receives a CONNACK response from the server.
def on_connect(client, userdata, flags, rc):
    if rc==0:
        client.connected_flag=True #set flag
        print("Connected with result code "+str(rc))
    else:
        print("Bad connection Returned code=",rc)
    client.subscribe("space/state")
# The callback for when a PUBLISH message is received from the server.
def on_message(client, userdata, msg):
    print(msg.topic+" "+str(msg.payload))
    if msg.payload=="False":
        print("Space is uit")
        os.system('sudo /bin/systemctl poweroff')
    else:
        print("Space is aan")
    client.loop_stop()
    client.disconnect()
client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message
client.connect("arbiter.vm.nurd.space", 1883, 60)
client.loop_forever()
</code>

Revision as of 00:31, 6 January 2019

HarkTV
IMG 20190105 215626.jpg
Owner Space
Status Working
Hostname harktv.dhcp.nurd.space
Location Zaal 2
Tool No
Tool category

HarkTV

IMG 20190105 215626.jpg {{{InventoryOwner}}}Property "Tool Owner" (as page type) with input value "{{{InventoryOwner}}}" contains invalid characters or is incomplete and therefore can cause unexpected results during a query or annotation process. Zaal 2

What

Workstation in Zaal 2. It has a barcode scanner which can be used for Partkeepr.

Auto shutdown

We want this machine to shutdown when space is closed. We check MQTT for this in a simple python script. We use paho, so let's install that:

apt-get install python-paho-mqtt

Normally the script would ask for a password to execute the shutdown command. We can avoid this with following line in /etc/sudoers (use visudo for this):

hark harktv =NOPASSWD: /bin/systemctl poweroff

Now we just run a cronjob every 5 minutes:

*/5 * * * * ~/space_status_shutdown.py

The script:

  1. !/usr/bin/env python
  2. 2019 The_Niz
  3. checks space status and shuts machine down if space is closed

import paho.mqtt.client as mqtt import os

  1. The callback for when the client receives a CONNACK response from the server.

def on_connect(client, userdata, flags, rc):

   if rc==0:
       client.connected_flag=True #set flag
       print("Connected with result code "+str(rc))
   else:
       print("Bad connection Returned code=",rc)
   client.subscribe("space/state")
  1. The callback for when a PUBLISH message is received from the server.

def on_message(client, userdata, msg):

   print(msg.topic+" "+str(msg.payload))
   if msg.payload=="False":
       print("Space is uit")
       os.system('sudo /bin/systemctl poweroff')
   else:
       print("Space is aan")
   client.loop_stop()
   client.disconnect()

client = mqtt.Client() client.on_connect = on_connect client.on_message = on_message

client.connect("arbiter.vm.nurd.space", 1883, 60) client.loop_forever()