cannot connect to aws iot using umqtt.simple

オープン
#915 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
20/100
issue の種類
バグ
明瞭さ
説明が足りない
活発さ
停滞
技術スタック
aws, python

調査の方向性

simple1.py の 92 行目にある connect と、MQTT バイトの送信後に空のレスポンスを示しているデバッグ出力から始めます。提供されている AWS IoT 設定で接続試行を再現し、その後レスポンス処理を追跡して失敗の原因を特定します。原因が確認され、接続の成功が実証されるか、必要なセットアップが文書化されれば完了です。

索引モデルが issue の本文から書いたものです。

説明

My code

import time
import machine
import network
import ujson
from simple1 import MQTTClient

SSID = b'Exxxye'
PASS = b'8xxx766'
CLIENT_ID = b'ixxxxxxxxxxxx6eb63'
AWS_ENDPOINT = b'xxxxx-1.amazonaws.com'

PUB_TOPIC = b'temperature'
SUB_TOPIC = b'temperature'
with open('/pri.der', 'rb') as f:
    DEV_KEY = f.read()

with open('/cert.der', 'rb') as f:
    DEV_CRT = f.read()

light = machine.Pin("LED", machine.Pin.OUT)
light.off()


def wifi_connect():
    print('Connecting to wifi...')
    wlan = network.WLAN(network.STA_IF)
    wlan.active(True)
    wlan.connect(SSID, PASS)
    while wlan.isconnected() == False:
        light.on()
        print('Waiting for connection...')
        time.sleep(0.5)
        light.off()
        time.sleep(0.5)
    print('Connection details: %s' % str(wlan.ifconfig()))

def mqtt_subscribe_callback(topic, msg):
    print("Received topic: %s message: %s" % (topic, msg))
    if topic == SUB_TOPIC:
        mesg = ujson.loads(msg)
        if 'state' in mesg.keys():
            if mesg['state'] == 'on' or mesg['state'] == 'ON' or mesg['state'] == 'On':
                light.on()
                print('Light is ON')
            else:
                light.off()
                print('Light is OFF')

def get_rpi_temperature():
    sensor = machine.ADC(4)
    voltage = sensor.read_u16() * (3.3 / 65535)
    temperature = 27 - (voltage - 0.706) / 0.001721
    return temperature


wifi_connect()


mqtt = MQTTClient(
    client_id=CLIENT_ID,
    server=AWS_ENDPOINT,
    port=8883,
    keepalive=120,
    ssl=True,
    ssl_params={'key':DEV_KEY, 'cert':DEV_CRT, 'server_side':False})

mqtt.connect()

mqtt.set_callback(mqtt_subscribe_callback)


mqtt.subscribe(SUB_TOPIC)

while True:
message = b'{"temperature":%s, "temperature_unit":"Degrees Celsius"}' % get_rpi_temperature()
    print('Publishing topic %s message %s' % (PUB_TOPIC, message))

    mqtt.publish(topic=PUB_TOPIC, msg=message, qos=1)

    # Check subscriptions for message
    mqtt.check_msg()
    time.sleep(5)

My error code:

Connecting to wifi...
Connection details: ('192.168.x.xx', '255.255.255.0', '192.168.xx.xx', '192.168.xx.xx')
dbug-msg: 0x9 b'04:4d:51:54:54:04:02:00:78'
dbug-resp: b''
Traceback (most recent call last):
File "", line 81, in
File "simple1.py", line 92, in connect
IndexError: bytes index out of range

please someone help me on this..i tried everything

主要言語
Python
スター
2.9k
フォーク
1.1k
平均マージ
7日 6時間
マージ済み PR(30日)
3

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

micropython/micropython-lib のほかの issue

micropython/micropython-lib の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。