デバイスでのデータ送信エラー
ESP32からサーバーへ送るプログラムにおいて、以下のようなエラーが出ていました。
・プログラム
# データ送信
sleepTime = send_data_to_firebase(temperature, macAddress)
print("sleepTime:", sleepTime)
# スリープに入る
# time.sleep(sleepTime)
machine.deepsleep(sleepTime)
・エラー
ampy --port /dev/tty.usbserial-0001 run main.py
mac_id : 08d1f9e822ec
macAddress : 08d1f9e822ec
Found DS18B20 sensors: [bytearray(b'(\xf5\tC\xd4\xe1<7')]
rom : bytearray(b'(\xf5\tC\xd4\xe1<7')
temperature : 20.7
Wi-Fiに接続しました。ssid : FS030W_P33278
Traceback (most recent call last):
File "/Users/user/anaconda3/bin/ampy", line 8, in <module>
sys.exit(cli())
^^^^^
File "/Users/user/anaconda3/lib/python3.11/site-packages/click/core.py", line 1157, in __call__
return self.main(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/user/anaconda3/lib/python3.11/site-packages/click/core.py", line 1078, in main
rv = self.invoke(ctx)
^^^^^^^^^^^^^^^^
File "/Users/user/anaconda3/lib/python3.11/site-packages/click/core.py", line 1688, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/user/anaconda3/lib/python3.11/site-packages/click/core.py", line 1434, in invoke
return ctx.invoke(self.callback, **ctx.params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/user/anaconda3/lib/python3.11/site-packages/click/core.py", line 783, in invoke
return __callback(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/user/anaconda3/lib/python3.11/site-packages/ampy/cli.py", line 338, in run
output = board_files.run(local_file, not no_output, not no_output)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/user/anaconda3/lib/python3.11/site-packages/ampy/files.py", line 309, in run
self._pyboard.execfile(filename, stream_output=True)
File "/Users/user/anaconda3/lib/python3.11/site-packages/ampy/pyboard.py", line 285, in execfile
return self.exec_(pyfile, stream_output=stream_output)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/user/anaconda3/lib/python3.11/site-packages/ampy/pyboard.py", line 277, in exec_
ret, ret_err = self.exec_raw(command, data_consumer=data_consumer)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/user/anaconda3/lib/python3.11/site-packages/ampy/pyboard.py", line 266, in exec_raw
return self.follow(timeout, data_consumer)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/user/anaconda3/lib/python3.11/site-packages/ampy/pyboard.py", line 230, in follow
raise PyboardError('timeout waiting for first EOF reception')
ampy.pyboard.PyboardError: timeout waiting for first EOF reception
Pyboardからの応答がタイムアウトしています。
machine.deepsleep()メソッドを呼び出す前に、応答を待つための短い待ち時間を挿入することで解決できました。
・コード
# データ送信
sleepTime = send_data_to_firebase(temperature, macAddress)
print("sleepTime:", sleepTime)
# データ送信が完了したことを確認するため待つ
time.sleep(5)
# スリープに入る
# time.sleep(sleepTime)
machine.deepsleep(sleepTime)