{"id":471,"date":"2022-09-01T02:56:18","date_gmt":"2022-09-01T02:56:18","guid":{"rendered":"https:\/\/mechied.com\/?post_type=portfolio&#038;p=471"},"modified":"2023-01-02T18:02:22","modified_gmt":"2023-01-02T18:02:22","slug":"smart-scale","status":"publish","type":"portfolio","link":"https:\/\/mechied.com\/index.php\/portfolio\/smart-scale\/","title":{"rendered":"Smart Scale"},"content":{"rendered":"\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button aligncenter has-custom-width wp-block-button__width-75\"><a class=\"wp-block-button__link has-vivid-cyan-blue-to-vivid-purple-gradient-background has-background wp-element-button\" href=\"https:\/\/programmerd.com\/scale\/\" style=\"border-radius:0px\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>Live Demo<\/strong><\/a><\/div>\n<\/div>\n\n\n\n<div style=\"height:22px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<div class=\"wp-block-media-text alignwide is-stacked-on-mobile\" style=\"grid-template-columns:65% auto\"><figure class=\"wp-block-media-text__media\"><img loading=\"lazy\" decoding=\"async\" width=\"500\" height=\"344\" src=\"https:\/\/mechied.com\/wp-content\/uploads\/2022\/08\/Screen-Shot-2022-08-30-at-2.01.12-PM-500x344.png\" alt=\"\" class=\"wp-image-472 size-full\" srcset=\"https:\/\/mechied.com\/wp-content\/uploads\/2022\/08\/Screen-Shot-2022-08-30-at-2.01.12-PM-500x344.png 500w, https:\/\/mechied.com\/wp-content\/uploads\/2022\/08\/Screen-Shot-2022-08-30-at-2.01.12-PM-300x206.png 300w, https:\/\/mechied.com\/wp-content\/uploads\/2022\/08\/Screen-Shot-2022-08-30-at-2.01.12-PM-768x528.png 768w, https:\/\/mechied.com\/wp-content\/uploads\/2022\/08\/Screen-Shot-2022-08-30-at-2.01.12-PM-400x275.png 400w, https:\/\/mechied.com\/wp-content\/uploads\/2022\/08\/Screen-Shot-2022-08-30-at-2.01.12-PM-600x412.png 600w, https:\/\/mechied.com\/wp-content\/uploads\/2022\/08\/Screen-Shot-2022-08-30-at-2.01.12-PM-800x550.png 800w, https:\/\/mechied.com\/wp-content\/uploads\/2022\/08\/Screen-Shot-2022-08-30-at-2.01.12-PM.png 1132w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/figure><div class=\"wp-block-media-text__content\">\n<p>I got a little too snack happy during Recurse so I wanted to be more aware of what I was eating. I created Smart Scale to help me calculate the total nutritional information of a recipe as I cook by connecting my kitchen scale to a web interface.<\/p>\n<\/div><\/div>\n\n\n\n<div style=\"height:15px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>I hacked a kitchen scale from Amazon to embed an ESP8266 IoT development board and programmed the board to send the weight reading via MQTT to a broker on my droplet server.  Then I made a React page where you interactively search for foods in a database and select one to use as your current ingredient.  The page automatically gets the scale weight data from MQTT (or fakes the data if you&#8217;re not logged in with the proper credentials).  If you don&#8217;t find what you want, or want to edit the nutritional information, you can update the database, which is written in Python using Django.  The page also calculates the total and average nutritional info for the recipe and you can divide the information by the number of servings.<\/p>\n\n\n\n<p>I also wanted to better understand authentication (after using JSON web tokens in my <a href=\"https:\/\/mechied.com\/index.php\/portfolio\/fulcrum-focus\/\" data-type=\"portfolio\" data-id=\"415\">Fulcrum Focus<\/a> app) so I integrated <a href=\"https:\/\/auth0.com\/\" data-type=\"URL\" data-id=\"https:\/\/auth0.com\/\">Auth0<\/a> as an authentication provider.  I created an authentication scheme for three different types of users: unauthenticated users who can only view the main food database, authenticated users who can view the main database and add user specific custom foods, and administrators, who can view and edit all foods.  The backend API endpoints are protected with token authentication and Auth0 scopes are used to grant administrator privileges.  The frontend queries the backend to determine the user&#8217;s access level and then tailors front end elements like disabling buttons and displaying tooltips.  Implementing this efficiently required using advanced React concepts like async, hooks, routers, and context.  The code is posted to my github <a href=\"https:\/\/github.com\/daleshort\/smart-scale\">here<\/a>.<\/p>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"Smart Scale - Recurse Center Friday Demo\" width=\"1200\" height=\"675\" src=\"https:\/\/www.youtube.com\/embed\/YvU_H9ExAd4?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<p>Here is my demonstration of the Smart Scale I gave during Friday Demos at Recurse Center.<\/p>\n<\/div>\n<\/div>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"500\" height=\"344\" src=\"https:\/\/mechied.com\/wp-content\/uploads\/2022\/08\/Screen-Shot-2022-08-30-at-2.01.31-PM-500x344.png\" alt=\"\" class=\"wp-image-473\" srcset=\"https:\/\/mechied.com\/wp-content\/uploads\/2022\/08\/Screen-Shot-2022-08-30-at-2.01.31-PM-500x344.png 500w, https:\/\/mechied.com\/wp-content\/uploads\/2022\/08\/Screen-Shot-2022-08-30-at-2.01.31-PM-300x206.png 300w, https:\/\/mechied.com\/wp-content\/uploads\/2022\/08\/Screen-Shot-2022-08-30-at-2.01.31-PM-768x528.png 768w, https:\/\/mechied.com\/wp-content\/uploads\/2022\/08\/Screen-Shot-2022-08-30-at-2.01.31-PM-400x275.png 400w, https:\/\/mechied.com\/wp-content\/uploads\/2022\/08\/Screen-Shot-2022-08-30-at-2.01.31-PM-600x412.png 600w, https:\/\/mechied.com\/wp-content\/uploads\/2022\/08\/Screen-Shot-2022-08-30-at-2.01.31-PM-800x550.png 800w, https:\/\/mechied.com\/wp-content\/uploads\/2022\/08\/Screen-Shot-2022-08-30-at-2.01.31-PM.png 1132w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><figcaption class=\"wp-element-caption\">Modal<\/figcaption><\/figure>\n<\/div>\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"319\" height=\"500\" src=\"https:\/\/mechied.com\/wp-content\/uploads\/2022\/08\/Screen-Shot-2022-08-30-at-2.04.32-PM-319x500.png\" alt=\"\" class=\"wp-image-474\" srcset=\"https:\/\/mechied.com\/wp-content\/uploads\/2022\/08\/Screen-Shot-2022-08-30-at-2.04.32-PM-319x500.png 319w, https:\/\/mechied.com\/wp-content\/uploads\/2022\/08\/Screen-Shot-2022-08-30-at-2.04.32-PM-192x300.png 192w, https:\/\/mechied.com\/wp-content\/uploads\/2022\/08\/Screen-Shot-2022-08-30-at-2.04.32-PM-300x470.png 300w, https:\/\/mechied.com\/wp-content\/uploads\/2022\/08\/Screen-Shot-2022-08-30-at-2.04.32-PM-400x626.png 400w, https:\/\/mechied.com\/wp-content\/uploads\/2022\/08\/Screen-Shot-2022-08-30-at-2.04.32-PM.png 497w\" sizes=\"auto, (max-width: 319px) 100vw, 319px\" \/><figcaption class=\"wp-element-caption\">Mobile Layout<\/figcaption><\/figure>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>Wifi connected scale and webpage to automatically calculate recipe nutrition as you cook<\/p>\n","protected":false},"author":1,"featured_media":472,"menu_order":7,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"_vp_format_video_url":"","_vp_image_focal_point":[],"footnotes":""},"portfolio_category":[12,10,7,11],"portfolio_tag":[],"class_list":["post-471","portfolio","type-portfolio","status-publish","format-standard","has-post-thumbnail","hentry","portfolio_category-django","portfolio_category-javascript","portfolio_category-python","portfolio_category-react"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/mechied.com\/index.php\/wp-json\/wp\/v2\/portfolio\/471","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mechied.com\/index.php\/wp-json\/wp\/v2\/portfolio"}],"about":[{"href":"https:\/\/mechied.com\/index.php\/wp-json\/wp\/v2\/types\/portfolio"}],"author":[{"embeddable":true,"href":"https:\/\/mechied.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"version-history":[{"count":11,"href":"https:\/\/mechied.com\/index.php\/wp-json\/wp\/v2\/portfolio\/471\/revisions"}],"predecessor-version":[{"id":575,"href":"https:\/\/mechied.com\/index.php\/wp-json\/wp\/v2\/portfolio\/471\/revisions\/575"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/mechied.com\/index.php\/wp-json\/wp\/v2\/media\/472"}],"wp:attachment":[{"href":"https:\/\/mechied.com\/index.php\/wp-json\/wp\/v2\/media?parent=471"}],"wp:term":[{"taxonomy":"portfolio_category","embeddable":true,"href":"https:\/\/mechied.com\/index.php\/wp-json\/wp\/v2\/portfolio_category?post=471"},{"taxonomy":"portfolio_tag","embeddable":true,"href":"https:\/\/mechied.com\/index.php\/wp-json\/wp\/v2\/portfolio_tag?post=471"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}