<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:media="http://search.yahoo.com/mrss/"><channel><title><![CDATA[KhalsaLabs]]></title><description><![CDATA[Khalsa Labs - Technology blog and place for curious minds]]></description><link>https://khalsalabs.com/</link><image><url>https://khalsalabs.com/favicon.png</url><title>KhalsaLabs</title><link>https://khalsalabs.com/</link></image><generator>Ghost 5.75</generator><lastBuildDate>Sun, 05 Apr 2026 02:57:40 GMT</lastBuildDate><atom:link href="https://khalsalabs.com/rss/" rel="self" type="application/rss+xml"/><ttl>60</ttl><item><title><![CDATA[IOT 101 - Minimizing Wifi Battery Consumption in IOT projects]]></title><description><![CDATA[<p>In the early development stages of <a href="https://www.petdrifts.com/?ref=khalsalabs.com" rel="noreferrer">PetDrifts</a>, we faced significant challenges with our MVP, which included a custom PCB equipped with an ESP32 C3 mini, sensor, and a Li-ion battery. One of the major issues was the rapid draining of the battery, a critical problem in our IoT device design</p>]]></description><link>https://khalsalabs.com/iot-101-minimizing-esp32-wifi-battery-consumption-in-iot-projects/</link><guid isPermaLink="false">67645d8e7cfb4c9346642113</guid><dc:creator><![CDATA[Harman Singh]]></dc:creator><pubDate>Thu, 19 Dec 2024 18:53:12 GMT</pubDate><content:encoded><![CDATA[<p>In the early development stages of <a href="https://www.petdrifts.com/?ref=khalsalabs.com" rel="noreferrer">PetDrifts</a>, we faced significant challenges with our MVP, which included a custom PCB equipped with an ESP32 C3 mini, sensor, and a Li-ion battery. One of the major issues was the rapid draining of the battery, a critical problem in our IoT device design</p><p>ESP32 based circuit was consuming significant power. The code was simply collecting data from sensors and sending it over network every 5 minutes. We were using a small battery (~250mAh) and esp32 c3. This circuit contains, mcu (built-in ADC) with pcb antenna, accelerations sensor, and some battery charging and regulating components. The firmware was collecting data in normal operation and sending it over network using HTTP POST call every n minutes (configurable and tried 5 to 15 minutes).</p><p>This IoT design was consuming battery so fast, that the battery was hardly lasting a day. To see what would be my usual battery battery runtime, I was using <a href="https://climbers.net/sbc/iot-battery-runtime-calculator/?cell=lir2450x2&amp;cellmah=250&amp;reg=mcp1700-33&amp;m1=15&amp;m1unit=0&amp;m1sec=86400&amp;m2=30&amp;m2unit=0&amp;ref=khalsalabs.com">this online tool</a></p><h2 id="finding-the-battery-killer-in-my-iot-project">Finding the Battery Killer in my IoT project</h2><p><br><strong>To find what was killing the battery</strong> so soon, I measured real-time current drawn by the circuit which was equal to an average esp32 current drawn (around ~35 mA, no surprise), but every 15 minutes I could clearly see a spikes ~190 mA during network activity (API call).<br><br><strong>To get a better insight </strong>on battery consumption, I got <strong>Nordic&apos;s power profiler kit</strong>. This is one of the best IoT tool I got so far. I could clearly saw the power consumption graphs and spikes during network operations.</p><figure class="kg-card kg-image-card"><img src="https://khalsalabs.com/content/images/2024/12/PPK2_TopView_Transparent_Vertical-copy.jpg" class="kg-image" alt loading="lazy" width="549" height="350"></figure><p>No surprise, this was matching to esp&apos;s datasheet:</p><figure class="kg-card kg-image-card"><img src="https://khalsalabs.com/content/images/2024/12/Screenshot-2024-12-19-at-11.51.14-AM.png" class="kg-image" alt loading="lazy" width="1808" height="816" srcset="https://khalsalabs.com/content/images/size/w600/2024/12/Screenshot-2024-12-19-at-11.51.14-AM.png 600w, https://khalsalabs.com/content/images/size/w1000/2024/12/Screenshot-2024-12-19-at-11.51.14-AM.png 1000w, https://khalsalabs.com/content/images/size/w1600/2024/12/Screenshot-2024-12-19-at-11.51.14-AM.png 1600w, https://khalsalabs.com/content/images/2024/12/Screenshot-2024-12-19-at-11.51.14-AM.png 1808w" sizes="(min-width: 720px) 720px"></figure><p>Now, I have few options to reduce this power consumption:<br><br>1. Use less frequent network calls <br>2. Lower the transmission power of module (compromise with range of device )<br>3. Optimize the network calls (explaining this further)</p><hr><h2 id="how-we-optimize-our-network-calls">How We Optimize Our Network Calls<br></h2><p>We were using REST APIs to send the data. On asking myself, could this be a problem. Oh yes! REST works with TCP which consumes network for its own benefit.</p><h3 id="rest-under-the-hood">REST Under the Hood</h3><p>REST APIs operate over <strong>HTTP</strong>, which in turn uses the <strong>TCP protocol</strong>. TCP is great for reliable data transfer, but reliability comes at the cost of additional overhead due to the <strong>three-way handshake process</strong>. Every REST call requires this handshake process before any data is exchanged, leading to potential delays in high-frequency or low-latency applications.</p><h3 id="tcps-three-way-handshake">TCP&apos;s T<strong>hree-Way Handshake</strong>:</h3><ol><li><strong>Client Sends a SYN (Synchronize) Packet</strong></li><li><strong>Server Responds with SYN-ACK (Synchronize-Acknowledge)</strong></li><li><strong>Client Sends an ACK (Acknowledge) Packet</strong></li></ol><hr><h3 id="solution-1-switching-to-udp">Solution #1: Switching to UDP</h3><p>Using UDP sockets in the firmware instead of TCP. This will save three extra call spent on TCP each time device send data to your server. However you will need to adjust your server to receive UDP data. UDP is less reliable than TCP, to ensure reliability you can add a mechanism like sync flags or retries. If reliable data transfer is must, then use Solution #2. <br>An example of simple UDP socket in micropython:</p><pre><code>import socket

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
server_address = (&apos;server_ip_address&apos;, 12345) #Add your server address 

# Send data
message = &apos;Sensor data here 0x111&apos;
sock.sendto(message.encode(), server_address)

# Close the socket
sock.close()</code></pre><h3 id="solution-2-switching-to-mqtt-for-reliability"><strong>Solution #2: Switching to MQTT (for reliability)</strong></h3><p>For the data I was sending, UDP was sufficient but to ensure better data delivery you can also use MQTT, this is a great alternative to REST. Under the hood, MQTT use persistent connection and one handshake per session to reduce power consumption. <br>You may need to add a MQTT broker as an additional component to your IoT architecture, if you decide to use MQTT.<br><br>We used both approaches for our MVP and observed a good improvement on battery saving. This wasn&apos;t enough to provide long lasting battery life (weeks of battery life in one charge) like other dog activity trackers in the market were providing. We switched to Bluetooth based MCUs to get months of battery life from our device!</p><p>Other resources to reduce power consumption on esp32:<br><a href="https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/low-power-mode/low-power-mode-wifi.html?ref=khalsalabs.com" rel="noreferrer">https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/low-power-mode/low-power-mode-wifi.html</a><br><a href="https://github.com/espressif/esp-idf/blob/master/examples/wifi/power_save/README.md?ref=khalsalabs.com" rel="noreferrer">https://github.com/espressif/esp-idf/blob/master/examples/wifi/power_save/README.md</a></p><p>Got more questions/curiosity about IoT:<br>connect with me:<a href="https://www.linkedin.com/in/harmandeep-singh-50997955/?ref=khalsalabs.com">LinkedIn</a><br>My free newsletter for startup stories: <a href="https://founderpedia.substack.com/?ref=khalsalabs.com" rel="noreferrer">founderpedia</a></p>]]></content:encoded></item><item><title><![CDATA[Writing Kubernetes CronJobs: A Simple Guide]]></title><description><![CDATA[A Kubernetes CronJob is essentially a job that runs on a scheduled basis. It allows you to run containers periodically,]]></description><link>https://khalsalabs.com/writing-kubernetes-cronjobs-guide-4/</link><guid isPermaLink="false">6754bb0c7cfb4c93466420e8</guid><category><![CDATA[kubernetes]]></category><category><![CDATA[crons]]></category><category><![CDATA[linux]]></category><dc:creator><![CDATA[Harman Singh]]></dc:creator><pubDate>Sun, 08 Dec 2024 21:21:23 GMT</pubDate><media:content url="https://khalsalabs.com/content/images/2024/12/kubernetesCrons-KhalsaLabs-2.png" medium="image"/><content:encoded><![CDATA[<img src="https://khalsalabs.com/content/images/2024/12/kubernetesCrons-KhalsaLabs-2.png" alt="Writing Kubernetes CronJobs: A Simple Guide"><p><br>Kubernetes CronJobs are a powerful tool for running scheduled tasks within your Kubernetes cluster. Think of them as cron jobs for containers &#x2014; they allow you to automate tasks like backups, batch jobs, or routine cleanups. In this guide, we&apos;ll walk through how to set up a CronJob in Kubernetes with a simple example.</p><h2 id="what-is-a-kubernetes-cronjob">What is a Kubernetes CronJob?</h2><p>A CronJob in Kubernetes is essentially a job that runs on a scheduled basis. It allows you to run containers periodically, much like the cron utility on Linux, but with the added benefits of Kubernetes&apos; orchestration.</p><h2 id="when-to-use-kubernetes-cronjobs">When to Use Kubernetes CronJobs</h2><p>CronJobs are ideal for tasks that need to run at specific intervals. For instance, you might use a CronJob for:</p><ul><li><strong>Database backups</strong> that run every night.</li><li><strong>Sending email reports</strong> once a day.</li><li><strong>System cleanups</strong> that run weekly.</li></ul><h2 id="setting-up-a-kubernetes-cronjob">Setting Up a Kubernetes CronJob</h2><p>To create a CronJob, you&#x2019;ll define it in a YAML file, specifying the schedule and the task you want it to run. Here&#x2019;s a basic example:</p><pre><code class="language-yaml">apiVersion: batch/v1
kind: CronJob
metadata:
  name: daily-backup
spec:
  schedule: &quot;0 2 * * *&quot;  # Run at 2 AM every day
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: backup-container
            image: my-backup-image:latest
            args:
            - /bin/sh
            - -c
            - &quot;tar -czf /backup/daily-backup.tar.gz /data&quot;
          restartPolicy: OnFailure
