Project Journal for Andrew Haggerty

=============== Week 15: =================

Entry 3: Website Work session 3 + project demo-----------------------------------------------------------------

Date: April 25th
Start Time: 1:00pm
Duration: 4.5 hours

Goal: Add a couple more settings and finishing touches to website
  • to start, try making a text box that can send a target email to a plaintext file
  • create a text box on the website using a form tag with method=POST
  • add text input tag with name=user_email
  • add a hidden input tag with its action set to save_email_input (this will correspond to our php function)
  • add a submission button
  • now design a function in functions.php to handle the text input when submit is pressed
  • function logic is like so:
    • 1. check if POST field user_email has been set
    • 2. if so, create data variable using sanitize_text_field() from POST[user_email]
    • 3. create file_path variable with value /var/www/html/uploads/email
    • 4. use file_put_contents(file_path, data) to write contents to the file
    • 5. use wp_redirect($_SERVER['HTTP_REFERRER']) to redirect to the original page
    • 6. add an action to map save_email_input to handle_email_input function
  • check that the function works as desired by submitting a new email and checking the file, file was changed as expected
  • now the website can modify a file based on text input!
  • create another identical text box to control distance threshold
  • create another plaintext file named threshold
  • replicate the user_email program with changed file names but with same logic
  • check that this implementation works with no errors by inputting a new distance threshold and checking the file: changes correctly
  • here is the script that handles user input from the website:
  • now, I want to add a timestamp showing when the sensor data files were last modified
  • this functionality is similar to what was used for auto emailing, using filemtime()
  • referred to date library documentation: date module
  • add a shortcode to functions.php with logic like so:
    • 1. set default timezone to EST using date_default_timezone_set()
    • 2. specify temp data file path
    • 3. if file path exists, return a formatted date
    • 4. else report that file was not found
    • 5. map the shortcode to the read_sensor_timestamp_shortcode function
  • call the shortcode on the website, and check that the value is correct: reads current time!
  • now, the website reports when data was last read in from the microcontroller visually to the user
  • finishing touches to website are purely visual, switch up some colors, font sizes, and add sections to page: Sensor Data and Settings Menu
  • demo to course staff!
  • Entry 2: Website Work session 2-----------------------------------------------------------------

    Date: April 24th
    Start Time: 2:00pm
    Duration: 4 hours

    Goal: Get LED color settings working
  • After the issues I had with the wordpress button blocks, I have decided to code the buttons with my own custom html.
  • Create a custom html block in wordpress
  • inside add in 4 identical button tags with respective background-color's set
  • specify the onclick() button to be my setColor() function
  • fill in the setColor(color) function to do console.log(color) when called
  • ensure that this simple script runs when I click each button by using the developer mode tabs and observing the console output
  • Now, I need to write code that sends the color value specified by setColor(color) to a file with path /var/www/html/uploads/LED_config
  • to do this, I'll need to use some php code to send a POST to the pi, which should then read the value into the specified file
  • my setColor() function logic goes like this:
    • use fetch() to create a post request to the admin-ajax.php program which calls set_led_color() in functions.php with parameter "color" which is a URI encoded version of the setcolor function input
    • get the server response using .then and throw an error if something went wrong
  • when I tried this script it failed, saying that wordpress does not support embedded php in html blocks
  • so, I need to add my function to functions.php and use add_action() to embed this script into the page footer upon page load
  • so, copy the original script into functions.php, and call it add_led_script()
  • then add a line: add_action('wp_footer', 'add_led_script') to make this function get called when wp_footer is being created
  • now, we have embedded the setColor script into the footer, and it can use nested php to carry out the POST method
  • next, I added one more function to the functions.php file: handle_set_led_color()
  • the logic goes like so:
    • first, check if the "color" field is set in POST
    • if so, create a plaintext-safe color variable by using sanitize_text_field() on the POST[color] field
    • specify the file path we want to alter by declaring a variable, in this case = '/var/www/html/uploads/LED_configuration'
    • use file_put_contents(file, color) to insert the data into the file
    • report which color was saved using echo
    • if color is not set, return an error: no color provided
    • lastly, kill the process with wp_die()
    • after the function, add actions to map the possible ajax calls to the function name
  • here is a picture of the scripts I wrote for LED control:
  • before this script works properly, I have to set proper permissions for the config file
  • using terminal, sudo chmod 666 var/www/html/uploads/LED_configuration
  • optimize the buttons styling by adding css for a black border and changing the text color, specifying font size and weight, padding, and border radius
  • test buttons to ensure they alter LED_configuration properly, and they do.
  • now that LED controls are working, I need to work on detecting when the fridge is unresponsive, and using a mail transfer agent to send an automated warning eail
  • start by researching some useful php functions by googling "file modify time php" and find this documentation: filemtime() documentation
  • write a script to send an email when the sensor data files have not been modified for 2 minutes or more
    • 1. specify the paths of temp and humidity files
    • 2. declare current time timestamp using date()
    • 3. check whether the difference between current time and filemtime(temp/humidity) is greater than 120
    • 4. if so, send an email to specified recipient using the mail() function
    • 5. if mail function succeeded, echo "Email sent successfully"
    • 6. else echo "Failed to send email"
  • test this by running it after the pcb has not been running for a while
  • result: program returns "successfully sent email" but no email was sent to specified recipient
  • decide to use PHPMailer instead of sendmail, since it is better configured for gmail
  • install PHPMailer from the public github repository
  • make changes to the code to work with PHPMailer according to its documentation: PHPMailer
  • try to run again, this time email is received successfully
  • edit crontab to run the program automatically every 5 minutes: */5 * * * * /usr/bin/php /www/var/html/send_email.php
  • check email to make sure this works, and it does continue to send emails
  • to prevent spam, add a new email_sent plaintext file with a boolean value
  • edit sensor read code to change value to false when it modifies data files
  • edit send_email code to change value to true when sending email, and not to send email if email_sent is set true
  • Entry 1: Website Work session-----------------------------------------------------------------

    Date: April 23rd
    Start Time: 1:00pm
    Duration: 3.5 hours

    Goal: Create a project website page that display image and sensor data
  • Connect to in-lab wifi router
  • navigate to 192.168.0.100-wp-admin to access wordpress admin account
  • login using given credentials
  • Create new page titled "Smart Fridge Kit"
  • Add an image block and try to link it to the location on RaspPI where image is captured: /var/www/html/uploads/camera1_latest.jpg
  • Using "link image via file path" nothing shows up, path must be wrong
  • try appending to current website path: "http://192.168.0.100/var/www/html/uploads/camera1_latest.jpg"
  • still no image displaying
  • when plugging in keyboard and mouse usbs into rasp PI, unexpectedly breaks the PI
  • HDMI output no longer displays on 2nd monitor, and the web server is no longer being hosted
  • to troubleshoot this issue, I first check each connection, such as the ethernet from router to PI, HDMI cable, power cable, and keyboard/mouse cables
  • after each connection appears fine, I try cutting power from the PI, then unplug each connection for about 30 seconds, then plug them back in
  • during this time, I also took out the SD card for a while, then put it back in
  • recconnect power cable, and check to see if PI properly booted back up, it did not
  • contact Pat about the issue, he decides to bring a replacement PI that we can use instead
  • retrieve new PI, transfer SD card to it, and connect each cable to it as it was configured before
  • this new PI properly boots, and I can resume working as I was
  • time to try a different method for wordpress images, the media library
  • look up how to manually upload images to the media library in wordpress on google, find this source: Media Library
  • from reading through this source, I learn where the media library is located: /var/www/html/wordpress/wp-content/uploads/
  • and that entries should be added like so:(previous path) ./(Current Year)/(Current Month), so in this case ./2025/04
  • use command line to move the image file: sudo mv /var/www/html/uploads/camera1_latest.jpg /var/www/html/wordpress/wp-content/uploads/2025/04/
  • also set permissions so that anyone can read the file: sudo chmod 666 ./ (new path)
  • now, the image is observable in the media library, and I can click to link it
  • view it as html in wordpress to oberve the src attribute: "src=http://192.168.0.100/wordpress/wp-content/uploads/2025/04/camera1_latest.jpg"
  • so I learned that the "/var/www/html/" part of the path is not needed when linking it on the website
  • try linking to the second image without media library, path only using "src=http://192.168.0.100/uploads/camera2_latest.jpg
  • now, I can link any image uploaded to the specified folder on the website without the use of wordpress media library
  • next, try to create scripts that will read text contents from 2 data files in the uploads folder: "temp" and "humidity"
  • google how to add website functions in wordpress and find this article: Shortcode tutorial
  • Easiest method is to create shortcodes that can be called directly from the website using [shortcode_name]
  • as I learned from the article, to add a function corresponding to your shortcode, you need to edit the wordpress theme you are using
  • ours is located at "/var/www/html/wordpress/wp-content/themes/twentytwentyfive/
  • the functions are located in functions.php inside that folder
  • try my hand at a simple file read script using my knowledge of PHP
  • the logic goes like this:
    • 1. set a file_path variable for the target path
    • 2. check that file_exists(file_path) returns true
    • 3. if so, set content variable that is html friendly using nl2br() function (new line to br) and file_get_contents(file_path)
    • 4. set desired unit variable
    • 5. return contents appended with unit
    • 6. if file does not exist return "file not found"
    • 7. use add_shortcode() to map the website shortcode to the function that should be called in functions.php
  • call shortcodes on the website, and observe result
  • no data is being read
  • ensure that permissions are correct by using sudo chmod 666 [filepath] for both temp and humidity
  • now the website reads the sensor values as they are shown in the plaintext files!
  • here are the scripts that I wrote:
  • next, begin working on LED color control settings
  • add 4 button blocks in wordpress, and select background color + name accordingly
  • "blue", "yellow", "green", "purple"
  • press buttons, nothing happens
  • observe raw html, notice there is no onclick function inside
  • try adding onclick() functions to each button and define a setColor() function (which doesn't do anything yet)
  • wordpress reports each button block as corrupted, and no longer displays the buttons
  • I press "try to resolve", and the buttons return to normal, but my custom code is removed
  • end of session due to upcoming lecture, next steps are to continue working on LED color control, and adding other useful settings
  • =============== Week 14: =================

    Entry 3: Checkoffs and RaspPI setup-----------------------------------------------------------------

    Date: April 18th
    Start Time: 12:30pm
    Duration: 3.5 hours

  • meet with pat to try to modify one of the finished PCBs flashable
  • help pat fly-wire RX and TX pins by stabilizing the targeted wire
  • begin code integration between pat and I's code by copying mine over and making modifications
  • merge all headers and declarations to be at the top
  • modularize my code so that it can be used in his main function
  • this is done by separating functionality between the LED strip code and Ultrasonic sensor code
  • clean up obsolete lines and fix code structure by consulting pat and removing whitespace/ fixing indentation
  • attempt flashing the newly modified pcb using the programming header for data, and usb-c connection for power
  • begin by flashing only a simple hello-world program
  • build, flash, monitor
  • the code successfully flashes
  • flash our real code base to the pcb
  • ensure that the temp and humidity sensor readings + LED strip are correctly operating
  • grab shivam to give us checkoffs for psdr 1 and 3 (temp sensor and led strip)
  • demonstrate functionality and explain code in detail
  • we successfully secure the checkoffs
  • ask for and acquire a wifi router to route our web server
  • pat acquires his raspPI from brandon
  • I setup the wifi router, unboxed and plugged in
  • pat tries to configure the raspPI to be accessable through our router
  • I use my laptop to connect to the network and check whether i can connect to the raspPI IP - connection timeout
  • wait for pat to reconfigure it to try and fix the issue
  • try again, with no change in result
  • ask another TA if they have a usb to micro-SD converter so that we can install a new OS onto the raspPI (pat wants to start from scratch)
  • acquire this hardware, and use it to download a fresh PI OS.
  • pop the sd card back in the PI and let it install
  • ran out of time, and had to leave
  • next goal is to finish troubleshooting the pi and make sure the web server is operational
  • Entry 2: Code testing with PCB and LED strip config -----------------------------------------------------------------

    Date: April 17th
    Start Time: 7:30pm
    Duration: 1 hour

    Goal: Configure LED strip to be safely testable and test my code on the finished PCB
  • To start, I had to try to reduce the brightness and led count of the strip to make it consume less power
  • we were concerned pulling too much amperage could damage the pcb if all components arent correctly installed
  • reducing the led count was as easy as changing the number in the literal definition
  • to reduce led brightness, I multiplied the rgb value for each LED by a constant less than or equal to 1
  • set brightness to 0.1
  • build flash monitor
  • see the leds lit up much dimmer than before, which means I achieved my goal
  • here is the dim and bright led settings respectively:
  • here is a snippet of the main function where the brightness setting was enacted
  • now, I begin trying to flash my code to the working pcb
  • using the pcb that pat and gustavo managed to use for the camera checkoff last night
  • press build, but receive a port error:
  • check that the port is correct, realize that when I plug into the pcb, desired port is not recognized by device
  • this most likely means the chip is not plugged in or unoperational
  • call pat to ask about this, he says that one of the wires broke on this pcb and it is not usable
  • next, try to use a newly finished version of the pcb that gustavo mentioned today
  • this pcb only uses usb-c connection rather than the programming header
  • press build but receive same error
  • this pcb is also unoperational, likely due to improper installation
  • since I am unable to flash to either finished pcb, I will try to test my code again tomorrow with someone else present
  • Entry 1: Manlab and HC-SR04 work -----------------------------------------------------------------

    Date: April 16th
    Start Time: 12:30pm
    Duration: 1.5 hours

    Goal: Fix the HC-SR04 so that data output is correct
  • build, flash, and monitor the code to remind me of the issue
  • currently, without the voltage divider in place, the distance readings come through, but they are inaccurate and unresponsive
  • since I've already debugged some possible issues with the code, and attempted to switch up the wiring configuration, I suspect the sensor could be defective
  • try plugging in a different sensor since we have multiple
  • build, flash, monitor
  • the readings come back correctly, and responded to my hand obstructing it
  • now the HC-SR04 is fully prototyped and ready to test with the PCB
  • for the rest of the lab, I was trying to help Pat debug the camera spi integration
  • he was having trouble with how the image was formatted (getting corrupted files)
  • we consulted the reference manual for this camera: datasheet
  • while checking the settings regisers for the camera, I suggested that the format register could be wrong/incorrectly listed
  • =============== Week 13: =================

    Entry 3: HC-SR04 Work session -----------------------------------------------------------------

    Date: April 11th
    Start Time: 4pm
    Duration: 3 hours

    Goal: Continue debugging the HC-SR04 code
  • build, flash, monitor to see how current code is performing
  • encounter new error:
  • error is "the following tasks/users did not reset the watchdog in time", so i suspect it could be a timeout error
  • additionally the backtrace mentions the exit occurs in the task_wdt_timeout_handling function within the task library
  • try setting tick rate to be higher (10000)
  • after build and flash, same error occurs
  • try setting tick rate to be lower (100)
  • after another build and flash, same error occurs, so this issue likely not caused by tick rate, reset value to original (1000)
  • parsing the backtrace further, the error occurs on line 96
  • the line is: "while(rtc_gpio_get_level(ECHO_GPIO) == 0);
  • timeout error makes sense as an infinite loop would be triggered if ECHO_GPIO is always 0
  • to make sure wiring was correct, I ensured that the wire from the HC's echo pin was routed to GPIO pin 5 as desired
  • going to try circumventing this error by commenting out these while loop waiting lines.
  • this caused a timer error from the surrounding timer functions
  • try commenting out a few different lines with no luck on fixing the error
  • need to learn how the timer library works
  • google freertos/timers.h
  • find this helpful resource from freertos: freertos website
  • read through the functions that are throwing errors: xTimerGenericCommand and xTimerStart()
  • while looking at xTimerCreate, realize that I'm not assigning the initialized timer object to the output of the create function
  • add that, build, flash, monitor
  • output now gives a distance reading, however it is locked at 0.09cm
  • there are a few things I don't like about the ultra function I pulled from the HC-SR04 example listed in the last entry, so I'll change it up a bit
  • here's the original ultra function:
  • ultra function needs to be simplified: should use regular gpio instead of rtc_gpio
  • to simplify timing functions, use a regular timer from the esp_timer.h library instead of using the more complex freertos library
  • make these changes
  • here's the updated ultra function:
  • says esp_timer.h cannot be found for some reason
  • make sure that it is included by adding esp_timer clause into PRIV_REQUIRES section of cmakelists.txt
  • build, flash, monitor
  • after simplification, the code works, but the distance reading is incorrect
  • seems to be oscillating between very small values: 0.03cm and 0.05cm
  • to attempt to debug, I'm placing print statements within ultra() to make sure echo duration looks correct.
  • build, flash, monitor
  • find that the echo duration is consistently 3-4 microseconds, which is far too short to be a correct reading
  • suspect that the sensor is getting a false reading, so I make the program wait 200 microseconds before checking echo
  • after another build, flash, monitor, the same behavior occurs.
  • after taking another look at the datasheet for HC-SR04, I realized that the echo pin outputs 5V, which is too much for our esp set to 3.3V
  • I need to add a voltage divider.
  • find a 1k ohm resistor and a 2.2k ohm resistor
  • connect them to the breadboard in the correct orientation
  • this results in echo timeout, so this fix seems incorrect.
  • copy journals into web file and add all images/links (20 mins)
  • Entry 2: Manlab, LED strip testing, and HC-SR04 initial grooming and configuration ------------------------------------

    Date: April 9th
    Start Time: 12:30pm
    Duration: 3.5 hours

    Goal: Test LED strip to get settable color values, and get started on configuring the Ultrasonic sensor.
  • for the first chunk of lab, Pat was working on configuring the camera code, so I tried to help him
  • getting an error where image data repeatedly contains the same bytes throughout the entire image
  • suggested checking that the way he's reading in image data is exactly how it is specified in data sheet
  • suggested that within the register he is reading there is garbage data in some spots that is never being cleared/updated
  • start working alone
  • start by doing a bit of debugging for the include error
  • looking at the working directory, I suspected a file I added from the original complex rmt example was interfering with my includes
  • delete the file, since we are using a different example
  • build, flash, monitor
  • led strip lights up as expected, include error resolved.
  • begin testing different color offset values to achieve desired colors
  • try 50 as offset, result: light bluish color
  • try a couple of different alterations in color (take out sine function they were using to create rainbow color effect)
  • try 100 as offset, result: pink-purple color
  • test a few different offsets, not changing the color at all
  • re-write the sin function, which must help create different hues which i didn't realize
  • after some finagling of the code, I was able to use color offset 75 to get a deeper blue hue, which I'll attempt to fine tune to a standard blue.
  • after many iterations of plugging in different values i found that:
  • yellow: 1.2 * 2pi
  • blue: 2.3 * 2pi
  • green: 2.9 * 2pi
  • these are the values we will use to give the user a couple of options for led color
  • start prototyping process for the HC-SR04 distance sensor
  • google examples of how to program it in esp-idf
  • find this resource: HC-SR04 example
  • include needed libraries and copy over ultrasonic sensor init function
  • add its execution to the main function and query it within while loop
  • build, flash, monitor
  • a problem occurs due to one of the literals being undefined: portTICK_RATE_MS
  • look up the needed tick rate for esp32, google says it should be 1000
  • add this definition in the literals section
  • build, flash, monitor
  • problem occurs: rtc_gpio_set_level(77): RTCIO number error
  • I'm assuming this has to do with the setting of gpio pins
  • change pin literals from GPIO_NUM_18 and GPIO_NUM_5 to just 18 and 5.
  • build, flash, monior
  • Entry 1: LED strip work session -----------------------------------------------------------------

    Date: April 8th
    Start Time: 7:15pm
    Duration: 2.5 hours

    Goal: Debg LED strip and get it to display pure white light.
  • start by googling examples of how to configure addressable led strips in ESP-IDF
  • found link led strip example
  • parsing file, trying to understand it
  • copy file into workspace, build
  • this example does not build correctly
  • luckily, there is led_strip_simple_encoder
  • go to example in ESP-IDF
  • set correct GPIO pin
  • build, flash, monitor
  • returned error: no UART data received: COM1
  • accidentally flashed on wrong port, switch to COM5
  • build, flash, monitor
  • build and flash goes through, start receiving status reports:
  • however, led strip does not turn on.
  • check that selected gpio pin is correct: current is 16.
  • realize that this is indeed the wrong pin, looks like strip is connected to 19, change pin value in literal declarations
  • strip lights up with rainbow configuration as expected
  • time to start trying to alter behavior of strip lighting to how I want
  • alter the code in for loop to make the offset constant throughout led color setting behavior, hoping to achieve uniform color.
  • build, flash, monitor
  • displays uniform color, but the color does strobe and change color gradually over the course of a few seconds
  • i'm aiming to achieve solid white color (not changing through time)
  • find another place where color offset is changed within the while loop, comment it out
  • build flash monitor
  • now displays pure white light uniformly.
  • paste example code into my project
  • build, flash, monitor to test it migrated correctly
  • does not work, issue with rmt driver path: no such file or directory found
  • to debug this, i found the location of this driver within the components directory :components\components\esp_driver_rmt\include\driver\rmt_tx.h and included it
  • building still gives an error saying it cant be found.
  • Next steps: Fix include issue by editing CMAKElists and test color values of led strip to obtain user-settable values

    =============== Week 12: =================

    Entry 2: Manlab and ESP-IDF setup + debugging -----------------------------------------------------------------

    Date: April 2nd
    Start Time: 12:30pm
    Duration: 4 hours

    Goal: Discuss project status and workload with teammates, setup ESP-IDF on lab computer (for my account) and debug issues
    • first half of session, Pat was using the lab computer and esp32 to test his code
    • he shared a github repo with the existing codebase with me
    • I began reading through what has been written thus far, and tried to make sense of what each function did
    • discussed with pat about what confusing lines/functions mean and tried to help with debugging while reading through codebase
    • began looking for resources online to help with the programming of the LED strip
    • found the github repo for the adafruit neopixel which we had referenced earlier in the semester
    • it is written in esp-idf, but is very complex with lots of architecture handling
    • adafruit neopixel library
    • begin reading through library to decipher how it works and whether it is useful for our cause
    • lots of confusing structures like the one shown here:
    • found the end of architecture handling at line 3285
    • rest of code in this file includes useful functions such as setpin, setpixelcolor, adjustbrightness, etc.
    • shown here is their set pixel color func:
    • read all functions listed and start making sense of how the LED strip may be contolled using an adressable pixel structure and r,g,b values
    • take control of lab computer and begin setting up esp-idf, as it hasnt been set up here
    • takes a while to download everything
    • clone our github repo into the newly created esp-idf project
    • takes a long time to download and migrate all files present
    • after setup, try to write a simple program and build
    • encounter error with cmake file: showing invalid/corrupted/not found
    • look into issues by googling error, not effective
    • run clean: errors and says to manually clean build folder
    • delete build folder
    • re-run build, same error
    • check cmake file location, looks ok
    • check that cmake file is listed within necessary makefiles
    • add file path to makefiles
    • re-run build, same error
    • re-install cmake, and add new file path to make file
    • re-run build, same error
    • terminate work session, time for 4:30 class

    Entry 1: A9 Research and Finishing -----------------------------------------------------------------

    Date: March 29th
    Start Time: 2:30pm
    Duration: 3 hours

    Goal: Complete Patent research and finish writing A9
    • Began the session by researching potential patents and patent infringements
    • pulled up lecture slides on legal and regulatory requirements
    • noted the definitions of useful, novel, and non-obvious clauses
    • started browsing patents
    • pulled up team 21's initial project prooposal and re-read the 3 listed patents
    • Smart Refrigerator
    • Home refrigerator systems imaging their interior and method
    • Refrigerator including a terminal, and method for controlling same
    • determined that the patent describing the terminal is no longer relevant, since we are no longer implements a display
    • began writing up descriptions and explanations for the 2 other patents
    • continually reference lecture slides and A9 examples for guidance
    • after finishing this writing, look for a 3rd relevant patent
    • skim several potential patents, pass up on a few due to similarity/ lack of uniqueness to other 2 examples
    • find a suitable patent: Home appliance, network connection system for home appliance and network connection method of home appliance
    • thoroughly read through the patent and its claims
    • write explanation for this patent with similar process of other 2
    • Begin writing the rest of the unfinished regulatory section
    • identify relevant regulatory bodies by googling things listed on the lecture slides
    • read some of the examples and read through their sources to learn more about the topic
    • write the rest of the explanation, citing a few sources from the examples

    =============== Week 11: =================

    Entry 2: Espressif IDF Learning -----------------------------------------------------------------

    Date: March 28th
    Start Time: 2:00pm
    Duration: 1.25 hours

    Goal: Learn more about ESP-IDF for upcoming software development phase
    • Start by googling tutorials about ESP-IDF
    • Skim through a few sites and browse videos
    • Found a tutorial from a dev at espressif: Beginners Guide to Key Concepts and Resources
    • Watched the video in full, taking detailed notes and often stopping/rewinding to write important information
    • Here are the full note sheets:
    • To summarize a few of the key things I learned:
    • How to utilize idf.py commands from terminal to build, flash, and monitor the project
    • How these functions will look when I run them and what their terminal output means
    • Some details about FreeRTOS for multithreading capabilities
    • What tasks are, how they are structured, and their various states
    • How FreeRTOS implements a scheduling algorithm to take care of user defined tasks
    • The general workflow of how I should implement desired features: Define Subsystems -> Find and Define components and libraries -> Read APIs -> Implement Connecting Logic
    • I learned a lot from this video, and feel confident about starting the bulk of the programming tasks in the upcoming week
    • Became much more prepared to use the tools needed for ESP32 programming
    • Scheduled a coding work session for this Sunday with Pat

    Entry 1: A9 Grooming and Research -----------------------------------------------------------------

    Date: March 26th
    Start Time: 12:30pm
    Duration: 2 hours

    Goal: Gain an understanding of what A9 is and begin working
    • Began familiarizing myself with the assignment by referencing the 2 examples posted on the assigment page
    • Read each example carefully to see which agencies typically apply to 477 projects
    • Found document on FCC regulations which was sourced by the second example: FCC Regulations
    • By reading the document, I determined that our device is an intentional radiator due to its Wi-Fi usage
    • Additionally determine that it will be a class B device since it will typically be installed in people's homes
    • Begin writing the regulatory analysis section of the assignment

    =============== Week 10: =================

    No entries.

    =============== Week 6: =================

    Entry 3: WiFi configuration -----------------------------------------------------------------

    Date: February 21st
    Start Time: 6:00pm
    Duration: 3.5 hours

    Goal: Connect to PAL3.0
    • Create new arduino sketch to combat program memory issues
    • This sketch only imports wifi to keep the library overhead light, since I'm only testing wifi today
    • copy over some of the previous code used for wifi connection
    • flash and test this code to see whether it works/ where it fails
    • output is indefinitely waiting for wifi to connect, meaning the something with the configuration failed
    • brainstorm ideas of why this could be failing
    • ideas like - wrong wifi library, misuse of wifi methods, not enough information for wifi to connect, incorrect ordering of function calls
    • realize it is possible there's not enough information for connection to PAL3.0
    • walk through manual PAL3.0 connection process
    • click connect - asks for username and password since it is an organization login
    • realize this could be the issue, since i'm only passing password to the wifi config
    • begin troubleshooting this issue - google how to connect to wifi with organization login using esp32 source: surprisingly useful reddit forum
    • one comment mentions the "WiFiClientSecureEnterprise" example for arduino IDE
    • look into this example, find a similarly named sketch and open it
    • this example passes some extra information to the wifi config which looks promising
    • example explicitly aims to connect to eduroam, which is accessible from the lab
    • enter my information into the example in an attempt to connnect to eduroam
    • flash and run - output reads that the esp32 did connect to eduroam, but it continuously fails to connect to the website given by example
    • this makes sense, as I don't have access to that website
    • modify my wifi setup code to use similar techniques as shown in the example
    • main differences are omission of a http target and omission of continuous looping print statements
    • this code only aims to connect to PAL3.0 and inform the user when connection occurs, also display IP address
    • flash and run - output reads successfully, connected to PAL3.0 and displays valid IP address
    • successful PAL3.0 connection is achieved and maintained
    Summary: Working session to troubleshoot existing wifi setup code. Discovered a useful example in the arduino IDE and used it to my advantage. I learned how to correctly connect to a wifi network if it has an organization login via arduino. Successfully connected to desired network, which progressed the firmware past a persistent issue that I'd been working on for over a week.3 Next steps will be to direct the wifi connection to a web host put up by the server, and begin transmitting information between the microcontroller and the web server.

    Entry 2: WiFi configuration research -----------------------------------------------------------------

    Date: February 20th
    Start Time: 3:00pm
    Duration: 1 hour

    Goal: Find out more about our wifi configuration issues
    • google how to connect esp32 to wifi network source: How to connect esp32 to Wifi tutuorial
    • watch video
    • learned common ways to configure, including using arduino
    • he uses wifi_multi.h instead of wifi.h
    • his code still looks similar to mine, which fails to connect to PAL3.0
    • google other sources, find a forum on wifi troubleshooting troubleshooting
    • some suggestions are using a phone hotspot to ensure connection, using post and get methods of HTTP to parse a login website
    • unsure of how useful these suggestions are - we can't use a hotspot for practicality reasons, and PAL3.0 doesn't utilize a website for user login
    Summary: Short research session to glean more information about esp32 wifi connection. Saw some code examples that look very similar to what I already have, heeded suggestions from troubleshooting forums. In the future, I will continue to troubleshoot possible issues with my wifi connection to get it up and running as soon as possible.

    Entry 1: LED strip -----------------------------------------------------------------

    Date: February 19th
    Start Time: 12:00pm
    Duration: 3.5 hours

    Goal: Configure the LED strip
    • Pat assigns me task of connecting the microcontroller to the LED shift register
    • Google how to connect to this particular LED strip source: RGB LED strips
    • Study example code from forum
    • Download and install the adafruit neopixel module
    • Make initial attempt to connect to led strip using similar code
    • code aims to initialize an adafruit_neopixel object with 400KHZ setting to pin 19 and turn the first LED red
    • Flash and run code - no lights turn on
    • check syntax, realize I forgot to run the .show() method
    • Flash and run again - still no lights
    • Reset the chip to ensure correct initialization of code
    • run again, this time random leds turn on - first 7 lights were on with assortment of different colors
    • look over code and compare to examples, find no discrepencies
    • check wiring on LED strip - everything looks good
    • examine strip closer and see arrows on each led indicating direction
    • feel strip and realize the lights are generating a lot of heat
    • question whether the strip is wired backwards
    • switch direction of wiring (so that the other end of the strip is connected)
    • flash and run again - similar issue but different lights turn on and with different colors
    • check bill of materials for part name
    • google the part and find digikey datasheet source: 1528-2710-ND
    • examine the picture provided carefully, compare to our led strip
    • realize this isn't the same strip
    • must have made a mistake when looking into our prototype part
    • worried that this led strip won't interface correctly, and that the library will be useless
    Summary: Made first attempts at configuring the LED strip that will be used to light the fridge for image capture. Some progress was made, but we couldn't correctly interface with the part. Since we've already ordered a different strip, we will wait to use that one in prototyping. Gained a better understanding of how the interfacing will look, and how to work with parts such as this In the future, we will need to commit more time to this functionality when the correct part arrives, as this is essential for the operation of our project.

    =============== Week 5: =================

    Entry 2: Temperature and Humidity sensor configuration -----------------------------------------------------------------

    Date: February 12th
    Start Time: 11:45am
    Duration: 3 hours

    Goal: Configure the Digilent Pmod Hygro Temperature and Humidity sensor.
    • Find reference manual for this sensor: PMOD HYGRO
    • Consult reference manual to see pin setup for standard operation
    • Wired the device (Vss, GND, SCL, SDA) using pins according to Pat's schematic
    • Research how to request readings from the device using arduino ide
    • Found source: link
    • Installed required HDC1080 Arduino library
    • Looked at examples that come with the library
    • wrote code to initialize a sensor object and request a reading
    • gets reading, but values look unrealistic (150 degrees C and 100 percent humidity)
    • debug by making sure my calls are correct for sensor read, found a typo mistake
    • rerun, get same issue
    • ensure wirings and pin placement is correct, found that device was wired one space off
    • rerun, get same issue
    • refer to esp32 data sheet to see what pins are ideal for i2c connection
    • find that pins 21 and 22 are ideal, rewire to those pins
    • rerun, now readings look correct, verify temperature
    • add a command to the list for requesing temps:
    • Run and observe
    • command works correctly, allowing for command line control via bluetooth
    • continue working on wifi capabilities from last session
    • write preliminary code for setting up connection to PAL3.0
    • simply sets up the microcontroller as a station, and passes "PAL3.0" as ssid and my purdue password as pw
    • Run and observe
    • code doesn't compile due to program memory being exceeded
    • the addition of the Wifi.h header pushed it to 128% capacity
    • research ways to better optimize the code: link
    • try cleaning up unneeded variables from previous sessions
    • minimize the amount of global variables
    • change memory heavy variables (longs and floats) to ints where floating point operation is not needed
    • run and observe, still wont finish compilation due to storage reasons
    • Next steps: remove the need for strings.h by simplifying string operations
    • minimizing library usage should reduce storage used

    Entry 1: A5 work and research -----------------------------------------------------------------

    Date: February 8th
    Start Time: 3:00pm
    Duration: 1 hour

    Goal: Research and Complete my section for A5 (Ultrasonic Sensor).
    • Navigate to digikey parts list
    • Search for ultrasonic sensors
    • Found potential part 1: MA40S4S
    • Compare product specifications posted on digikey
    • Compile a table with notes and specs:
    • Process of elimination
    • H2K sensor is $15.14, which is much more expensive than the other two parts
    • It boasts 300kHz sampling rate, but our application doesn't require extremely fast rates, since door opening is a human motion
    • H2K eliminated
    • After further research of the MA40S4S: link
    • The sensor can struggle in cold temperatures when being stored for long periods of time
    • One advantage is that the sensor is smaller than the remaining candidate
    • This sensor is double the price of the HC
    • MA4 eliminated
    • Choose HC-SR04 sensor as ideal candidate
    • Write analysis based on this research and consideration


    =============== Week 4: =================

    Entry 3: ESP32 Bluetooth Troubleshooting -----------------------------------------------------------------

    Date: February 7th
    Start Time: 2:00pm
    Duration: 3 hours

    Goal: Transmit data between phone and ESP32 via Bluetooth
    • Research ways to connect ESP32 to bluetooth: ESP32 Blueooth config
    • Install bluetooth serial monitor on phone for convenient interfacing
    • Copy example code from source
    • Flash and attempt BT connection
    • Connection succeeds, send message "hello" from phone
    • Serial monitor displays "hello"
    • Modify code to dump BT input into string variable and print to serial
    • Fails to print anything
    • Debugging, realize I'm reading from Serial rather than SerialBT
    • Modify and test again
    • Serial monitor prints sent message, but it displays raw byte data
    • consult tutorial reference, watch config video
    • Realize to debug, must read in bytes one at a time as "char", then convert to string and concat
    • Flash and test
    • Correctly displays "hello" from string sent on phone
    • Modify code to create command conditional on user input
    • If user input == "sensor", fetch sensor data
    • Flash + test, not working. No data fetched when sensor sent
    • Debug: Found that BT_out (user input) is cleared before conditional. Fix
    • Flash + test, still not working, same as before
    • Debug: trim whitespace from BT_out before check
    • Flash + test: command now works, controller fetches sensor data when "sensor" sent via bluetooth
    Extended Goal: Connect ESP32 to wifi using bluetooth SSID and Password selection
    • Research wifi setup on ESP32: ESP32 wifi
    • Modify code to request wifi ssid from user and pw for attempted wifi connect
    • Incomplete modifications, possible infinite while loop caused
    Summary:
    Modified ESP32 code using Arduino IDE and debugged. At the end of session, working sensor command via bluetooth was achieved. Started on configuring wifi, but steps were not complete. In next session, utilize newfound knowledge of bluetooth communication to enable user-led wi-fi configuration.

    Entry 2: Lab meeting and ESP32 Testing -----------------------------------------------------------------

    Date: February 5th
    Start Time: 12:00pm
    Duration: 3 hours

    Goal: connect ESP32 to distance sensor
    • Found a tutorial for reference: Getting Started with ESP32/
    • Followed directions to install Arduino IDE and dedicated drivers
    • After IDE install, selected ESP32 devboard as "board"
    • Plugged in usb from microcontroller to laptop
    • Found which port the usb is (Port 5)
    • Selected correct port for "port" in tools dropdown
    • Found a wi-fi scan example program under examples dropdown
    • Ran example code, received incorrect boot number error
    • After several tests, discovered that the "boot" button on ESP32 must be pressed during flash
    • Ran example code again, successfully flashed to ESP32
    • Opened serial terminal to view output and verify correctness of wi-fi scan
    • Studied code for reading sensor in reference tutorial: ESP32 with Ultrasonic sensor
    • Copied code toread sensor data each pulse (from above reference)
    • Flashed ESP32 and viewed output in serial
    • Test distance numbers by placing object in front of ultrasonic sensor
    • Sensor read is responsive to obstruction
    • Sensor range reads about ~30 inches with no obstruction
    • Modified code to include a door_open boolean (1 if dist_inches > 15, 0 O/W)
    • Flash and observe serial, consistently prints correct door_open value. Accuracy modifications will be made once mounted on fridge.
    • Successfully interfaced ultrasonic sensor and ESP32
    • Microprocessor hypothetically has accurate door readings for future event triggers
    example2

    Entry 1: A3 Work and Research -----------------------------------------------------------------

    Date: February 1st
    Start Time: 6:00pm
    Duration: 2.5 hours

    Goal: Research and Write the necessary details for A3 - Software overview
    • Much of the conceptual work for A3 was highlighted in Week 3 - Entry 2
    • Open project description and PSDRs for reference
    • Wrote Software Overview, highlighted the implementations of our key software functionalities: Server setup, ESP32 to Server communication, Landing page website, and firmware for data transmission and event handling
    • Researched algorithm pertaining to ESP32 to Server communication: TCP Protocol
    • Learned that TCP will help us reliably transfer data between devices (no packet loss)
    • Learned how TCP is implemented using 3-way handshake and send-ack sequences
    example2
    • Researched data structure pertaining to firmware: Priority Queue
    • Learned that PQs will allow for event priority and efficient queue handling
    • Learned the operations that make up a PQ implementation: enqueue, dequeue, and peek
    example2
    • Open operational logic and machine state diagrams for reference
    • Detail packet construction based on agreed upon specifications
    • Describe packet types: control and data, who sends them, and what they contain
    Summary: Gained better understanding of data structures and algorithms that will make up the software components of the project. Documented a basis for software creation, giving a framework for later work to be done. In the near future, firmware should be written for the microcontroller to start testing event handling and operational logic. Server setup must occur to enable packet construction and transmission testing.

    =============== Week 3: =================

    Entry 3: Project Journal and Summary -----------------------------------------------------------------

    Date: January 31st
    Start Time: 6:00pm
    Duration: 1.5 hours

    During the session, I updated my project journal entries on the team website and submitted the brightspace assignment. It took me a while to revise my written notes to an acceptable level of detail , and to describe the tasks that we completed this week. The result of this is that in reflecting upon the past week, I have a better understanding of our overall project status and of what needs to get done going forward. It will also serve as detailed written documentation detailing what our team discussed and features we want to implement, as well as how we came to those conclusons. The next steps are to begin the implementation of the functionality detailed in Entry 2, with the goal being that by the end of week 4, we'll have some working functionality for our prototype.

    Entry 2: Lab Pre-meeting and Meeting -----------------------------------------------------------------

    Date: January 29th
    Start Time: 11:30am
    Duration: 3 hours

    During this session, my teammates and I did a lot of discussion about the layout and operational logic of our project. Although mostly conceptual, we worked through several ambiguities regarding the design of our project to create a basis of logic for its setup and event handling. We approched this task by drafting a visual representation in draw.io, so the process described are the key considerations we made in the creation of the figure below.

    1. Event Priority
    During the event handling phase of our machine, the microcontroller will be waiting for one of 3 events to happen: Door open, Incoming packet from the server, and data clock active (for periodic sensor readings). After discussion, we decided that door open should be highest priority, since it is a time sensitive event. On door open detection, the device should immediately take necessary steps for image capture and storage. We came to this conclusion because we don't want the door to close while handling another event. Secondly, incoming server packets should be of secondary importance, which would indicate a change of settings (such as sensor reading frequency). On receipt of a server control packet, the microcontroller will parse the packet and change any necessary flags within its configuration accordingly. Lastly, if the data clock flag is active, it means that a sensor reading should be made and sent for packet construction. Afterward, the data clock flag will be reset.

    2. Packet construction
    A packet construction procedure and network protocol is critical to efficient transmission of data between the server and microcontroller. In our system a standard TCP protocol will be used (reliable transmission), and there are control packets sent strictly from the server to the circuit, as well as data packets sent from the circuit to the server. The circuit should construct a packet to be sent upon the occurrence of both events 1 and 3. On event 1 (door open), the circuit should collect and store image data into a packet, as well as read sensor data and reset the data clock. As per TCP protocol, upon packet send, the circuit will wait for an acknowledgement from the server. After a set amount of time with no acknowledgement, the circuit will resend and repeat this process until ACK is received. On event 3 (data clock active), sensor reading will be made and stored for packet construction, but unlike event 1, no image will be captured, and a flag will be set indicating no replacement image is being sent to the server. Sending procedure is the same as event 1.

    The result of this was that we gained a stronger idea of the logic that will be involved in the hardware and software design of our project. We now have several written visuals depicting device operation, which should serve as references to the general device layout for when we begin to work on specific functionality. This contributed significantly to project progress, because it will not only help in the writing of 'Software Overview - A3', it also set our team up for next steps in acquiring hardware to map to functionalities described in our visuals. example2


    Entry 1: A2 Work and Research -----------------------------------------------------------------

    Date: January 25th
    Start Time: 7:30pm
    Duration: 2 hours

    During this work session, I began the research for the 'Theory of Operation' and 'Computational Constraints' sections of our functional description assignment, A2. I did this by looking up articles about components that we know will be included in our project, specifically temperature sensors and still-capture cameras. I learned about the mechanics of an NTC thermistor, which can output variable resistance as a function of temperature. This enables precise temperature sensing, which will play a vital role in the functionality of our project. I also learned about how still-capture cameras use CCD sensors to capture images using the photoelectric effect. This played into the next part of the report, because the need to capture images would create concern for memory scarcity. After researching the operation of cameras, I knew that the memory demand would be too high for a microcontroller alone to handle. This led us to make a design decision to include an SD card for image storage, which will need to be interfaced with our microcontroller through a compatible port. As a result, I was able to use what I learned to complete my part in A2, and give our team more documentation and understanding in the operation of our project. Additionally, we were already able to make pivotal design decisions based on our findings. This benefits the progress of the project, because the team now has written documentation that details vital parts and specifications which will be useful reference during the construction phase. Going forward, the team should continue to reread and reference the research that's been done as foundational understanding of how different aspects of the project relate to our overall goals.
    example1
    References:
    NTC Thermistor: https://eepower.com/resistor-guide/resistor-types/ntc-thermistor/#
    CCD Sensor: https://www.radiantvisionsystems.com/blog/ccd-sensors-albert-einstein-and-photoelectric-effect#:~:text=They%20based%20CCD%20technology%20on,them%20to%20be%20read%20digitally.

    =============== Week 2: =================

    Entry 1: Lab meeting -----------------------------------------------------------------

    Date: January 22nd
    Start Time: 12:30am
    Duration: 2 hours

    Attended the second manlab for the course. We had some discussions about the functional specification document which brought up some contention points for our project. Namely the methods of powering the microcontroller and sensors: direct cabling, rechargable battery, standard battery, and fridge power draw were all presented as possible options. We decided that the best course to take is direct cabling using a flat cable to prevent cool air leakage. We were also addressed by Prof. Phillips and the TAs about refining our design specifications. Specifically, PSDR 1 is too general and has no mention of the microcontroller. PSDR 4 and 5 need to more specifically mention our planned Web application and hosting method.



    =============== Week 1: =================

    Entry 2: A1 Group meeting -----------------------------------------------------------------

    Date: January 18th
    Start Time: 12:00pm
    Duration: 1 hour

    All of the members met virtually to collaborate on assignment A1. I helped with the brainstorming process for PSDRs. We decided on the essential functionality of the project, and we made the decision to consider an external LCD display as a secondary goal since it wasn't part of the critical functions we want to offer. Next, we each filled in our expertise section and divied up report assignments for the future. After that, we listed potential project parts and divided them up for pricing research. I found information about humidity sensors, a WiFi board, and a micro controller that could all potentially be used.



    Entry 1: Lab Meeting -----------------------------------------------------------------

    Date: January 15th
    Start Time: 12:30am
    Duration: 2 hours

    Attended the first manlab for the course. The team members were all officially introduced to each other, and we discussed our initial project plans with the TA's. Conversed with group members and decided on some of the project logistics. We decided we should use the mini-fridge Pat offered to provide vs. buying a new/full-sized fridge. The website was created, and we each populated the page with our personal info.