ClearBlade / ClearBlade-Python-SDK

A Python SDK for interacting with the ClearBlade Platform.
Apache License 2.0
4 stars 4 forks source link

CB Error: Connection error. #16

Open iamjai-dev opened 3 years ago

iamjai-dev commented 3 years ago

I have attached script which is used to get messaging service from ClearBlade, when I try to establish the connection the following error occurs. May I know what the source of this error is?

We have a portal that is build with react and its seems the below URL is working fine and it accepting the request and logging successfully but when I try to connect the same URL using Python-SDK.

Error

CB Error: Connection error. Check that https://platform.iotright.com/api/v/1/user/auth is up and accepting requests.

from snapconnect import snap
from clearblade.ClearBladeCore import System, Query
import time
from clearblade.ClearBladeCore import cbLogs
global comm
from decouple import config
#"/x1B/xE4/xA7" --> SynapseBrick

dim_level = 0

cbLogs.DEBUG = False
cbLogs.MQTT_DEBUG = False

SystemKey = config('SYSTEMKEY')
SystemSecret = config('SYSTEMSECRET')

url = config('URL')

mySystem = System(SystemKey, SystemSecret, url)

cbUser = mySystem.User(config('CB_USERNAME'), config('CB_PASSWORD'))

mqtt = mySystem.Messaging(cbUser)

def on_connect(client, userdata, flags, rc):
    print("Connected with result code "+str(rc))

    client.subscribe("/lighting/nodes/#")

def on_message(client, userdata, msg):  
    print(msg.topic+" "+str(msg.payload))
    nodeAddr = str(msg.payload.decode('utf-8'))
    print(nodeAddr)
    comm.rpc("/x1B/xE4/xA7", "get_dim_level")
    print("msg published")

def on_disconnect(client, userdata, rc):
    print("client disconnected mqtt; attempting reconnection")
    client.reconnect()    

def rpcSuccess(obj):
    global responseFlag
    print('rpc success')

def get_dim(level):
    global dim_level
    dim_level = level
    print("dim level ",dim_level)

mqtt.on_connect = on_connect
mqtt.on_message = on_message 
mqtt.on_disconnect = on_disconnect

comm = snap.Snap(funcs={'get_dim':get_dim, 'rpcSuccess':rpcSuccess})
# comm.rpc("/x1B/xE4/xA7", "test")
comm.open_serial(1,'/dev/snap0')

mqtt.connect()

print('MQTT connected')

while(True):
    time.sleep(1)
yashjain28 commented 3 years ago

Hi, @iamjai-dev can you confirm what URL are you passing in the function? it should be: https://platform.iotright.com and not https://platform.iotright.com/api/v/1/user/auth

iamjai-dev commented 3 years ago

I have tried with this URL https://platform.iotright.com as you mentioned, and facing the same issue?

yashjain28 commented 3 years ago

@iamjai-dev You are connecting as a user, do you know if your user's role has the right permissions for the message topic you are subscribing to? I tried to work with another system on the same instance (platform.iotright.com) and I am not able to replicate it. If the problem persists let me know. We can potentially schedule a call.

iamjai-dev commented 3 years ago

@yashjain28 Ya the user I am connecting with has a role admin. But the problem persists, let me know when you are free we can schedule a call. Thanks.

yashjain28 commented 3 years ago

I can talk now or we can schedule a call for 11:30 am central time tomorrow. If you can confirm, share your work email so that I'll share a zoom link.

iamjai-dev commented 3 years ago

@yashjain28, For your information I have solved the issue by using the Paho-MQTT client library and it's connecting to ClearBlade now without any issue.