Hi Sven, thanks you so much for the reply!
I tried using the exit() function but it did no purpose to the code and I did not use RevPiPyLoad as I am using HTTP instead of MQTT. As for the values, it changes in the piTest but not in the program.
The naming was given by the pictory and is running under the Boolean type.
The following is the code I am currently working with please take a look.
#!/usr/bin/python
import random
import requests
import time
import revpimodio2
import os
import uuid
import subprocess
from subprocess import PIPE, Popen
revpi = revpimodio2.RevPiModIO(autorefresh=True)
input_value = float(revpi.io.Input_Bit_4.value)
scan_value = float(revpi.io.Input_Bit_4.value)
rada_value = float(revpi.io.Input_Bit_5.value)
TOKEN = "BBFF-cBDjtysoQbVrWDaejfaGm6fDCR7ovo" # Assign your Ubidots TOKEN
DELAY = 3 # Set the delay desired to post the data
s = requests.Session()
s.headers.update({'x-test': 'true'})
def build_json(variable_1, value_1, variable_2, value_2, variable_3, value_3, variable_4, value_4, variable_5, value_5, variable_6, value_6):
try:
data = {variable_1: value_1, variable_2: value_2, variable_3: value_3, variable_4: value_4, variable_5: value_5, variable_6: value_6}
return data
except:
return None
def post_variable(device, value_1, value_2, value_3, value_4, value_5, value_6):
try:
url = "
https://industrial.api.ubidots.com/api/v1.6/devices/" + device
headers = {"X-Auth-Token": TOKEN, "Content-Type": "application/json"}
data = build_json("temperature", value_1, "light", value_2, "voltage",value_3, "Scanner", value_4, "Radar", value_5, "E-Stop", value_6)
response = requests.post(url=url, headers=headers, json=data)
return response.json()
except:
pass
def ubidots_light():
if input_value == 1:
light_value = True
else:
light_value = False
print("Input: ",input_value)
print("Ubi Light: ",light_value)
print("-"*20)
return light_value
def measure_temp():
temp = os.popen("vcgencmd measure_temp").readline()
temp1 = temp.replace("temp=","")
temp_value = temp1.replace("'C","")
print(temp1)
return temp_value
def measure_volts():
volt = os.popen("vcgencmd measure_volts core").readline()
volt1 = volt.replace("volt=","")
volt_value = volt1.replace("V","")
print(volt1)
return volt_value
def scanner (scan_value):
if scan_value == 1:
scanner_value = True
else:
scanner_value = False
print("Scanner: ",scan_value)
print("Scanner Indicator: ",scanner_value)
print("-"*20)
return scanner_value
def radar (rada_value):
if rada_value == 1:
radar_value = True
else:
radar_value = False
print("Radar: ",rada_value)
print("Radar Indicator: ",radar_value)
print("-"*20)
return radar_value
def e_stop (e_value):
if e_value == 1:
estop_value = True
else:
estop_value = False
print("E-Stop: ",e_value)
print("E-Stop Indicator: ",estop_value)
print("-"*20)
return estop_value
if __name__ == "__main__":
device_mac = ':'.join(['{:02x}'.format((uuid.getnode() >> ele) & 0xff) for ele in range(0,8*6,8)][::-1])
while True:
e_value = random.randint(0,1)
scanner_value = scanner(scan_value)
radar_value = radar(rada_value)
estop_value = e_stop(e_value)
temp_value = measure_temp()
light_value = ubidots_light()
volt_value = measure_volts()
time.sleep(DELAY)
post_variable(device_mac, temp_value, light_value, volt_value, scanner_value, radar_value, estop_value)
exit()
Please enlighten me with your help and I am truly grateful
Regards,
Yvonne