質問するログイン新規登録

質問編集履歴

2

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

2023/12/02 02:03

投稿

nihonnnoheso
nihonnnoheso

スコア6

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

1

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

2023/12/01 08:29

投稿

nihonnnoheso
nihonnnoheso

スコア6

title CHANGED
File without changes
body 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,22 +25,25 @@
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
+ ```
22
29
 
23
30
 
24
31
 
25
32
 
26
33
 
27
34
 
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,5 +90,4 @@
81
90
  else:
82
91
  time.sleep(5.0)
83
92
 
84
-
93
+ ```
85
-