def notify_particle():
# The particle device gets notified about changes here
peak_v = float(getRedisValue("peak"))
balance_v = float(getRedisValue("balance"))
# If the balance exceeds the peak/below 0, then the servo/needle might break.
# Because of this, the angle's value gets checked before sending to particle.io
if balance_v > peak_v:
balance_v = peak_v
elif balance_v < 0:
balance_v = 0
# Prevent division by zero
if peak_v <= 0:
peak_v = 1
angle_v = angle(peak_v, balance_v)
data = {"access_token": particle_token, "arg": angle_v}
requests.post("https://api.particle.io/v1/devices/{}/gotoPos".format(device_id), data=data)
return angle_v
评论列表
文章目录