The first step is to confirm that we can read the light from the JUUL. I created the circuit below with two major components:
The button and resistor in the middle were for testing and are non-functional.
The sketch initializes the Color Sensor Board to raise an interrupt line when the light value exceeds a threshold. Color values are read over I2C connection and output to the serial connection which is monitored in a window. The result is demonstrated in the video to the right. It works with the comparatively low light levels of the JUUL LED - just not easily demonstrated in a video.
The next step is put the ESP32 to sleep when not active to save battery then wake it to process activity. We want to wake when the LED illuminates then process based on color and light pattern. We also want to wake on button press to exchange data with smartphone. I think we can use one wake process to serve light and button because in the case of the button press, there will be no light and we can code to that permutation. If not, I will add a second interrupt line later.
The next issue I want to tackle is preserving the data in the on-board flash storage (4mb) - which survives the sleep/wake cycle. I was silent in my requirements about how long a period the device can go between smart phone syncs. I will shoot for 7 days, assume a heavy user is vaping 100 times per day and another 50 events per day - battery check and such. That means I want to be able to store 1050 rows. Each row will contain date and readings and possibly debug information for a total of 1,000 bytes. 1050*1000 = ~1mb.
Done - easy. Look at the Persistence Commit above and you will find it.
I am prioritizing Bluetooth ahead of other work because it is an unknown and because I think it will become my reference for Date/Time Management.
The requirement is to pair with a single smart phone and ignore all other attempts to pair unless the monitor is opened up. I may use a combination of outside button and open-case sensor or I may have to implement a dedicated button.
I may have to record relative time then convert to real time at upload.