in groups/arm/ggd/utils.py [0:0]
def local_shadow_connect(device_name, config_file, root_ca, certificate,
private_key, group_ca_dir):
cfg = GroupConfigFile(config_file)
ggd_name = cfg['devices'][device_name]['thing_name']
iot_endpoint = cfg['misc']['iot_endpoint']
dip = DiscoveryInfoProvider()
dip.configureEndpoint(iot_endpoint)
dip.configureCredentials(
caPath=root_ca, certPath=certificate, keyPath=private_key
)
dip.configureTimeout(10) # 10 sec
logging.info(
"[shadow_connect] Discovery using CA:{0} cert:{1} prv_key:{2}".format(
root_ca, certificate, private_key
))
gg_core, discovery_info = discover_configured_core(
config_file=config_file, dip=dip, device_name=ggd_name,
)
if not gg_core:
raise EnvironmentError("[core_connect] Couldn't find the Core")
ca_list = discovery_info.getAllCas()
core_list = discovery_info.getAllCores()
group_id, ca = ca_list[0]
core_info = core_list[0]
logging.info("Discovered Greengrass Core:{0} from Group:{1}".format(
core_info.coreThingArn, group_id)
)
group_ca_file = save_group_ca(ca, group_ca_dir, group_id)
# local Greengrass Core discovered
# get a shadow client to receive commands
mqttsc = AWSIoTMQTTShadowClient(ggd_name)
# now connect to Core from this Device
logging.info("[core_connect] gca_file:{0} cert:{1}".format(
group_ca_file, certificate))
mqttsc.configureCredentials(group_ca_file, private_key, certificate)
mqttc = mqttsc.getMQTTConnection()
mqttc.configureOfflinePublishQueueing(10, DROP_OLDEST)
if not mqtt_connect(mqttsc, gg_core):
raise EnvironmentError("connection to Master Shadow failed.")
# create and register the shadow handler on delta topics for commands
# with a persistent connection to the Master shadow
master_shadow = mqttsc.createShadowHandlerWithName(
cfg['misc']['master_shadow_name'], True)
return mqttc, mqttsc, master_shadow, ggd_name