#!/usr/bin/env python
import cayenne.client
import time
import logging
from MCP3008 import MCP3008
import datetime
MQTT_USERNAME = “”
MQTT_PASSWORD = “”
MQTT_CLIENT_ID = “”
TRIGGER_CHANNEL = 2
DATA_CHANNEL = 1
THRESHOLD = 200
delay = 1
i=0
i1 = 0
x = 0
minutes = 0
timestamp = 0
def on_message(message):
print("message received: " + str(message))
# If there is an error processing the message return an error string, otherwise return nothing.
client = cayenne.client.CayenneMQTTClient()
client.on_message = on_message
client.begin(MQTT_USERNAME, MQTT_PASSWORD, MQTT_CLIENT_ID)
while True:
client.loop()
time.sleep(delay)
adc = MCP3008()
sensor_value = adc.read(channel = 0) #you can change the adapt of the channel to be read
print(“Applied Voltage: %.2f” % (sensor_value / 1023.0 * 3.3))
if (sensor_value >= THRESHOLD):
i = i + 1
i1 = i/60
client.virtualWrite(DATA_CHANNEL, i1, “Product”, “minutes”)
else:
x = x + 1
minutes = x/60
client.virtualWrite(TRIGGER_CHANNEL, minutes, “Product”, “minutes”)
so basically my problem is that I want to continuously run my data collection, but I only want to send the time to the dashboard every say minute or so, this is just to reduce the amount of data points that I pull out of the plotter for excel. I tried looking online for some help but I am just getting more confused, if anyone could help that would be great. I just took out my username and password info because I was not sure if it mattered.