質問編集履歴
1
質問を明確にしました。
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
通信時にタイムアウトエラー発生
|
test
CHANGED
@@ -1,8 +1,4 @@
|
|
1
1
|
##やろうとしていること
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
MQTTメッセージを受信(Subscribe)し、
|
6
2
|
|
7
3
|
受信メッセージに応じた処理を行う。
|
8
4
|
|
@@ -18,159 +14,7 @@
|
|
18
14
|
|
19
15
|
|
20
16
|
|
21
|
-
②の処理が実行されると、プログラムが終了してしまいます。(スイッチを押す前にプログラムが終了してしまいます。)
|
22
|
-
|
23
|
-
終了したときに表示されるエラー情報を↓に添付しますが、
|
24
|
-
|
25
|
-
このエラーの内容、なぜこのエラーが起こるのかが分かりません。
|
26
|
-
|
27
17
|
|
28
|
-
|
29
|
-
##プログラム(Subscribe)
|
30
|
-
|
31
|
-
```python
|
32
|
-
|
33
|
-
#!/usr/bin/python
|
34
|
-
|
35
|
-
# coding: utf-8
|
36
|
-
|
37
|
-
import time
|
38
|
-
|
39
|
-
from AWSIoTPythonSDK.MQTTLib import AWSIoTMQTTClient
|
40
|
-
|
41
|
-
import subprocess
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
CLIENT_ID = "AWS"
|
46
|
-
|
47
|
-
ENDPOINT = "hoge.amazonaws.com" # <random>.iot.<region>.amazonaws.com
|
48
|
-
|
49
|
-
PORT = 8883
|
50
|
-
|
51
|
-
ROOT_CA = "/home/pi/dev/aws/rootCA.pem"
|
52
|
-
|
53
|
-
PRIVATE_KEY = "/home/pi/dev/aws/hogee.pem.key"
|
54
|
-
|
55
|
-
CERTIFICATE = "/home/pi/dev/aws/hoge.pem.crt"
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
TOPIC = "test"
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
client = AWSIoTMQTTClient(CLIENT_ID)
|
66
|
-
|
67
|
-
client.configureEndpoint(ENDPOINT, PORT)
|
68
|
-
|
69
|
-
client.configureCredentials(ROOT_CA, PRIVATE_KEY, CERTIFICATE)
|
70
|
-
|
71
|
-
# AWSIoTMQTTClient connection configuration
|
72
|
-
|
73
|
-
client.configureAutoReconnectBackoffTime(1, 32, 20)
|
74
|
-
|
75
|
-
# -1:infinite
|
76
|
-
|
77
|
-
client.configureOfflinePublishQueueing(-1)
|
78
|
-
|
79
|
-
# Draining: 2 Hz
|
80
|
-
|
81
|
-
client.configureDrainingFrequency(2)
|
82
|
-
|
83
|
-
# 10 sec
|
84
|
-
|
85
|
-
client.configureConnectDisconnectTimeout(10)
|
86
|
-
|
87
|
-
# 5 sec
|
88
|
-
|
89
|
-
client.configureMQTTOperationTimeout(5)
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
def mycallback(client, userdata, message):
|
94
|
-
|
95
|
-
print("Received message '" + str(message.payload) + "' on topic '" + message.topic + "' with QoS " + str(message.qos))
|
96
|
-
|
97
|
-
if message.payload == "rrr":
|
98
|
-
|
99
|
-
print("rrr")
|
100
|
-
|
101
|
-
subprocess.check_call(['python','/home/pi/dev/rrr.py'])
|
102
|
-
|
103
|
-
elif message.payload == "xxxx":
|
104
|
-
|
105
|
-
print("xxxx")
|
106
|
-
|
107
|
-
subprocess.check_call(['python','/home/pi/dev/xxxx.py'])
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
if __name__ == "__main__":
|
112
|
-
|
113
|
-
try:
|
114
|
-
|
115
|
-
client.connect()
|
116
|
-
|
117
|
-
while True:
|
118
|
-
|
119
|
-
client.subscribe(TOPIC, 1, mycallback)
|
120
|
-
|
121
|
-
time.sleep(1)
|
122
|
-
|
123
|
-
except KeyboardInterrupt:
|
124
|
-
|
125
|
-
GPIO.cleanup()
|
126
|
-
|
127
|
-
```
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
##プログラム(実行するとエラーになってしまうコード)
|
134
|
-
|
135
|
-
```python
|
136
|
-
|
137
|
-
if __name__ == '__main__':
|
138
|
-
|
139
|
-
try:
|
140
|
-
|
141
|
-
# Setup leds
|
142
|
-
|
143
|
-
setup(LED1, LED2, LED3, LED4)
|
144
|
-
|
145
|
-
print("Received xxxx ...")
|
146
|
-
|
147
|
-
# Run blinking forever
|
148
|
-
|
149
|
-
while True:
|
150
|
-
|
151
|
-
sw_state = GPIO.input(SW)
|
152
|
-
|
153
|
-
if sw_state == True:
|
154
|
-
|
155
|
-
blink(LED1, LED2, LED3, LED4)
|
156
|
-
|
157
|
-
buzzer()
|
158
|
-
|
159
|
-
else:
|
160
|
-
|
161
|
-
GPIO.cleanup()
|
162
|
-
|
163
|
-
break
|
164
|
-
|
165
|
-
except KeyboardInterrupt:
|
166
|
-
|
167
|
-
GPIO.cleanup()
|
168
|
-
|
169
|
-
```
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
18
|
|
175
19
|
##エラー
|
176
20
|
|