</code></pre><h2 id="breaking-down-kubernetes-cronjob">Breaking Down Kubernetes CronJob</h2><ul><li><strong>apiVersion</strong>: Defines the version of the Kubernetes API you&apos;re using.</li><li><strong>kind</strong>: Specifies that we&apos;re creating a CronJob.</li><li><strong>schedule</strong>: This is the cron syntax to set when the job runs. In this case, it&#x2019;s set to run daily at 2:00 AM.</li><li><strong>jobTemplate</strong>: Defines the job itself. This includes:<ul><li><strong>container name</strong>: The name of the container you want to run.</li><li><strong>image</strong>: The Docker image used for the container.</li><li><strong>args</strong>: The commands executed by the container (in this case, a backup command).</li></ul></li></ul><h2 id="testing-your-kubernetes-cronjob">Testing Your Kubernetes CronJob</h2><p>Once you&#x2019;ve applied the CronJob, you can check its status by running:</p><pre><code class="language-bash">kubectl get cronjobs
</code></pre><p>To view the logs for a specific CronJob execution, use:</p><pre><code class="language-bash">kubectl logs &lt;pod-name&gt;
</code></pre><p>If you need to troubleshoot, you can also describe the CronJob:</p><pre><code class="language-bash">kubectl describe cronjob daily-backup
</code></pre><h3 id="managing-kubernetes-cronjob-frequency">Managing Kubernetes CronJob Frequency</h3><p>CronJob schedules follow the cron syntax, which looks like this:</p><pre><code>* * * * *  
| | | | |  
| | | | +---- Day of the week (0 - 6) (Sunday=0)
| | | +------ Month (1 - 12)
| | +-------- Day of the month (1 - 31)
| +---------- Hour (0 - 23)
+------------ Minute (0 - 59)
</code></pre><p>For example:</p><ul><li><code>&quot;0 3 * * *&quot;</code> runs the job at 3 AM every day.</li><li><code>&quot;*/15 * * * *&quot;</code> runs the job every 15 minutes.</li></ul><h3 id="tip-about-kubernetes-crons">Tip About Kubernetes Crons:</h3><p>Make sure to also specify the <code>startingDeadlineSeconds</code> field to control how long the CronJob will wait for the job to complete before considering it failed. Avoid a Forever running job &#x1F604;</p>]]></content:encoded></item><item><title><![CDATA[Elon Musk’s AI Startup, xAI, Hits $50 Billion Valuation]]></title><description><![CDATA[Elon Musk’s AI startup, xAI, is now valued at $50 billion, according to The Wall Street Journal. The xAI valuation has doubled since spring]]></description><link>https://khalsalabs.com/elon-musks-ai-startup-xai-hits-50-billion-valuation/</link><guid isPermaLink="false">6742b63b7cfb4c93466420a0</guid><dc:creator><![CDATA[Harman Singh]]></dc:creator><pubDate>Sun, 24 Nov 2024 05:22:26 GMT</pubDate><media:content url="https://khalsalabs.com/content/images/2024/11/elon-musk-xai.jpg" medium="image"/><content:encoded><![CDATA[<h3 id="elon-musk%E2%80%99s-ai-startup-xai-is-now-valued-at-50-billion-according-to-the-wall-street-journal-the-xai-valuation-has-doubled-since-spring-showing-its-rapid-growth-in-the-competitive-ai-industry">Elon Musk&#x2019;s AI startup, xAI, is now valued at $50 billion, according to <em>The Wall Street Journal</em>. The xAI valuation has doubled since spring, showing its rapid growth in the competitive AI industry.</h3><h3 id="xai-raises-5-billion-in-new-funding">xAI Raises $5 Billion in New Funding</h3><img src="https://khalsalabs.com/content/images/2024/11/elon-musk-xai.jpg" alt="Elon Musk&#x2019;s AI Startup, xAI, Hits $50 Billion Valuation"><p>In its latest funding round, xAI raised $5 billion, boosting its valuation from $24 billion earlier this year. The company&#x2019;s major backers include <strong>Sequoia Capital</strong>, <strong>Andreessen Horowitz</strong>, and <strong>Qatar&#x2019;s sovereign wealth fund</strong>. Altogether, xAI has raised $11 billion in 2023, making it one of the fastest-growing AI companies.</p><h3 id="xai-valuation-now-higher-than-x">xAI Valuation Now Higher Than X</h3><p>The $50 billion xAI valuation is now far greater than X&#x2019;s current worth. Fidelity, an investor in X, recently valued the social media platform at just $9.4 billion, a sharp drop from the $44 billion Musk paid to acquire it. This decline comes as X faces financial struggles, including a big drop in advertising revenue after several major brands left the platform.</p><h3 id="why-musk-founded-xai">Why Musk Founded xAI</h3><p>Musk started xAI in 2023 as an alternative to OpenAI, the company he co-founded in 2015 but left in 2019. Musk has been critical of OpenAI for moving away from its original nonprofit goals. xAI aims to make advancements in AI while providing a fresh competitor in the market.</p><h3 id="what%E2%80%99s-next-for-xai">What&#x2019;s Next for xAI?</h3><p>With a strong $50 billion valuation and billions in funding, xAI is set to expand its influence in the AI industry. The company&#x2019;s fast growth highlights the potential for AI startups to attract big investors and reshape the future of technology.<br><br>Elon Musk&#x2019;s ambitious plans for xAI show that the AI industry is just getting started, and his company is leading the way.</p>]]></content:encoded></item><item><title><![CDATA[The Essence of Paul Grahm's Essay on Hard Work: How to Hard Work]]></title><description><![CDATA[Paul Graham in startup world, offers an exploration of what it truly means to work hard in his enlightening essay, "How to Work Hard".]]></description><link>https://khalsalabs.com/the-essence-of-paul-graham-essay-on-hard-work/</link><guid isPermaLink="false">66115f5f7cfb4c934664203f</guid><category><![CDATA[hardwork, startups, paul graham, essays, case study]]></category><dc:creator><![CDATA[Harman Singh]]></dc:creator><pubDate>Sat, 06 Apr 2024 15:16:01 GMT</pubDate><media:content url="https://khalsalabs.com/content/images/2024/04/paul-grahm-startups-1.jpeg" medium="image"/><content:encoded><![CDATA[<h3 id></h3><img src="https://khalsalabs.com/content/images/2024/04/paul-grahm-startups-1.jpeg" alt="The Essence of Paul Grahm&apos;s Essay on Hard Work: How to Hard Work"><p>In the realm of success and achievement, the concept of hard work often gets oversimplified. </p><h2 id="paul-graham-a-luminary-in-the-tech-and-startup-world-offers-an-exploration-of-what-it-truly-means-to-work-hard-in-his-enlightening-essay-how-to-work-hard">Paul Graham, a luminary in the tech and startup world, offers an exploration of what it truly means to work hard in his enlightening essay, &quot;How to Work Hard.&quot; </h2><p>Through his rich narrative and insightful examples, Graham dismantles the conventional wisdom surrounding hard work, guiding us through the deeper layers of dedication and effort required to achieve greatness.</p><h4 id="the-triumvirate-of-success">The Triumvirate of Success</h4><p>At the heart of exceptional achievement lies a trio of critical components:<br><br>1. Natural ability<br>2. Practice<br>3. Effort</p><p>Graham introduces us to titans across various fields&#x2014;<strong>Bill Gates</strong> in business, <strong>Lionel Messi </strong>in sports, and <strong>P.G. Wodehouse</strong> in literature&#x2014;whose legendary successes stem not merely from their innate talents but from an unwavering commitment to <strong>hard work</strong>. These examples serve to underscore a crucial message: while talent is a significant part of the equation, it is the relentless pursuit of perfection and the willingness to put in an extraordinary amount of effort that truly sets the greats apart.</p><h4 id="debunking-the-myth-of-effortlessness">Debunking the Myth of Effortlessness</h4><p>Graham challenges the myth that talent and hard work are mutually exclusive, a notion often glamorized by popular culture. This binary perspective overlooks the reality that the path to excellence is paved with both giftedness and grit. The essay advocate that both elements are essential for achieving outlier success.</p><h4 id="rediscovering-the-meaning-of-work">Rediscovering the Meaning of Work</h4><p>One of the most compelling aspects of Graham&apos;s essay is his personal reflection on the evolution of his <strong>work ethic</strong>, beginning with a decision at the age of 13 to stop watching TV. This anecdote marks the beginning of a journey towards understanding and embracing the true nature of work&#x2014;a pursuit that goes beyond the confines of school assignments and enters the realm of self-imposed discipline and meaningful engagement.</p><p>Graham argues that real work possesses an inherent necessity, a criterion that transcends mere busywork. This realization often comes with maturity and is critical for those aiming to channel their efforts into genuine impact.</p><h4 id="the-balancing-act-of-hard-work">The Balancing Act of Hard Work</h4><p>The quest for greatness is not about maximizing the number of hours spent working; it&apos;s about finding the <strong>optimal balance where effort enhances quality</strong> rather than detracts from it. Graham shares insights from his own experiences across different domains, highlighting the importance of recognizing one&apos;s limits and the delicate interplay between pushing oneself and maintaining the integrity of one&apos;s work.</p><h4 id="a-call-to-embrace-the-hard-work-ethic">A Call to Embrace the Hard Work Ethic</h4><p>&quot;Working hard towards greatness&quot; is a <strong>dynamic process</strong> of setting goals, applying oneself fully, and being open to recalibrating one&apos;s path as needed. It demands an honest assessment of one&apos;s abilities and the humility to adapt. Graham in his essay, emphasis on the relationship between talent, hard work, and a passion for the craft.</p><p><strong>In the essence</strong>, Paul Graham&apos;s reflections move beyond the conventional narratives of hard work, offering a profound and multifaceted understanding of what it takes to achieve greatness. His insights serve as a valuable guide for anyone looking to navigate the complexities of ambition, dedication, and success. Through the stories of renowned figures and personal anecdotes.</p><blockquote class="kg-blockquote-alt">Graham&apos;s essay illuminates the path to greatness, revealing that at the intersection of talent and effort lies the true essence of hard work.</blockquote>]]></content:encoded></item><item><title><![CDATA[Download Guide - ESP32 and Micropython For Network Security]]></title><description><![CDATA[Excited to make most out of your esp32? Start with the guide by following the links provided. Each chapter offers hands-on experience and valuable insights, guiding you towards mastering network security with MicroPython on ESP32.]]></description><link>https://khalsalabs.com/how-to-use-micropython-on-esp32-your-ultimate-free-guide/</link><guid isPermaLink="false">65c0ee997cfb4c9346641f95</guid><dc:creator><![CDATA[Samiha Dokadia]]></dc:creator><pubDate>Tue, 06 Feb 2024 06:10:47 GMT</pubDate><media:content url="https://khalsalabs.com/content/images/2024/02/Mini-Guide-ESP--2-.png" medium="image"/><content:encoded><![CDATA[<h2 id="free-network-security-guide-with-esp32-and-micropython">Free Network Security Guide with ESP32 and MicroPython </h2><img src="https://khalsalabs.com/content/images/2024/02/Mini-Guide-ESP--2-.png" alt="Download Guide - ESP32 and Micropython For Network Security"><p></p><h2 id="introduction">Introduction</h2><p>ESP32 is pretty powerful micro-controller, when combined with power of python it can do a heck of work. We put together esp32 and micropython projects and created a Hack Guide for Esp32 and MicroPython containing tutorials focused on Network and Security. Here, we have our free part-1 of the guide.</p><h3 id="why-micropython-and-esp32">Why MicroPython and ESP32?</h3><p>MicroPython stands out as amazing implementation of Python 3, ideal for microcontrollers like the ESP32. Its simplicity, interactivity, and portability make it an excellent choice for programmers seeking an accessible yet powerful language. Paired with the ESP32&apos;s built-in Wi-Fi and Bluetooth capabilities, MicroPython becomes a perfect tool for network security for every programmer.</p><h2 id="what-this-free-mini-guide-covers">What this Free Mini Guide Covers</h2><p>Our free mini-guide is perfect for beginners, with its complete knowledge and made in easy-to-use steps. Let&apos;s check into the guide&apos;s chapters, each designed to make network security easy for you</p><h3 id="topics-covered">Topics Covered:</h3><h3 id="1-installing-micropython-on-esp32">1. Installing MicroPython on ESP32</h3><ul><li>Navigate through the installation process effortlessly</li><li>Set up your development environment for MicroPython on ESP32</li></ul><h3 id="2-calling-a-rest-api-from-esp32-with-micropython">2. Calling a REST API from ESP32 with MicroPython</h3><ul><li>Understand the basics of REST APIs</li><li>Learn to interact with external services for enhanced functionality</li></ul><h3 id="3sending-emails-using-esp32-micropython-and-sendgrid">3.Sending Emails using ESP32, MicroPython, and SendGrid</h3><ul><li>Explore the intricacies of sending emails from your ESP32</li><li>Utilize MicroPython to communicate with third party email APIs</li></ul><h3 id="4-creating-a-port-scanner-using-esp32-and-micropython">4. Creating a Port Scanner using ESP32 and MicroPython</h3><ul><li>Develop a robust port-scanning application</li><li>Enhance your network security toolkit with MicroPython on ESP32</li></ul><h3 id="how-to-get-the-free-mini-guide">How to Get the Free Mini Guide</h3><figure class="kg-card kg-image-card kg-width-full"><img src="https://khalsalabs.com/content/images/2024/02/Mini-Guide-ESP--1-.png" class="kg-image" alt="Download Guide - ESP32 and Micropython For Network Security" loading="lazy" width="1580" height="1056" srcset="https://khalsalabs.com/content/images/size/w600/2024/02/Mini-Guide-ESP--1-.png 600w, https://khalsalabs.com/content/images/size/w1000/2024/02/Mini-Guide-ESP--1-.png 1000w, https://khalsalabs.com/content/images/2024/02/Mini-Guide-ESP--1-.png 1580w"></figure><p>Download the guide from following link. Each chapter will help you to make more out of your esp32 projects</p><div class="kg-card kg-file-card"><a class="kg-file-card-container" href="https://khalsalabs.com/content/files/2024/02/Mini-Guide-ESP.pdf" title="Download" download><div class="kg-file-card-contents"><div class="kg-file-card-title">Mini Guide ESP</div><div class="kg-file-card-caption">Here is your free guide to learn Network Security using Esp32 &amp; MicroPython</div><div class="kg-file-card-metadata"><div class="kg-file-card-filename">Mini Guide ESP.pdf</div><div class="kg-file-card-filesize">979 KB</div></div></div><div class="kg-file-card-icon"><svg viewbox="0 0 24 24"><defs><style>.a{fill:none;stroke:currentColor;stroke-linecap:round;stroke-linejoin:round;stroke-width:1.5px;}</style></defs><title>download-circle</title><polyline class="a" points="8.25 14.25 12 18 15.75 14.25"/><line class="a" x1="12" y1="6.75" x2="12" y2="18"/><circle class="a" cx="12" cy="12" r="11.25"/></svg></div></a></div><h2 id="follow-us-for-next-guide-launch">Follow us for next guide launch!</h2><p>We are grateful to <strong>LaunchBulls</strong> who helped us bringing this guide to life. Follow this <a href="https://www.instagram.com/launchbulls/?ref=khalsalabs.com" rel="noreferrer">instagram</a> and <a href="https://twitter.com/launchbulls?ref=khalsalabs.com" rel="noreferrer">twitter/X</a> for awesome products like this guide. Happy coding and learning!</p>]]></content:encoded></item><item><title><![CDATA[Leetcode Linkedlist]]></title><description><![CDATA[<p>206.&#xA0;Reverse Linked List <em>Easy</em></p><p><em>Link :&#xA0;</em><a href="https://leetcode.com/problems/reverse-linked-list/?ref=khalsalabs.com">https://leetcode.com/problems/reverse-linked-list/</a></p><p>Given the&#xA0;<code>head</code>&#xA0;of a singly linked list, reverse the list, and return&#xA0;<em>the reversed list</em>.</p><p><strong>Example 1:</strong></p><figure class="kg-card kg-image-card"><img src="https://assets.leetcode.com/uploads/2021/02/19/rev1ex1.jpg" class="kg-image" alt loading="lazy"></figure><p><strong>Input:</strong> head = [1,2,3,4,5]<br><strong>Output:</strong> [5,4,3,2,1]</p><p><strong>Example 2:</strong></p><figure class="kg-card kg-image-card"><img src="https://assets.leetcode.com/uploads/2021/02/19/rev1ex2.jpg" class="kg-image" alt loading="lazy"></figure><p><strong>Input:</strong></p>]]></description><link>https://khalsalabs.com/leetcode-linkedlist/</link><guid isPermaLink="false">65bc4d997cfb4c9346641f6d</guid><dc:creator><![CDATA[Jagroop Singh]]></dc:creator><pubDate>Fri, 02 Feb 2024 02:09:54 GMT</pubDate><media:content url="https://khalsalabs.com/content/images/2024/02/Screenshot-2024-02-01-at-8.04.25-PM.png" medium="image"/><content:encoded><![CDATA[<img src="https://khalsalabs.com/content/images/2024/02/Screenshot-2024-02-01-at-8.04.25-PM.png" alt="Leetcode Linkedlist"><p>206.&#xA0;Reverse Linked List <em>Easy</em></p><p><em>Link :&#xA0;</em><a href="https://leetcode.com/problems/reverse-linked-list/?ref=khalsalabs.com">https://leetcode.com/problems/reverse-linked-list/</a></p><p>Given the&#xA0;<code>head</code>&#xA0;of a singly linked list, reverse the list, and return&#xA0;<em>the reversed list</em>.</p><p><strong>Example 1:</strong></p><figure class="kg-card kg-image-card"><img src="https://assets.leetcode.com/uploads/2021/02/19/rev1ex1.jpg" class="kg-image" alt="Leetcode Linkedlist" loading="lazy"></figure><p><strong>Input:</strong> head = [1,2,3,4,5]<br><strong>Output:</strong> [5,4,3,2,1]</p><p><strong>Example 2:</strong></p><figure class="kg-card kg-image-card"><img src="https://assets.leetcode.com/uploads/2021/02/19/rev1ex2.jpg" class="kg-image" alt="Leetcode Linkedlist" loading="lazy"></figure><p><strong>Input:</strong> head = [1,2]<br><strong>Output:</strong> [2,1]</p><p><strong>Example 3:</strong></p><p><strong>Input:</strong> head = []<br><strong>Output:</strong> []</p><p><strong>Constraints:</strong></p><ul><li>The number of nodes in the list is the range&#xA0;<code>[0, 5000]</code>.</li><li><code>-5000 &lt;= Node.val &lt;= 5000</code></li></ul><p>Most Optimized C++ solution </p><pre><code class="language-C++">/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
class Solution {
public:
    ListNode* reverseList(ListNode* head) {
        ListNode* ans = NULL;
        while(head){
            ListNode* tmp = new ListNode(head-&gt;val);
            tmp-&gt;next = ans;
            ans = tmp;
            head = head-&gt;next;
        }
        return ans;
    }
};</code></pre><h2 id="reversing-a-singly-linked-list">Reversing a Singly-Linked List</h2>
<p>This solution focuses on taking a singly-linked list (think of it as a conga line where everyone holds the shoulder of the person in front of them) and reversing the order so that the first person ends up at the end and the last person leads the line.</p>
<h3 id="how-it-works">How It Works</h3>
<p>Imagine each person in the line stepping out and forming a new line in the opposite direction. This process ensures that the original order is completely reversed by the end.</p>
<ol>
<li>
<p><strong>Starting Point</strong>: We begin with an empty new line (<code>ans</code>), which will eventually become the reversed list.</p>
</li>
<li>
<p><strong>Processing Each Person</strong>: As long as there are still people in the original line (<code>head</code>), we do the following for each person:</p>
<ul>
<li>Create a new person (<code>tmp</code>) that is a copy of the current leader of the original line.</li>
<li>Have this new person point (<code>next</code>) to the current leader of the new line (<code>ans</code>). If the new line is empty, they just stand looking back at the empty space.</li>
<li>Move this new person to the front of the new line, making them the new leader (<code>ans = tmp</code>).</li>
<li>Move to the next person in the original line (<code>head = head-&gt;next</code>).</li>
</ul>
</li>
<li>
<p><strong>Completing the Reversal</strong>: This process repeats until there are no more people in the original line. Each iteration effectively moves the current person from the front of the original line to the front of the new line, reversing the order.</p>
</li>
<li>
<p><strong>Final Step</strong>: Once the original line is empty, the new line (<code>ans</code>) is now the original line but in reverse order. We return this as the result.</p>
</li>
</ol>
<h3 id="technical-explanation">Technical Explanation</h3>
<ul>
<li>We initialize <code>ans</code> as <code>NULL</code> to signify the start of the new, reversed list.</li>
<li>In each iteration of the loop, we:
<ul>
<li>Create a new node (<code>tmp</code>) with the same value as the current node pointed to by <code>head</code>.</li>
<li>Set <code>tmp-&gt;next</code> to <code>ans</code>, effectively placing it at the beginning of the new list.</li>
<li>Update <code>ans</code> to point to <code>tmp</code>, moving the front of the new list forward.</li>
<li>Move to the next node in the original list (<code>head = head-&gt;next</code>).</li>
</ul>
</li>
<li>Once <code>head</code> is <code>NULL</code>, indicating we&apos;ve processed the entire original list, <code>ans</code> points to the head of the newly reversed list.</li>
</ul>
<p>This algorithm ensures that the list is reversed with a linear time complexity relative to the length of the list, efficiently reordering the elements without modifying their values.</p>
]]></content:encoded></item><item><title><![CDATA[Leetcode LinkedList]]></title><description><![CDATA[<p><strong>21.&#xA0;Merge Two Sorted Lists</strong> <em>Easy</em></p><p><em>Link : </em><a href="https://leetcode.com/problems/merge-two-sorted-lists/?ref=khalsalabs.com">https://leetcode.com/problems/merge-two-sorted-lists/</a></p><p>You are given the heads of two sorted linked lists&#xA0;<code>list1</code>&#xA0;and&#xA0;<code>list2</code>.</p><p>Merge the two lists into one&#xA0;<strong>sorted</strong>&#xA0;list. The list should be made by splicing together the nodes of</p>]]></description><link>https://khalsalabs.com/leetcode/</link><guid isPermaLink="false">65bc4b027cfb4c9346641f45</guid><dc:creator><![CDATA[Jagroop Singh]]></dc:creator><pubDate>Fri, 02 Feb 2024 02:02:09 GMT</pubDate><media:content url="https://khalsalabs.com/content/images/2024/02/Screenshot-2024-02-01-at-7.52.57-PM.png" medium="image"/><content:encoded><![CDATA[<img src="https://khalsalabs.com/content/images/2024/02/Screenshot-2024-02-01-at-7.52.57-PM.png" alt="Leetcode LinkedList"><p><strong>21.&#xA0;Merge Two Sorted Lists</strong> <em>Easy</em></p><p><em>Link : </em><a href="https://leetcode.com/problems/merge-two-sorted-lists/?ref=khalsalabs.com">https://leetcode.com/problems/merge-two-sorted-lists/</a></p><p>You are given the heads of two sorted linked lists&#xA0;<code>list1</code>&#xA0;and&#xA0;<code>list2</code>.</p><p>Merge the two lists into one&#xA0;<strong>sorted</strong>&#xA0;list. The list should be made by splicing together the nodes of the first two lists.</p><p>Return&#xA0;<em>the head of the merged linked list</em>.</p><p><strong>Example 1:</strong></p><figure class="kg-card kg-image-card"><img src="https://assets.leetcode.com/uploads/2020/10/03/merge_ex1.jpg" class="kg-image" alt="Leetcode LinkedList" loading="lazy"></figure><p><strong>Input:</strong> list1 = [1,2,4], list2 = [1,3,4]<br><strong>Output:</strong> [1,1,2,3,4,4]</p><p><strong>Example 2:</strong></p><p><strong>Input:</strong> list1 = [], list2 = []<br><strong>Output:</strong> []</p><p><strong>Example 3:</strong></p><p><strong>Input:</strong> list1 = [], list2 = [0]<br><strong>Output:</strong> [0]</p><p><strong>Constraints:</strong></p><ul><li>The number of nodes in both lists is in the range&#xA0;<code>[0, 50]</code>.</li><li><code>-100 &lt;= Node.val &lt;= 100</code></li><li>Both&#xA0;<code>list1</code>&#xA0;and&#xA0;<code>list2</code>&#xA0;are sorted in&#xA0;<strong>non-decreasing</strong>&#xA0;order.</li></ul><p>Optimized solution in C++:</p><pre><code class="language-C++">/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
class Solution {
public:
    ListNode* mergeTwoLists(ListNode* list1, ListNode* list2) {
        ListNode* res = new ListNode(-1);
        ListNode* ans = res;
        while(list1 &amp;&amp; list2){
            if(list1-&gt;val &lt;= list2-&gt;val){
                ans-&gt;next= new ListNode(list1-&gt;val);
                list1= list1-&gt;next;
            }
            else{
                ans-&gt;next= new ListNode(list2-&gt;val);
                list2= list2-&gt;next;
            }
            ans= ans-&gt;next;
        }
        if(list1){
            ans-&gt;next= list1;
        }
        if(list2){
            ans-&gt;next= list2;
        }
        return res-&gt;next;
    }
};</code></pre><p>Solution Explanation: </p><h2 id="merging-two-sorted-lists">Merging Two Sorted Lists</h2>
<p>This solution is about combining two sorted lists (let&apos;s call them <code>list1</code> and <code>list2</code>) into one single sorted list. Imagine you have two lines of people, each line is ordered by height. You want to form a new line that keeps everyone in order of height, pulling the shortest person available from the front of either line each time.</p>
<h3 id="how-it-works">How It Works</h3>
<ol>
<li>
<p><strong>Creating a Starting Point</strong>: First, we create an imaginary person (or a temporary starting node) that stands before the new line starts forming. This helps us easily add people to the new line without worrying about who is first.</p>
</li>
<li>
<p><strong>Comparing Heights (Values)</strong>: We look at the first person in each line. Whichever person is shorter (or if they&apos;re the same height, it doesn&apos;t matter which one we choose), we add them to the end of the new line and then step forward in the line they came from.</p>
</li>
<li>
<p><strong>Repeating the Process</strong>: We keep doing this - comparing the first person in each line, adding the shorter one to the new line, and stepping forward in their line. If one line runs out of people, we simply add the rest of the people from the other line to the end of the new line.</p>
</li>
<li>
<p><strong>Final Step</strong>: After we&apos;ve gone through both lines entirely, our new line is complete. But remember the imaginary person we placed at the start? They&apos;re not actually part of the new line, so we make sure the new line starts with the first real person we added.</p>
</li>
</ol>
<h3 id="technical-explanation">Technical Explanation</h3>
<ul>
<li>A new list node (<code>res</code>) with a value of <code>-1</code> is created to act as the starting point. The <code>ans</code> pointer is used to add new nodes to the list.</li>
<li>As long as there are elements in both <code>list1</code> and <code>list2</code>, we compare their values.
<ul>
<li>If <code>list1</code>&apos;s value is less than or equal to <code>list2</code>&apos;s, we add <code>list1</code>&apos;s value to the new list and move <code>list1</code> forward.</li>
<li>Otherwise, we add <code>list2</code>&apos;s value and move <code>list2</code> forward.</li>
</ul>
</li>
<li>If we reach the end of one list, we connect the remaining elements of the other list directly to the new list.</li>
<li>Finally, since the first node (<code>-1</code>) was just a placeholder, we return the list starting from the next node, which is the actual start of our merged list.</li>
</ul>
<p>This solution effectively merges two sorted lists into one, maintaining the sorted order, with a time complexity that is linear to the combined length of the two lists.</p>
]]></content:encoded></item><item><title><![CDATA[Port scanning using esp32 and micropython]]></title><description><![CDATA[In this tutorial we will be coding our own port scanner for port scanning using esp32 and micropython. This code is for educational purposes]]></description><link>https://khalsalabs.com/port-scanner-using-esp32-and-micropython/</link><guid isPermaLink="false">65a3465bc83dc71184f1800c</guid><dc:creator><![CDATA[Harman Singh]]></dc:creator><pubDate>Sun, 14 Jan 2024 05:05:06 GMT</pubDate><media:content url="https://khalsalabs.com/content/images/2024/01/port-scan-esp32.png" medium="image"/><content:encoded><![CDATA[<img src="https://khalsalabs.com/content/images/2024/01/port-scan-esp32.png" alt="Port scanning using esp32 and micropython"><p>In this tutorial we will be coding our own port scanner for port scanning using esp32 and micropython. Please note that this is for educational purposes only. Scanning networks without permission <strong>can be illegal and unethical</strong>. Lets dive into a brief introduction of port scanning, why its unethical and then coding one for us.</p><h3 id="what-is-port-scanning">What is Port Scanning?</h3><p>Port scanning is a way to discover open spots, called ports, on a computer&apos;s network. This helps to understand which parts of the network or computer on network can talk to the outside world. </p><h3 id="why-port-scanning-is-unethical">Why Port Scanning is Unethical?</h3><p>Scanning ports on someone else&apos;s network is not only unethical but also illegal in many countries. Its similar to the methodically checking all doors and windows in a building to find which ones are open. Hackers usually use this method on a network or computer to see how far they can reach and what they can access on target computer or network.</p><h3 id="other-uses-of-port-scanning">Other uses of Port Scanning</h3><p>You might have question, if its unethical why the hell this information is available so easily and people like me are giving away the code to perform this scan. The one major use of port scanning is in <strong>vulnerability scanning</strong>. To perform an assessment about how vulnerable a network is to cyber attacks or security breaches.</p><h3 id="code-to-connect-to-the-network-for-performing-scan">Code to Connect to The Network for Performing Scan</h3><pre><code class="language-python">import network
import time

