質問編集履歴
2
プログラムを簡素化しました、メッセージ数が少ないとエラーが起きなくなることを確認しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,50 +1,31 @@
|
|
1
1
|
ラズベリーパイピコをmicropythonにて動作テスト中、
|
2
2
|
メモリ不足を表すエラー「OSError: [Errno 12] ENOMEM」が発生します
|
3
3
|
|
4
|
+
メッセージ数を少なくすれば、エラーが起きなくなるのですが、
|
5
|
+
会社の業務改善に使用する関係上、一度のプログラムでメッセージ数を10件ほど送らなければならないという背景があります
|
6
|
+
ラズベリーパイピコのメモリは256KB程度であり、
|
7
|
+
メッセージを送った程度ではいっぱいになるはずがないと思います
|
4
8
|
|
5
9
|
そこで質問ですが、
|
10
|
+
・メモリ不足エラーを解消する、プログラムの書き方はないでしょうか?
|
11
|
+
・調べても見つからなかったのですが、ラズベリーパイピコのメモリを増設する方法はないのでしょうか?
|
6
12
|
|
13
|
+
調べた結果、whileの書き方やif構文などの書き方に問題があるなどの結果が出てきたため、
|
14
|
+
一度while 関数、if関数など余計な条件はすべて削除し、
|
7
|
-
|
15
|
+
「30秒ごとにメッセージを送る」というプログラムを書きました
|
8
16
|
|
9
|
-
ラズベリーパイピコのメモリは256KB程度であり、
|
10
|
-
メッセージを送った
|
17
|
+
LINEからメッセージを7通ほど送ったところで、メモリ不足のエラーが発生してしまいます
|
11
|
-
プログラムの書き方の問題でしょうか?
|
12
|
-
なにかしらの方法でメモリを増強するしかないのでしょうか?
|
13
18
|
|
14
|
-
|
19
|
+
メッセージ数を5つ以内に収めると
|
15
|
-
|
16
|
-
```ここに言語を入力
|
17
|
-
message=red right
|
18
|
-
|
20
|
+
問題なくプログラムが動作することを確認しました
|
19
|
-
message=red right remind
|
20
|
-
message=red right remind
|
21
|
-
message=red right remind
|
22
|
-
message=red right remind
|
23
|
-
Traceback (most recent call last):
|
24
|
-
File "<stdin>", line 39, in <module>
|
25
|
-
File "urequests.py", line 184, in post
|
26
|
-
File "urequests.py", line 83, in request
|
27
|
-
OSError: [Errno 12] ENOMEM
|
28
|
-
```
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
21
|
|
35
22
|
|
36
23
|
・ソースコードは以下の通りになります
|
37
24
|
|
38
25
|
```ここに言語を入力
|
39
|
-
|
26
|
+
import machine, utime
|
40
|
-
import
|
27
|
+
import network, urequests
|
41
|
-
from utime import sleep
|
42
|
-
#「ssid」ファイルにてSSIDとパスワードを読み込む
|
43
28
|
from ssid import SSID, PASS
|
44
|
-
|
45
|
-
|
46
|
-
#ラズベリーパイピコがcds光センサーから光を受け取る
|
47
|
-
cds = machine.ADC(0)
|
48
29
|
|
49
30
|
wlan = network.WLAN(network.STA_IF)
|
50
31
|
wlan.active(True)
|
@@ -52,43 +33,68 @@
|
|
52
33
|
|
53
34
|
line_header = {
|
54
35
|
'Content-Type' : 'application/x-www-form-urlencoded',
|
55
|
-
'Authorization': 'Bearer' + ' ' + '
|
36
|
+
'Authorization': 'Bearer' + ' ' + '「LINE notify API」' }
|
56
|
-
|
57
|
-
#赤ライト リマインド3秒おきに5回
|
58
|
-
# パトライトの明かりが30000以上になったらライトが点灯しているとみなす
|
59
37
|
|
60
|
-
while True:
|
61
|
-
|
38
|
+
while(not wlan.isconnected()):
|
39
|
+
print('connecting...')
|
40
|
+
utime.sleep(1.0)
|
41
|
+
print('connected.')
|
62
|
-
|
42
|
+
line_message = 'message=' + 'device found'
|
63
|
-
|
43
|
+
print(line_message)
|
64
|
-
|
44
|
+
urequests.post('https://notify-api.line.me/api/notify', headers = line_header, data = line_message)
|
45
|
+
|
46
|
+
#30秒に一度、LINEメッセージを送る
|
65
|
-
|
47
|
+
utime.sleep(30.0)
|
66
|
-
for i in range(5,0,-1):
|
67
|
-
#リマインド中に明かりが30000を下回ったら作業者がライト消したとみなして、再度ループ
|
68
|
-
|
48
|
+
print('connected.')
|
69
|
-
|
49
|
+
line_message = 'message=' + 'device found'
|
70
|
-
|
50
|
+
print(line_message)
|
71
|
-
|
51
|
+
urequests.post('https://notify-api.line.me/api/notify', headers = line_header, data = line_message)
|
72
|
-
|
52
|
+
utime.sleep(30.0)
|
53
|
+
print('connected.')
|
73
|
-
|
54
|
+
line_message = 'message=' + 'device found'
|
74
|
-
|
55
|
+
print(line_message)
|
75
|
-
|
56
|
+
urequests.post('https://notify-api.line.me/api/notify', headers = line_header, data = line_message)
|
76
|
-
|
57
|
+
utime.sleep(30.0)
|
58
|
+
print('connected.')
|
77
|
-
|
59
|
+
line_message = 'message=' + 'device found'
|
78
|
-
|
60
|
+
print(line_message)
|
79
|
-
|
61
|
+
urequests.post('https://notify-api.line.me/api/notify', headers = line_header, data = line_message)
|
80
|
-
|
62
|
+
utime.sleep(30.0)
|
81
|
-
# リマインド完了後、明かりが消えるまで待機
|
82
|
-
# 明かりが消えたら、改めてプログラムを最初から
|
83
|
-
|
63
|
+
print('connected.')
|
84
|
-
|
64
|
+
line_message = 'message=' + 'device found'
|
85
|
-
|
65
|
+
print(line_message)
|
86
|
-
|
66
|
+
urequests.post('https://notify-api.line.me/api/notify', headers = line_header, data = line_message)
|
87
|
-
machine.reset()
|
88
|
-
else:
|
89
|
-
|
67
|
+
utime.sleep(30.0)
|
90
|
-
|
68
|
+
print('connected.')
|
69
|
+
line_message = 'message=' + 'device found'
|
91
|
-
|
70
|
+
print(line_message)
|
71
|
+
urequests.post('https://notify-api.line.me/api/notify', headers = line_header, data = line_message)
|
72
|
+
|
92
73
|
|
93
74
|
```
|
94
75
|
|
76
|
+
|
77
|
+
|
78
|
+
エラーメッセージは以下の通りになります
|
79
|
+
|
80
|
+
|
81
|
+
```ここに言語を入力
|
82
|
+
message=device found
|
83
|
+
connected.
|
84
|
+
message=device found
|
85
|
+
connected.
|
86
|
+
message=device found
|
87
|
+
connected.
|
88
|
+
message=device found
|
89
|
+
connected.
|
90
|
+
message=device found
|
91
|
+
connected.
|
92
|
+
message=device found
|
93
|
+
Traceback (most recent call last):
|
94
|
+
File "<stdin>", line 48, in <module>
|
95
|
+
File "urequests.py", line 184, in post
|
96
|
+
File "urequests.py", line 83, in request
|
97
|
+
OSError: [Errno 12] ENOMEM
|
98
|
+
>>>
|
99
|
+
```
|
100
|
+
|
1
プログラムのコードを</>で囲み、質問をより明確にしました
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,13 +1,19 @@
|
|
1
1
|
ラズベリーパイピコをmicropythonにて動作テスト中、
|
2
2
|
メモリ不足を表すエラー「OSError: [Errno 12] ENOMEM」が発生します
|
3
3
|
|
4
|
+
|
5
|
+
そこで質問ですが、
|
6
|
+
|
7
|
+
・メモリ不足エラーを解消する方法はないでしょうか?
|
8
|
+
|
4
9
|
ラズベリーパイピコのメモリは256KB程度であり、
|
5
|
-
メッセージを送った程度ではいっぱいになるはずがないと思
|
10
|
+
メッセージを送った程度ではいっぱいになるはずがないと思います
|
11
|
+
プログラムの書き方の問題でしょうか?
|
6
|
-
メモリ
|
12
|
+
なにかしらの方法でメモリを増強するしかないのでしょうか?
|
7
13
|
|
14
|
+
エラーメッセージは以下の通りになります
|
8
15
|
|
9
|
-
|
16
|
+
```ここに言語を入力
|
10
|
-
|
11
17
|
message=red right
|
12
18
|
message=red right remind
|
13
19
|
message=red right remind
|
@@ -19,6 +25,8 @@
|
|
19
25
|
File "urequests.py", line 184, in post
|
20
26
|
File "urequests.py", line 83, in request
|
21
27
|
OSError: [Errno 12] ENOMEM
|
28
|
+
```
|
29
|
+
|
22
30
|
|
23
31
|
|
24
32
|
|
@@ -27,14 +35,15 @@
|
|
27
35
|
|
28
36
|
・ソースコードは以下の通りになります
|
29
37
|
|
38
|
+
```ここに言語を入力
|
30
39
|
|
31
40
|
import machine,utime,time,network, urequests
|
32
41
|
from utime import sleep
|
33
|
-
|
42
|
+
#「ssid」ファイルにてSSIDとパスワードを読み込む
|
34
43
|
from ssid import SSID, PASS
|
35
44
|
|
36
45
|
|
37
|
-
|
46
|
+
#ラズベリーパイピコがcds光センサーから光を受け取る
|
38
47
|
cds = machine.ADC(0)
|
39
48
|
|
40
49
|
wlan = network.WLAN(network.STA_IF)
|
@@ -45,8 +54,8 @@
|
|
45
54
|
'Content-Type' : 'application/x-www-form-urlencoded',
|
46
55
|
'Authorization': 'Bearer' + ' ' + '(LINE API)' }
|
47
56
|
|
48
|
-
|
57
|
+
#赤ライト リマインド3秒おきに5回
|
49
|
-
|
58
|
+
# パトライトの明かりが30000以上になったらライトが点灯しているとみなす
|
50
59
|
|
51
60
|
while True:
|
52
61
|
if cds.read_u16() > 30000:
|
@@ -55,7 +64,7 @@
|
|
55
64
|
urequests.post('https://notify-api.line.me/api/notify', headers = line_header, data = line_message)
|
56
65
|
time.sleep(3.0)
|
57
66
|
for i in range(5,0,-1):
|
58
|
-
|
67
|
+
#リマインド中に明かりが30000を下回ったら作業者がライト消したとみなして、再度ループ
|
59
68
|
if cds.read_u16() < 30000:
|
60
69
|
line_message = 'message=' + 'right off'
|
61
70
|
print(line_message)
|
@@ -69,8 +78,8 @@
|
|
69
78
|
print(line_message)
|
70
79
|
urequests.post('https://notify-api.line.me/api/notify', headers = line_header, data = line_message)
|
71
80
|
while True:
|
72
|
-
|
81
|
+
# リマインド完了後、明かりが消えるまで待機
|
73
|
-
|
82
|
+
# 明かりが消えたら、改めてプログラムを最初から
|
74
83
|
if cds.read_u16() < 30000:
|
75
84
|
line_message = 'message=' + 'restart'
|
76
85
|
print(line_message)
|
@@ -81,6 +90,5 @@
|
|
81
90
|
else:
|
82
91
|
time.sleep(5.0)
|
83
92
|
|
93
|
+
```
|
84
94
|
|
85
|
-
|
86
|
-
|