And this is the code where all the sensor's input are taken in, then calculate the position by cross-referencing the above table
state = Position[0]
connected = 0
if __name__ == '__main__':
try:
if connected == 0:
client = mqtt.Client()
client.on_connect = on_connect
client.connect("test.mosquitto.org", 1883, 60)
#client.loop_forever()
connected = 1
# start timer to check each state duration
start = time.time()
for i in range(numberOfsamples):
Dictionary = [False , False , False , False ]
for j in range(len(Inputs)):
if Inputs[j][i] >= threshold[j]:
Dictionary[j] = True
print(Dictionary)
for i ,v in enumerate(Matrix):
if Dictionary == v[1]:
POS = Matrix[i][0]
print(POS, 'MATCH >> Sensor: ', i, '\n')
end = time.time()
endTime = end - start
if state != POS:
publishState(POS,endTime)
start = end
state = POS
time.sleep(0.5)
publishState("End of Session",0)
time.sleep(3)
except KeyboardInterrupt:
print("Measurement stopped by User")
publishState("End of Session",0)
time.sleep(3)
The last part is where each state is already calculated, the function below is called to send the body position to the subscribes MQTT clients
This is the Position matrix that is decided on from another issue.
And this is the code where all the sensor's input are taken in, then calculate the position by cross-referencing the above table
The last part is where each state is already calculated, the function below is called to send the body position to the subscribes MQTT clients