# Initialize Wi-Fi Interface
wlan = network.WLAN(network.STA_IF)
wlan.active(True)

# wifi creds
ssid = &apos;&lt;YOUR WIFI SSID&gt;&apos;
password = &apos;&lt;YOU WIFI PASSWORD&gt;&apos;

print(wlan.isconnected())
time.sleep(0.5)

# Connect to the Wi-Fi network
wlan.connect(ssid, password)

print(&apos;Connected to Wi-Fi&apos;)</code></pre><h3 id="complete-code-for-port-scanner-using-micropython">Complete Code for Port Scanner using Micropython</h3><figure class="kg-card kg-code-card"><pre><code class="language-python">import socket
import time
import network

# Initialize Wi-Fi Interface
wlan = network.WLAN(network.STA_IF)
wlan.active(True)

# wifi creds
ssid = &apos;&lt;YOUR WIFI SSID&gt;&apos;
password = &apos;&lt;YOU WIFI PASSWORD&gt;&apos;

print(wlan.isconnected())
time.sleep(0.5)

# Connect to the Wi-Fi network
wlan.connect(ssid, password)

print(&apos;Connected to Wi-Fi&apos;)

###
print(wlan.ifconfig())
###

def scan_port(ip, port):
    s = usocket.socket(usocket.AF_INET,usocket.SOCK_STREAM)
    try:
        s.settimeout(5)
        s.connect((ip, port))
        return True
    except OSError as e:
        # print(e) ## uncomment for debugging
        return False
    finally:
        s.close()

