Yep, the last reading was posted on March 13, 2019, at 10:48am, three days prior to starting this post. I’m not sure why it stopped.
I decided to take the opportunity to update my Arduino code to include color temperature and lux (perceived brightness) readings from the TCS34725 sensor. I originally wanted to include these but my initial tests five weeks ago gave readings that were all over the place depending on how I was initiating the sensor. Tom suggested I used this for more accuracy:
Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_700MS, TCS34725_GAIN_1X);
…as well as use this updated method to calculate color temperature:
colorTemp = tcs.calculateColorTemperature_dn40(red, green, blue, clear);
Note: I had to update the TCS34725 library to version 1.3.0 to access that dn40 algorithm.
Updated Code on Github
Part 1: Processing MQTT Data
A quick recap before we continue. So far I learned how to publish sensor data from my WiFi-connected Arduino MKR1000 to a server using MQTT protocol. That server, which was set up especially for this class, is running Mosquitto, an open source MQTT broker, and I can subscribe to the broker’s data topics to see my sensor’s data in real time. I also figured out how to connect my Arduino to a power supply to publish data continuously to the broker to start logging it over an extended period of time. To save this data, Don wrote a Node.js script on the same server that subscribes to the MQTT topics and then inserts data into a shared class PostgreSQL database living elsewhere on AWS. We practiced writing SQL queries against that PostgresQL database, as well as a few other databases (InfluxDB, MongoDB, and TimescaleDB) for comparison.
For this week, we learned how to write our own Node.js script to subscribe to the MQTT topics we care about and insert them into our own database. Because I’m interested in setting up my own Timescale database in the future, I modified the provided code to subscribe to the MQTT topic for my device and send the values for all readings (temperature, humidity, red, green, blue, color temperature, and lux) into my personal database in the TimescaleDB. I really didn’t do much work here—just updated MQTT subscription route to my device. However, I solidified my conceptual understanding of what’s happening behind the scenes. (Note that this Node.js script only runs when launched from my Terminal and while my computer is active.)