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

PubSub Not working related to issue #39 #47

Closed satay99 closed 6 years ago

satay99 commented 7 years ago

I had tried the procedure layout as per issue #39. However, I still encountered the same issue as setup failed (-5). Had run the YunSerialTerminal example and still got the same result. Checked the certificates, keys and policies and they are OK.

Connect to Yun via terminal and run the python program directly (basicPubSub.py) and got a return error of [Errno -2] Name or service not known.

Any help will be appreciated.

hedeshianaws commented 7 years ago

Thank you for your interest in AWS IoT.

[Errno -2] Name or service not known

This means there was a DNS resolution failure. This can either be caused by an issue with your network, network misconfiguration on the device, or using an invalid AWS IoT dataplane endpoint.

I would start by verifying that you can ping a server external to your network via hostname, and then validate your IoT endpoint hostname (it'll be something.iot.region.amazonaws.com and specific to your account)

satay99 commented 7 years ago

Firstly, thank you very much for the reply.

I have realised that I have used the arn number rather than the end point in the command line. I had amended the end point but still I got an error that said -

'AWSIoTPythonSDK.core.protocol.mqttCore - DEBUG - Disconnect result code 1'. and refuse to connect.

I have also amended the end point in the sketch via aws_iot_config.h with the same error output -

Setup failed -5

However, when I viewed from the AWS IoT dashboard, I saw a connection. This connection come from running the arduino sketch.

Any idea what is the cause ? Thank you again.

liuszeng commented 7 years ago

Hi @satay99 ,

Thank you very much for providing the information.

Can you attach the IoT policy that is associated with your certificate? If we are able to see the incoming connection on the dashboard and still experience connection failure, it might be caused by some authorization issues.

Thanks, Liusu

satay99 commented 7 years ago

Thank you again for the reply.

This is the policy :- { "Version": "2012-10-17", "Statement": [ { "Action": [ "iot:Publish", "iot:Subscribe", "iot:Connect", "iot:Receive" ], "Effect": "Allow", "Resource": [ "*" ] } ] }

liuszeng commented 7 years ago

Hi @satay99 ,

Thank you very much for providing the information.

The policy itself looks fine. Can you double check if the policy is attached to the certificate you are using? In your AWS IoT Console -> Security -> Policies, you should be able to find the association like shown below: screen shot 2017-06-09 at 2 42 50 pm

In the meantime, I did a quick experiment running the sample using a certificate without any policy attached to it and got the following output:

2017-06-09 14:28:33,785 - AWSIoTPythonSDK.core.protocol.mqttCore - DEBUG - Paho MQTT Client init.
2017-06-09 14:28:33,785 - AWSIoTPythonSDK.core.protocol.mqttCore - INFO - ClientID: 2489553b2daa235165145a967ae4b0165b5a96efccb65d47309f21953e1348cd
2017-06-09 14:28:33,785 - AWSIoTPythonSDK.core.protocol.mqttCore - INFO - Protocol: MQTTv3.1.1
2017-06-09 14:28:33,785 - AWSIoTPythonSDK.core.protocol.mqttCore - DEBUG - Register Paho MQTT Client callbacks.
2017-06-09 14:28:33,785 - AWSIoTPythonSDK.core.protocol.mqttCore - DEBUG - mqttCore init.
2017-06-09 14:28:33,785 - AWSIoTPythonSDK.core.protocol.mqttCore - DEBUG - Load CAFile from: /fake/path/aws-iot-rootCA.crt
2017-06-09 14:28:33,786 - AWSIoTPythonSDK.core.protocol.mqttCore - DEBUG - Load Key from: /fake/path/private.pem.key
2017-06-09 14:28:33,786 - AWSIoTPythonSDK.core.protocol.mqttCore - DEBUG - Load Cert from: /fake/path/certificate.pem.crt
2017-06-09 14:28:33,786 - AWSIoTPythonSDK.core.protocol.mqttCore - DEBUG - Custom setting for backoff timing: baseReconnectTime = 1 sec
2017-06-09 14:28:33,786 - AWSIoTPythonSDK.core.protocol.mqttCore - DEBUG - Custom setting for backoff timing: maximumReconnectTime = 32 sec
2017-06-09 14:28:33,786 - AWSIoTPythonSDK.core.protocol.mqttCore - DEBUG - Custom setting for backoff timing: minimumConnectTime = 20 sec
2017-06-09 14:28:33,786 - AWSIoTPythonSDK.core.protocol.mqttCore - DEBUG - Custom setting for publish queueing: queueSize = -1
2017-06-09 14:28:33,786 - AWSIoTPythonSDK.core.protocol.mqttCore - DEBUG - Custom setting for publish queueing: dropBehavior = Drop Newest
2017-06-09 14:28:33,786 - AWSIoTPythonSDK.core.protocol.mqttCore - DEBUG - Custom setting for draining interval: 0.5 sec
2017-06-09 14:28:33,786 - AWSIoTPythonSDK.core.protocol.mqttCore - DEBUG - Set maximum connect/disconnect timeout to be 10 second.
2017-06-09 14:28:33,786 - AWSIoTPythonSDK.core.protocol.mqttCore - DEBUG - Set maximum MQTT operation timeout to be 5 second
2017-06-09 14:28:33,787 - AWSIoTPythonSDK.core.protocol.mqttCore - INFO - Connection type: TLSv1.2 Mutual Authentication
2017-06-09 14:28:34,111 - AWSIoTPythonSDK.core.protocol.mqttCore - DEBUG - Disconnect result code 1
2017-06-09 14:28:34,112 - AWSIoTPythonSDK.core.util.progressiveBackoffCore - DEBUG - backOff: current backoff time is: 1 sec.
2017-06-09 14:28:35,413 - AWSIoTPythonSDK.core.protocol.mqttCore - DEBUG - Disconnect result code 1
2017-06-09 14:28:35,414 - AWSIoTPythonSDK.core.util.progressiveBackoffCore - DEBUG - backOff: current backoff time is: 2 sec.
2017-06-09 14:28:37,719 - AWSIoTPythonSDK.core.protocol.mqttCore - DEBUG - Disconnect result code 1
...

Is it by any chance similar to what you saw when you were experiencing the issue?

Thanks, Liusu

satay99 commented 7 years ago

Thank you very much for the reply.

You were right that the certificate is not associated with the policy.

This seems to solve the problem. Running the basicPubSub.py file directly from the terminal and connection was made.

However, running using the sketch BasicPubSub.ino failed with the same error message like before :

Setup failed ! -5

Checked the aws_iot_config.h, all the certificates' name and end point were all correct. What could be the possible error ?

liuszeng commented 7 years ago

Hi @satay99 ,

Thank you for providing the information.

From the previous posts, we were able to correctly configure the credentials and use them to successfully connect to AWS IoT. For the error code "-5", it means that the serial1 communication is having trouble between ATmega chip and AR9331 chip. You can try the following:

  1. Use command cat /proc/cmdline to show the baud rate configured on your embedded Linux in serial1. The baud rates supported by the SDK are 250K and 115.2K.
  2. Do a power cycle for the board and try to unload the sketch again. Note that the board will need 80-90 seconds to get ready for sketch upload.
  3. Add a Serail.println(rw_buf) in the SDK after this line and see if there is any extra output in your Arduino IDE Serial monitor.

Thanks, Liusu

satay99 commented 7 years ago

Thank you very much again for the reply.

Tried the following as suggested (please let me know if I did it wrong) :-

  1. run the command as suggested on terminal and found out that the baud rate is 250000.
  2. change Serial.begin baud rate to 250000 in the sketch.
  3. include the print statement as suggested in aws_iot_mqtt.cpp.
  4. power cycle the Yun and reload the sketch.

There is no printout from the serial terminal of the arduino IDE and get the same message as 'setup failed -5'.

Where did it go wrong ?

liuszeng commented 7 years ago

Hi @satay99 ,

Sorry that the suggestion does not work for you. If you cannot see any output coming back from the embedded Linux, it means that the serial1 connection in between is not working properly. You can try the following things:

  1. After power cycle the board, try to get YunSerialTerminal sample working with serial1 at baud rate 250K. After that, try again with the SDK sample sketch.
  2. If 1 does not work, try to reset the board .

Hope the above helps.

Liusu

satay99 commented 7 years ago

Thank you very much for the reply.

I had run the YunSerialTerminal and it works as it should be. I could change the baud rate as indicated in the YunSerialTerminal sketch.

I had also reset the board by pressing the "YÚN RST" reset button. It is not working either.

Any idea ?

satay99 commented 7 years ago

Trying to debug the error and find out that rw_buf is empty.

By the way what is the expected return type of this command : exec_cmd(CMD_CHECK_LINUX_LIVE, true, false);

Thanks in advance.

liuszeng commented 7 years ago

Hi @satay99 ,

exec_cmd(...) writes the command in rw_buf over serial1 to the embedded Linux Python runtime and receives the response back into rw_buf. If rw_buf is empty, it means that there is no response coming back from the Python runtime running on embedded Linux.

exec_cmd(CMD_CHECK_LINUX_LIVE, true, false); basically run the command uname on the embedded Linux. It should return the OS information, which indicates that the serial1 connection is working correctly.

Thanks, Liusu

satay99 commented 7 years ago

Thank you Liusu.

When I run the command 'uname' on the Linux terminal, it returns "Linux". Somehow serial1 connection is not working.

liuszeng commented 7 years ago

Hi @satay99 ,

Can you try the following?

  1. Upload an empty sketch to the board. This is to make sure that the board does not automatically run sketch that might occupy any on-board resources when it is powered up again.
  2. Try to reset the OpenWRT to its default state by pressing the "WLAN RST" button for more than 30 sec? Instructions can be found below:

    To reset the OpenWrt-Yun distribution to its default state, press the WiFi reset button (WLAN RST) for at least 30 seconds. The board reverts to the original settings: like just taken out of the box or to the latest update of the OpenWRT image you have reflashed before. Among other things, this removes all installed files and network settings.

  3. Try to upload the SDK sample again.

Detailed info about step2 can be found at the Arduino Yun Guide: https://www.arduino.cc/en/Guide/ArduinoYun#toc12

Thanks, Liusu

satay99 commented 7 years ago

Thank you again for the reply.

I had tried to reset the Yun earlier twice but the result is the same.

I will try with a new unit and see if it was a hardware problem and keep you updated.

vareddy-zz commented 6 years ago

Hi @satay99 , Since there haven't been any updates on this issue in a long time, we will close this issue. Please feel free to open another one if you have any more questions about the Arduino SDK. Thanks! Varun