def port_scanner(ip, start_port, end_port):
    print(&quot;Scanning IP: &quot;, ip)
    for port in range(start_port, end_port+1):
        if scan_port(ip, port):
            print(&quot;Port&quot;, port, &quot;is open&quot;)
        else:
            print(&quot;Port&quot;, port, &quot;is closed&quot;)

# Example usage
ip_to_scan = &apos;198.1.0.1&apos;  # Replace with the IP you want to scan
start_port = 1
end_port = 100  # Scanning 100 ports, adjust as needed


## starting port scaning
print(&quot;Running port scaning..&quot;)
port_scanner(ip_to_scan, start_port, end_port)</code></pre><figcaption><p><span style="white-space: pre-wrap;">main.py</span></p></figcaption></figure><p>In above code, replace the value of <strong>ip_to_scan</strong> with the IP where you want to perform test and provide the range of ports in <strong>start_port</strong> and <strong>end_port</strong>. Save the code as <strong>main.py</strong> on you micropython enabled device.</p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://khalsalabs.com/content/images/2024/01/port-scanning-result.png" class="kg-image" alt="Port scanning using esp32 and micropython" loading="lazy" width="2000" height="1118" srcset="https://khalsalabs.com/content/images/size/w600/2024/01/port-scanning-result.png 600w, https://khalsalabs.com/content/images/size/w1000/2024/01/port-scanning-result.png 1000w, https://khalsalabs.com/content/images/size/w1600/2024/01/port-scanning-result.png 1600w, https://khalsalabs.com/content/images/size/w2400/2024/01/port-scanning-result.png 2400w" sizes="(min-width: 720px) 720px"><figcaption><span style="white-space: pre-wrap;">port scan results using esp32</span></figcaption></figure><p>Voila! you get your esp32 ready for port scanning !</p>]]></content:encoded></item><item><title><![CDATA[How to send email using esp32 with micropython and brevo]]></title><description><![CDATA[In this tutorial we will go step by step about how to send email using esp32 with micropython and brevo smtp rest api.]]></description><link>https://khalsalabs.com/how-to-send-email-using-esp32-with-micropython-and-sendgrid/</link><guid isPermaLink="false">65a0b7fbc83dc71184f17fa9</guid><category><![CDATA[esp32]]></category><category><![CDATA[IoT]]></category><category><![CDATA[micropython]]></category><category><![CDATA[email]]></category><dc:creator><![CDATA[Harman Singh]]></dc:creator><pubDate>Sat, 13 Jan 2024 04:26:17 GMT</pubDate><media:content url="https://khalsalabs.com/content/images/2024/01/send-email-khalsalabs.png" medium="image"/><content:encoded><![CDATA[<img src="https://khalsalabs.com/content/images/2024/01/send-email-khalsalabs.png" alt="How to send email using esp32 with micropython and brevo"><p>Brevo (formally Sendinblue) is widely used for its reliability and ease of integration, offers a REST API for sending emails. In this tutorial we will go step by step about how to send email using esp32 with micropython and brevo</p><h3 id="prerequisites">Prerequisites</h3><ol><li><strong>ESP32 Module:</strong> With MicroPython firmware installed.</li><li><strong>Brevo Account:</strong> Sign up for a free brevo account here.</li><li><strong>Brevo API Key:</strong> Create an API key in your Brevo account.</li></ol><h2 id="step-by-step-guide">Step-by-Step Guide<br></h2><h3 id="step-1-setting-up-your-environment">Step 1: Setting Up Your Environment</h3><ol><li><strong>Connect ESP32 to Your Computer</strong></li><li><strong>Use Thonny to write and save your code</strong></li></ol><h3 id="step-2-code-to-connect-esp32-to-wi-fi">Step 2: Code to Connect ESP32 to Wi-Fi</h3><pre><code>import network

