Trying to publish data using a RPI with Piplate DAQC plate


#1

I’m new to this but I’m trying to read a couple of sensors off of a DAQC Piplate and publish the data to Cayenne in python. I’m having trouble even connecting my Python script using mqtt and I really don’t know where to start since most of the turorials that I’ve found deal with the temperature & humidity sensors.

This is my the main python script without the tkinter code:

import piplates.DAQCplate as DAQC
import RPi.GPIO as GPIO
import time

def task():
global lastPgas
global lastPin
global lastPout

## Gas Line in  
val=round(DAQC.getADC(0,2),1)
val=(40.128*val-0.107)
lastPgas=val
PgasText.set(str(val)+'psi')

## Pressure P1  
val=round(DAQC.getADC(0,0),1)
val=39.984*val-0.3864
lastPin=val
PinText.set(str(val)+'psi')

## Pressure P2  
val=round(DAQC.getADC(0,1),1)
val=40.109*val-0.4478
lastPout=val
PoutText.set(str(val)+'psi')

   
root.after(100,task)

def shutdown():
DAQC.CLOSE()
root.destroy()
root.quit()


#2

Hi @Cerbero17, welcome to the Cayenne Community

Can you try connecting again as we were just having some MQTT device connectivity issues in the last hour that we now believe to be resolved. You might have run into them.

Does your python code contain the Cayenne connectivity code? I don’t see it here but maybe you stripped it out for privacy reasons? It should look basically like this (with your MQTT Username/Password/Client ID in the place of the placeholders, of course):

import cayenne.client
import time

# Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
MQTT_USERNAME  = "MQTT_USERNAME"
MQTT_PASSWORD  = "MQTT_PASSWORD"
MQTT_CLIENT_ID = "MQTT_CLIENT_ID"


# The callback for when a message is received from Cayenne.
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)

i=0
timestamp = 0

while True:
    client.loop()
    #this is just example sensor data that you don't need in the client from here to the end of file.
    if (time.time() > timestamp + 10):
        client.celsiusWrite(1, i)
        client.luxWrite(2, i*10)
        client.hectoPascalWrite(3, i+800)
        timestamp = time.time()
        i = i+1

#3

Thanks a lot for your reply. With that code I was able to connect to the dashboard but I’ve having trouble finding a way or a specific command to push the results of my variables to the dashboard. I think I just have the wrong command or syntax or something. What could I use to push those variables to the dashboard?