Issue
Here used to be our potentiostat UART output. It's raw and messy. We need to extract the data manually before plotting the results. Our former workflow was to extract the data from the logs, remove the timestamps and unnecessary symbols printed in our logs, save the file as CSV and let the python script do the job to plot the data.
Our Potentiostat raw output
The plotting process takes a while as we have to look at the starting data all the way to the end. Then we have to name the file and configure the script about the parameters we used during the measurements. Finally we convert the voltage to current before we can plot the data.
Plotting our cyclic voltammetry data (ferricyanide)
For small amount of data, it's still manageable as the workflow is still simple and doesn't require a meticulous process. We can still include the parameters to the plotting function as we remember it. However, when we have lots of measurement data, extracting the data and considering so many measurement data would be cumbersome. Additionally, we need to store the whole data including the parameters to make the data more accurate and reliable when we want to replicate the experiment. Therefore, additional data such as device parameters need to be included. However, a conundrum would appear, if we add another column in the CSV files just for tthe device parameters, the CSV would be more complicated and full of empty data.
Solution: JSON
in order to store all of the experimental and its metadata (device configurations), JSON format is more appropriate as we can integrate structured and unstructured data into one. We can store both metadata as a value and experiments data as arrays. This way, the data is more structured and we don't have to fill any empty data just like CSV.
Now the question is how do we collect and store the data? As we know, we stream the UART data to the PC using serial port. This streaming process can be passed through the local server that would log the ouput into the data. We can capture the data based on the "topic" or "key" of the object so that we can selectively choose which data to plot.
Selecting what to plot based on topic/object key is a good approach. However, this approach is still not bulletproof as we also use the same function to measure the voltage and current in the the potentiostat. Therefore, there should be a "flag" whether the device is running the measurement or just measuring the voltage for the background voltage. Therefore, when the running flag is disable, it would record the background voltage. On the other hand, when it's enabled it would collect the data and directly plot it to the graph. After the measurement is completed, the device would update the flag to false meaning the measurement is completed and the program would save the measurement as well as plotting the graph.
(plotting the graph)
That's the better approach rather than adding changing some sign in the output of the potentiostat device, our current approach as it's prone to error due to interrupt during streaming the data.