##### Initialize Wi-Fi Interface
wlan = network.WLAN(network.STA_IF)
wlan.active(True)


#### wifi creds
ssid = &apos;&lt;YOUR-SSID&gt;&apos;
password = &apos;&lt;YOUR-PASSWORD&gt;&apos;

print(wlan.isconnected())
time.sleep(0.5)

# Connect to the Wi-Fi network
wlan.connect(ssid, password)</code></pre><h3 id="step-3-upload-the-urequests-library-to-esp32">Step 3: Upload the urequests library to esp32</h3><p>This library can be single file named urequests.py or a folder named &quot;urequests&quot; with a <strong>&quot;__</strong>init<strong>__.</strong>py<strong>&quot; </strong>file inside. In the code example attached I used the library with folder. You can download the file <a href="https://pypi.org/project/micropython-urequests/?ref=khalsalabs.com#files" rel="noreferrer">from here</a> and extract the init file to urequests folder inside root directory of esp32. <br>It should look like this: <em>/urequests/__init__.py</em></p><h3 id="step-4-sending-an-email-using-brevo-api">Step 4: Sending an Email using Brevo API</h3><pre><code class="language-python">import urequests
import ujson

brevo_api_key = &apos;&lt;YOUR-API-KEY-HERE&gt;&apos;

url = &apos;https://api.brevo.com/v3/smtp/email&apos;

headers = {
    &apos;accept&apos;: &apos;application/json&apos;,
    &apos;api-key&apos;: brevo_api_key,
    &apos;content-type&apos;: &apos;application/json&apos;,
}

data = {
    &quot;sender&quot;: {
        &quot;name&quot;: &quot;ESP32 CLIENT&quot;,
        &quot;email&quot;: &quot;&lt;YOUR-EMAIL-ID&gt;&quot;
    },
    &quot;to&quot;: [
        {
            &quot;email&quot;: &quot;&lt;RECEIVER-EMAIL-ID&gt;&quot;,
            &quot;name&quot;: &quot;&lt;RECEIVER NAME&gt;&quot;
        }
    ],
    &quot;subject&quot;: &quot;Hello world from Esp32&quot;,
    &quot;htmlContent&quot;: &quot;&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;&lt;p&gt;Hello,&lt;/p&gt;This is my first test email sent from esp32 using Brevo.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;&quot;
}

response = urequests.post(url, data=ujson.dumps(data), headers=headers)</code></pre><h2 id="complete-code-for-sending-email-from-esp32">Complete Code for sending email from esp32</h2><figure class="kg-card kg-code-card"><pre><code>import urequests
import ujson
import network
import time

# Initialize Wi-Fi Interface
wlan = network.WLAN(network.STA_IF)
wlan.active(True)

wlan.disconnect()

# wifi creds
ssid = &apos;&lt;YOUR-SSID&gt;&apos;
password = &apos;&lt;YOUR-PASSWORD&gt;&apos;

print(wlan.isconnected())
time.sleep(0.5)

# Connect to the Wi-Fi network
wlan.connect(ssid, password)

print(&apos;Connected to Wi-Fi&apos;)

brevo_api_key = &apos;&lt;YOUR-API-KEY-HERE&gt;&apos;

url = &apos;https://api.brevo.com/v3/smtp/email&apos;

headers = {
    &apos;accept&apos;: &apos;application/json&apos;,
    &apos;api-key&apos;: brevo_api_key,
    &apos;content-type&apos;: &apos;application/json&apos;,
}

data = {
    &quot;sender&quot;: {
        &quot;name&quot;: &quot;ESP32 CLIENT&quot;,
        &quot;email&quot;: &quot;&lt;YOUR-EMAIL-ID&gt;&quot;
    },
    &quot;to&quot;: [
        {
            &quot;email&quot;: &quot;&lt;RECEIVER-EMAIL-ID&gt;&quot;,
            &quot;name&quot;: &quot;&lt;RECEIVER NAME&gt;&quot;
        }
    ],
    &quot;subject&quot;: &quot;Hello world from Esp32&quot;,
    &quot;htmlContent&quot;: &quot;&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;&lt;p&gt;Hello,&lt;/p&gt;This is my first test email sent from esp32 using Brevo.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;&quot;
}

response = urequests.post(url, data=ujson.dumps(data), headers=headers)


if response.status_code == 201:
    print(&quot;Email sent successfully!&quot;)
else:
    print(&quot;Failed to send email. Response:&quot;, response.text)
response.close()
</code></pre><figcaption><p><span style="white-space: pre-wrap;">code to send email from esp32</span></p></figcaption></figure><p>Voila! this is all you need to send email from esp32. You can download this code with requests library in the file below and place on your esp32 (add your api key and emails) in places like &lt;YOUR-API-KEY-HERE&gt;</p><div class="kg-card kg-file-card"><a class="kg-file-card-container" href="https://khalsalabs.com/content/files/2024/01/code-email.zip" title="Download" download><div class="kg-file-card-contents"><div class="kg-file-card-title">code-email</div><div class="kg-file-card-caption">code for sending email from esp32</div><div class="kg-file-card-metadata"><div class="kg-file-card-filename">code-email.zip</div><div class="kg-file-card-filesize">4 KB</div></div></div><div class="kg-file-card-icon"><svg viewbox="0 0 24 24"><defs><style>.a{fill:none;stroke:currentColor;stroke-linecap:round;stroke-linejoin:round;stroke-width:1.5px;}</style></defs><title>download-circle</title><polyline class="a" points="8.25 14.25 12 18 15.75 14.25"/><line class="a" x1="12" y1="6.75" x2="12" y2="18"/><circle class="a" cx="12" cy="12" r="11.25"/></svg></div></a></div>]]></content:encoded></item><item><title><![CDATA[How Call a REST API from ESP32 Using MicroPython]]></title><description><![CDATA[To call a REST API from an ESP32 using MicroPython, you'll typically need to connect the ESP32 to a Wi-Fi network and then use HTTP]]></description><link>https://khalsalabs.com/how-to-call-a-rest-api-from-esp32-micropython/</link><guid isPermaLink="false">659db306c83dc71184f17f35</guid><dc:creator><![CDATA[Harman Singh]]></dc:creator><pubDate>Thu, 11 Jan 2024 04:09:29 GMT</pubDate><media:content url="https://khalsalabs.com/content/images/2024/01/micropython-restapi.png" medium="image"/><content:encoded><![CDATA[<img src="https://khalsalabs.com/content/images/2024/01/micropython-restapi.png" alt="How Call a REST API from ESP32 Using MicroPython"><p></p><p>To call a REST API from an ESP32 using MicroPython, you&apos;ll typically need to connect the ESP32 to a Wi-Fi network and then use HTTP methods to interact with the API. Below is a step-by-step tutorial to achieve this.</p><h2 id="we-will-use-micropython-in-this-tutorial-to-call-rest-api-from-esp32">We will use micropython in this tutorial to call REST API from ESP32:</h2><h3 id="what-do-you-need">What do you need</h3><ol><li><strong>ESP32 with MicroPython Installed</strong>: Learn how to install <a href="https://khalsalabs.com/how-to-install-micropython-on-esp32-guide/" rel="noreferrer">micropython on esp32 here</a></li><li>Wi-Fi network Details (SSID and password).</li></ol><h3 id="step-1-code-to-connect-esp32-to-wi-fi"><br>Step 1: Code to Connect ESP32 to Wi-Fi</h3><pre><code>import network

# Initialize Wi-Fi Interface
wlan = network.WLAN(network.STA_IF)
wlan.active(True)

# wifi creds
ssid = &apos;your_wifi_ssid&apos;
password = &apos;your_wifi_password&apos;

# Connect to Your Wi-Fi:
while not wlan.isconnected():
    pass
print(&apos;Connected to Wi-Fi&apos;))</code></pre><h3 id="step-2-install-urequests-library-if-not-present">Step 2: Install urequests Library (If Not Present)</h3><p>The urequests library is used for making HTTP requests. It may or may not be included in your MicroPython firmware (its included in latest micropython).<br><br>If you are using older version of micropython, lets download the urequest with this simple step:<br>Download the file <a href="https://raw.githubusercontent.com/lucien2k/wipy-urllib/master/urequests.py?ref=khalsalabs.com" rel="noreferrer">from here</a> and save it on the root directory of your esp32 (using thonny or any file transfer tool like ampy). Using thonny it will be easier.</p><h3 id="step-3-code-to-call-rest-api">Step 3: Code to Call REST API</h3><pre><code>import urequests

# calling a publicaly available REST API
url = &apos;http://api.example.com/data&apos;
response = urequests.get(url)

# checking the response
if response.status_code == 200:
   print(response.text) # printing API response
else:
  print(&apos;Failed. Error code:&apos;, response.status_code)</code></pre><h3 id="step-4-run-your-code-complete-code-here">Step 4: Run Your Code (complete code here)</h3><figure class="kg-card kg-code-card"><pre><code>import network
import urequests

# Initialize Wi-Fi Interface
wlan = network.WLAN(network.STA_IF)
wlan.active(True)

# wifi creds
ssid = &apos;your_wifi_ssid&apos;
password = &apos;your_wifi_password&apos;

# Connect to Your Wi-Fi:
while not wlan.isconnected():
    pass
print(&apos;Connected to Wi-Fi&apos;))

# calling a publicaly available REST API

url = &apos;https://dog.ceo/api/breeds/list/all&apos; # you can use your API url here
response = urequests.get(url)

# checking the response
if response.status_code == 200:
   print(response.text) # printing API response
