Ошибка при подключении к ip ядра Greengrass - PullRequest
0 голосов
/ 11 декабря 2019

Подключение к AWS-END-POINT правильно, но когда я попытался подключиться к ядру Greengrass с использованием локальной сети ip. Я получаю следующую ошибку:

E/flutter (12349): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled 
Exception: HandshakeException: Handshake error in client (OS Error:
E/flutter (12349): CERTIFICATE_VERIFY_FAILED: Hostname 
mismatch(handshake.cc:352))

Я уже проверил ядро ​​greengrass. работает нормальноЯ думаю, что может быть некоторая проблема использования IP-адреса вместо URL-адреса. но я не уверен. Кто-нибудь может помочь, пожалуйста?

Код, который я использую,

import 'dart:async';
import 'dart:io';
import 'package:mqtt_client/mqtt_client.dart';

import 'dart:convert' show utf8;
import 'dart:convert';

Future main() async {

const String url =
'192.168.8.102';
const int port = 8883;
const String clientId =
'Flutter_tmfacility_0_1';

MqttClient client = MqttClient.withPort(url,clientId,port);

client.secure = true;
// Set the security context as you need, note this is the standard Dart SecurityContext class.

final SecurityContext context = new SecurityContext(withTrustedRoots: true); context.setTrustedCertificatesBytes(utf8.encode('GREEN GRASS CORE CERT HERE'));
context.useCertificateChainBytes(utf8.encode(' CLIENT CERT HERE'));
context.usePrivateKeyBytes(utf8.encode(' MY PRIVATE KEY HERE '));

client.securityContext = context;
client.setProtocolV311();
// logging if you wish
client.logging(on: false);
print('Before Connecting');

await client.connect(url);

print('After Connecting');
if (client.connectionStatus.state == MqttConnectionState.connected) {
print('iotcore client connected');
} else {
print(
'ERROR iotcore client connection failed - disconnecting, state is ${client.connectionStatus.state}');
client.disconnect();
}
const String topic = '$aws/things/Pi_tmfacility_0_1/shadow/update';
String payload = '{'state':{'desired': {'name' : 'usama'}} }';

final MqttClientPayloadBuilder builder = MqttClientPayloadBuilder();
builder.addString(json.encode(payload));

print('into the publish to get single device shadow ');
client.publishMessage(topic, MqttQos.atMostOnce, builder.payload);
print('Sleeping....');
await MqttUtilities.asyncSleep(10);
print('Disconnecting');
client.disconnect();
return 0;
}

[enter image description here][1]


  [1]: https://i.stack.imgur.com/hihvh.png
...