Issue - Raspberry Pi Button Data Sending To Cayenne Using API


#1

Hi guys!
I’m having problem with sending data to Cayenne.

I’m using this code: https://www.instructables.com/id/Cayenne-Python-and-MQTT-Tutorials-Digital-İnput/

When I start the script, my raspberry pi connects to cayenne but when I press the button, I’m not getting Button Pressed! message and my widget in cayenne does not change to 1.


#2

@cagriserpin do not create multiple topics.
what does the terminal output message. can you share here.
Also in previous topic you said cayenne python library gave you same issue and did not connect, so is it working now?


#3

Yes it is! I don’t know why but it’s working now :smiley:
Here is the terminal output:
Connecting to mqtt.mydevices.com:1883
Connected with result code 0
SUB v1/53494ac0-0dd8-11e9-a056-c5cffe7f75f9/things/aefa5470-338c-11e9-8cb9-732fc93af22b/cmd/+

PUB v1/53494ac0-0dd8-11e9-a056-c5cffe7f75f9/things/aefa5470-338c-11e9-8cb9-732fc93af22b/sys/model
Python

PUB v1/53494ac0-0dd8-11e9-a056-c5cffe7f75f9/things/aefa5470-338c-11e9-8cb9-732fc93af22b/sys/version
1.1.0


#4

can you provide more output from the terminal? does it output anything when the button is pressed?


#5

Like I said first, no. Just this and nothing else. I’m pretty sure that i connected button right. If you want I can send you a picture of my connection.


#6

UPDATE:
Somehow I’m getting message when I press the button but issue still continues. Here is the output:

Connecting to mqtt.mydevices.com:1883
Connected with result code 0
SUB v1/53494ac0-0dd8-11e9-a056-c5cffe7f75f9/things/aefa5470-338c-11e9-8cb9-732fc93af22b/cmd/+

PUB v1/53494ac0-0dd8-11e9-a056-c5cffe7f75f9/things/aefa5470-338c-11e9-8cb9-732fc93af22b/sys/model
Python

PUB v1/53494ac0-0dd8-11e9-a056-c5cffe7f75f9/things/aefa5470-338c-11e9-8cb9-732fc93af22b/sys/version
1.1.0

PUB v1/53494ac0-0dd8-11e9-a056-c5cffe7f75f9/things/aefa5470-338c-11e9-8cb9-732fc93af22b/data/3
1

Button pressed

PUB v1/53494ac0-0dd8-11e9-a056-c5cffe7f75f9/things/aefa5470-338c-11e9-8cb9-732fc93af22b/data/3
0

Button released


#7

this is correct. what is the issue now? you should see a widget auto created on the dashboard.


#8

Nope. Widget is not changing :confused:


#9

If you want I can give you my TeamViewer id and password, so you can check what is wrong easily?


#10

Oh I realised something. I can see changes in android app but I can’t see it on web.


#11

First delete the widget from the dashboard then make the following changes in your code and run it. next, it will auto create a green temporary widget add it by pressing + on top right of the widget.

def send_on():
      client.virtualWrite(3, 1, "digital_sensor", "d") #Publish "1" to Cayenne MQTT Broker Channel 3
      print("Button pressed\n")

def send_off():
  client.virtualWrite(3, 0, "digital_sensor", "d") #Publish "0" to Cayenne MQTT Broker Channel 3
  print("Button released\n")

#12

Thank you so much. It works now! You’re the best!