Read the statement by Michael Teeuw here.
MMM-Temperature uncaught exception...
-
I wrote a script to use the SHT31-D temperature and humidity sensor from adafruit. The script works in that it correctly displays the temp and humidity. The log file however shows the following:
[02.08.2023 19:53.15.002] [LOG] MMM-Temperature: Updating sensor values
[02.08.2023 19:53.15.002] [LOG] MMM-Temperature Calling: /home/mpi-admin/MagicMirror/modules/MMM-Temperature/scripts/sht31
[02.08.2023 19:53.15.338] [LOG] {“temperature_c”:24.78637369344625,“humidity”:42.03402761882963,“temperature_f”:76.61547264820325,“error”:false}
[02.08.2023 19:53.15.339] [LOG] MMM-Temperature: New Values of sensor with id 0 (Indoor): {“temperature_c”:“24.8”,“humidity”:“42.0”,“temperature_f”:“76.6”,“error”:false,“temperature”:“76.6”}
[02.08.2023 19:53.15.339] [LOG] Sending temp update: [{“temperature_c”:“24.8”,“humidity”:“42.0”,“temperature_f”:“76.6”,“error”:false,“temperature”:“76.6”}]
[02.08.2023 19:53.15.346] [ERROR] Whoops! There was an uncaught exception…
[02.08.2023 19:53.15.362] [ERROR] Error: write EFAULT
at afterWriteDispatched (node:internal/stream_base_commons:160:15)
at writeGeneric (node:internal/stream_base_commons:151:3)
at Socket._writeGeneric (node:net:930:11)
at Socket._write (node:net:942:8)
at writeOrBuffer (node:internal/streams/writable:392:12)
at _write (node:internal/streams/writable:333:10)
at Writable.write (node:internal/streams/writable:337:10)
at execSync (node:child_process:981:20)
at node:electron/js2c/asar_bundle:2:12711
at Class.updateSensorValues (/home/mpi-admin/MagicMirror/modules/MMM-Temperature/node_helper.js:65:24)
at Class.socketNotificationReceived (/home/mpi-admin/MagicMirror/modules/MMM-Temperature/node_helper.js:165:12)
at Socket. (/home/mpi-admin/MagicMirror/js/node_helper.js:104:11)
at Socket.emit (node:events:513:28)
at Socket.emitUntyped (/home/mpi-admin/MagicMirror/node_modules/socket.io/dist/typed-events.js:69:22)
at /home/mpi-admin/MagicMirror/node_modules/socket.io/dist/socket.js:703:39
at process.processTicksAndRejections (node:internal/process/task_queues:77:11) {
errno: -14,
code: ‘EFAULT’,
syscall: ‘write’
}This is my script:
#!/usr/bin/env python3 #Install Dependencies: # cd ~ # sudo pip3 install --upgrade adafruit-python-shell # wget https://raw.githubusercontent.com/adafruit/Raspberry-Pi-Installer-Scripts/master/raspi-blinka.py # sudo python3 raspi-blinka.py # sudo pip3 install adafruit-circuitpython-sht31d # import board import adafruit_sht31d import json i2c = board.I2C() h = adafruit_sht31d.SHT31D(i2c) result = {} try: result["temperature_c"] = h.temperature result["humidity"] = h.relative_humidity result["temperature_f"] = (result["temperature_c"]*1.8) + 32 result["error"] = False except: result["temperature_c"] = 0.0 result["humidity"] = 0.0 result["temperature_f"] = (result["temperature_c"]*1.8) + 32 result["error"] = True print(json.dumps(result))
Any help would be appreciate. Python is not my native language.
-
@Brown19 Hi,
your python script looks good to me and also the output of node_helper till the moment it tries to send the data to the frontend.
Can you provide your MagicMirror and nodejs version information to me, please? -
I tried your script and the current version of the module in both of my setups (2.24.0 native and 2.25.0-develop container) and do not have any problems.
As i wrote already the problem looks like there is problem during communication between the node_helper.js and the frontend (either electron or the browser of your choice).
-
@wishmaster270 I’m running 2.24.0 and node is v18.17.0
-
@Brown19 Do you see any errors in the development console of the browser?
-
@Brown19
Hi,today i installed a new instance of MagicMirror 2.24.0 with both your node version 18 any my current used one (16).
In the installation which uses electron i can reproduce the error now. But i am pretty sure this is a problem related to the combination of the version 2.24.0 and the used electron version.
I found this thread with the same error but MMM-Tools instead in the forum of bogusnet, too.
It might be a general MagicMirror issue and not a problem of the module.Maybe one of the core developers can have a look into it. I never had been that deep in the MagicMirror code and do not have much time to investigate the problem at the moment.
-
@wishmaster270 what module is this? I’ll look at it tonight.
-
@sdetweil Hi Sam, it looks like both MMM-Temperature and MMM-Tools cause the error.
-
i did some more investigation today and think i found a solution.
Although the exception looks different i think the problem is theexecSync
command.
The only way i was able to fix it is to usespawnSync
.But i can not say where or why the problem happens.
I tried different node versions (latest 16, 18, 20) and different electron versions (25.3.0, 25.3.2 and 25.4.0) withexecSync
.I will release a new version of
MMM-Temperature
today which usesspawnSync
instead ofexecSync
. -
@wishmaster270 good catch. I think exec is foreground, spawn is background.