質問編集履歴

2

プログラムを簡素化しました、メッセージ数が少ないとエラーが起きなくなることを確認しました

2023/12/02 02:03

投稿

nihonnnoheso
nihonnnoheso

スコア6

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
- message=red right remind
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 machine,utime,time,network, urequests
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' + ' ' + '(LINE API)' }
36
+ 'Authorization': 'Bearer' + ' ' + 'LINE notify API' }
56
-
57
- #赤ライト リマインド3秒おきに5回
58
- # パトライトの明かりが30000以上になったらライトが点灯しているとみなす
59
37
 
60
- while True:
61
- if cds.read_u16() > 30000:
38
+ while(not wlan.isconnected()):
39
+ print('connecting...')
40
+ utime.sleep(1.0)
41
+ print('connected.')
62
- line_message = 'message=' + 'red right'
42
+ line_message = 'message=' + 'device found'
63
- print(line_message)
43
+ print(line_message)
64
- urequests.post('https://notify-api.line.me/api/notify', headers = line_header, data = line_message)
44
+ urequests.post('https://notify-api.line.me/api/notify', headers = line_header, data = line_message)
45
+
46
+ #30秒に一度、LINEメッセージを送る
65
- time.sleep(3.0)
47
+ utime.sleep(30.0)
66
- for i in range(5,0,-1):
67
- #リマインド中に明かりが30000を下回ったら作業者がライト消したとみなして、再度ループ
68
- if cds.read_u16() < 30000:
48
+ print('connected.')
69
- line_message = 'message=' + 'right off'
49
+ line_message = 'message=' + 'device found'
70
- print(line_message)
50
+ print(line_message)
71
- urequests.post('https://notify-api.line.me/api/notify', headers = line_header, data = line_message)
51
+ urequests.post('https://notify-api.line.me/api/notify', headers = line_header, data = line_message)
72
- break
52
+ utime.sleep(30.0)
53
+ print('connected.')
73
- line_message = 'message=' + 'red right remind'
54
+ line_message = 'message=' + 'device found'
74
- print(line_message)
55
+ print(line_message)
75
- urequests.post('https://notify-api.line.me/api/notify', headers = line_header, data = line_message)
56
+ urequests.post('https://notify-api.line.me/api/notify', headers = line_header, data = line_message)
76
- time.sleep(3.0)
57
+ utime.sleep(30.0)
58
+ print('connected.')
77
- line_message = 'message=' + 'remind end'
59
+ line_message = 'message=' + 'device found'
78
- print(line_message)
60
+ print(line_message)
79
- urequests.post('https://notify-api.line.me/api/notify', headers = line_header, data = line_message)
61
+ urequests.post('https://notify-api.line.me/api/notify', headers = line_header, data = line_message)
80
- while True:
62
+ utime.sleep(30.0)
81
- # リマインド完了後、明かりが消えるまで待機
82
- # 明かりが消えたら、改めてプログラムを最初から
83
- if cds.read_u16() < 30000:
63
+ print('connected.')
84
- line_message = 'message=' + 'restart'
64
+ line_message = 'message=' + 'device found'
85
- print(line_message)
65
+ print(line_message)
86
- urequests.post('https://notify-api.line.me/api/notify', headers = line_header, data = line_message)
66
+ urequests.post('https://notify-api.line.me/api/notify', headers = line_header, data = line_message)
87
- machine.reset()
88
- else:
89
- time.sleep(5.0)
67
+ utime.sleep(30.0)
90
- else:
68
+ print('connected.')
69
+ line_message = 'message=' + 'device found'
91
- time.sleep(5.0)
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

プログラムのコードを</>で囲み、質問をより明確にしました

2023/12/01 08:29

投稿

nihonnnoheso
nihonnnoheso

スコア6

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
- >「ssid」ファイルにてSSIDとパスワードを読み込む
42
+ #「ssid」ファイルにてSSIDとパスワードを読み込む
34
43
  from ssid import SSID, PASS
35
44
 
36
45
 
37
- >ラズベリーパイピコがcds光センサーから光を受け取る
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
- >赤ライト リマインド3秒おきに5回
57
+ #赤ライト リマインド3秒おきに5回
49
- > パトライトの明かりが30000以上になったらライトが点灯しているとみなす
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
- >リマインド中に明かりが30000を下回ったら作業者がライト消したとみなして、再度ループ
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
-