Greengrass device connection refused

0

Hi,

I am working through Module 5 of the Greengrass tutorial and am encountering a socket connection error when running the lightController.py script as instructed here:

https://docs.aws.amazon.com/greengrass/latest/developerguide/comms-disabled.html

C:\Users\Steve\Documents\IoT\Certs2>python lightController.py --endpoint a3pujgfo1m12iq-ats.iot.us-west-2.amazonaws.com --rootCA root-ca-cert.pem --cert 40d1bca263.cert.pem --key 40d1bca263.private.key --thingName GG_TrafficLight --clientId GG_Switch
Greengrass core has already been discovered.
GGC Host Address: 127.0.0.1
GGC Group CA Path: ./groupCA/root-ca.crt
Private Key of lightController thing Path: 40d1bca263.private.key
Certificate of lightController thing Path: 40d1bca263.cert.pem
Client ID(thing name for lightController): GG_Switch
Target shadow thing ID(thing name for trafficLight): GG_TrafficLight
2019-10-20 18:04:40,098 - AWSIoTPythonSDK.core.protocol.mqtt_core - INFO - MqttCore initialized
2019-10-20 18:04:40,098 - AWSIoTPythonSDK.core.protocol.mqtt_core - INFO - Client id: GG_Switch
2019-10-20 18:04:40,098 - AWSIoTPythonSDK.core.protocol.mqtt_core - INFO - Protocol version: MQTTv3.1.1
2019-10-20 18:04:40,098 - AWSIoTPythonSDK.core.protocol.mqtt_core - INFO - Authentication type: TLSv1.2 certificate based Mutual Auth.
2019-10-20 18:04:40,098 - AWSIoTPythonSDK.core.protocol.mqtt_core - INFO - Configuring offline requests queueing: max queue size: 0
2019-10-20 18:04:40,098 - AWSIoTPythonSDK.core.protocol.mqtt_core - INFO - Configuring offline requests queue draining interval: 0.100000 sec
2019-10-20 18:04:40,098 - AWSIoTPythonSDK.core.protocol.mqtt_core - INFO - Configuring endpoint...
2019-10-20 18:04:40,098 - AWSIoTPythonSDK.core.protocol.mqtt_core - INFO - Configuring certificates...
2019-10-20 18:04:40,098 - AWSIoTPythonSDK.core.protocol.mqtt_core - INFO - Configuring reconnect back off timing...
2019-10-20 18:04:40,098 - AWSIoTPythonSDK.core.protocol.mqtt_core - INFO - Base quiet time: 1.000000 sec
2019-10-20 18:04:40,098 - AWSIoTPythonSDK.core.protocol.mqtt_core - INFO - Max quiet time: 32.000000 sec
2019-10-20 18:04:40,098 - AWSIoTPythonSDK.core.protocol.mqtt_core - INFO - Stable connection time: 20.000000 sec
2019-10-20 18:04:40,098 - AWSIoTPythonSDK.core.protocol.mqtt_core - INFO - Configuring connect/disconnect time out: 10.000000 sec
2019-10-20 18:04:40,098 - AWSIoTPythonSDK.core.protocol.mqtt_core - INFO - Configuring MQTT operation time out: 5.000000 sec
2019-10-20 18:04:40,098 - AWSIoTPythonSDK.core.protocol.mqtt_core - INFO - Performing sync connect...
2019-10-20 18:04:40,098 - AWSIoTPythonSDK.core.protocol.mqtt_core - INFO - Performing async connect...
2019-10-20 18:04:40,098 - AWSIoTPythonSDK.core.protocol.mqtt_core - INFO - Keep-alive: 600.000000 sec
Traceback (most recent call last):
  File "lightController.py", line 203, in <module>
    myAWSIoTMQTTShadowClient.connect()
  File "C:\Python27\lib\site-packages\AWSIoTPythonSDK\MQTTLib.py", line 1271, in connect
    return self._AWSIoTMQTTClient.connect(keepAliveIntervalSecond)
  File "C:\Python27\lib\site-packages\AWSIoTPythonSDK\MQTTLib.py", line 513, in connect
    return self._mqtt_core.connect(keepAliveIntervalSecond)
  File "C:\Python27\lib\site-packages\AWSIoTPythonSDK\core\protocol\mqtt_core.py", line 196, in connect
    self.connect_async(keep_alive_sec, self._create_blocking_ack_callback(event))
  File "C:\Python27\lib\site-packages\AWSIoTPythonSDK\core\protocol\mqtt_core.py", line 223, in connect_async
    raise e
