reader primarily for the iot-mkr680, uses a small C wrapper for communicating with /dev/ttyACM0 and PHP for heavy lifting

kyle c221d981d8 explains how to install sysv init for systems that use it 2 gadi atpakaļ
expirements 5f54680414 adds daemon to read sensor and send data to mmcgo.com 2 gadi atpakaļ
.gitignore e0d5b73d44 add some stuff for mmcgo, SYSV init script added too 2 gadi atpakaļ
README.md c221d981d8 explains how to install sysv init for systems that use it 2 gadi atpakaļ
mkr680-read.c 41d8168457 can call read multiple times, was only reading 64 bytes on some computers 2 gadi atpakaļ
mkr680-sender.service 5f54680414 adds daemon to read sensor and send data to mmcgo.com 2 gadi atpakaļ
mkr680-sysv-init 0158fd07f4 working directory is possibly important 2 gadi atpakaļ
sender.php 12ea7e2439 add some sanity checks to bme680 sensor data 2 gadi atpakaļ

README.md

itm-mkr680

Found a sensor that uses the Bosch Indoor Air Quality Sensor, BEM680, it measures gas, pressure, humidity, and temperature. In 2021 the sensor cost 20USD, but I found the IOTeam itm-mkr680 rev B board on arrow dot com that includes an SAMD21 mcu for around 17USD. The SAMD21 has a built-in USB PHY and the pre-programmed firmware seems to yeild data that seems reasonable. The USB PHY is configured as a USB serial adapter that is connected to a UART running at 9600 baud. Sending the capital 'R' tells the sensor to output it's most recent reading. I have not found a datasheet or any user manual for the software. Again, I have not checked any of this infomation, but this project is meant to read this data and make it available to a larger computer with improved output capabilities, like charts and other general purpose computer software. udevadm info --name=/dev/ttyACM0

the hectoPascal bug

the version: Firmware v1.0.0 - BSEC v1.4.5.1 reported by the itm-mkr680 reports the pressure as hPa but in reality it is measuring Pa. If one just imagined that the device reported pascals, no conversion is needed, otherwise to convert the reported unit one needs to divide by 100 for hecto pascals. We are not going to convert and instead rename everything to Pa.

testing usb uart

use screen /dev/ttyACM0, you might need to check the device file permissions beforehand

to terminate screen press [ctrl] + [a] then [\], this will cause screen to prompt an interactive close menu

expirements

trying to open the usb uart from php is kind of lame, fopen in php does not allow setting some of the flags needed to prevent the interactive firmware on the itm-mkr680 from misbehaving. The interactive interface sends characters to us, but by default the ctty flag is set causing linux to echo these charaters back to the itm-mkr680. it then interprets those characters and responds with an error message, this cycles. we need to turn off the ctty flag, to do this php has dio, but we need to install something for that.

in the end an okay solution was to write a program that opens the serial port, sends the 'R' and dumps the output before php processing

main program

the sender.php program sends the sensor data to mmcgo once every 15 minutes, it uses a.out to communicate with /dev/ttyACM0 where the sensor is connected

installation

make sure that the sender.php program has the right sensor name when sending POST data to mmcgo, this name is custom and assigned to the sensor. copy the systemd service file to /etc/systemd/system/, then enable it systemctl enable mkr680-sender.service

the sender.php is going to run a program mkr680-reader, this is the small serial wrapper, compile then symlink, gcc mkr680-read.c; ln -s a.out mkr680-reader is sufficient.

for system v init systems

copy the init scipt to /etc/init.d/ and use chkconfig to enable runlevels sudo chkconfig mkr680-sysv-init on. on an old ubuntu system I ran into two problems, it was using upstart so chkconfig was not installed by default, and insserv was installed in a wierd directory, fixed with:

sudo apt-get install chkconfig insserv
sudo ln -s /usr/lib/insserv/insserv /sbin/

sensors and their names

get the sensor id using udevadm info --name=/dev/ttyACM0 |grep ID_SERIAL=

sensor serial
H IOTEAM_ITM-MKR680_845AB949504E5336362E3120FF032E37
I connected to mmcgo, udevadm did not work
J IOTEAM_ITM-MKR680_F7300297504E5336362E3120FF012F0D