else:
  print(&apos;Failed. Error code:&apos;, response.status_code)
</code></pre><figcaption><p><span style="white-space: pre-wrap;">REST API Call from esp32 using micropython</span></p></figcaption></figure><ol><li>save above code file named as <strong>main.py </strong>and transfer to your esp32 (using thonny). You can also directly save file using thonny to your esp32. (shown in image)</li></ol><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://khalsalabs.com/content/images/2024/01/thonny-options.png" class="kg-image" alt="How Call a REST API from ESP32 Using MicroPython" loading="lazy" width="2000" height="1128" srcset="https://khalsalabs.com/content/images/size/w600/2024/01/thonny-options.png 600w, https://khalsalabs.com/content/images/size/w1000/2024/01/thonny-options.png 1000w, https://khalsalabs.com/content/images/size/w1600/2024/01/thonny-options.png 1600w, https://khalsalabs.com/content/images/size/w2400/2024/01/thonny-options.png 2400w" sizes="(min-width: 720px) 720px"><figcaption><span style="white-space: pre-wrap;">selecting usb in thonny options</span></figcaption></figure><ol><li>Reset esp32 and you will see the API call going from esp32, result will be printed on console (thonny&apos; console).</li></ol><h3 id="step-5-verify-the-output">Step 5: Verify the Output</h3><pre><code>Check the output on the serial console (thonny&apos;s serial console). You should see the response from the REST API! Cheers
</code></pre>]]></content:encoded></item><item><title><![CDATA[How to Install MicroPython on ESP32 Tutorial]]></title><description><![CDATA[how to install micropython on esp32 tutorial, micropython binaries and flash them to esp32. Then verify the working of micropython on esp32]]></description><link>https://khalsalabs.com/how-to-install-micropython-on-esp32-guide/</link><guid isPermaLink="false">659cbd86c83dc71184f17eed</guid><category><![CDATA[esp32]]></category><category><![CDATA[micropython]]></category><category><![CDATA[IoT]]></category><category><![CDATA[dart tutorial]]></category><category><![CDATA[microcontroller]]></category><dc:creator><![CDATA[Harman Singh]]></dc:creator><pubDate>Tue, 09 Jan 2024 03:51:20 GMT</pubDate><media:content url="https://khalsalabs.com/content/images/2024/01/micropython-3.png" medium="image"/><content:encoded><![CDATA[<img src="https://khalsalabs.com/content/images/2024/01/micropython-3.png" alt="How to Install MicroPython on ESP32 Tutorial"><p>In this how to install micropython on esp32 tutorial, we will download the official micropython binaries and flash them to esp32. Then verify the working of micropython on esp32.</p><h4 id="what-you-need">What You Need:</h4><ol><li><strong>ESP32 Module</strong>: This is the hardware you&apos;ll be programming.</li><li><strong>Micro USB Cable</strong>: To connect ESP32 to your computer.</li><li><strong>Computer</strong>: With internet access to download necessary files and software.</li></ol><h2 id="steps-to-install-micropython-on-esp32">Steps to install micropython on esp32:</h2><p></p><h2 id="step-1-download-the-firmware">Step 1: Download the Firmware</h2><ol><li><strong>Go to the MicroPython Website</strong>: Visit <a href="https://micropython.org/download/esp32/?ref=khalsalabs.com">the MicroPython downloads page</a>.</li><li><strong>Select Firmware for ESP32</strong>: Look for the section labeled &apos;Firmware for ESP32 boards&apos;.</li><li><strong>Download the Latest Version</strong>: Click on the link to download the latest firmware (.bin file) to your computer.</li></ol><h2 id="step-2-install-esptoolpy">Step 2: Install esptool.py</h2><ol><li><strong>Install Python</strong>: Make sure you have Python installed on your computer. You can download it from <a href="https://www.python.org/downloads/?ref=khalsalabs.com">the Python official website</a>.</li><li><strong>Open Command Line</strong>: Open Command Prompt (Windows) or Terminal (macOS/Linux).</li><li><strong>Install esptool</strong>: Type <code>pip install esptool</code> and press Enter. This tool is used to communicate with the ESP32 chip. <a href="https://docs.espressif.com/projects/esptool/en/latest/esp32/?ref=khalsalabs.com" rel="noreferrer">Link to documentation</a></li></ol><h2 id="step-3-connect-esp32-to-computer">Step 3: Connect ESP32 to Computer</h2><ol><li><strong>Plug in Your ESP32</strong>: Use the micro USB cable to connect the ESP32 to your computer.</li><li><strong>Check the COM Port</strong>:<ul><li>On Windows, open <strong>Device Manager</strong> and look under &apos;<strong>Ports (COM &amp; LPT)</strong>&apos; to find out which COM port the ESP32 is connected to.</li><li>On macOS/Linux, open Terminal and type <code>ls /dev/tty.*</code> to list the devices connected.</li></ul></li></ol><h2 id="step-4-erase-the-flash">Step 4: Erase the Flash</h2><ol><li><strong>Open Command Line</strong>: If you closed it earlier, open it again.</li><li><strong>Go to the ESP32 Port</strong>: Type <code>esptool.py --port COMx erase_flash</code> (replace &apos;COMx&apos; with the correct COM port).</li><li><strong>Execute the Command</strong>: Press Enter to erase the existing flash on the ESP32.</li></ol><h2 id="step-5-flash-micropython">Step 5: Flash MicroPython</h2><ol><li><strong>Locate the Downloaded Firmware</strong>: Find where you saved the <strong>.bin </strong>file (that you downloaded in step 1)</li><li><strong>Flash the Firmware</strong>: Type <code>esptool.py --port COMx --baud 460800 write_flash -z 0x1000 path-to-your-downloaded.bin</code> (replace &apos;COMx&apos; with your COM port and &apos;path-to-your-downloaded.bin&apos; with the path to the downloaded .bin file).</li></ol><h2 id="step-6-verify-installation">Step 6: Verify Installation<br></h2><h3 id="verify-installation-using-thonny">Verify installation using Thonny</h3><p>One simple way to verify the installation is install <a href="https://thonny.org/?ref=khalsalabs.com" rel="noreferrer">thonny</a> and select  your COM Port or <code>tty</code> connected device from settings. You will see the <code>&gt;&gt;&gt;</code> sign on thonny&apos;s shell indicating that micropython is installed. </p><h3 id="verify-installation-using-putty-on-windows">Verify installation using Putty on windows:</h3><ol><li><strong>Install a Serial Terminal</strong>: Install a program like PuTTY or use the built-in terminal for communication. Open the serial terminal, select the COM port, set the baud rate to 115200, and connect.</li><li><strong>Check for MicroPython Prompt</strong>: You should see the MicroPython prompt <code>&gt;&gt;&gt;</code>. If you see this, congratulations, MicroPython is installed!</li></ol><p></p><p>You&apos;ve successfully installed MicroPython on your ESP32. Enjoy! To see what you can do using micropython, I have a tutorial to host a website using micropython <a href="https://khalsalabs.com/hosting-a-website-on-esp32-webserver-with-microdot-step-by-step-guide/" rel="noreferrer">here</a></p>]]></content:encoded></item><item><title><![CDATA[Top 3 Free Newsletters for Startup Stories: A Must-Read for Entrepreneurs]]></title><description><![CDATA[Entrepreneurs, don't miss these must-read free newsletters for startup stories. Stay informed and inspired with our top picks. ]]></description><link>https://khalsalabs.com/top-3-free-newsletters-for-startup-stories-a-must-read-for-entrepreneurs/</link><guid isPermaLink="false">6568f693a04d26b78344067d</guid><category><![CDATA[newsletter]]></category><dc:creator><![CDATA[Harman Singh]]></dc:creator><pubDate>Sat, 02 Dec 2023 18:03:01 GMT</pubDate><media:content url="https://khalsalabs.com/content/images/2023/11/founderpedia-app.png" medium="image"/><content:encoded><![CDATA[<img src="https://khalsalabs.com/content/images/2023/11/founderpedia-app.png" alt="Top 3 Free Newsletters for Startup Stories: A Must-Read for Entrepreneurs"><p></p><p>Entrepreneurs are always on the lookout for resources that can provide insights, inspiration, and practical advice. Newsletters, packed with startup stories, can be a goldmine of information especially when they are <strong>free</strong>. I subscribed to multiples and read many, here are my top three picks, each offering unique perspectives and invaluable lessons from the startup universe.</p><h3 id="1-startup-digest">1. Startup Digest</h3><p><strong>Why It&apos;s My Top Pick:</strong> Startup Digest stands out for its comprehensive coverage and customization. It&apos;s more than just a newsletter; it&apos;s a curated experience tailored to your interests. Whether you&apos;re interested in fintech, healthtech, or any other sector, Startup Digest has got you covered.</p><p><strong>What You&apos;ll Get:</strong> Subscribers receive a weekly digest of the latest trends, stories, and tips from various startup sectors. The content is rich and varied, offering something for everyone. The personalized approach means you get the most relevant information, saving you time and keeping you focused on your niche.</p><h3 id="2-the-hustle">2. The Hustle</h3><p><strong>Why It Ranks Second:</strong> The Hustle is perfect for those who want their <strong>startup news</strong> with a side of personality. It&#x2019;s known for its conversational tone and ability to dissect complex topics into enjoyable reads.</p><p><strong>What You&apos;ll Get:</strong> Daily updates provide a mix of the latest startup news, technology trends, and business strategies. The newsletter has a knack for unearthing fascinating stories and presenting them in a way that&apos;s both informative and entertaining. If you&apos;re looking for a daily dose of startup insights that feels like a chat with a knowledgeable friend, The Hustle is for you.</p><h3 id="3-founderpediaapp">3. FounderPedia.app</h3><p><strong>Why It&apos;s a Must-Subscribe:</strong> FounderPedia earns its place for its focused and deep-diving content. While it may not have the broad appeal of Startup Digest or the daily frequency of The Hustle, it stands out for its in-depth<strong> case studies</strong>.</p><p><strong>What You&apos;ll Get:</strong> This newsletter is offering detailed startup stories that go beyond the surface. Each issue is a deep dive into a single <strong>startup&apos;s journey</strong>, offering lessons learned, strategies employed, and the real-world challenges faced. For those looking to understand the essentials and backstage of building a startup, <a href="https://founderpedia.app/?ref=khalsalabs.com" rel="noreferrer">FounderPedia</a> is an invaluable resource. <br>You can check this out here: <a href="https://founderpedia.app/?ref=khalsalabs.com">https://founderpedia.app/</a><br></p><h3 id="bonuslennys-newsletter">Bonus - Lenny&apos;s Newsletter</h3><p>I recently came accross it and its more that only a newsletter as Lenny has podcast and youtube channel. I am putting it in a bonus list. If you are behind the secret recipe of success, this is must read newsletter on substack.<br>You can check the stories out here: <a href="https://www.lennysnewsletter.com/?ref=khalsalabs.com">https://www.lennysnewsletter.com/</a></p><hr><h3 id="final-thoughts">Final Thoughts</h3><p>Each of these newsletters brings something unique to the table. For entrepreneurs seeking knowledge, inspiration, and practical advice, subscribing to these free newsletters is a step towards informed and successful entrepreneurship.</p><hr><p><em>Note: The opinions expressed in this blog post are based on my personal experiences and preferences. The ranking and descriptions are intended to guide readers towards resources that could be beneficial in their entrepreneurial journey. </em></p>]]></content:encoded></item><item><title><![CDATA[Hosting a Website on ESP32 Webserver with Microdot: Step-by-Step Guide]]></title><description><![CDATA[A step-by-step guide to hosting a website on ESP32 Webserver with Microdot. Learn the process for efficient and compact web hosting. ]]></description><link>https://khalsalabs.com/hosting-a-website-on-esp32-webserver-with-microdot-step-by-step-guide/</link><guid isPermaLink="false">653445fd159539e6e6e3d9fe</guid><dc:creator><![CDATA[Harman Singh]]></dc:creator><pubDate>Fri, 03 Nov 2023 20:24:08 GMT</pubDate><media:content url="https://khalsalabs.com/content/images/2023/11/Screenshot-2023-11-03-at-14-23-20-ESP32.png" medium="image"/><content:encoded><![CDATA[<h1 id></h1><h2 id="esp32-is-famous-micro-controller-for-hobby-and-commercial-projects-in-this-tutorial-well-explore-how-to-host-a-website-on-an-esp32-using-the-microdot-framework">ESP32 is famous micro-controller for hobby and commercial projects. In this tutorial, we&apos;ll explore how to host a website on an ESP32 using the Microdot framework.</h2><img src="https://khalsalabs.com/content/images/2023/11/Screenshot-2023-11-03-at-14-23-20-ESP32.png" alt="Hosting a Website on ESP32 Webserver with Microdot: Step-by-Step Guide"><p></p><h2 id="what-is-microdot">What is Microdot?</h2><p>Microdot is a lightweight Python web framework designed for light weight operations. It offers a minimalist yet efficient way to create web applications. Its light weight makes it excellent choice for microcontrollers like the ESP32.</p><h2 id="prerequisites">Prerequisites</h2><p>Before diving into the ESP32 webserver setup, make sure you have the following:</p><ul><li>An ESP32 microcontroller with MicroPython firmware installed.</li><li>A development environment (e.g., Thonny or VS Code with PlatformIO) ready to go.</li><li>The Microdot library (we&apos;ll guide you through the installation).</li></ul><h2 id="installing-microdot-on-your-esp32">Installing Microdot on Your ESP32</h2><p>To get started hosting a website on your ESP32, you&apos;ll need to install the Microdot framework. Follow these steps:</p><h3 id="1-download-and-install-the-microdot-library">1. Download and Install the Microdot Library</h3><p>Begin by downloading the Microdot library from the official GitHub repository. You need to download micropython.py file and place it in the root directory of esp32.<br><a href="https://github.com/miguelgrinberg/microdot/tree/main/src/microdot?ref=khalsalabs.com" rel="noreferrer">Official Download link</a></p><h3 id="2-create-your-esp32-web-application">2. Create Your ESP32 Web Application</h3><p>With Microdot installed, you can start building your web application. Use the provided code as a starting point:</p><pre><code class="language-python">from microdot import Microdot
from microdot import send_file
import network

