You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<p>With that out of the way, there are two other components I need for this to work: a collector which will collect all of the data sent back from the atmotube and a worker which will log it to a csv. Unlike above, where I logged each advertising packet as I came in, I am going to make these run asynchronously using <code>asyncio</code>. I think this is what really <em>should</em> be done, instead of blocking for file i/o every time a callback function is triggered.</p>
2313
+
<p>With that out of the way, there are two other components I need for this to work: a collector which will collect all of the data sent back from the atmotube and a worker which will log it to a csv. Unlike above, where I logged each advertising packet as it came in, I am going to make these run asynchronously using <code>asyncio</code>. I think this is what really <em>should</em> be done, instead of blocking for file i/o every time a callback function is triggered.</p>
2314
2314
<p>To make this happen I largely copied <a href="https://github.com/hbldh/bleak/blob/develop/examples/async_callback_with_queue.py">what was done in this example</a> which uses an async queue to pass data between the two workers. The basic idea is:</p>
2315
2315
<ol type="1">
2316
2316
<li>The collector starts up and scans for the atmotube, by MAC address.</li>
<li>When the logger starts it creates a new csv file with the given <code>filename</code>, and writes the column headers.</li>
2428
2428
<li>The worker waits for data to appear on the queue and, once it does, takes it out (first in first out).</li>
2429
-
<li>The result on the queue is lined up to the right columns in the csv, I check for the attribute <code>battery_level</code> as a lazy check of which type of result it is.</li>
2429
+
<li>The result from the queue is lined up to the right columns in the csv, I check for the attribute <code>battery_level</code> as a lazy check of which type of result it is.</li>
2430
2430
<li>Finally the worker writes the result as new row on the csv.</li>
2431
2431
<li>If the result is <code>None</code>, that is a signal that the collector has finished and the loop exits.</li>
2432
2432
<li>Regardless, once the logger has processed the data from the queue, it calls <code>task_done()</code> to notify the queue of this and the loop begins again.</li>
@@ -2781,7 +2781,7 @@ Figure 6: Time series data of indoor PM2.5 concentrations, a 1-hr sample us
2781
2781
</div>
2782
2782
</div>
2783
2783
<p>With no context it looks like something is horribly wrong, what are all those gaps in the data? My atmotube is set to only sample every 15 minutes, this is usually how I leave it to save on battery. This also explains some of the weirdness with the data, why does each sample start with a rapidly increasing concentration before levelling out? The atmotube is returning data right when the sampling fan has just turned on; this is not yet an accurate sample of the ambient air, it is the stagnant air inside the atmotube. This is a much more obvious problem with VOC data, it is clearly visible on the app as a funky saw-tooth wave where the VOC concentration plunges whenever the fan starts and, once it stops, slowly creeps up. It is an artifact of how the atmotube is sampling the air, not of how the data is being collected.</p>
2784
-
<p>If the atmotube is set to always on mode, these artifacts go away, but if you want to monitor it in other configurations it is worth considering how the data should be cleaned up. For example watching for the <code>pm_sensor</code> flag to turn on then throwing out the first ~30s of pm data before looking at the rest. The GATT notifications make it very clear when the atmotube is sampling and when it isn’t. There will be a notification that <code>pm_sensor</code> has turned from 0 to 1, then data will start arriving with pm data, then a notification that the <code>pm_sensor</code> has turned from 1 to 0, followed by an empty row of pm data. See a snipped of the csv below. Note that <code>pm_sensor</code> values and actual pm values are always on seperate rows.</p>
2784
+
<p>If the atmotube is set to always on mode, these artifacts go away, but if you want to monitor it in other configurations it is worth considering how the data should be cleaned up. For example watching for the <code>pm_sensor</code> flag to turn on then throwing out the first ~30s of pm data before looking at the rest. The GATT notifications make it very clear when the atmotube is sampling and when it isn’t. There will be a notification that <code>pm_sensor</code> has turned from 0 to 1, then data will start arriving with pm data, then a notification that the <code>pm_sensor</code> has turned from 1 to 0, followed by an empty row of pm data. See a snippet of the csv below. Note that <code>pm_sensor</code> values and actual pm values are always on seperate rows.</p>
0 commit comments