Can I have a simple flow to connect by using Auth Code and GET request by Python code?
Hello Sir,
You need an python example ?
Hi dear,
Yes I want write a simple Python GET request.
But now I’m triyng to use the Python mqtt release for Cayenne.
cayenne-mqtt · PyPI
I receive an error:
TypeError: on_connect() takes 3 positional arguments but 4 were given
File “Example-01-SendData.py”, line 19, in
client.loop()
File “/usr/local/lib/python3.6/site-packages/cayenne/client.py”, line 150, in loop
self.client.loop()
File “/usr/local/lib/python3.6/site-packages/paho/mqtt/client.py”, line 995, in loop
rc = self.loop_read(max_packets)
File “/usr/local/lib/python3.6/site-packages/paho/mqtt/client.py”, line 1273, in loop_read
rc = self._packet_read()
File “/usr/local/lib/python3.6/site-packages/paho/mqtt/client.py”, line 1838, in _packet_read
rc = self._packet_handle()
File “/usr/local/lib/python3.6/site-packages/paho/mqtt/client.py”, line 2291, in _packet_handle
return self._handle_connack()
File “/usr/local/lib/python3.6/site-packages/paho/mqtt/client.py”, line 2349, in _handle_connack
self.on_connect(self, self._userdata, flags_dict, result)
TypeError: on_connect() takes 3 positional arguments but 4 were given
Can you post the python code here? Don’t forget to delete the username and other credentials
It’s the example code…
G.G.
from mobile.
Up…
The last error is:
TypeError: on_connect() takes exactly 3 arguments (4 given)
I use this code:
import cayenne.client
import time
MQTT_USERNAME = “MQTT_USERNAME”
MQTT_PASSWORD = “MQTT_PASSWORD”
MQTT_CLIENT_ID = “MQTT_CLIENT_ID”
def on_message(message):
print("message received: " + str(message))
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()
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
Hello All,
I’m using MQTT quiete intensively in my project as well. You can also use “original” paho mqtt
library which is well described at GitHub - eclipse/paho.mqtt.python: paho.mqtt.python . on_connect
method is described here: GitHub - eclipse/paho.mqtt.python: paho.mqtt.python
Y