# Set your Wi-Fi credentials - We need them to connect the ESP32 to your network
ssid = &apos;your_SSID&apos;
password = &apos;your_PASSWORD&apos;

# Create a Wi-Fi station (STA) interface
sta_if = network.WLAN(network.STA_IF)
sta_if.active(True)

# Connect to the Wi-Fi network
sta_if.connect(ssid, password)

# Wait until the ESP32 is connected to the network
while not sta_if.isconnected():
    pass
print(&apos;Connected to Wi-Fi&apos;)


# web server code starts here
app = Microdot()

@app.route(&apos;/&apos;)
def index(request):
    return send_file(&apos;index.html&apos;)

app.run(port=80)
</code></pre><p><strong>NB: </strong>Update your wifi ssid (name) and password in above code<br><br>Save above code in your <strong>code.py</strong> on root directory of ESP32. This code connect esp32 to network and creates a web application serving an <code>index.html</code> file when you access the root URL.</p><h3 id="3-create-a-basic-html-file">3. Create a basic HTML file</h3><pre><code class="language-html">&lt;html&gt;
&lt;title&gt; Website Hosted on Esp32 &lt;/title&gt;
&lt;body&gt;
&lt;p&gt; Hello World ! &lt;/p&gt;
&lt;p&gt; This website is hosted on esp32 &lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;

</code></pre><p>I used little css in my <a href="https://esp.khalsalabs.com/?ref=khalsalabs.com" rel="noreferrer">esp32 website here</a></p><h3 id="4-upload-the-web-files"><br>4. Upload the Web Files</h3><p>Now, upload your web files, named as <code>index.html</code> file, to your ESP32. Make sure you copy the file at the root directory.</p><h3 id="5-start-the-esp32-web-server">5. Start the ESP32 Web Server</h3><p>Restart your ESP32 to start the web server (make sure the micropython is installed before you install microdot).</p><h3 id="6-access-your-esp32-webserver">6. Access Your ESP32 Webserver</h3><p>Once it is running, you can access your website by entering your ESP32&apos;s IP address in a web browser. For example, if your ESP32&apos;s IP address is <code>192.168.1.100</code>, input <code>http://192.168.1.100</code> in your browser.<br>(To find the IP of ESP32 device, one of the easiest way is to check from device connected list of your router)</p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://khalsalabs.com/content/images/2023/11/20231105_120607.jpg" class="kg-image" alt="Hosting a Website on ESP32 Webserver with Microdot: Step-by-Step Guide" loading="lazy" width="1024" height="987" srcset="https://khalsalabs.com/content/images/size/w600/2023/11/20231105_120607.jpg 600w, https://khalsalabs.com/content/images/size/w1000/2023/11/20231105_120607.jpg 1000w, https://khalsalabs.com/content/images/2023/11/20231105_120607.jpg 1024w" sizes="(min-width: 720px) 720px"><figcaption><span style="white-space: pre-wrap;">Esp32 S2 Mini wtih MicroPython pre installed</span></figcaption></figure><p>Congratulations! You&apos;ve successfully hosted a website on your ESP32 webserver like my <a href="https://esp.khalsalabs.com/?ref=khalsalabs.com" rel="noreferrer">esp32 website</a>. <br>Like to discuss or see more projects like this, connect with me at <a href="harmandeep-singh-50997955" rel="noreferrer">LinkedIn here</a>!</p>]]></content:encoded></item><item><title><![CDATA[Our Top 5 Best Smart Dog Collars]]></title><description><![CDATA[<!--kg-card-begin: html-->
<p>So, you&#x2019;ve decided to enter the world of pet technology with a smart collar? Well, you&#x2019;re in for a treat! In this blog, we&#x2019;re answering all your questions and even reviewing 5 Smart Collars that. Ditch your plain old collars to these high-tech wonders</p>]]></description><link>https://khalsalabs.com/top-5-best-smart-dog-collars/</link><guid isPermaLink="false">65335d18c0f9cfe42fd0e90a</guid><dc:creator><![CDATA[Samiha Dokadia]]></dc:creator><pubDate>Thu, 21 Sep 2023 06:38:10 GMT</pubDate><content:encoded><![CDATA[<!--kg-card-begin: html-->
<p>So, you&#x2019;ve decided to enter the world of pet technology with a smart collar? Well, you&#x2019;re in for a treat! In this blog, we&#x2019;re answering all your questions and even reviewing 5 Smart Collars that. Ditch your plain old collars to these high-tech wonders today!</p>



<p><br>Before we jump into our top 5 picks, let&#x2019;s answer the question burning in your mind: &#x201C;Why does my dog need a smart collar?&#x201D;<br>Smart collars can help you track your dog&#x2019;s health and never forget their exercise schedule, providing proactive care from anywhere.</p>



<h2> The Top 5 Smart Dog Collars on the Market</h2>



<h3>1: Petdrifts Lite Smart Collar- Tracking Dog Wellness</h3>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" src="https://khalsalabs.com/content/images/wordpress/2023/09/multi-collar-1024x453.png" alt class="wp-image-1668" width="840" height="371" srcset="https://khalsalabs.com/content/images/wordpress/2023/09/multi-collar-1024x453.png 1024w, https://khalsalabs.com/content/images/wordpress/2023/09/multi-collar-300x133.png 300w, https://khalsalabs.com/content/images/wordpress/2023/09/multi-collar-768x340.png 768w, https://khalsalabs.com/content/images/wordpress/2023/09/multi-collar-400x177.png 400w, https://khalsalabs.com/content/images/wordpress/2023/09/multi-collar.png 1080w" sizes="(max-width: 840px) 100vw, 840px"><figcaption>Petdrifts Lite Smart Collar is available in <a href="https://shop.petdrifts.com/?ref=khalsalabs.com" target="_blank" rel="noreferrer noopener">different styles</a></figcaption></figure>



<p><br>The Lite Smart Collar is the perfect tool for monitoring your dog&#x2019;s health. With an activity tracker, you can ensure that your dog is getting enough exercise.. </p>



<p>It makes it easy to check for any possible illnesses that may cause your dog to sleep a lot. Also, it sends you a health alert directly to your phone, so you can address any issues early on. It&#x2019;s not about tracking your dog; it&#x2019;s about understanding their needs. Your pup deserves the best, and this smart collar is here to deliver it.<br>So, what are you waiting for? Join the waitlist to grab amazing offers and have a buddy to watch your dog. Because when it comes to your dog, their health and happiness are all that matter</p>



<p>C<a href="https://shop.petdrifts.com/?ref=khalsalabs.com">lick here to join the waitlist </a></p>



<p><em>Availability- On the official website-<a href="https://shop.petdrifts.com/?ref=khalsalabs.com" target="_blank" rel="noreferrer noopener">shop.petdrifts.com</a></em>. In Canada and US</p>



<p><br>Petdrifts Lite smart collar has certain advantages and disadvantages. You can keep an eye on your dog&#x2019;s health real time using your phone. Also, there&#x2019;s a discount of up to 30% for early buyers. Sadly, the product right now has a waitlist and this version doesn&#x2019;t include a GPS tracker.</p>



<h3> 2: Fi Smart Collar &#x2013; Stylish Meets Savvy</h3>



<figure class="wp-block-image size-full"><img loading="lazy" width="336" height="150" src="https://khalsalabs.com/content/images/wordpress/2023/09/download.jpg" alt class="wp-image-1670" srcset="https://khalsalabs.com/content/images/wordpress/2023/09/download.jpg 336w, https://khalsalabs.com/content/images/wordpress/2023/09/download-300x134.jpg 300w" sizes="(max-width: 336px) 100vw, 336px"></figure>



<p></p>



<p>The Fi Smart Collar isn&#x2019;t just a fashion statement; it&#x2019;s your pup&#x2019;s digital BFF. With its sleek design and GPS tracking capabilities this collar is a good pick </p>



<p><a href="https://www.amazon.com/Fi-Smart-Dog-Collar-Waterproof/dp/B0C43ZKWJT?ref=khalsalabs.com">Available only on Amazon in the US</a></p>