socket.error: [Errno 10061] No connection could be made because the target machine actively refused it

My local core connection information shows only the IP address of the Raspberry Pi Greengrass device, 192.168.1.125 on port 8883. I am able to ping the device from my computer and have confirmed the Greengrass daemon is running. Why is this happening? I have made it through all the other Greengrass training modules without issue so far.

Thanks,

Steve

asked 5 years ago553 views
8 Answers
0

Some help here would be appreciated. I reflashed my Raspberry Pi and did the tutorials again, only to find myself blocked with the same problem:

socket.error: (Errno 10061) No connection could be made because the target machine actively refused it

Additionally, I can ping my laptop machine from the Raspberry Pi and vice versa, so it looks like basic connectivity is established. And I confirmed that the Greengrass daemon is running.

Thanks in advance,

Steve

Edited by: silverage on Nov 3, 2019 4:27 PM

answered 4 years ago
0

Hi Steve,

Do you have any firewall settings blocking the traffic on your local network and your computer?
Can you check the output of "telnet 192.168.1.125 8883"?

You could also try to run lightController.py script from the RPi, same host where the Greengras Core is running. Let me know if you see the same issue.

Thanks,
aws-hui

answered 4 years ago
0

Hi,

Thanks for the reply. The Telnet connection looks normal so I dont think that a firewall is blocking things.

I have packaged the lightController.py script as a Lambda function, included the Lambda in my Greengrass group, created a subscription, and deployed the group. I am not clear however on how to verify that the Lambda is working as expected. My subscription is configured as follows:

Source: lightController (Lambda - long life)
Target: IoT Cloud
Topic: $aws/things/GG_TrafficLight/shadow/update

How do I then test the Lambda and confirm that it is working on the Raspberry Pi? In the lightController function code I could not find where it writes to a topic.

Thanks,

Steve

Edited by: silverage on Nov 13, 2019 5:28 PM

answered 4 years ago
0

Hi silverage,

You can enable logs on your lambda functions and then monitor the logs to see the lambda get triggered and then publish on a topic.
https://docs.aws.amazon.com/greengrass/latest/developerguide/gg-troubleshooting.html#troubleshooting-logs

Thanks,
KR-AWS

AWS
KR-AWS
answered 4 years ago
0

Ok, I am seeing an error in lightController.log:

[2019-11-24T22:29:46.063Z][FATAL]-lambda_runtime.py:131,Failed to import handler function "lightController.function_handler" due to exception: No module named AWSIoTPythonSDK.MQTTLib
[2019-11-24T22:29:46.888Z][FATAL]-lambda_runtime.py:371,Failed to initialize Lambda runtime due to exception: No module named AWSIoTPythonSDK.MQTTLib

The directory structure for the Lambda function is lightController / greengrassdk / lightController.py

Also seeing the following in runtime.log:

[2019-11-24T22:43:50.26Z][INFO]-Worker Memory Usage (KB).	{"workerId": "1713b1ce-c1fb-4bcd-4619-659b76bc253f", "funcArn": "arn:aws:lambda:us-west-2:468820349153:function:lightController:1", "memSize": 16384, "memUsed": 11304}
[2019-11-24T22:43:50.26Z][ERROR]-Worker is ungracefully killed.	{"workerId": "1713b1ce-c1fb-4bcd-4619-659b76bc253f", "funcArn": "arn:aws:lambda:us-west-2:468820349153:function:lightController:1", "state": "exit status 1"}

Thanks,

Steve

answered 4 years ago
0

Hi Silverage,

Make sure lightController.py is in the folder that contains greengrasssdk. See:
https://docs.aws.amazon.com/greengrass/latest/developerguide/create-lambda.html

Check the following commands:

which python2.7

Which version of python does your lambda use? This lambda requires python2.7.

Thanks,
KR-AWS

AWS
KR-AWS
answered 4 years ago
0

You appear to be missing the IoT SDK: https://pypi.org/project/AWSIoTPythonSDK/1.0.0/ . Go ahead and download that and include it with your lambda zip and it should start to work; or at least give a different error.

Michael
answered 4 years ago
0

I was stuck in the same issue. Then I came upon a solution in stackoverflow I think. It asked me to delete the GroupCA folder that was created in my folder. The error was due to some certificate expiration. It worked for me

answered 4 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions