aws / aws-iot-device-sdk-arduino-yun

SDK for connecting to AWS IoT from an Arduino Yún.
Apache License 2.0
163 stars 77 forks source link

Connect Failed! (-1) issue using BasicPubSub Example #28

Closed mumairkhugyani closed 7 years ago

mumairkhugyani commented 7 years ago

Hello, I am trying to connect my YUN (with OpenWrt) to AWS IoT using this SDK. I have followed every step carefully, when I try using BasicPubSub Example I face an issue of "Connect failed" with code "-1".

One thing that is in my notice is when i used: _"easyinstall pip & pip install AWSIoTPythonSDK==1.0.0" , I received few warnings include missing SNI and insecure platform. (I just don't know that they matter or not)

I am very new to this stuff and with very basic knowledge, Please Help!!

I have followed this issue: #25 but still without any way out.

mumairkhugyani commented 7 years ago

@liuszeng please help me in this issue.

liuszeng commented 7 years ago

Hi @mumairkhugyani ,

Thank you very much for your interest in AWS IoT Arduino Yun SDK!

"Connect failed: -1" means unexpected response is returned from the OpenWRT. To get more details for traffic happens between the two processors, you can add the following line after this: https://github.com/aws/aws-iot-device-sdk-arduino-yun/blob/master/AWS-IoT-Arduino-Yun-Library/aws_iot_mqtt.cpp#L851

Serial.println(rw_buf);

Can you attach your IDE serial console output when you are experiencing the issue?

If your host machine is Linux or Mac OS, you should be able to use the automated script provided along with the SDK to help you do the setup: https://github.com/aws/aws-iot-device-sdk-arduino-yun/blob/master/AWSIoTArduinoYunInstallAll.sh

Instructions are available here: https://github.com/aws/aws-iot-device-sdk-arduino-yun#installation

Thanks, Liusu

mumairkhugyani commented 7 years ago

@liuszeng Thank you very much for your reply.

Currently I am using Linino on my board , but i have also tried the whole procedure on openWRT but results on both are same. SD card is installed and did the CHMOD command for run.py (but no luck). and I am trying to configure the board using windows 10 as host.

after adding the LINE as you mentioned, output on IDE I got is:

> root@ichair:~/AWS-IoT-Python-Runtime/runtime# 
/bin/ash: 1: not found
/bin/ash: /root: Permission denied
/bin/ash: 1: not found
/bin/ash: /root: Permission denied
/bin/ash: 1: not found
/bin/ash: /root: Permission denied
/bin/ash: 1: not found
/bin/ash: /root: Permission denied
Linux
/

I T

G T

Connect failed!
-1

> 

I will be really thankful to you for guiding me on this. It is most important thing to do and I have to implement it ASAP.

P.S: In wait of your reply, I will try to configure YUN using linux via VMWare (running it virtually on Windows 10)

liuszeng commented 7 years ago

Hi @mumairkhugyani ,

Thank you very much for providing the information.

Do you have ssh access to your Linino on your YUN? Can you try to use the same credential and run Python SDK sample on it? Instructions can be found here: https://github.com/aws/aws-iot-device-sdk-python#installation

Let's start with verifying the credential and the Python runtime.

Thanks, Liusu

mumairkhugyani commented 7 years ago

@liuszeng thankyou once again.

Yes, I have ssh access to Linino on my YUN.

I cant confirm it that I'll be able to run PYTHON SDK on my YUN or not.

Basically, I have to collect values from different sensors and have to upload them on AWS IoT. As I am new to all these things so for clearing concepts and to check my device connection to AWS IoT I am using this BasicPubSub Example.

Regards,

liuszeng commented 7 years ago

Hi @mumairkhugyani ,

The AWS IoT Arduino Yun SDK is now backed by AWS IoT Python SDK. Since we cannot get much information from the serial console output, we need more information on the Linino side where all the heavy lifting work is done (connecting to AWS IoT).

Ideally, you should already have the certificate, private key and rootCA uploaded to your Linino during the steps to set up IoT Yun SDK. Can you try the following instructions on your Linino and check the logs?

  1. Ssh into Linino

  2. Install the latest version of AWS IoT Python SDK

    git clone https://github.com/aws/aws-iot-device-sdk-python.git
    cd aws-iot-device-sdk-python
    python setup.py install
  3. Run basicPubSub sample using the credential you uploaded

    python basicPubSub.py -e <endpoint> -r <rootCAFilePath> -c <certFilePath> -k <privateKeyFilePath>

Thanks, Liusu

mumairkhugyani commented 7 years ago

@liuszeng
Ok I will try it and will give you respons.

Please have a look at my config file and certificates naming formats:

define AWS_IOT_MQTT_HOST "atfeqkx9dh5s.iot.us-west-2.amazonaws.com" // your endpoint

define AWS_IOT_MQTT_PORT 8883 // your port

define AWS_IOT_CLIENT_ID "ichair" // your client ID

define AWS_IOT_MY_THING_NAME "IChair" // your thing name

define AWS_IOT_ROOT_CA_FILENAME "VeriSign-Class 3-Public-Primary-Certification-Authority-G5.pem" // your root-CA filename

define AWS_IOT_CERTIFICATE_FILENAME "59d1f9ac36-certificate.pem.crt" // your certificate filename

define AWS_IOT_PRIVATE_KEY_FILENAME "59d1f9ac36-private.pem.key" // your private key filename

mumairkhugyani commented 7 years ago

@liuszeng , Extremely sorry to disturb you again and again just because of my poor knowledge.

root@ichair:~/aws-iot-device-sdk-python/samples/basicPubSub#

 python basicPubSub.py -e atfeqkx9dh5s.iot.us-west-2.amazonaws.com -r /root/AWS-IoT-Python-Runtime/certs/Ver
iSign-Class 3-Public-Primary-Certification-Authority-G5.pem -c /root/AWS-IoT-Python-Runtime/certs/59d1f9ac36-certificate.pem -k /root/AWS-IoT-Python-Runtime/certs/59d1f
9ac36-private.pem
Missing '-c' or '--cert'
Missing '-k' or '--key'
root@ichair:~/aws-iot-device-sdk-python/samples/basicPubSub#

It looks like there is issue in naming of my certificates, or in the extensions of certificates kindly guide me in it. So we can progress further to if any other issues exist.

Once again thank you very much for guiding and helping me. Stay Blessed

liuszeng commented 7 years ago

Hi @mumairkhugyani ,

You can rename the root CA file using the following command on Linino:

mv VeriSign-Class\ 3-Public-Primary-Certification-Authority-G5.pem rootCA.crt

Notice the escape. This renames it to "rootCA.crt".

Then you should be able to run the sample with command line options.

Thanks, Liusu

mumairkhugyani commented 7 years ago

Hello @liuszeng , Once again thanks a lot for your help.

I ran basicPubSub.py using python SDK but it also gave connection issue with following outputs:

root@ichair:~/aws-iot-device-sdk-python/samples/basicPubSub# python basicPubSub.py -e atfeqkx9dh5s
.iot.us-west-2.amazonaws.com -r /root/AWS-IoT-Python-Runtime/certs/rootCA.pem -c /root/AWS-IoT-Pyt
hon-Runtime/certs/59d1f9ac36-certificate.pem.crt -k /root/AWS-IoT-Python-Runtime/certs/59d1f9ac36-
private.pem.key
2017-01-28 15:53:16,181 - AWSIoTPythonSDK.core.protocol.mqttCore - DEBUG - Paho MQTT Client init.
2017-01-28 15:53:16,185 - AWSIoTPythonSDK.core.protocol.mqttCore - INFO - ClientID: basicPubSub
2017-01-28 15:53:16,188 - AWSIoTPythonSDK.core.protocol.mqttCore - INFO - Protocol: MQTTv3.1.1
2017-01-28 15:53:16,192 - AWSIoTPythonSDK.core.protocol.mqttCore - DEBUG - Register Paho MQTT Client callbacks.
2017-01-28 15:53:16,196 - AWSIoTPythonSDK.core.protocol.mqttCore - DEBUG - mqttCore init.
2017-01-28 15:53:16,200 - AWSIoTPythonSDK.core.protocol.mqttCore - DEBUG - Load CAFile from: /root/AWS-IoT-Python-Runtime/certs/rootCA.pem
2017-01-28 15:53:16,203 - AWSIoTPythonSDK.core.protocol.mqttCore - DEBUG - Load Key from: /root/AWS-IoT-Python-Runtime/certs/59d1f9ac36-private.pem.key
2017-01-28 15:53:16,207 - AWSIoTPythonSDK.core.protocol.mqttCore - DEBUG - Load Cert from: /root/AWS-IoT-Python-Runtime/certs/59d1f9ac36-certificate.pem.crt
2017-01-28 15:53:16,210 - AWSIoTPythonSDK.core.protocol.mqttCore - DEBUG - Custom setting for backoff timing: baseReconnectTime = 1 sec
2017-01-28 15:53:16,214 - AWSIoTPythonSDK.core.protocol.mqttCore - DEBUG - Custom setting for backoff timing: maximumReconnectTime = 32 sec
2017-01-28 15:53:16,217 - AWSIoTPythonSDK.core.protocol.mqttCore - DEBUG - Custom setting for backoff timing: minimumConnectTime = 20 sec
2017-01-28 15:53:16,221 - AWSIoTPythonSDK.core.protocol.mqttCore - DEBUG - Custom setting for publish queueing: queueSize = -1
2017-01-28 15:53:16,224 - AWSIoTPythonSDK.core.protocol.mqttCore - DEBUG - Custom setting for publish queueing: dropBehavior = Drop Newest
2017-01-28 15:53:16,228 - AWSIoTPythonSDK.core.protocol.mqttCore - DEBUG - Custom setting for draining interval: 0.5 sec
2017-01-28 15:53:16,232 - AWSIoTPythonSDK.core.protocol.mqttCore - DEBUG - Set maximum connect/disconnect timeout to be 10 second.
2017-01-28 15:53:16,235 - AWSIoTPythonSDK.core.protocol.mqttCore - DEBUG - Set maximum MQTT operation timeout to be 5 second
2017-01-28 15:53:16,240 - AWSIoTPythonSDK.core.protocol.mqttCore - INFO - Connection type: TLSv1.2 Mutual Authentication
2017-01-28 15:53:21,192 - AWSIoTPythonSDK.core.protocol.mqttCore - DEBUG - Disconnect result code 1
2017-01-28 15:53:21,196 - AWSIoTPythonSDK.core.util.progressiveBackoffCore - DEBUG - backOff: current backoff time is: 1 sec.
2017-01-28 15:53:24,308 - AWSIoTPythonSDK.core.protocol.mqttCore - DEBUG - Disconnect result code 1
2017-01-28 15:53:24,313 - AWSIoTPythonSDK.core.util.progressiveBackoffCore - DEBUG - backOff: current backoff time is: 2 sec.
2017-01-28 15:53:28,529 - AWSIoTPythonSDK.core.protocol.mqttCore - DEBUG - Disconnect result code 1
2017-01-28 15:53:28,533 - AWSIoTPythonSDK.core.util.progressiveBackoffCore - DEBUG - backOff: current backoff time is: 4 sec.
2017-01-28 15:53:30,955 - AWSIoTPythonSDK.core.protocol.mqttCore - ERROR - Connect timeout.
Traceback (most recent call last):
  File "basicPubSub.py", line 133, in <module>
    myAWSIoTMQTTClient.connect()
  File "/usr/lib/python2.7/site-packages/AWSIoTPythonSDK/MQTTLib.py", line 403, in connect
    return self._mqttCore.connect(keepAliveIntervalSecond)
  File "/usr/lib/python2.7/site-packages/AWSIoTPythonSDK/core/protocol/mqttCore.py", line 299, in connect
    raise connectTimeoutException()
AWSIoTPythonSDK.exception.AWSIoTExceptions.connectTimeoutException
root@ichair:~/aws-iot-device-sdk-python/samples/basicPubSub#

still stuck... :( waiting for your help and support

and my dashboard of AWS IoT shows sometimes activity of connections (number of connected and time).

Plus, I haven't mention my topic name while using PYTHON SDK to publish message, if I have to please guide me where should I mention it. (it is just a thought in mind I don't know it is relevant to my issue or not)

Regards,

liuszeng commented 7 years ago

Hi @mumairkhugyani ,

Thank you very much for providing the information.

From the log, we can see that you got disconnected from the server when you attempted the connect. Can you verify that you have attached IoT policy with proper permissions to the certificate you are using here?

To be more specific, to get the PubSub sample working, you will need to the permission to connect, publish, subscribe and receive. Samples about IoT policy can be found here: http://docs.aws.amazon.com/iot/latest/developerguide/pub-sub-policy.html

You should be able to check the policy attachment of your certificate in your AWS IoT Console.

To get more information about the issue, another thing you can do is to check the Cloud Watch Log. To configure Cloud Watch Log for AWS IoT, please check the instructions here: http://docs.aws.amazon.com/iot/latest/developerguide/cloud-watch-logs.html

Please let us know how it goes.

Thanks, Liusu

mumairkhugyani commented 7 years ago

Hello @liuszeng thank you very much for your such support.

10 mins before i was exploring some other issues and there was your reply on Amazon forum about the resources in policy. I just changed it to "*" from specific topic and I got SUCCESS in it.

Now I am uploading values to cloud using BasicPubSub.

Just one last question. Now I'll be able to use the YUN SDK with this issue solved?

Once again thanks a lot for your such support. Always stay blessed Regards,

liuszeng commented 7 years ago

Hi @mumairkhugyani ,

Glad to know that you got it working with Python device SDK sample. Success in running the sample means that your credentials are configured with proper permissions.

You now should be able to use the sample credential to connect to AWS IoT with Yun SDK. Note that we have installed a newer version (1.1.1) of IoT Python SDK on your Linino for debugging purpose. To get the Yun SDK working correctly, I recommend you to uninstall it, reinstall and stick to the version (1.0.0) that Yun SDK is using as its backend. You also want to make sure the config header file for PubSub sample is updated to match the credential file name changes.

Thanks, Liusu

mumairkhugyani commented 7 years ago

@liuszeng One more thing I Did was some changes in configuration related to time:

# AWSIoTMQTTClient connection configuration
myAWSIoTMQTTClient.configureAutoReconnectBackoffTime(1, 250, 20)  #original 32
myAWSIoTMQTTClient.configureOfflinePublishQueueing(-1)  # Infinite offline Publish queueing
myAWSIoTMQTTClient.configureDrainingFrequency(2)  # Draining: 2 Hz
myAWSIoTMQTTClient.configureConnectDisconnectTimeout(250)  #original 10 sec
myAWSIoTMQTTClient.configureMQTTOperationTimeout(5)  # 5 sec

So it worked after these changes

Regards,

mumairkhugyani commented 7 years ago

@liuszeng As i did some time configurations for python SDK. I think so we have slow internet connection so thats why have to increase time, Now, From Where I can do those time configurations in YUN SDK which I did for python.??

its not working through YUN SDK. Setup Failed! Error is coming now. i haven't done the clean installation. I will update after doing complete clean installation.

mumairkhugyani commented 7 years ago

Hello @liuszeng,

Thank you very much for your guidance and support, Thank you Amazon.

Everything is good now and I am able to run the BasicPubSub example for YUN using AWS-IOT-YUN-SDK.

Regards,