<p>Pros of this device include a long battery life of up to 6 months and Wi-Fi connectivity. However, it is too expensive and bulky for smaller dog breeds and requires monthly subscriptions to be paid.</p>



<p></p>



<h3>3: Link AKC Smart Collar &#x2013; The Total Package</h3>



<figure class="wp-block-image size-full"><img loading="lazy" width="299" height="169" src="https://khalsalabs.com/content/images/wordpress/2023/09/download-1.jpg" alt class="wp-image-1671"><figcaption>Link AKC Smart Collar for your dogs</figcaption></figure>



<p><strong><br></strong>&#x201C;Link up&#x201D; with the Link AKC Smart Collar and enjoy a comprehensive canine experience. This collar includes GPS, activity monitoring, and temperature alerts for your dog</p>



<p><em><a href="https://www.amazon.in/Link-Akc-Smart-Dog-Collar/dp/B01MFG7ELX?ref=khalsalabs.com">Available on- Amazon</a></em></p>



<p>The Pro GPS tracker is perfect for adventurous pups, tracking all of your dog&#x2019;s activities. However, the battery drains easily in GPS mode and there is no sleep tracker to check if your pup is getting enough rest.</p>



<p></p>



<h3>4: PetSafe Stay &amp; Play &#x2013; The Invisible Guardian</h3>



<p><img src="https://lh5.googleusercontent.com/0WbYSHKMEaPLZnQJA5K4_wkqIf6WxaQagmXoisoNl1RecyMwtYWdaOAUVX7tN5DPjctydj18jzRFiR4E_6SZrtAaK-bO_V4AjDuEUTVJJDArtoj_lfIowKK9dlU3LM5Bk3W1cZb16358" style="width: 300px"></p>



<p><br>Keep your dog safe with PetSafe Stay &amp; Play. It creates a digital boundary, so there is no need for a fence.</p>



<p><a href="https://www.amazon.in/PetSafe-PIF00-12917-Stay-Wireless-Fence/dp/B0055L8RRC?ref=khalsalabs.com">Availability- Only on Amazon</a></p>



<p>Proper use of pet Safe Stay and play ensures your dog&#x2019;s safety and security. You can keep your dog in the backyard without any worries. However, they do not track vital information such as activity and sleep, and they can be expensive and hard to install.</p>



<h3>5: Tractive LTE GPS Dog Tracker &#x2013; Pocket-Sized Protection</h3>



<p><br>Don&#x2019;t let the small size fool you! The Tractive LTE GPS Dog Tracker is a big deal. It&#x2019;s perfect for smaller pups who escape a lot out on their own.</p>



<p><em><a href="https://www.amazon.in/Tractive-LTE-GPS-Dog-Tracker/dp/B08C5DQ2MP?ref=khalsalabs.com">Available on Amazon</a></em></p>



<p>This GPS tracker is perfect for active pups with a virtual fence option for safety. A Monthly fee is required for full access to all features. No sleep or heart rate tracking is available.</p>



<h2>Setting Up Your Smart Collar &#x2013; It&#x2019;s Easier and Better!</h2>



<p>Changing from a plain old collar to a high-tech smart collar might seem tough. But it is an easy process and can be done in a few minutes. Get ready to simplify pet care with the smart collars.</p>



<h2> The Future of Pup Parenting</h2>



<figure class="wp-block-image"><img src="https://shop.petdrifts.com/images/collar-pup.png" alt="discover-highlight"><figcaption>Sneak Peak into Petdrifts Lite Smart Collar</figcaption></figure>



<p>In conclusion, these smart dog collars are game-changers for pet parents. From GPS tracking to invisible fences, they&#x2019;ve got it all. Say goodbye to the old collar, and hello to the future of pup parenting!</p>



<p>There you have it, the top 5 smart dog collars that&#x2019;ll have your pup happy. Remember, it&#x2019;s not just about staying connected; it&#x2019;s about understanding your pet&#x2019;s needs. So, whether your pup is an adventurous dog or a homebody, there&#x2019;s a smart collar out there that&#x2019;s the perfect fit!</p>



<p>Upgrade your dog&#x2019;s style and safety with a smart collar. Show your love for your dog by investing in one. They deserve the best.!<br>Have you got any questions or recommendations about smart dog collars? Please drop them in the comments below, and let&#x2019;s keep the conversation going. Happy parenting, dog lovers! &#x1F43E;</p>
<!--kg-card-end: html-->]]></content:encoded></item><item><title><![CDATA[Dockerize Flask Service  - Docker and Flask in 5 Easy Steps]]></title><description><![CDATA[<!--kg-card-begin: html-->
<h2>In this tutorial, we will walk through the process of Dockerize FlasK  Python service step by step. Docker and flask is an easy example of containerizing a python application.</h2>


<figure class="wp-block-post-featured-image"><img width="512" height="190" src="https://khalsalabs.com/content/images/wordpress/2023/09/docker-flask.png" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="docker flask python" loading="lazy" srcset="https://khalsalabs.com/content/images/wordpress/2023/09/docker-flask.png 512w, https://khalsalabs.com/content/images/wordpress/2023/09/docker-flask-300x111.png 300w, https://khalsalabs.com/content/images/wordpress/2023/09/docker-flask-400x148.png 400w" sizes="(max-width: 512px) 100vw, 512px"></figure>


<p>Docker is a platform that offer containerization solution for software applications, and python is our favourite and powerful language. Let&#x2019;</p>]]></description><link>https://khalsalabs.com/dockerize-flask-service-docker-and-flask-in-5-easy-steps/</link><guid isPermaLink="false">65335d18c0f9cfe42fd0e909</guid><dc:creator><![CDATA[Harman Singh]]></dc:creator><pubDate>Sat, 16 Sep 2023 19:55:26 GMT</pubDate><media:content url="https://khalsalabs.com/content/images/wordpress/2023/09/docker-flask.png" medium="image"/><content:encoded><![CDATA[<!--kg-card-begin: html-->
<h2>In this tutorial, we will walk through the process of Dockerize FlasK  Python service step by step. Docker and flask is an easy example of containerizing a python application.</h2>


<figure class="wp-block-post-featured-image"><img width="512" height="190" src="https://khalsalabs.com/content/images/wordpress/2023/09/docker-flask.png" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="Dockerize Flask Service  - Docker and Flask in 5 Easy Steps" loading="lazy" srcset="https://khalsalabs.com/content/images/wordpress/2023/09/docker-flask.png 512w, https://khalsalabs.com/content/images/wordpress/2023/09/docker-flask-300x111.png 300w, https://khalsalabs.com/content/images/wordpress/2023/09/docker-flask-400x148.png 400w" sizes="(max-width: 512px) 100vw, 512px"></figure>


<img src="https://khalsalabs.com/content/images/wordpress/2023/09/docker-flask.png" alt="Dockerize Flask Service  - Docker and Flask in 5 Easy Steps"><p>Docker is a platform that offer containerization solution for software applications, and python is our favourite and powerful language. Let&#x2019;s combine the power of both. <br>What about <strong>Flask</strong>, this is a web framework that is written in python and use to build web applications using python.<br><br>In current tutorial, we will be using web python application. For very basic or command line python application (hello world program) using docker, please follow <s>this tutorial </s><br></p>



<h3>1. Prerequisites</h3>



<p>Before we begin, ensure that you have the following tools installed on your system:</p>



<ul><li><strong>Docker</strong>: Download and install Docker from the <a href="https://www.docker.com/get-started?ref=khalsalabs.com">official website</a>.</li><li><strong>Python</strong>: Download and install Python from the <a href="https://www.python.org/?ref=khalsalabs.com">official website</a>.</li></ul>



<h3>2. Create a Python Service</h3>



<p>For the purpose of this tutorial, we will create a simple Python service that exposes a &#x201C;<strong>Hello, World!&#x201D;</strong> message via a REST API using the <strong>Flask web framework.</strong></p>



<p>Create a directory for your project and create a Python script named <code><strong>app.py</strong></code> with following code:</p>



<pre class="wp-block-code"><code># app.py
from flask import Flask

app = Flask(__name__)

@app.route(&apos;/&apos;)
def hello_world():
    return &apos;Hello, World!&apos;

if __name__ == &apos;__main__&apos;:
    app.run(debug=True, host=&apos;0.0.0.0&apos;)
</code></pre>



<p>Now, create a <code><strong>requirements.txt</strong></code> file to list the Python packages required for your service, with the following line in it:</p>



<pre class="wp-block-code"><code>Flask==2.0.1</code></pre>



<h3>3. Write a Dockerfile</h3>



<p>A <strong>Dockerfile</strong> is a script used to build a Docker image. Create a file named <code>Dockerfile</code> (no file extension) in the same directory as your Python script <strong>app.py</strong> and <code>r<strong>equirements.txt</strong></code> with the following content:</p>



<pre class="wp-block-code"><code># Use the official Python image as the base image
FROM python:3.8-slim

# Set the working directory in the container
WORKDIR /app

# Copy the current directory contents into the container at /app
COPY . /app

# Install Python dependencies
RUN pip install --no-cache-dir -r requirements.txt

# Expose port 80
EXPOSE 80

# Define the command to run your application
CMD [&quot;python&quot;, &quot;app.py&quot;]
</code></pre>



<p>You can name this file: <strong>Dockerfile</strong> without any extension</p>



<p>This Dockerfile does the following:</p>



<ul><li>It starts with the official Python 3.8 image.</li><li>Sets the working directory to <code>/app</code> in the container.</li><li>Copies the contents of the current directory (your Python code and <code>requirements.txt</code>) to the container.</li><li>Installs the Python dependencies listed in <code>requirements.txt</code>.</li><li>Exposes port 80 (the default for HTTP).</li><li>Specifies the command to run your application, which is <code>python app.py</code>.</li></ul>



<h3>4. Build the Docker Image</h3>



<p>Navigate to the directory containing your <strong>Dockerfile</strong> and <strong>Python code</strong> in your terminal and run the following command to build the Docker image:</p>



<pre class="wp-block-code"><code>docker build -t python-service .</code></pre>



<ul><li><code>-t python-service</code> assigns the name &#x201C;python-service&#x201D; to your Docker image. You can choose any name you like. This is to tag the docker image with specific name.<br></li></ul>



<h3>5. Run the Docker Container</h3>



<p>Now that you have built the Docker image, you can run a Docker container from it. Use the following command:</p>



<pre class="wp-block-code"><code>docker run -d -p 8080:80 python-service</code></pre>



<ul><li><code>-d</code> runs the container in detached mode.</li><li><code>-p 8080:80</code> maps port 8080 on your host machine to port 80 in the container.</li><li><code>python-service</code> is the name of the image you built earlier.</li></ul>



<p><br><strong>Congratulations</strong>! You&#x2019;ve successfully Dockerized a Python service. Your Flask-based &#x201C;Hello, World!&#x201D; service is now running in a Docker container and accessible at <code><strong>http://localhost:8080</strong></code> in your <strong>web browser</strong>.</p>



<p><br></p>
<!--kg-card-end: html-->]]></content:encoded></item></channel></rss>