<?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:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sparsh on Medium]]></title>
        <description><![CDATA[Stories by Sparsh on Medium]]></description>
        <link>https://medium.com/@sparsh308?source=rss-9593c0400ae3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*-GO53fon_BdiTbFbxPJ8Aw.jpeg</url>
            <title>Stories by Sparsh on Medium</title>
            <link>https://medium.com/@sparsh308?source=rss-9593c0400ae3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 14:45:19 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sparsh308/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Reverse Engineering the Godrej Smart Matic BLE Air Freshener with ESP32]]></title>
            <link>https://sparsh308.medium.com/reverse-engineering-the-godrej-smart-matic-ble-air-freshener-with-esp32-8b916b4978e7?source=rss-9593c0400ae3------2</link>
            <guid isPermaLink="false">https://medium.com/p/8b916b4978e7</guid>
            <category><![CDATA[godrej]]></category>
            <category><![CDATA[esp32]]></category>
            <category><![CDATA[iot]]></category>
            <category><![CDATA[bluetooth]]></category>
            <category><![CDATA[ble]]></category>
            <dc:creator><![CDATA[Sparsh]]></dc:creator>
            <pubDate>Wed, 05 Aug 2026 13:53:37 GMT</pubDate>
            <atom:updated>2026-08-05T13:53:37.067Z</atom:updated>
            <content:encoded><![CDATA[<p>Take complete local control of your Bluetooth-enabled air freshener using an ESP32, reverse engineering, and a few lines of C++.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0W1ZTXGMFQGMt5fQBwHOTA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l5df6zUrrTL1E0NHdTDK_A.png" /></figure><h3>Introduction</h3><p>Like many IoT devices, the <strong>Godrej Smart Matic</strong> air freshener relies entirely on a mobile application for control. While the official app works well, it doesn’t provide any integration with platforms such as Home Assistant, MQTT, or custom automation systems.</p><p>I wanted something different:</p><ul><li>Trigger a spray from Home Assistant</li><li>Integrate it with motion sensors</li><li>Schedule sprays using my own automation</li><li>Eliminate dependence on the official mobile application</li></ul><p>Since the Smart Matic communicates over Bluetooth Low Energy (BLE), I decided to reverse engineer its protocol.</p><p>This article documents the complete process — from discovering the BLE services to triggering a spray from an ESP32.</p><h3>Understanding the Device</h3><p>The first step was identifying the BLE services exposed by the Smart Matic.</p><p>Using <strong>nRF Connect</strong>, I connected to the diffuser and discovered that it exposes a standard <strong>Nordic UART Service (NUS)</strong>.</p><pre>Service<br>6E400000-B5A3-F393-E0A9-E50E24DCCA9E</pre><p>Characteristics:</p><pre>6E400001<br>6E400002<br>6E400003<br>6E400004</pre><p>Initially it wasn’t obvious which characteristic actually accepted commands.</p><h3>Finding the Device</h3><p>One interesting challenge appeared immediately.</p><p>On iOS, nRF Connect does <strong>not</strong> expose the Bluetooth MAC address. Instead, Apple provides a CoreBluetooth UUID.</p><p>Example:</p><pre>2210877C-4A4B-B981-E29E-46B32DA0E5C6</pre><p>Unfortunately, ESP32 BLE clients require the actual MAC address.</p><p>To obtain it, I wrote a simple ESP32 scanner.</p><p>The ESP32 discovered:</p><pre>Found Smart Matic!<br>A4:C1:38:20:51:24</pre><p>Now we had everything required to connect.</p><h3>Connecting with ESP32</h3><p>I used the excellent <strong>NimBLE-Arduino</strong> library.</p><p>The ESP32 scanned for the device by name.</p><pre>if (device-&gt;getName() == &quot;Smart Matic&quot;) {<br>    advDevice = device;<br>}</pre><p>Once discovered, the client connects:</p><pre>client-&gt;connect(advDevice);</pre><p>Connection succeeded immediately.</p><pre>Connected!</pre><h3>The First Problem</h3><p>Although the connection worked, the device refused to expose any services.</p><p>My output looked like this:</p><pre>Connected!<br>Service not found</pre><p>After some investigation I realized that newer versions of <strong>NimBLE-Arduino</strong> require explicit GATT discovery.</p><p>The fix was simply:</p><pre>client-&gt;discoverAttributes();</pre><p>After adding this single line:</p><pre>Connected!<br>Attributes discovered.<br>Service found.<br>Characteristic found.</pre><p>Everything suddenly started working.</p><h3>Discovering the Correct Characteristic</h3><p>Although the Nordic UART service exposes multiple characteristics, only one accepted the spray command.</p><p>The working characteristic turned out to be:</p><pre>6E400004-B5A3-F393-E0A9-E50E24DCCA9E</pre><h3>The Magic Packet</h3><p>After observing BLE traffic from the official application, I extracted the command responsible for triggering a spray.</p><pre>BF 62 6D 54<br>18 68 62 6D<br>4E 18 9A 62<br>72 49 00 FF</pre><p>Or in code:</p><pre>uint8_t cmd[] = {<br>    0xBF,0x62,0x6D,0x54,<br>    0x18,0x68,0x62,0x6D,<br>    0x4E,0x18,0x9A,0x62,<br>    0x72,0x49,0x00,0xFF<br>};</pre><p>Writing these sixteen bytes instantly triggers a spray.</p><pre>characteristic-&gt;writeValue(cmd, sizeof(cmd), false);</pre><h3>Testing</h3><p>Instead of spraying automatically every time the ESP32 booted, I added a serial interface.</p><p>Typing</p><pre>Type  s into the Serial Monitor sends the BLE packet.</pre><p>Output:</p><pre>Found Smart Matic!<br>A4:C1:38:20:51:24<br>Connected!<br>Attributes discovered.<br>Service found.<br>Characteristic found.<br>Ready!</pre><pre>Type &#39;s&#39; then press Enter.</pre><pre>Spray triggerThis made testing significantly easier while experimenting with different packets.</pre><h3>Where to Go From Here</h3><p>Now that the BLE protocol is understood, integrating the diffuser into a smart home becomes straightforward.</p><p>Some ideas include:</p><ul><li>Home Assistant integration</li><li>ESPHome BLE client</li><li>MQTT control</li><li>REST API</li><li>Voice assistant integration</li><li>Motion-triggered spraying</li><li>Presence detection</li><li>Scheduled fragrance intervals</li><li>Battery monitoring</li><li>LED status control</li></ul><p>The official app is no longer required once these features are implemented.</p><h3>Lessons Learned</h3><p>This project was a good reminder that many BLE devices are much simpler than they appear.</p><p>A little patience, a BLE explorer, and an ESP32 were enough to unlock complete local control.</p><p>The biggest lessons were:</p><ul><li>iOS hides Bluetooth MAC addresses.</li><li>Always call discoverAttributes() before looking for services when using recent versions of NimBLE-Arduino.</li><li>The correct write characteristic isn’t always obvious.</li><li>Reverse engineering BLE devices is often easier than reverse engineering Wi-Fi-based products.</li></ul><h3>Final Thoughts</h3><p>Reverse engineering consumer BLE devices is one of the most rewarding areas of embedded development. It allows inexpensive, closed products to become fully programmable components in your own automation ecosystem.</p><p>With a single ESP32 and a 16-byte packet, the Godrej Smart Matic transforms from a phone-controlled gadget into a fully automatable smart home device.</p><p>This is only the beginning. The next step is decoding every BLE command exposed by the device so features like spray intervals, LED control, battery reporting, and complete Home Assistant support can be implemented.</p><h3>Resources</h3><ul><li>ESP32-C3</li><li>NimBLE-Arduino</li><li>nRF Connect</li><li>Arduino IDE</li><li>Godrej Smart Matic</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8b916b4978e7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How I Made My RF-Controlled BLDC Ceiling Fan Smart  Using ESP32 And RF Sniffing ️‍♂️.]]></title>
            <link>https://sparsh308.medium.com/how-i-made-my-rf-controlled-bldc-ceiling-fan-smart-using-esp32-and-rf-sniffing-%EF%B8%8F-%EF%B8%8F-0260025c49bc?source=rss-9593c0400ae3------2</link>
            <guid isPermaLink="false">https://medium.com/p/0260025c49bc</guid>
            <category><![CDATA[arduino]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[radio-frequency]]></category>
            <category><![CDATA[iot]]></category>
            <dc:creator><![CDATA[Sparsh]]></dc:creator>
            <pubDate>Thu, 17 Apr 2025 19:45:14 GMT</pubDate>
            <atom:updated>2025-04-20T21:00:21.316Z</atom:updated>
            <content:encoded><![CDATA[<h3>How I Converted My Remote Controlled BLDC Ceiling Fan to Smart IoT 🧠 Using ESP32 And RF Sniffing 🕵️‍♂️</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XmNm2sp1P7dOQUuR_b54eQ.png" /></figure><p>When I decided to upgrade my room’s ceiling fan, I was looking for something that was energy-efficient, modern, and ideally, IoT-enabled. I was ready to automate it — hook it into Home Assistant, control it via voice, or schedule it through automations.</p><p>Naturally, I started looking for <strong>IoT BLDC fans</strong>.</p><p>But there was a problem.</p><h3>❌ No Smart BLDC Fans in 1400 mm Size?</h3><p>Most of the IoT-enabled ceiling fans in the market come in the <strong>standard 1200 mm (48-inch)</strong> size.</p><p>I needed a <strong>1400 mm (56-inch)</strong> fan for better airflow in my room. After a lot of searching, I realised no brand was offering good smart fans in that size category.</p><p>So I settled on the <strong>Havells Enticer BLDC 1400 mm</strong> — it’s stylish, efficient, and comes with a remote. I figured, “No worries, I’ll just make it smart myself!”</p><h3>🔦 I Thought It Was IR-Controlled…</h3><p>As soon as I unboxed the fan and saw the remote, I didn&#39;t see the IR transmitter. I knew it was either RF or BLE, but I was sure it was RF.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/447/1*Eteo3YYS6YuwPoQGB7P3KQ.gif" /></figure><h3>📻 Discovering the RX500 RF Module</h3><p>Out of curiosity, I peeked inside the fan’s canopy and examined the control board.</p><p>There it was — a tiny <strong>433 MHz RX500 receiver module</strong>. This was a superheterodyne RF module that receives <strong>ASK/OOK encoded</strong> signals from the remote and passes them as digital pulses to the fan’s microcontroller.</p><p>That changed everything.</p><p>If I could sniff those signals and mimic them, I could control the fan using <strong>ESP32 and a 433 MHz transmitter</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*BQ_fkUYGSpz-Ho6qRt05sA.gif" /></figure><h3>🕵️‍♂️ Sniffing the RF Signals</h3><p>Using a basic <strong>RXB6, RXB22 433 MHz receiver module</strong> and the <strong>rc-switch</strong> library on ESP32, I started sniffing signals from the original remote.</p><p>Be sure of Frequency as many common tx rx pairs work on 315 MHz or 433MHz, i by mistake bought 315MHz fs1000a transmitter which didn’t work and then specifically brought STX882 433MHz TX module.</p><pre>#include &lt;RCSwitch.h&gt;<br>RCSwitch mySwitch = RCSwitch();<br><br>void setup() {<br>  Serial.begin(115200);<br>  mySwitch.enableReceive(digitalPinToInterrupt(4)); // Receiver on GPIO 4<br>}<br>void loop() {<br>  if (mySwitch.available()) {<br>    Serial.print(&quot;Received: &quot;);<br>    Serial.println(mySwitch.getReceivedValue());<br>    Serial.print(&quot;Bit Length: &quot;);<br>    Serial.println(mySwitch.getReceivedBitlength());<br>    Serial.print(&quot;Pulse Length: &quot;);<br>    Serial.println(mySwitch.getReceivedPulseLength());<br>    Serial.print(&quot;Protocol: &quot;);<br>    Serial.println(mySwitch.getReceivedProtocol());<br>    mySwitch.resetAvailable();<br>  }<br>}</pre><p>Or you can directly use this example code. <a href="https://github.com/sui77/rc-switch/blob/master/examples/ReceiveDemo_Advanced/ReceiveDemo_Advanced.ino">https://github.com/sui77/rc-switch/blob/master/examples/ReceiveDemo_Advanced/ReceiveDemo_Advanced.ino</a> (to Sniff RF signal)</p><p>I finally got the codes printed in serial output :</p><pre>Decimal: 202055755 (32Bit) Binary: 00001100000010110010000001001011 Tri-State: not applicable PulseLength: 268 microseconds Protocol: 1<br>Raw data: 8328,265,719,265,720,265,719,265,720,757,265,719,265,227,758,265,719,265,720,265,719,265,721,265,758,757,227,265,719,757,227,758,227,265,719,303,720,757,227,265,719,265,720,265,720,265,720,267,757,263,720,759,227,263,720,266,718,757,267,227,757,718,227,757,228,<br><br>Decimal: 202055770 (32Bit) Binary: 00001100000010110010000001011010 Tri-State: not applicable PulseLength: 269 microseconds Protocol: 1<br>Raw data: 8367,264,720,265,719,265,757,228,757,719,265,720,265,227,757,265,758,227,757,227,758,227,759,225,720,756,227,305,680,758,265,719,265,227,758,265,719,757,228,265,719,265,719,266,757,227,682,304,720,265,718,795,190,304,680,796,227,757,227,266,717,759,227,265,719,<br><br>Decimal: 202055770 (32Bit) Binary: 00001100000010110010000001011010 Tri-State: not applicable PulseLength: 267 microseconds Protocol: 1<br>Raw data: 8292,265,719,265,720,265,719,265,719,758,265,719,265,265,720,265,719,265,720,265,719,265,759,227,719,758,227,265,719,757,227,758,227,265,757,227,757,758,227,266,718,265,720,265,719,266,758,227,758,264,719,759,227,263,720,757,265,723,263,227,756,758,227,265,720,</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*vDxL4cab3A0OnXStTm9C5A.gif" /></figure><h3>🔁 Realisation: The Remote Uses Rotating Codes!</h3><p>When I pressed the <strong>Power</strong> button multiple times, I didn’t receive the same value.</p><p>Instead, I got Decimal values like:</p><pre>202055695, 202055710, 202055725, ..., 202055800</pre><p>The same thing happened for <strong>Speed 1</strong>:</p><pre>202048783, 202048798, ..., 202048888</pre><p>After some testing, I noticed a pattern:</p><p><em>The remote uses </em><strong><em>a set of 8 codes per button</em></strong><em>, rotating through them on each press.</em></p><p>It’s a <strong>basic code obfuscation mechanism</strong> — not full-fledged rolling code, but enough to prevent naive replay attacks.</p><p>But it got more interesting…😈</p><h3>🔄 Global Index Behaviour 🤯</h3><p>Let’s say I press Power and get the 5th code.</p><p>If I press Speed 1 next, it doesn’t give me the first Speed 1 code — it gives the 6th!</p><p>That means the remote maintains a <strong>global index</strong>, not per-button.</p><p>This was key to emulating the behaviour correctly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*Q41S49OBbm97gbfNclJr-w.gif" /></figure><h3>🧠 ESP32 Transmitter Code: Mimicking the Remote</h3><p>Now I knew:</p><ul><li>Protocol: <strong>1</strong></li><li>Pulse length: <strong>268–271 µs</strong></li><li>Signal length: <strong>32 bits</strong></li><li>Global rotation applies to all buttons</li></ul><p>I connected a 433 MHz transmitter to ESP32 and built this:</p><pre>#include &lt;RCSwitch.h&gt;<br>RCSwitch mySwitch = RCSwitch();<br><br>unsigned long powerCodes[8] = {<br>  202055695, 202055710, 202055725, 202055740,<br>  202055755, 202055770, 202055785, 202055800<br>};<br><br>unsigned long speed1Codes[8] = {<br>  202048783, 202048798, 202048813, 202048828,<br>  202048843, 202048858, 202048873, 202048888<br>};<br>int globalIndex = 0;<br>void setup() {<br>  Serial.begin(115200);<br>  mySwitch.enableTransmit(5); // Transmitter on GPIO 5<br>  mySwitch.setProtocol(1);<br>  mySwitch.setPulseLength(270);<br>}<br>void loop() {<br>  // Example: Send power signal<br>  mySwitch.send(powerCodes[globalIndex % 8], 32);<br>  delay(500);<br>  globalIndex++;<br>  // Example: Send speed 1 signal<br>  mySwitch.send(speed1Codes[globalIndex % 8], 32);<br>  delay(500);<br>  globalIndex++;<br>}</pre><p>By incrementing the global index after <strong>every button press</strong>, the fan continues to respond like it does to the original remote.</p><p>🚀 we have now successfully reverse-engineered the remote protocol! 🔥</p><p>This insight makes my smart fan IoT controller way more robust and realistic.<br>Now your ESP32 will perfectly mimic the fan remote behavior — the fan will never reject a command for being “out of sync.” 🤘🤠🎉</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*NVfEuIZ4V-GHqWtiWAO-Ig.gif" /></figure><h3>💡 Bonus Idea: Replace RF Module with ESP-01</h3><p>While emulating the remote via RF worked great, another idea struck me:</p><p><em>What if I </em><strong><em>completely bypass</em></strong><em> the RF layer? 😈</em></p><p>Since the RX500 outputs digital pulses to the fan’s microcontroller, I could:</p><ol><li>Sniff the output signals from RX500 when buttons are pressed</li><li>Replicate those exact signals using <strong>ESP-01 GPIO</strong></li><li>Replace the RX500 with the ESP-01 itself</li></ol><p>This would make the fan <strong>truly IoT-native</strong>, using Wi-Fi and MQTT without relying on RF transmission at all. I’m currently working on decoding the digital waveform in detail for that next-level upgrade.</p><h3>🧠 Conclusion</h3><p>I could’ve gone for a ready-made IoT smart fan, but none existed in a <strong>1400 mm size that was good</strong>. That pushed me to buy a <strong>regular 1400mm BLDC fan</strong> with a remote and make it smart myself. 😊</p><p>What started as a plan to build an IR blaster ended up becoming an insightful journey into <strong>433 MHz RF signal decoding</strong>, <strong>rotating code systems</strong>, and <strong>ESP32-based home automation</strong>.</p><p>Next stop 🚏: full Wi-Fi control using an ESP-01 directly inside the fan 🌚.</p><p>If you’re hacking your appliances or exploring RF/IR decoding, I’d love to hear your experience!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0260025c49bc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Automating WLED RGB Lamp with Home Assistant and PagerDuty: A Step-by-Step Guide]]></title>
            <link>https://sparsh308.medium.com/automating-wled-rgb-lamp-with-home-assistant-and-pagerduty-a-step-by-step-guide-ba911f3bfd3e?source=rss-9593c0400ae3------2</link>
            <guid isPermaLink="false">https://medium.com/p/ba911f3bfd3e</guid>
            <category><![CDATA[home-assistant]]></category>
            <category><![CDATA[wled]]></category>
            <category><![CDATA[pagerduty]]></category>
            <category><![CDATA[rgb]]></category>
            <dc:creator><![CDATA[Sparsh]]></dc:creator>
            <pubDate>Fri, 27 Sep 2024 19:03:22 GMT</pubDate>
            <atom:updated>2024-09-27T19:18:52.786Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bswQVKTbHcpWkPOGSyNxAQ.jpeg" /></figure><h3><strong>Introduction</strong></h3><p>In this article, I’ll walk you through how to automate a WLED RGB lamp using Home Assistant based on PagerDuty incident alerts. Whether you’re a tech enthusiast looking to automate your home or a cloud engineer wanting to track incidents visually, this project blends the best of both worlds. I’ll explain the setup process, the automation logic, and how you can replicate it with minimal hassle.</p><h3>Prerequisites</h3><p>Before diving into the automation, there are a few things you’ll need to have set up:</p><h4>1. Home Assistant</h4><p>Home Assistant is an open-source home automation platform that can run on a Raspberry Pi or any Linux machine. If you haven’t set it up yet, here are the key steps:</p><ul><li>Install Home Assistant (official guide).</li><li>Access the Home Assistant interface via the web UI.</li><li>Set up MQTT if you plan to integrate it later.</li></ul><h4>2. WLED RGB Lamp</h4><p>WLED is a free, open-source firmware that allows you to control LED strips over Wi-Fi. Here’s what you need:</p><ul><li>A WLED-compatible microcontroller (such as an ESP8266 or ESP32).</li><li>An RGB LED strip.</li><li>Flash WLED firmware onto your microcontroller (WLED Setup Guide).</li><li>Link to flash ESP32 with WLED firmware : <a href="https://install.wled.me/">https://install.wled.me/</a></li></ul><h4>3. PagerDuty Account</h4><p>Since the automation will respond to PagerDuty incidents, you’ll need an active PagerDuty account. Ensure that:</p><ul><li>You have the <strong>PagerDuty USER API TOKEN</strong>. that can be created under the user setting of your Pager duty account.</li></ul><h4>4. Network Setup</h4><p>Ensure that your Home Assistant instance, WLED lamp, and any external services (like PagerDuty) are on the same network or accessible through a secure connection.</p><h3>The Project Overview</h3><p>The goal of this project is simple: When a PagerDuty incident is triggered acknowledged or resolved the WLED lamp will change color and mode to Blink red when the Alert is Triggered or yellow when the Incident is acknowledged, and Green when the Incident is resolved. When the incident is resolved.</p><p>This allows you to have a visual indication of your incident response status without needing to constantly check your phone or computer.</p><h3>Step-by-Step Guide</h3><h4>Step 1: Add the PagerDuty Sensor to the Home Assistant</h4><p>First, we’ll create a REST sensor in Home Assistant that polls the PagerDuty API every 30 seconds to check for incidents.</p><pre>sensor:<br>  - platform: rest<br>    name: PagerDuty Incidents<br>    resource: https://api.pagerduty.com/incidents?user_ids[]=YOUR_USER_ID&amp;statuses[]=triggered&amp;statuses[]=acknowledged&amp;statuses[]=resolved<br>    headers:<br>      Authorization: &quot;Token token=YOUR_API_TOKEN&quot;<br>      Accept: &quot;application/vnd.pagerduty+json;version=2&quot;<br>    value_template: &gt;<br>      {% if value_json.incidents | length &gt; 0 %}<br>        {% set statuses = value_json.incidents | map(attribute=&#39;status&#39;) | list %}<br>        {% if &#39;triggered&#39; in statuses %}<br>          triggered<br>        {% elif &#39;acknowledged&#39; in statuses %}<br>          acknowledged<br>        {% else %}<br>          resolved<br>        {% endif %}<br>      {% else %}<br>        resolved<br>      {% endif %}<br>    scan_interval: 30</pre><p><strong>Explanation:</strong></p><ul><li>We query the PagerDuty API to check for incidents assigned to you.</li><li>Based on the incident status (triggered, acknowledged, or resolved), the sensor value updates accordingly.</li></ul><h3>Create WLED Presets</h3><p>Steps to create three different WLED presets for your automation in Home Assistant. These presets will define specific lighting configurations (such as colors or effects) that you can trigger based on PagerDuty incident statuses.</p><h4>Step 1: Access the WLED Web Interface</h4><ol><li>Open a browser and enter the IP address of your WLED device.</li><li>This will bring you to the WLED control panel, where you can manually control your RGB lamp and save different presets.</li></ol><h4>Step 2: Configure and Save WLED Presets</h4><p>You can create different lighting presets by adjusting the colors and effects in the WLED web interface.</p><h4>Preset 1: Blink Red for Triggered Incidents</h4><ol><li>In the <strong>WLED web interface</strong>, go to the <strong>LED Preferences</strong> section (usually found in the “Color” tab).</li><li>Select <strong>Red</strong> from the color wheel or enter the RGB value: 255, 0, 0.</li><li>If you’d like, set a specific effect (e.g., <strong>BLINK</strong>) in the <strong>Effects</strong> section.</li><li>Scroll down and click <strong>Save Preset</strong>.</li><li>In the preset name or number field, enter <strong>1</strong> and give it a name like “Red — Triggered”.</li><li>Click <strong>Save</strong>.</li></ol><h4>Preset 2: Yellow for Acknowledged Incidents</h4><ol><li>In the <strong>WLED web interface</strong>, return to the <strong>Color</strong> tab.</li><li>Select <strong>Yellow</strong> from the color wheel or enter the RGB value: 255, 255, 0.</li><li>Optionally, choose another effect (e.g., <strong>Solid</strong> or any other subtle effect).</li><li>Scroll down and click <strong>Save Preset</strong>.</li><li>Enter <strong>2</strong> as the preset number and name it “Yellow — Acknowledged”.</li><li>Click <strong>Save</strong>.</li></ol><h4>Preset 3: Green for Resolved Incidents</h4><ol><li>In the <strong>WLED web interface</strong>, go to the <strong>Color</strong> tab once again.</li><li>Select <strong>Green</strong> from the color wheel or enter the RGB value: 0, 255, 0.</li><li>Optionally, set the effect to <strong>Solid</strong> or any other visual effect.</li><li>Scroll down and click <strong>Save Preset</strong>.</li><li>Enter <strong>3</strong> as the preset number and name it “Green — Resolved”.</li><li>Click <strong>Save</strong>.</li></ol><h3>Step 3: Test the Presets in WLED</h3><p>After saving the three presets you can test them directly in the WLED interface by selecting each preset from the list. Ensure that each one displays the correct color and effect as intended.</p><h3>Step 4: Link the Presets to Home Assistant Automation</h3><p>Now that the presets are saved, you can use these preset numbers in your Home Assistant automation. Here’s a quick reminder of how to call these presets from Home Assistant automation:</p><h3>Create an Automation for Lamp Control</h3><p>Next, we’ll create an automation that will change the WLED lamp’s color depending on the incident status.</p><p><strong>Explanation:</strong></p><ul><li>This automation listens for state changes in the sensor.pagerduty_incidents home assistant entity</li><li>When the state changes, it uses the different preset of your WLED lamp to reflect the current status.</li></ul><p><strong>Testing the Automation</strong></p><p>If you don’t have a physical WLED lamp set up yet, you can simulate or debug your automation by logging the outputs or using a virtual light entity in Home Assistant. Simply monitor the states and actions in the <strong>Developer Tools &gt; States</strong>.</p><h3>Scope for Improvement: Webhook Integrations</h3><p>While this project leverages the REST API to poll PagerDuty every 30 seconds, there are more efficient ways to handle incident alerts — one of which is using <strong>PagerDuty webhooks</strong>. Webhooks allow you to receive real-time incident updates without continuous polling. Here’s how this can improve the setup:</p><h4>1. Real-Time Updates</h4><p>With webhooks, incident notifications will be instant. Instead of waiting for the REST sensor to poll every 30 seconds, the moment PagerDuty triggers, acknowledges, or resolves an incident, it can immediately send a notification to your Home Assistant instance. This can significantly reduce latency.</p><h4>2. Reduced Load</h4><p>Polling the PagerDuty API every 30 seconds puts a constant load on both PagerDuty and your network. By using webhooks, you only communicate with PagerDuty when an actual event occurs, which can improve performance and reduce unnecessary traffic.</p><h4>3. Simpler Logic</h4><h4>Implementing Webhooks</h4><p>To implement webhooks, you would:</p><ul><li>Set up a webhook endpoint in Home Assistant that listens for PagerDuty events.</li><li>Configure your PagerDuty service to send webhooks for <strong>triggered</strong>, <strong>acknowledged</strong>, and <strong>resolved</strong> events.</li><li>Write automations based on the incoming webhook data to update your WLED RGB lamp in real time.</li></ul><p>If you’re comfortable setting up webhooks, this is a highly recommended improvement that will make your automation more efficient and responsive.</p><h3>Final Thoughts</h3><p>This project showcases how easy it is to automate visual alerts for PagerDuty incidents using a Home Assistant server and a WLED RGB lamp. Once set up, you’ll never miss an incident, and you’ll always have a quick, visual indicator of your system’s health.</p><p>Feel free to modify this project further, perhaps adding more complex conditions, sound notifications, or even integrations with other smart devices.</p><p>If you found this tutorial helpful, share it with others who might be interested in home automation or visual incident tracking. Let’s keep automating!</p><p><strong>Happy automating!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ba911f3bfd3e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Home Automation with ESP32, ESP-RainMaker, and Home Assistant With Manual control (with/without…]]></title>
            <link>https://sparsh308.medium.com/home-automation-with-esp32-esp-rainmaker-and-home-assistant-with-manual-control-with-without-0a146fd0b189?source=rss-9593c0400ae3------2</link>
            <guid isPermaLink="false">https://medium.com/p/0a146fd0b189</guid>
            <category><![CDATA[smart-home]]></category>
            <category><![CDATA[home-assistant]]></category>
            <category><![CDATA[home-automation]]></category>
            <category><![CDATA[mqtt]]></category>
            <category><![CDATA[esp-rainmaker]]></category>
            <dc:creator><![CDATA[Sparsh]]></dc:creator>
            <pubDate>Wed, 17 Jul 2024 08:13:19 GMT</pubDate>
            <atom:updated>2024-07-17T08:13:19.416Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HprxEix1VfiJxlAAyXJ92A.png" /></figure><h3>Home Automation with ESP32, ESP-RainMaker, and Home Assistant With Manual control (with/without internet)</h3><h3>Introduction</h3><p>Home automation has become popular, making our lives more convenient and efficient. In this article, I will walk you through an exciting home automation project using an ESP32 microcontroller and Home Assistant, a powerful open-source home automation platform. We will integrate the ESP32 with the Rainmaker Cloud and MQTT to control home appliances like lights and fans, providing a seamless experience regardless of internet connectivity.</p><p>In my journey of building a home automation system, I aimed to control devices such as lights and fans using an ESP32 microcontroller. While Home Assistant offers cloud capabilities, it requires a subscription for full functionality. I wanted to leverage free cloud services, leading me to integrate ESP Rainmaker with Home Assistant. This article walks you through my project setup, from configuring the hardware and software to managing device states and commands via MQTT topics.</p><h3>Project Overview</h3><p>This project aims to control home appliances using:</p><ol><li><strong>Manual retrofit switches</strong> for direct control.</li><li><strong>Rainmaker Cloud</strong> for remote control when the internet is available.</li><li><strong>Home Assistant with MQTT</strong> for local control via a Home Assistant server running on a Raspberry Pi.</li></ol><h3>Hardware and Software Requirements</h3><ol><li><strong>Hardware:</strong></li></ol><ul><li>ESP32 Microcontroller</li><li>Relays and connected appliances (lights, fan, etc.)</li><li>Retro-fit switches (switches that are already installed in your home)</li><li>Raspberry Pi running Home Assistant</li></ul><ol><li><strong>Software:</strong></li></ol><ul><li>Arduino IDE for ESP32 programming</li><li>Home Assistant installed on Raspberry Pi</li><li>MQTT broker (built into Home Assistant)</li></ul><h3>Step-by-Step Process</h3><h4>1. Setting Up the Hardware</h4><ul><li>Connect the ESP32 GPIO pins to the relay modules controlling your appliances.</li><li>Connect the retro-fit switches to the corresponding GPIO pins on the ESP32.</li><li>Ensure proper connections to avoid damage to the components.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1001/1*o8lTvfmHXN65kFmSICkMow.jpeg" /></figure><h4>2. Configuring the ESP32</h4><ul><li>Install the ESP32 board package in the Arduino IDE.</li><li>Include necessary libraries for Wi-Fi, Rainmaker, and MQTT.</li><li>Define GPIO pins for relays and switches.</li><li>Set up Wi-Fi provisioning using Rainmaker.</li><li>Connect to the MQTT broker and subscribe to relevant topics for each appliance.</li><li>Implement manual control logic to handle switch states.</li></ul><p><strong>Integrating ESP rainmaker</strong></p><ul><li>Use the Rainmaker library to set up devices and parameters.</li><li>Handle Wi-Fi provisioning events to connect to the Rainmaker cloud.</li><li>Implement callbacks to update device states and respond to commands from the Rainmaker app.</li></ul><p><strong>Initialization:</strong></p><ul><li>Initialize GPIO pins, set up Wi-Fi, and provision Rainmaker.</li><li>Connect to the MQTT broker and subscribe to command topics for each appliance.</li></ul><p><strong>Handling MQTT Messages:</strong></p><ul><li>Implement functions to handle incoming MQTT messages and update the relay states accordingly.</li><li>After any change, Publish each appliance&#39;s state to the corresponding MQTT state topic.</li></ul><p><strong>Manual Control:</strong></p><ul><li>Continuously read the state of the retro-fit switches and update the relay states.</li><li>Ensure the updated state is published to the MQTT broker and Rainmaker.</li></ul><p><strong>State Management:</strong></p><ul><li>Use different MQTT topics for command and state to ensure clear communication.</li><li>For example, the command topic for Light 1 is /homeassistant/esp32/cmd/switch1 and the state topic is /homeassistant/esp32/state/switch1.</li><li>This separation ensures that commands from Home Assistant and state updates from the ESP32 are handled independently.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z3rZ3oatJoveKl_sqAkpMw.png" /></figure><pre><br><br>#include &quot;RMaker.h&quot;<br>#include &quot;WiFi.h&quot;<br>#include &quot;WiFiProv.h&quot;<br>#include &lt;MQTTPubSubClient.h&gt;<br><br><br>const char *service_name = &quot;PROV_12345&quot;;<br>const char *pop = &quot;1234567&quot;;<br><br>// define the Device Names<br>char deviceName_1[] = &quot;Light 1&quot;;<br>char deviceName_2[] = &quot;Light 2&quot;;<br>char deviceName_3[] = &quot;Fan&quot;;<br>char deviceName_4[] = &quot;Amplifier&quot;;<br><br>// define the GPIO connected with Relays and switches<br>static uint8_t RelayPin1 = 23;  //D23<br>static uint8_t RelayPin2 = 21;  //D22<br>static uint8_t RelayPin3 = 18;  //D21<br>static uint8_t RelayPin4 = 22;  //D19<br><br>static uint8_t SwitchPin1 = 13;  //D13<br>static uint8_t SwitchPin2 = 14;  //D12<br>static uint8_t SwitchPin3 = 27;  //D14<br>static uint8_t SwitchPin4 = 12;  //D27<br><br>static uint8_t wifiLed    = 2;   //D2<br>static uint8_t gpio_reset = 0;<br><br>WiFiClient client;<br>MQTTPubSubClient mqtt;<br><br>// MQTT Parameters<br>const char* mqtt_broker = &quot;homeassistant.local&quot;;<br>const int mqtt_port = 1888;<br>const char* mqtt_user = &quot;&lt;mqtt_user&gt;&quot;;<br>const char* mqtt_pass =&quot;&lt;mqtt_password&gt;&quot;;<br><br>const char* switch1cmdTopic = &quot;/homeassistant/esp32/cmd/switch1&quot;;<br>const char* switch2cmdTopic = &quot;/homeassistant/esp32/cmd/switch2&quot;;<br>const char* switch3cmdTopic = &quot;/homeassistant/esp32/cmd/switch3&quot;;<br>const char* switch4cmdTopic = &quot;/homeassistant/esp32/cmd/switch4&quot;;<br><br>const char* switch1stateTopic = &quot;/homeassistant/esp32/state/switch1&quot;;<br>const char* switch2stateTopic = &quot;/homeassistant/esp32/state/switch2&quot;;<br>const char* switch3stateTopic = &quot;/homeassistant/esp32/state/switch3&quot;;<br>const char* switch4stateTopic = &quot;/homeassistant/esp32/state/switch4&quot;;<br><br><br><br><br><br><br>/* Variable for reading pin status*/<br>// Relay State<br>bool toggleState_1 = LOW; //Define integer to remember the toggle state for relay 1<br>bool toggleState_2 = LOW; //Define integer to remember the toggle state for relay 2<br>bool toggleState_3 = LOW; //Define integer to remember the toggle state for relay 3<br>bool toggleState_4 = LOW; //Define integer to remember the toggle state for relay 4<br><br>// Switch State<br>bool SwitchState_1 = LOW;<br>bool SwitchState_2 = LOW;<br>bool SwitchState_3 = LOW;<br>bool SwitchState_4 = LOW;<br><br>//The framework provides some standard device types like switch, lightbulb, fan, temperature sensor.<br>static Switch my_switch1(deviceName_1, &amp;RelayPin1);<br>static Switch my_switch2(deviceName_2, &amp;RelayPin2);<br>static Switch my_switch3(deviceName_3, &amp;RelayPin3);<br>static Switch my_switch4(deviceName_4, &amp;RelayPin4);<br><br>void sysProvEvent(arduino_event_t *sys_event)<br>{<br>    switch (sys_event-&gt;event_id) {      <br>        case ARDUINO_EVENT_PROV_START:<br>#if CONFIG_IDF_TARGET_ESP32<br>        Serial.printf(&quot;\nProvisioning Started with name \&quot;%s\&quot; and PoP \&quot;%s\&quot; on BLE\n&quot;, service_name, pop);<br>        printQR(service_name, pop, &quot;ble&quot;);<br>#else<br>        Serial.printf(&quot;\nProvisioning Started with name \&quot;%s\&quot; and PoP \&quot;%s\&quot; on SoftAP\n&quot;, service_name, pop);<br>        printQR(service_name, pop, &quot;softap&quot;);<br>#endif        <br>        break;<br>        case ARDUINO_EVENT_WIFI_STA_CONNECTED:<br>        Serial.printf(&quot;\nConnected to Wi-Fi!\n&quot;);<br>        digitalWrite(wifiLed, true);<br>        connectToMQTTHost();<br>        mqtt.begin(client);<br>        connectToMQTT();<br>        break;<br>    }<br>}<br><br>void connectToMQTT() {<br>    if (mqtt.connect(&quot;esp32&quot;, mqtt_user, mqtt_pass)) {<br>        Serial.println(&quot;Connected to MQTT broker!&quot;);<br>        subscribeToMQTT();<br>        <br>    } else {<br>        Serial.println(&quot;Failed to connect to MQTT broker&quot;);<br>    }<br>}<br><br>void connectToMQTTHost() {<br>    Serial.print(&quot;connecting to host...&quot;);<br>    while (!client.connect(mqtt_broker, mqtt_port)) {<br>        Serial.print(&quot;.&quot;);<br>        delay(1000);<br>    }<br>    Serial.println(&quot; connected!&quot;);<br><br>}<br><br>void subscribeToMQTT() {<br>    mqtt.subscribe(switch1cmdTopic, [](const String &amp;payload, const size_t size) {<br>        handleMQTTMessage(switch1cmdTopic, payload);<br>    });<br>    mqtt.subscribe(switch2cmdTopic, [](const String &amp;payload, const size_t size) {<br>        handleMQTTMessage(switch2cmdTopic, payload);<br>    });<br>    mqtt.subscribe(switch3cmdTopic, [](const String &amp;payload, const size_t size) {<br>        handleMQTTMessage(switch3cmdTopic, payload);<br>    });<br>    mqtt.subscribe(switch4cmdTopic, [](const String &amp;payload, const size_t size) {<br>        handleMQTTMessage(switch4cmdTopic, payload);<br>    });<br>}<br><br>void handleMQTTMessage(const String &amp;topic, const String &amp;message) {<br>    if (topic == switch1cmdTopic) {<br>        toggleState_1 = (message == &quot;on&quot;);<br>        digitalWrite(RelayPin1, toggleState_1 ? LOW : HIGH);<br>        my_switch1.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, toggleState_1);<br>        Serial.printf(&quot;switch 1= %s\n&quot; , message);<br>                                        mqtt.publish(switch1stateTopic, toggleState_1 ? &quot;on&quot; : &quot;off&quot;);<br><br><br>    }<br>    if (topic == switch2cmdTopic) {<br>        toggleState_2 = (message == &quot;on&quot;);<br>        digitalWrite(RelayPin2, toggleState_2 ? LOW : HIGH);<br>        my_switch2.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, toggleState_2);<br>        Serial.printf(&quot;switch 2= %s\n&quot; , message);<br>                                mqtt.publish(switch2stateTopic, toggleState_2 ? &quot;on&quot; : &quot;off&quot;);<br><br><br>    }<br>    if (topic == switch3cmdTopic) {<br>        toggleState_3 = (message == &quot;on&quot;);<br>        digitalWrite(RelayPin3, toggleState_3 ? LOW : HIGH);<br>        my_switch3.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, toggleState_3);<br>                Serial.printf(&quot;switch 3= %s\n&quot; , message);<br>                        mqtt.publish(switch3stateTopic, toggleState_3 ? &quot;on&quot; : &quot;off&quot;);<br><br><br>    }<br>    if (topic == switch4cmdTopic) {<br>        toggleState_4 = (message == &quot;on&quot;);<br>        digitalWrite(RelayPin4, toggleState_4 ? LOW : HIGH);<br>        my_switch4.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, toggleState_4);<br>                Serial.printf(&quot;switch 4= %s\n&quot; , message);<br>                        mqtt.publish(switch4stateTopic, toggleState_4 ? &quot;on&quot; : &quot;off&quot;);<br><br><br>    }<br>}<br><br>void write_callback(Device *device, Param *param, const param_val_t val, void *priv_data, write_ctx_t *ctx)<br>{<br>    const char *device_name = device-&gt;getDeviceName();<br>    const char *param_name = param-&gt;getParamName();<br><br>    if(strcmp(device_name, deviceName_1) == 0) {<br>      <br>      Serial.printf(&quot;Lightbulb = %s\n&quot;, val.val.b? &quot;true&quot; : &quot;false&quot;);<br>      <br>      if(strcmp(param_name, &quot;Power&quot;) == 0) {<br>          Serial.printf(&quot;Received value = %s for %s - %s\n&quot;, val.val.b? &quot;true&quot; : &quot;false&quot;, device_name, param_name);<br>        toggleState_1 = val.val.b;<br>        (toggleState_1 == false) ? digitalWrite(RelayPin1, HIGH) : digitalWrite(RelayPin1, LOW);<br>        param-&gt;updateAndReport(val);<br>        mqtt.publish(switch1stateTopic, toggleState_1 ? &quot;on&quot; : &quot;off&quot;);<br><br>      }<br>      <br>    } else if(strcmp(device_name, deviceName_2) == 0) {<br>      <br>      Serial.printf(&quot;Switch value = %s\n&quot;, val.val.b? &quot;true&quot; : &quot;false&quot;);<br><br>      if(strcmp(param_name, &quot;Power&quot;) == 0) {<br>        Serial.printf(&quot;Received value = %s for %s - %s\n&quot;, val.val.b? &quot;true&quot; : &quot;false&quot;, device_name, param_name);<br>        toggleState_2 = val.val.b;<br>        (toggleState_2 == false) ? digitalWrite(RelayPin2, HIGH) : digitalWrite(RelayPin2, LOW);<br>        param-&gt;updateAndReport(val);<br>        mqtt.publish(switch2stateTopic, toggleState_2 ? &quot;on&quot; : &quot;off&quot;);<br><br>      }<br>  <br>    } else if(strcmp(device_name, deviceName_3) == 0) {<br>      <br>      Serial.printf(&quot;Switch value = %s\n&quot;, val.val.b? &quot;true&quot; : &quot;false&quot;);<br><br>      if(strcmp(param_name, &quot;Power&quot;) == 0) {<br>        Serial.printf(&quot;Received value = %s for %s - %s\n&quot;, val.val.b? &quot;true&quot; : &quot;false&quot;, device_name, param_name);<br>        toggleState_3 = val.val.b;<br>        (toggleState_3 == false) ? digitalWrite(RelayPin3, HIGH) : digitalWrite(RelayPin3, LOW);<br>        param-&gt;updateAndReport(val);<br>        mqtt.publish(switch3stateTopic, toggleState_3 ? &quot;on&quot; : &quot;off&quot;);<br><br>      }<br>  <br>    } else if(strcmp(device_name, deviceName_4) == 0) {<br>      <br>      Serial.printf(&quot;Switch value = %s\n&quot;, val.val.b? &quot;true&quot; : &quot;false&quot;);<br><br>      if(strcmp(param_name, &quot;Power&quot;) == 0) {<br>        Serial.printf(&quot;Received value = %s for %s - %s\n&quot;, val.val.b? &quot;true&quot; : &quot;false&quot;, device_name, param_name);<br>        toggleState_4 = val.val.b;<br>        (toggleState_4 == false) ? digitalWrite(RelayPin4, HIGH) : digitalWrite(RelayPin4, LOW);<br>        param-&gt;updateAndReport(val);<br>        mqtt.publish(switch4stateTopic, toggleState_4 ? &quot;on&quot; : &quot;off&quot;);<br><br>      }  <br>    }  <br>}<br><br>void manual_control()<br>{<br>  if (digitalRead(SwitchPin1) == LOW &amp;&amp; SwitchState_1 == LOW) {<br>    digitalWrite(RelayPin1, LOW);<br>    toggleState_1 = 1;<br>    SwitchState_1 = HIGH;<br>    my_switch1.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, toggleState_1);<br>    mqtt.publish(switch1stateTopic, &quot;on&quot;);<br>    Serial.println(&quot;Switch-1 on&quot;);<br>  }<br>  if (digitalRead(SwitchPin1) == HIGH &amp;&amp; SwitchState_1 == HIGH) {<br>    digitalWrite(RelayPin1, HIGH);<br>    toggleState_1 = 0;<br>    SwitchState_1 = LOW;<br>    my_switch1.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, toggleState_1);<br>    mqtt.publish(switch1stateTopic, &quot;off&quot;);<br><br>    Serial.println(&quot;Switch-1 off&quot;);<br>  }<br>  if (digitalRead(SwitchPin2) == LOW &amp;&amp; SwitchState_2 == LOW) {<br>    digitalWrite(RelayPin2, LOW);<br>    toggleState_2 = 1;<br>    SwitchState_2 = HIGH;<br>    my_switch2.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, toggleState_2);<br>    mqtt.publish(switch2stateTopic, &quot;on&quot;);<br><br>    Serial.println(&quot;Switch-2 on&quot;);<br>  }<br>  if (digitalRead(SwitchPin2) == HIGH &amp;&amp; SwitchState_2 == HIGH) {<br>    digitalWrite(RelayPin2, HIGH);<br>    toggleState_2 = 0;<br>    SwitchState_2 = LOW;<br>    my_switch2.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, toggleState_2);<br>    mqtt.publish(switch2stateTopic, &quot;off&quot;);<br><br>    Serial.println(&quot;Switch-2 off&quot;);<br>  }<br>  if (digitalRead(SwitchPin3) == LOW &amp;&amp; SwitchState_3 == LOW) {<br>    digitalWrite(RelayPin3, LOW);<br>    toggleState_3 = 1;<br>    SwitchState_3 = HIGH;<br>    my_switch3.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, toggleState_3);<br>    mqtt.publish(switch3stateTopic, &quot;on&quot;);<br><br>    Serial.println(&quot;Switch-3 on&quot;);<br>  }<br>  if (digitalRead(SwitchPin3) == HIGH &amp;&amp; SwitchState_3 == HIGH) {<br>    digitalWrite(RelayPin3, HIGH);<br>    toggleState_3 = 0;<br>    SwitchState_3 = LOW;<br>    my_switch3.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, toggleState_3);<br>    mqtt.publish(switch3stateTopic, &quot;off&quot;);<br><br>    Serial.println(&quot;Switch-3 off&quot;);<br>  }<br>  if (digitalRead(SwitchPin4) == LOW &amp;&amp; SwitchState_4 == LOW) {<br>    digitalWrite(RelayPin4, LOW);<br>    toggleState_4 = 1;<br>    SwitchState_4 = HIGH;<br>    my_switch4.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, toggleState_4);<br>    mqtt.publish(switch4stateTopic, &quot;on&quot;);<br><br>    Serial.println(&quot;Switch-4 on&quot;);<br>  }<br>  if (digitalRead(SwitchPin4) == HIGH &amp;&amp; SwitchState_4 == HIGH) {<br>    digitalWrite(RelayPin4, HIGH);<br>    toggleState_4 = 0;<br>    SwitchState_4 = LOW;<br>    my_switch4.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, toggleState_4);<br>    mqtt.publish(switch4stateTopic, &quot;off&quot;);<br>    Serial.println(&quot;Switch-4 off&quot;);<br><br>  }<br>}  <br><br>void setup()<br>{<br>    uint32_t chipId = 0;<br>    <br>    Serial.begin(115200);<br>    <br>    // Set the Relays GPIOs as output mode<br>    pinMode(RelayPin1, OUTPUT);<br>    pinMode(RelayPin2, OUTPUT);<br>    pinMode(RelayPin3, OUTPUT);<br>    pinMode(RelayPin4, OUTPUT);  <br>    pinMode(wifiLed, OUTPUT);<br>    <br>    // Configure the input GPIOs<br>    pinMode(SwitchPin1, INPUT_PULLUP);<br>    pinMode(SwitchPin2, INPUT_PULLUP);<br>    pinMode(SwitchPin3, INPUT_PULLUP);<br>    pinMode(SwitchPin4, INPUT_PULLUP);<br>    pinMode(gpio_reset, INPUT);<br>    <br>    // Write to the GPIOs the default state on booting<br>    digitalWrite(RelayPin1, !toggleState_1);<br>    digitalWrite(RelayPin2, !toggleState_2);<br>    digitalWrite(RelayPin3, !toggleState_3);<br>    digitalWrite(RelayPin4, !toggleState_4);<br>    digitalWrite(wifiLed, LOW);<br><br>    Node my_node;    <br>    my_node = RMaker.initNode(&quot;SmartRoom Control Esp32&quot;);<br><br>    //Standard switch device<br>    my_switch1.addCb(write_callback);<br>    my_switch2.addCb(write_callback);<br>    my_switch3.addCb(write_callback);<br>    my_switch4.addCb(write_callback);<br><br>    //Add switch device to the node   <br>    my_node.addDevice(my_switch1);<br>    my_node.addDevice(my_switch2);<br>    my_node.addDevice(my_switch3);<br>    my_node.addDevice(my_switch4);<br><br><br>    //This is optional <br>    //RMaker.enableOTA(OTA_USING_PARAMS);<br>    //If you want to enable scheduling, set time zone for your region using setTimeZone(). <br>    //The list of available values are provided here https://rainmaker.espressif.com/docs/time-service.html<br>    // RMaker.setTimeZone(&quot;Asia/Shanghai&quot;);<br>    // Alternatively, enable the Timezone service and let the phone apps set the appropriate timezone<br>    //RMaker.enableTZService();<br>    //RMaker.enableSchedule();<br><br>    //Service Name<br>    for(int i=0; i&lt;17; i=i+8) {<br>      chipId |= ((ESP.getEfuseMac() &gt;&gt; (40 - i)) &amp; 0xff) &lt;&lt; i;<br>    }<br><br>    Serial.printf(&quot;\nChip ID:  %d Service Name: %s\n&quot;, chipId, service_name);<br><br>    Serial.printf(&quot;\nStarting ESP-RainMaker\n&quot;);<br>    RMaker.start();<br><br>    WiFi.onEvent(sysProvEvent);<br>#if CONFIG_IDF_TARGET_ESP32<br>    WiFiProv.beginProvision(WIFI_PROV_SCHEME_BLE, WIFI_PROV_SCHEME_HANDLER_FREE_BTDM, WIFI_PROV_SECURITY_1, pop, service_name);<br>#else<br>    WiFiProv.beginProvision(WIFI_PROV_SCHEME_SOFTAP, WIFI_PROV_SCHEME_HANDLER_NONE, WIFI_PROV_SECURITY_1, pop, service_name);<br>#endif<br><br>    my_switch1.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, false);<br>    my_switch2.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, false);<br>    my_switch3.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, false);<br>    my_switch4.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, false);<br><br><br>}<br><br>void loop()<br>{<br>    // Read GPIO0 (external button to reset device<br>    if(digitalRead(gpio_reset) == LOW) { //Push button pressed<br>        Serial.printf(&quot;Reset Button Pressed!\n&quot;);<br>        // Key debounce handling<br>        delay(100);<br>        int startTime = millis();<br>        while(digitalRead(gpio_reset) == LOW) delay(50);<br>        int endTime = millis();<br><br>        if ((endTime - startTime) &gt; 10000) {<br>          // If key pressed for more than 10secs, reset all<br>          Serial.printf(&quot;Reset to factory.\n&quot;);<br>          RMakerFactoryReset(2);<br>        } else if ((endTime - startTime) &gt; 3000) {<br>          Serial.printf(&quot;Reset Wi-Fi.\n&quot;);<br>          // If key pressed for more than 3secs, but less than 10, reset Wi-Fi<br>          RMakerWiFiReset(2);<br>        }<br>    }<br>    delay(100);<br><br>    if (WiFi.status() != WL_CONNECTED)<br>    {<br>      //Serial.println(&quot;WiFi Not Connected&quot;);<br>      digitalWrite(wifiLed, false);<br>    }<br>    else<br>    {<br>      //Serial.println(&quot;WiFi Connected&quot;);<br>      digitalWrite(wifiLed, true);<br>    }<br><br>    manual_control();<br>    if(mqtt.isConnected()){<br>    mqtt.update();<br>    }<br>    <br>}</pre><h4>Setting Up Home Assistant</h4><ul><li>Install and configure Home Assistant on the Raspberry Pi.</li><li>Ensure the MQTT broker is enabled in the Home Assistant configuration.</li><li>Add MQTT integration in Home Assistant by including the following configuration for each switch in the configuration.yaml file:</li></ul><pre># Example configuration.yaml entry<br>mqtt:<br>  - switch:<br>      unique_id: light1_switch<br>      name: &quot;Light 1&quot;<br>      state_topic: &quot;/homeassistant/esp32/state/switch1&quot;<br>      value_template: &quot;{{ value == &#39;on&#39; }}&quot;<br>      command_topic: &quot;/homeassistant/esp32/cmd/switch1&quot;<br>      payload_on: &quot;on&quot;<br>      payload_off: &quot;off&quot;<br>      state_on: true<br>      state_off: false<br>      retain: false<br># Example configuration.yaml entry<br>  - switch:<br>      unique_id: light2_switch<br>      name: &quot;light 2&quot;<br>      state_topic: &quot;/homeassistant/esp32/state/switch2&quot;<br>      value_template: &quot;{{ value == &#39;on&#39; }}&quot;<br>      command_topic: &quot;/homeassistant/esp32/cmd/switch2&quot;<br>      payload_on: &quot;on&quot;<br>      payload_off: &quot;off&quot;<br>      state_on: true<br>      state_off: false<br>      retain: false<br>  - switch:<br>      unique_id: fan_switch<br>      name: &quot;fan&quot;<br>      state_topic: &quot;/homeassistant/esp32/state/switch3&quot;<br>      value_template: &quot;{{ value == &#39;on&#39; }}&quot;<br>      command_topic: &quot;/homeassistant/esp32/cmd/switch3&quot;<br>      payload_on: &quot;on&quot;<br>      payload_off: &quot;off&quot;<br>      state_on: true<br>      state_off: false<br>      retain: false<br>  - switch:<br>      unique_id: bedroom_switch4<br>      name: &quot;Amplifer&quot;<br>      state_topic: &quot;/homeassistant/esp32/state/switch4&quot;<br>      value_template: &quot;{{ value == &#39;on&#39; }}&quot;<br>      command_topic: &quot;/homeassistant/esp32/cmd/switch4&quot;<br>      payload_on: &quot;on&quot;<br>      payload_off: &quot;off&quot;<br>      state_on: true<br>      state_off: false<br>      retain: false</pre><p>You can also add home assistant app in your android mobile and use widget to have easier access to mqtt button on your home screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UEFpQpcFCmFn8_A7PiQN3Q.png" /></figure><h3>Conclusion</h3><p>By integrating ESP32 with Home Assistant using MQTT, we have created a robust home automation system that provides local control via retrofit switches, remote control via Rainmaker, and local control via Home Assistant. This setup ensures that your home automation system remains functional and accessible regardless of internet connectivity. With this comprehensive guide, you can now set up and customize your home automation project, making your home smarter and more efficient and flexible.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0a146fd0b189" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[IoT Enabled Smart Music Reactive WLED RGB Light Tutorial.]]></title>
            <link>https://sparsh308.medium.com/iot-enabled-smart-music-reactive-wled-rgb-light-tutorial-83121a00c930?source=rss-9593c0400ae3------2</link>
            <guid isPermaLink="false">https://medium.com/p/83121a00c930</guid>
            <category><![CDATA[rgb-led-strip-lights]]></category>
            <category><![CDATA[wled]]></category>
            <category><![CDATA[music-reactive-lights]]></category>
            <category><![CDATA[esp32-tutorial]]></category>
            <category><![CDATA[ws2812]]></category>
            <dc:creator><![CDATA[Sparsh]]></dc:creator>
            <pubDate>Fri, 28 Apr 2023 19:11:32 GMT</pubDate>
            <atom:updated>2023-04-28T19:11:32.874Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MYsWu0oGCRd1mB1MXC750g.png" /></figure><p>RGB LEDs that can be individually addressed, also known as WS2812B or NeoPixels, have become incredibly popular and are a must-have for any DIY project that involves lighting. However, controlling these types of LEDs can be challenging, especially if you want to use your smartphone to manage them.</p><p>Fortunately, there’s a free, feature-rich, open-source mobile app called WLED that makes controlling addressable LEDs much easier, convenient, and even fun! In this tutorial, we’ll show you how to install WLED on an ESP32 board and use it to control a string of addressable LEDs.</p><p>Parts you will need :</p><p>WS2812b RGB Addressable DIGITAL LEDS strip</p><p>1x ESP32</p><p>1x 1nmp441 I2S mic (or any other this was best as far as my experience)</p><p>bunch of female-to-male / female-to-female jumper wire</p><p>5v power supply (you can use a phone charger)</p><p>Laptop to configure.</p><p>Installing WLED on an ESP32 Board is easy. Here’s what you need to do:</p><p>1. Connect your ESP32 board to your computer using a USB cable that supports data transfer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/423/1*eihf16m56KCoK3LIXwE5PQ.jpeg" /></figure><p>2. Open a web browser and go to install.wled.me. Make sure your browser supports Web Serial (such as Google Chrome, Microsoft Edge, or Opera).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/664/1*y8jH7gpyyVio6uxa1NXCxw.jpeg" /></figure><p>3. Click “Install.”</p><p>4. Select the COM port to which your ESP32 is connected and click “Connect.” WLED uses the Web Serial API to open serial ports on your computer. If nothing appears, you may need to update your USB-to-serial drivers, or you may not be using a USB cable that supports data transfer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/664/1*QMmvktD3nXHUHBeHsjuqKQ.jpeg" /></figure><p>5. Click “Install WLED” to begin the installation process.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/664/1*IgdoOPI1gXAffo7uHXeuZw.jpeg" /></figure><p>6. Confirm the installation to flash the firmware to the board. Be aware that all data on the device will be erased. Some ESP32 boards require you to press the BOOT button before selecting the final install button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/664/1*w2GLsPByaWLS9weHdou4SQ.jpeg" /></figure><p>7. The installation process should start, and it will only take a few minutes to complete. You can release the BOOT button as it was able to connect.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/664/1*EPMUsAQUT2plNIqMJ-3fDQ.jpeg" /></figure><p>8. Click “Next” to complete the installation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/664/1*bruIxZPyz2grZR-O-vblzA.jpeg" /></figure><p>9. Enter your Wi-Fi credentials and click “Connect.” This will connect your ESP32 to your Wi-Fi network and save the details for later use. Note that the Wi-Fi network must be 2.4 GHz; the ESP32 does not support 5 GHz networks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/664/1*R5rH_CnUtJybascl3l2OnA.jpeg" /></figure><p>NOTE: The WiFi network must be 2.4 GHz; the ESP32 does not support 5 GHz networks.</p><p>10. The message “Device connected to the network!” should appear. Click “Visit Device” to access the WLED User Interface (UI).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/664/1*9QCk3OfqjH6EeUuyEZoVpA.jpeg" /></figure><p>11. Make a note of the URL as you will need it to access the WLED UI.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/666/1*LYjc8O_pHjP4Khdulx1Rzw.jpeg" /></figure><h3>Connecting a WS2812x Addressable LED Strip to an ESP32</h3><p>Once you’ve finished configuring the WLED, unplug the ESP32 from the USB port. Let’s wire up an addressable LED strip to the ESP32.</p><p>The wiring is relatively simple. There are only three wires to connect: two for power and one for data transmission.</p><p>Connect the Red wire (+5V/VCC) of the addressable LED strip to the ESP32’s VIN pin and the White/Yellow wire (GND) to the ESP32’s GND pin.</p><p>Finally, connect the Green wire (DIN) of the LED strip to the ESP32’s GPIO16 (RX2), via a 330 Ohm resistor. This in-line resistor is there to protect the data pin. A resistor between 220 and 470 Ohm should do nicely. Try to place the resistor as close to your addressable LEDs as possible.</p><p>If you have a few LEDs you can plug the ESP32 into your computer using a USB cable and power the strip directly through the board.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YVgfOmHYX5YjhLvLwiXQuA.png" /><figcaption>Circuit connections</figcaption></figure><p>If you have a larger project that requires more LEDs, USB power won’t be enough. Instead, you should inject power into the strip from an external source. Keep in mind that each RGB LED consumes about 60mA (20mA per color channel) when the brightness is set to full. That means that for every 30 LEDs, your LED strip could be drawing up to 1.8 Amps.</p><p>Once the wiring is complete, LEDs should come to life and emit a soft yellow light. If this isn’t the case, double-check your wiring before proceeding.</p><p>From here everything can now be done via the WLED App.</p><h3>Using the WLED Mobile App</h3><ol><li>Download the WLED app from the Google Play Store or the Apple App Store on your smartphone or tablet.</li></ol><p>2. Open the app and click on the plus icon in the upper right corner to open up the discovery page.</p><p>3. Hit Discover Lights. This will search through your WIFI for all connected boards running WLED software.</p><p>4. Once it says Found WLED! click the Tick icon in the upper-right corner. This will bring you back to the home page where you will have a list of all the WLED devices on your network.</p><p>5. Click on the newly discovered device to open the control panel.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/255/0*A6Qhqda-xgOy0KOw.png" /></figure><p>6. Select a color using the color wheel. And voilà, you now have fully operational, remotely activated addressable LEDs!</p><p>If the color of the LEDs does not match the color you selected in the app, go to Config &gt; LED Preferences and adjust the Color Order setting under Hardware Setup until it does.</p><p>7. If you have multiple WLED devices, you may want to change the name displayed on the app to differentiate them. Go to Config &gt; User Interface and name it whatever you want, then hit Save.</p><h3>Changing Effects</h3><p>WLED offers over <a href="https://kno.wled.ge/features/effects/">180 different effects</a>. This is where the real fun begins.</p><p>1. Navigate to the Effects tab and select an effect. The LEDs will respond immediately.</p><p>2. You can change the speed and intensity of the effect. The further you move the slider, the faster and more intense the effect.</p><p>3. Each effect has its own color scheme, which you can easily change in the Color Picker section. This will keep the animation effect but replace the colors.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/255/0*Zlauttn_rJarGH66.png" /></figure><h3>A Quick Tour of the WLED UI.</h3><p>WLED’s User Interface may appear overwhelming at first, but it’s simple to use once you get used to it. Here’s a quick overview:</p><p>1. Configuration: This section contains buttons like Power (to turn the lights on or off), Timer (to set when the lights should turn on and off), Sync (to synchronize multiple WLED devices across your network), Peek (to preview animation effects), Config (to configure the number of LEDs and the GPIO port), and a Brightness slider (to control the overall brightness).</p><p>2. Color Picker: This section lets you change the color of the LEDs, whether they are static or animated. You can access various color palettes for use in effects by scrolling down this section.</p><p>3. Effects/Animation: Here you’ll find a library of ready-made animations for your lights. Each effect has its own color scheme, but you can easily customize it in the Color Picker section.</p><p>4. Segment: If you have a large array or matrix of LEDs, you can split them into segments and assign a different color, animation, or color scheme to each segment.</p><p>5. Presets: Here, you can create presets for your custom light show, as well as a playlist to cycle through the many available animations.</p><h3>Tips and Recommendations</h3><p>There are a few tips and recommendations to keep in mind when designing your setup with ESP32:</p><ul><li>ESP32 can handle up to ten strips at a time.</li><li>While most strip types have yet to be tested, the following are known to work: WS281x, SK6812 RGBW, PWM white</li><li>As soon as the installation is complete, select the LEDs type, pin numbers, length, and color order of your LED strips on the LED settings page.</li><li>Framerate can be increased significantly by selecting the appropriate power supply for the setup and turning off the WLED brightness limiter setting.</li><li>There are no pin restrictions; feel free to use any available pin.</li><li>The performance is determined by how many LEDs you drive with the ESP32 and how many ESP32 output pins you use.</li><li>For excellent performance, it is recommended to use 512 LEDs/pin with 4 outputs for a total of 2048 LEDs.</li><li>For optimal performance, it is recommended to use 800 LEDs/pin with 4 outputs for a total of 3200 LEDs.</li><li>For good performance, you can use 1000 LEDs/pin with 4 outputs for a total of 4000 LEDs.</li><li>For marginal performance, you can use 1000 LEDs/pin with 5 outputs for a total of 5000 LEDs.</li><li>For marginal performance, you can use 800 LEDs/pin with 6 outputs for a total of 4800 LEDs.</li><li>ESP32 is capable of calculating approximately 65k-85k LEDs per second (that’s 1000 LEDs @~70fps, 2000 LEDs @~35fps, 4000 LEDs @~18fps)</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=83121a00c930" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[MIDI CHRISTMAS LIGHT-SHOW(2018)]]></title>
            <link>https://sparsh308.medium.com/midi-christmas-light-show-2018-a4825c97566c?source=rss-9593c0400ae3------2</link>
            <guid isPermaLink="false">https://medium.com/p/a4825c97566c</guid>
            <dc:creator><![CDATA[Sparsh]]></dc:creator>
            <pubDate>Wed, 09 Dec 2020 15:29:03 GMT</pubDate>
            <atom:updated>2020-12-09T15:29:03.178Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cNYOyWeFwwKlfeKGm3N8fQ.png" /></figure><p>This Arduino project creates a music light show by controlling a number of lights according to a song in correct sync with the music. It uses MIDI signals from a music software running on a computer to sync the lights with the music.</p><p>This Arduino project can be used to control stage lights and fog machines (which don’t have DMX) with a computer and achieve wonderful synchronization for performances on stage which is not possible with manual lighting control consoles.</p><p>I was watching Christmas song videos on Youtube and <a href="https://www.youtube.com/watch?v=cMRaSeVFEiQ">this video of Christmas lights flashing according to the music </a>caught my eye. So I decided to make one of those with an Arduino. But I was wondering how I would sync the lights according to a song or how I would send data in sync with a song. I got the idea of using MIDI signals for that when I was working with a song on a sound editing software. So I hacked the MIDI signals from the software (which was in sync with a song) and turned them into light control data.</p><h3>Project Files:</h3><p><a href="https://github.com/sparsh308/Midi-Christmas-Light-Show">https://github.com/sparsh308/Midi-Christmas-Light-Show</a></p><h3>What are the stuff required to do this?</h3><h4>An Arduino<br>74HC595 IC (3 nos.) (1 for each 8 channels)<br>8 channel relay board (3 nos.) (1 for each 8 channels)<br>1μF capacitor</h4><h3>How did I control the lights in sync with a song?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rjUW292xnSCT4-Dy_qIOAw.png" /></figure><p>This is the screenshot of Studio One software (Digital Audio Workstation software) that I used for this project. The MIDI track in the DAW software is in sync with a song. So I turned on/off notes from C3 to E6 (excluding sharp notes) in the MIDI track for controlling the lights. I used <a href="http://projectgus.github.io/hairless-midiserial/">Hairless MIDI to serial bridge</a>,to sent the MIDI signals to the Arduino and programmed it to turn on/off specific relay according to the notes received. So now the DAW software actually controls the lights according to the song.</p><h3>Block diagram:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b3euPnCfRYiaEd5vsDFr3g.png" /></figure><h3>The Circuit:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*pvnjlVprXTW4IFpNSlciIw.jpeg" /></figure><p>The lights are connected to the relays on the relay boards.</p><h3>How it works:</h3><p>Three 74HC595 s are used for controlling the relays. Three bytes are used for storing the states(on/off) of the lights in the program. The music software sends out the MIDI data and the Arduino receives it and sets the corresponding bit of one of the three bytes to 0 or 1. Then the three bytes are shifted out to the registers and then that is latched on so the relays turn on/off. All the bytes are sent and only after that is finished, they are latched and that prevents the relays from turning on/off while shifting the data.</p><h3>Step 1:</h3><p>Set up the circuit as shown in the figure and connect an external relay power source (remove the jumper in most relay boards) since it is not recommended to draw the power needed for working of the relays from the Arduino board.</p><p><strong>PLEASE NOTE: IF YOU ARE POWERING THE RELAY BOARD WITH 12V, MAKE SURE THAT THERE IS NO CONNECTION (by accident) BETWEEN THE EXTERNAL RELAY BOARD VCC (12V) AND THE 5V ON THE RELAY BOARD. (REMOVE THE JUMPER IN MOST RELAY BOARDS)</strong><br><strong>IF THERE IS ANY CONNECTION, IT CAN DESTROY THE ARDUINO AND ICs.</strong></p><h3>Step 2:</h3><p><strong>Set up the software.</strong><br>Install Studio One (or any DAW software). I used Studio One 2 Free. Most of the features work in the free version.<br>Install <a href="http://www.tobias-erichsen.de/software/loopmidi.html">loopMIDI</a> for creating a virtual MIDI port.<br>Run loopMIDI and start a virtual MIDI port.<br>Set up the loopMIDI port as a new instrument in the DAW software.<br>To do that in Studio One 2:<br>Press Ctrl+,<br>Go to ‘External Devices’ &gt;Add &gt; New Instrument &gt; Send to: loopMIDI port &gt; OK &gt; OK</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/840/0*ILLLK4jkye35OQaM" /></figure><p>Open <a href="https://github.com/sparsh308/Midi-Christmas-Light-Show/blob/main/carol%20of%20the%20bells%20lights.song">this </a>file for the song ‘Carol of the bells’.</p><p>The .wav file will be missing. Download it <a href="https://github.com/sparsh308/Midi-Christmas-Light-Show/blob/main/carol%20of%20the%20bells%20lights.song">here </a>and select the downloaded file.(click on view Raw to download the song).</p><p>Now click the area shown below and select New Instrument.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/606/0*f-UFpcpp7xpUp-3M" /></figure><p>If you are not using StudioOne, you can start a new song, create a MIDI track and send its output to the newly created instrument.</p><h3>Step 3:</h3><p>Copy and paste this program:</p><pre>#include&quot;notes_bits.h&quot;<br><br>//Pin connected to latch pin (ST_CP) of 74HC595<br>const int latchPin = 9;<br>//Pin connected to clock pin (SH_CP) of 74HC595<br>const int clockPin = 8;<br>//Pin connected to Data in (DS) of 74HC595<br>const int dataPin = 10;<br><br>int pitch, cmd, velocity;<br>int light;<br>boolean state;<br><br>byte lightData1 = 0, lightData2 = 0, lightData3 = 0; //<br><br>void setup() {<br> pinMode(latchPin, OUTPUT);<br> pinMode(dataPin, OUTPUT); <br> pinMode(clockPin, OUTPUT);<br> Serial.begin(38400);<br> <br>}<br><br>void loop() {<br><br> //read the midi signal<br> if(Serial.available()&gt;2) {<br> cmd = Serial.read();<br> pitch = Serial.read();<br> velocity = Serial.read();<br> <br> //the lights are set according to the data on MIDI ch.1<br> if(cmd==144) state=0; //144 ch1 noteON ; 0=relayON<br> else if(cmd==128) state=1; //128 ch1 noteOFF ; 1=relayOFF<br> <br> // so that lights don&#39;t change while the new data is being shifted<br> digitalWrite(latchPin, LOW);<br><br> light = getBit(pitch);<br> // set the corresponding bit in lightData<br> if(light&lt;8)<br> bitWrite(lightData1, light, state);<br> else if(light&lt;16){<br> light-=8;<br> bitWrite(lightData2, light, state);<br> }<br> else {<br> light-=16;<br> bitWrite(lightData3, light, state);<br> }<br> <br> <br> // shift out the data<br> shiftOut(dataPin, clockPin, MSBFIRST, lightData3);<br> shiftOut(dataPin, clockPin, MSBFIRST, lightData2);<br> shiftOut(dataPin, clockPin, MSBFIRST, lightData1);<br><br> // turn on the lights according to the new data<br> digitalWrite(latchPin, HIGH);<br><br> }<br>}</pre><p>Also make a <strong>notes_bits.h</strong> file.</p><p>Copy and paste the code below to it.</p><pre>/*<br> * Which bit has to be turned ON or OFF is found<br> * with the below function.<br> * <br> * The range of music notes used for the control<br> * of lights is from C3 to E6.<br> * (sharp notes are excluded) (total 24 lights)<br> * <br> * So, this function will return the number of the bit<br> * to be set.<br> * For eg, C3(note 62) corresponds to the first light,<br> * So this function will return &#39;1&#39;.<br> * <br> * Similarly, &#39;2&#39; is returned for D3(note 64), etc.<br> * <br> */<br><br>int getBit(int p) {<br> switch(p) {<br> case 60: return 0; //note C3 (middle C)<br> case 62: return 1; //D3<br> case 64: return 2; //E3<br> case 65: return 3; //F3<br> case 67: return 4; //G3<br> case 69: return 5; //A3<br> case 71: return 6; //B3<br> case 72: return 7; //C4<br> case 74: return 8; //D4<br> case 76: return 9; //E4<br> case 77: return 10; //F4<br> case 79: return 11; //G4<br> case 81: return 12; //A4<br> case 83: return 13; //B4<br> case 84: return 14; //C5<br> case 86: return 15; //D5<br> case 88: return 16; //E5<br> case 89: return 17; //F5<br> case 91: return 18; //G5<br> case 93: return 19; //A5<br> case 95: return 20; //B5<br> case 96: return 21; //C6<br> case 98: return 22; //D6<br> case 100: return 23; //E6<br> }<br>}</pre><h3>Step 4:</h3><p>Connect the lights and power the relay board and connect the Arduino to the computer.</p><p>Then open Hairless Serial to MIDI bridge and select the Arduino port as the serial port and MIDI In port as loopMIDI.</p><p>Then, go to File &gt; Preferences &gt; Set the Baud rate to 38400 &gt; OK</p><p>We have to change the baud rate because we need it to be higher than the baud rate of MIDI which is 31250. If the baud rate is below that, we will have a noticeable delay in the lights.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/395/0*vF2ZKnRQhPmbU4ar" /></figure><p>Then tick the SerialMIDI bridge option.</p><h3>To start the lights:</h3><p>Go back to Studio One and play the song. You should see the Green LED on screen in Hairless Serial to MIDI bridge blinking. If that is there, the then your relays should also work.<br>Now you’ll see your light show according to the song. You can do the circuit on a line or dot PCB. I did it on a line PCB. This is how it looked at the end.</p><p>I also connected an external amplifier and speaker to the computer and kept it outside the house for my Christmas Light show. Here is the final working video:</p><p>Link To Working Video:</p><p><a href="https://www.youtube.com/watch?v=FSY-jbwNDdA&amp;feature=youtu.be&amp;ab_channel=SparshKishore">https://www.youtube.com/watch?v=FSY-jbwNDdA&amp;feature=youtu.be&amp;ab_channel=SparshKishore</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a4825c97566c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building Flutter Chat App using Firebase with Geo location sharing.
 (In Depth)]]></title>
            <link>https://sparsh308.medium.com/building-flutter-chat-app-using-firebase-with-geo-location-sharing-in-depth-d9247c3c64cf?source=rss-9593c0400ae3------2</link>
            <guid isPermaLink="false">https://medium.com/p/d9247c3c64cf</guid>
            <category><![CDATA[linuxworld]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[chat-app-development]]></category>
            <category><![CDATA[chat]]></category>
            <dc:creator><![CDATA[Sparsh]]></dc:creator>
            <pubDate>Sun, 18 Oct 2020 18:44:58 GMT</pubDate>
            <atom:updated>2020-10-18T18:44:58.555Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uHGuA3cVN5sifuH2SFxdIA@2x.png" /><figcaption>💜</figcaption></figure><h3>❗️❗️Task 5 — Flutter App Development (LW)❗️❗️</h3><p>Description:</p><p>1) Create a chat app representing beautiful UI</p><p>2)store/retrieve user data into firebase</p><p>3) Integrate the app with map API</p><p>4)prompt current location of your friend on Google maps of the user on click of the Button.</p><blockquote><em>This blog will guide you on how to develop high performing chat app with Geo location sharing in Flutter with Firebase in simple steps…</em></blockquote><p>Let’s begin with the essential points</p><blockquote><strong><em>4 Major Steps to Develop Chat App in Flutter With Firebase</em></strong></blockquote><ul><li>Firebase Authorization: Sign in, Sign up or Sing Out</li><li>Firebase Firestore for Installing Plugins: Upload, Remove and Retrieve Data Stored in Cloud Firestore</li><li>Creating the Layout of the Chat App Screen</li><li>Final Linking of the Flutter Chat App with Firebase</li><li>Adding Geolocation sharing.</li></ul><p>Before moving on Further first lets understand the firestore storage.</p><h4><strong>What is Cloud Firestore? 🔥</strong></h4><p>Cloud Firestore is a flexible, scalable database for mobile, web, and server development from Firebase and Google Cloud Platform. Like Firebase Realtime Database, it keeps your data in sync across client apps through real-time listeners and offers offline support for mobile and web so you can build responsive apps that work regardless of network latency or Internet connectivity. Cloud Firestore also offers seamless integration with other Firebase and Google Cloud Platform products, including Cloud Functions.</p><p>Firestore Database consists of 3 things</p><ol><li><strong>Collections </strong>— Collections are nothing but a set of document.</li><li><strong>Documents </strong>— Documents are set of sub-collections and field.</li><li><strong>Fields</strong> — Field consists of attribute and value. The values are of the type of string, number, Boolean, map, array, null, timestamp, geopoints and reference.</li></ol><ul><li>If you observe the building blocks of Firestore you can find that it is similar to JSON structure where you can store data in any form, any structure and any depth.</li></ul><h4><strong>Any complex feature can be implemented easily with proper model design. In this article we will learn how to define and implement model both abstract and specific for programming language</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZxIuW7hVyohHpVb6-K6fqQ.png" /><figcaption>Basic user flow of our chat app.</figcaption></figure><h4><strong>Now lets get started:</strong></h4><h3>Step 0 : Setting up the Basic architecture of app of easier development process.</h3><h4>Open the pubspec.yaml file in your project and add the following dependencies into it.</h4><pre>firebase_core: &quot;0.5.0&quot; <br>shared_preferences: ^0.5.12 // To store the login state of the user <br>simple_animations: ^1.3.3 //(optional) for Fade in animation<br>firebase_auth: ^0.18.1+1  //for firebase authentication<br>google_sign_in: &quot;^4.5.1&quot;  //for google signin functionality<br>geolocator: ^5.3.2+2  // for accessing user geolocation   <br>google_maps_flutter: ^0.5.30   // google map integration </pre><p>1️⃣<strong> create all the screens in a single folder named as view with the different names as:</strong></p><ul><li>Singin.dart</li><li>Singup.dart</li><li>Home.dart(Home page to display active converstaions).</li><li>Conversation_screen.dart</li><li>map.dart // for displaying the map</li><li>search.dart // user search screen</li></ul><p>2️⃣<strong>create the following file in a single folder named as Services with the different names as: These file will include the file which deals with authentication and database services.</strong></p><ul><li>Auth.dart</li><li>database.dart</li></ul><p><strong>3️⃣create the following file in a single folder named as helper with the different names .This folder will include the files which deals with Helping functions // <em>Don’t panic we will understand the use of each and every file further</em></strong><em>.</em></p><ul><li>Helper.dart // Shared preference Will allow us to Save so info loke login status and logged in Username and email to store in phone memory.</li></ul><pre>import &#39;package:shared_preferences/shared_preferences.dart&#39;;</pre><pre>import &#39;package:flutter/material.dart&#39;;</pre><pre>class HelperFunction {<br>static String sharedPreferencesUserLoggedInKey = &quot;ISLOGGEDIN&quot;;<br>static String sharedPreferencesUserNameKey = &quot;USERNAMEKEY&quot;;<br>static String sharedPreferencesUserEmailKey = &quot;USEREMAILKEY&quot;;</pre><pre>static Future&lt;void&gt; saveuserLoggedInSharedPreference(<br>bool isUserLoggedIn) async {<br>SharedPreferences prefs = await SharedPreferences.getInstance();<br>return await prefs.setBool(<br>sharedPreferencesUserLoggedInKey, isUserLoggedIn);<br>}<br>static Future&lt;void&gt; saveuserNameSharedPreference(String userName) async {<br>SharedPreferences prefs = await SharedPreferences.getInstance();<br>return await prefs.setString(sharedPreferencesUserNameKey, userName);<br>}<br>static Future&lt;void&gt; saveuserEmailSharedPreference(String userEmail) async {<br>SharedPreferences prefs = await SharedPreferences.getInstance();<br>return await prefs.setString(sharedPreferencesUserEmailKey, userEmail);<br>}<br>//getting the data form shared preferences<br>static Future&lt;bool&gt; GetuserLoggedInSharedPreference() async {<br>SharedPreferences prefs = await SharedPreferences.getInstance();<br>return prefs.getBool(sharedPreferencesUserLoggedInKey);<br>}<br>static Future&lt;String&gt; getuserNameSharedPreference() async {<br>SharedPreferences prefs = await SharedPreferences.getInstance();<br>return prefs.getString(sharedPreferencesUserNameKey);<br>}<br>static Future&lt;String&gt; getuserEmailSharedPreference() async {<br>SharedPreferences prefs = await SharedPreferences.getInstance();<br>return prefs.getString(sharedPreferencesUserEmailKey);<br>}<br>}</pre><ul><li>authenticate.dart // This file will will help user to choose to signup or signin with will be the base file which will redirecte the user to different scaffold for signup and signin.</li></ul><pre>import &#39;package:flutter/material.dart&#39;;<br>class Authenticate extends StatefulWidget {<br>@override<br>_AuthenticateState createState() =&gt; _AuthenticateState();<br>}<br>class _AuthenticateState extends State&lt;Authenticate&gt; {<br>bool showlogin = true;<br>@override<br>Widget build(BuildContext context) {<br>void toggleView() {<br>setState(() {<br>showlogin = !showlogin;<br>});<br>}<br>if (showlogin) {<br>return LoginPage(toggleView);<br>} else {<br>return SignUp(toggleView);<br>}<br>}<br>}</pre><p>4️⃣<strong>create the following files in a single folder named as Model with the different names .This folder will include the files which deals Model(data) part of the application.</strong></p><ul><li>Constants.dart // you can add more value that you want to save in phone memeory.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/570/1*6m4EhAixDROy0H7gbrh0zA.jpeg" /></figure><ul><li>SearchModel.dart(model data for user searchlist)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/689/1*ii3ESayMnOdDk_sRMBmfsg.jpeg" /></figure><p>&gt; user.dart</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/557/1*n9aqt6z_DBvvskssYOgCZw.jpeg" /></figure><h3>Step 1: Firebase Authentication in the App: Sign in, Sign up or Sing Out</h3><p>This is a most essential part of any chat app to keep your data secure by directly sign-in the app with your username. So here’s what you need to understand to create a sign-in/Sign up with email and password.</p><p><strong>If you are choosing to proceed with the Google Sign-in, then refer this link for information : </strong><a href="https://firebase.flutter.dev/docs/auth/usage"><strong>https://firebase.flutter.dev/docs/auth/usage</strong></a></p><p>First Make the UI for the Login page .</p><p>As we Know that we Will keep our all Authentication related function in a single dart file named authentication in Services folder.</p><p>Include the following Functions in the dart file, We will use these function at the time of implementation.</p><pre><strong>//code for google signUp using email and password</strong><br>Future signUpWithEmailAndPassword(String email, String password) async {<br>try {<br>UserCredential userCredential = await _auth<br>.createUserWithEmailAndPassword(email: email, password: password);<br>User user = userCredential.user;<br>return _usercheck(user);<br>} on FirebaseAuthException catch (e) {<br>if (e.code == &#39;weak-password&#39;) {<br>print(&#39;The password provided is too weak.&#39;);<br>return 0;<br>}<br> else if (e.code == &#39;email-already-in-use&#39;) {<br>print(&#39;The account already exists for that email.&#39;);return 1;<br>}<br>} catch (e) {<br>print(e.toString());<br>}<br>}</pre><pre><strong>//Code for Google Signin using email and password</strong><br>User1 _usercheck(User user) {<br>if (user != null) {<br>return User1(userId: user.uid);<br>} else {<br>return null;<br>}<br>}<br>Future signinWithEmailAndPassword(String email, String password) async {<br>try {<br>UserCredential userCredential = await _auth.signInWithEmailAndPassword(<br>email: email, password: password);<br>User user = userCredential.user;<br>return _usercheck(user);<br>} on FirebaseAuthException catch (e) {<br>if (e.code == &#39;user-not-found&#39;) {<br>print(&#39;No user found for that email.&#39;);<br>return 0;<br>} else if (e.code == &#39;wrong-password&#39;) {<br>print(&#39;Wrong password provided for that user.&#39;);<br>return 1;<br>}<br>}<br>}</pre><pre><strong>//Sign Out Function</strong><br>Future signOut() async {<br>try {<br>BotToast.showText(<br>text: &quot;logged out Successfully&quot;,<br>);<br>HelperFunction.saveuserLoggedInSharedPreference(false);<br>return await _auth.signOut();<br>} catch (e) {<br>print(e.toString());<br>}<br>}<br>}</pre><p><strong>Implementing the SignMeup function in Signup View file which we have to call under OnPressed method of a button by calling this function it will take the text from the text controller and call the required google signup function which we have added in authentication file.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/863/1*B41uJ60X_AnNGS7qp6vSTw.jpeg" /></figure><p>Now as soon as user sign up for first time we have to save the user info in phone memory we will do that using shared preferences and we have to make a user in database to do that</p><p>add the following functions in database.dart file.</p><pre><strong>// We have to call this function as soon as user signup this function will upload the user data to Firestore for registration.</strong><br>uploaduserInfo(userMap) {<br>FirebaseFirestore.instance.collection(&quot;users&quot;).add(userMap);<br>}</pre><h3>Step 2: Implementing Chat Home Screen</h3><p>Now after logged in We have to create the Home screen which will contain the active Chats list.</p><p>Create a desired Ui for the home screen and use the below provided code for backend integration .</p><p>Following function in home.dart file will fetch the logged in username that we have saved during Signin Process, then after fetching the logged in username it will search the active chatroom in the firebase database which include the name of the user .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/812/1*A01Fk8W8PL2yAGxB7H7OYg.jpeg" /></figure><p>The Above getuserInfo will fetch the following chatroom for database.chat room will be created when any one of two member message the other person for the first time. that we will implement later.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rjTDK-GdZYy1fszSlPaquQ.jpeg" /></figure><p>Now after Fetching the active chat room using the following chat list widget we will display the each chat tile according the data fetched.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/965/1*5tCU7geEiMrWsekS5pkYFg.jpeg" /></figure><h3>Chat Tile</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/762/1*XCJ7n7ParjjEnFxeoOGvdA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/862/1*s1QQvSblaXeMXlbX0t8Tag.jpeg" /></figure><h3>Step 3: Implementing Search Screen.</h3><p>First implement the search screen basic layout which will contain a text box for username to search. after pressing the search button the following code will be executed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/771/1*LLzwhtb9JW59XlPQJjW9yQ.jpeg" /></figure><p>fetch function will call the <strong>getusername</strong> function. add the following function in database.dart file</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/969/1*4yu7f0IN5X0b_pEgycP7Ww.jpeg" /><figcaption>This Function Will Search The user by its username is database.</figcaption></figure><pre><strong>//getusername search function will fetch the username.</strong><br><br><strong>//This function will append all searched user in List of type searchmodel</strong></pre><h4><strong>Now to show the fetched users list we will use the following list widget which will return the search tile which two parameter that is username and email id.</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/543/1*OKIT6r_1tLmn6VwdGdIuRw.jpeg" /></figure><h4>Now after clicking on each tile we want to the conversation screen where we can chat to the searched user. But First we want to create the chat room in database. for that call the following fucntion which will create the chatroom with a specific unique id that id will be like username1_username2 .</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/769/1*I2pE1TxFFao-JuqFnMOwwA.jpeg" /><figcaption>it will create the chatroom in firestore database.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/818/1*QcpyYYcY8eei7bDpakO8uQ.jpeg" /><figcaption>This function will create the unique id for the chatroom.</figcaption></figure><h3>Step 4: Implementing Conversation Screen.</h3><p>For the UI we need to include a text box and a button which will send the message and a chat list which will display the message from the both user who are chatting with each other .. message from the receiver will display on left and message send by the sender will appear on right.</p><p>Following is the <strong>chatmessagelist</strong> which will create a Stream of data to synchronize the message on database and app</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/874/1*1EU25THx4Csf235xUCWF7Q.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/884/1*U6suU87kfyp32is3EBkqWA.jpeg" /></figure><p>Now to send the message we need a function which will take the text from the textconroller and call the setconversation method which we will include in database.dart file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3TDbQcEbvXj4ncg1JKFDFA.jpeg" /></figure><p>Add the following method in database.dart file. this method will send the message to database.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/733/1*JIHjOexiMl0xua-uu1ISvA.jpeg" /></figure><h3>Step 5: Implementing Geo Location feature.</h3><p>for this we will add a button in conversation screen appbar actions button pressing which we will be able to see the location of the user.</p><p>But first we want every user should update its location to the database for this we want a function which will execute first on user home screen or where ever you want. Add the following in database.dart and call them when you want the user to update its current location.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/765/1*HIMEIcGHRupoN3fwuaA35w.jpeg" /></figure><p>Now add the following in map.dart This will be the screen which will show your friends location on google map.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/667/1*q6n_f72ClYkrPZ-Rv3W8vg.jpeg" /><figcaption><strong>this function will fetch the location of your friend.</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/832/1*uO2HKTEcIPR1WHbp7j9Niw.jpeg" /><figcaption>widget for displaying google map</figcaption></figure><h3>That’s it by now i guess you had a pretty good idea how to build a chat app using flutter. for more detail you can check out the GitHub link for the the project : Link will be added soon.</h3><p>Thank You for Reading . 😘</p><p>like this article if you came so far reading it 😄</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d9247c3c64cf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Linux Remote CLI Flutter Mobile App using python — CGI Programming.]]></title>
            <link>https://sparsh308.medium.com/linux-remote-cli-flutter-mobile-app-using-python-cgi-programming-4bbaf6f45b51?source=rss-9593c0400ae3------2</link>
            <guid isPermaLink="false">https://medium.com/p/4bbaf6f45b51</guid>
            <category><![CDATA[cli]]></category>
            <category><![CDATA[redhat-linux]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[vimal-daga]]></category>
            <category><![CDATA[linuxworld]]></category>
            <dc:creator><![CDATA[Sparsh]]></dc:creator>
            <pubDate>Mon, 05 Oct 2020 18:20:31 GMT</pubDate>
            <atom:updated>2020-10-05T18:32:52.525Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x-9jlyXJH_Jbndr-_bTlWA.png" /></figure><h3>Linux Remote CLI Flutter Mobile App using python — CGI With Firebase Stream Builder.(Task 4)</h3><p>Linux CLI Mobile App using <strong>Firebase</strong>, <strong>Redhat</strong> , <strong>Linux Flutter Integration using streamBuilder</strong>.</p><p>This is Part Two of Linux Cli Mobile App In this Tutorial we will Use Stream Builder To Access the Firebase.</p><p>Link for part 1:<a href="https://medium.com/@sparsh308/linux-remote-cli-flutter-mobile-app-using-python-cgi-programming-6c495b00fd41"><strong>click here</strong></a></p><p>what is Stream Builder : Refer This Video For detail explaination :<a href="https://www.youtube.com/watch?v=MkKEWHfy99Y&amp;ab_channel=GoogleDevelopers"><strong> click Here</strong></a></p><p>Welcome to my Demonstration Project article based on Linux Remote CLI Flutter Mobile App .</p><p><em>This is demonstration project , based on development of </em>Linux Remote CLI <em>Flutter application using Integration of </em><strong><em>Google firebase (firestore to store the response) </em></strong><em>and </em><strong><em>Redhat Linux</em></strong><em> using </em><strong>Python — CGI Programming<em>.</em></strong></p><p><strong>Task 4 : Flutter App Development‼️</strong></p><p>1. Create an app that can run any linux command using API</p><p>2. Output will be saved in Firestore.</p><p>3. From Firestore, get this output and print on screen.</p><p>4. Use Stream Builder to save data.</p><h3>What is Command line?</h3><p>The Linux command line is a text interface to your computer. Often referred to as the shell, terminal, console, prompt or various other names, it can give the appearance of being complex and confusing to use. To access the Command line of any Linux system we must have an access to the physical server to perform any operation on it.</p><p><strong>In this project article we will learn how to make app from which we can perform any Linux command remotely from our mobile. 😃</strong></p><p><strong>What is CGI Programming?</strong></p><p>The Common Gateway Interface, or CGI, is a set of standards that define how information is exchanged between the web server and a custom script. The CGI specs are currently maintained by the NCSA.</p><h3>What is CGI?</h3><ul><li>The Common Gateway Interface, or CGI, is a standard for external gateway programs to interface with information servers such as HTTP servers.</li></ul><h3>Web Browsing</h3><p>To understand the concept of CGI, let us see what happens when we click a hyper link to browse a particular web page or URL.</p><ul><li>Your browser contacts the HTTP web server and demands for the URL, i.e., filename.</li><li>Web Server parses the URL and looks for the filename. If it finds that file then sends it back to the browser, otherwise sends an error message indicating that you requested a wrong file.</li><li>Web browser takes response from web server and displays either the received file or error message.</li></ul><p>However, it is possible to set up the HTTP server so that whenever a file in a certain directory is requested that file is not sent back; instead it is executed as a program, and whatever that program outputs is sent back for your browser to display. This function is called the Common Gateway Interface or CGI and the programs are called CGI scripts. These CGI programs can be a Python Script, PERL Script, Shell Script, C or C++ program, etc.</p><p><strong>In this we can use Python instead of shell scripts for automation. Python provides methods to run shell commands, giving us the same functionality of those shells scripts. Learning how to run shell commands in Python opens the door for us to automate computer tasks in a structured and scalable way.</strong></p><p>To know more about cgi-programming refer this <a href="https://www.tutorialspoint.com/python/python_cgi_programming.htm"><strong>link</strong></a> :</p><h3>Web Server Support and Configuration 😄</h3><p>Before you proceed with CGI Programming, make sure that your Web Server supports CGI and it is configured to handle CGI Programs. All the CGI Programs to be executed by the HTTP server are kept in a pre-configured directory. This directory is called CGI Directory and by convention it is named as /var/www/cgi-bin. By convention, CGI files have extension as. <strong>cgi,</strong> but you can keep your files with python extension <strong>.py</strong> as well.</p><p>By default, the Linux server is configured to run only the scripts in the cgi-bin directory in /var/www. If you want to specify any other directory to run your CGI scripts, comment the following lines in the httpd.conf file −</p><pre>&lt;Directory &quot;/var/www/cgi-bin&quot;&gt;<br>   AllowOverride None<br>   Options ExecCGI<br>   Order allow,deny<br>   Allow from all<br>&lt;/Directory&gt;</pre><pre>&lt;Directory &quot;/var/www/cgi-bin&quot;&gt;<br>Options All<br>&lt;/Directory&gt;</pre><p>This file is kept in /var/www/cgi-bin directory and it has following content. Before running your CGI program, make sure you have change mode of file using <strong>chmod 755 linux.py</strong> UNIX command to make file executable.</p><pre>#!/usr/bin/python3import cgi<br>import subprocess<br>print(&quot;content-type:text/html&quot;)<br>print()<br>mydata=cgi.FieldStorage()<br>output=subprocess.getoutput(&quot;sudo &quot; +mydata.getvalue(&quot;x&quot;))<br>print(output)</pre><h3>GET and POST Methods</h3><p>You must have come across many situations when you need to pass some information from your browser to web server and ultimately to your CGI Program. Most frequently, browser uses two methods two pass this information to web server. These methods are GET Method and POST Method.</p><h3>Passing Information using GET method</h3><p>The GET method sends the encoded user information appended to the page request. The page and the encoded information are separated by the ? character as follows −</p><pre>&quot;http://192.168.84.130/cgi-bin/docker.py?x=${mycmd}&quot;;http://&lt;serverIP&gt;/cgi-bin/pythonfile.py?x=${mycmd}<br>//mycmd filed will take the command name which we have to execute.To check the server ip address you can use ifconfig command.</pre><p>The GET method is the default method to pass information from browser to web server and it produces a long string that appears in your browser’s Location:box. Never use GET method if you have password or other sensitive information to pass to the server.</p><p>Note: Before you can access the server remotely you need to set firewall To know more about firewall refer this <a href="https://blog.resellerclub.com/a-step-by-step-guide-on-how-to-configure-firewall-in-linux/"><strong><em>link</em></strong></a><strong><em>.</em></strong></p><p>for this tutorial purpose i had disabled my firewall : To disable the firewall use command : <strong>systemctl stop firewalld</strong></p><p><strong>Now</strong> <strong>Check SELinux Status:</strong></p><p>The SELinux service is enabled by default on CentOS and most other RHEL-based systems. However, this might not be the case for your system.</p><p>Start by checking the status of SELinux on your system with the command:</p><pre>sestatus</pre><p>To disable SELinux temporarily, type in the following command in the terminal:</p><pre>sudo setenforce 0</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/34/0*sS2qLv06fz0rcm4V" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*Oq8DygaxcXXxqGHr.png" /></figure><p>Now We will able to Perform Command operation on Linux remotely using http :</p><p>Now we will make an simple Interface flutter app to perform Linux commands.</p><p>To know how to Connect Firebase Firebase Storage Refer This article: <strong>https:/</strong><a href="https://firebase.flutter.dev/docs/firestore/usage/"><strong>/firebase.flutter.dev/docs/firestore/usage/</strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/735/1*_zxmwr4rlh6bfvFkUFGntA.png" /></figure><p>This is a demonstration image : Enter any Command in Text filed and execute that command remotely.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/739/0*InIH1tHtVbPrRCy0.jpeg" /><figcaption><strong>Function that will execute and fetch the http response from the Linux server.</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/831/1*vXdyy4kY_PIWU3xMIIPeJw.jpeg" /><figcaption><strong>Stream Builder Code for firebase</strong></figcaption></figure><p><strong>Firebase Cloud Firestore Console.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J5BvsHQK0FTH38ydSkUL-w.jpeg" /></figure><p>GitHub Link : <a href="https://github.com/sparsh308/Linux_Remote_cli_Using_StreamBuilder">https://github.com/sparsh308/Linux_Remote_cli_Using_StreamBuilder</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4bbaf6f45b51" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Linux Remote CLI Flutter Mobile App using python — CGI Programming.]]></title>
            <link>https://sparsh308.medium.com/linux-remote-cli-flutter-mobile-app-using-python-cgi-programming-6c495b00fd41?source=rss-9593c0400ae3------2</link>
            <guid isPermaLink="false">https://medium.com/p/6c495b00fd41</guid>
            <category><![CDATA[redhat-linux]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[command-line]]></category>
            <dc:creator><![CDATA[Sparsh]]></dc:creator>
            <pubDate>Sun, 04 Oct 2020 14:45:03 GMT</pubDate>
            <atom:updated>2020-10-04T14:51:07.165Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wINFGjj88z-30j8ZryexMA.png" /></figure><h3>Linux Remote CLI Flutter Mobile App using py<strong>thon — CGI Programming.</strong></h3><p>Linux CLI Mobile App using <strong>Firebase</strong>, <strong>Redhat</strong> , <strong>Linux Flutter Integration</strong>.</p><p>Welcome to my Demonstration Project article based on Linux Remote CLI Flutter Mobile App .</p><p><em>This is demonstration project , based on development of </em>Linux Remote CLI <em>Flutter application using Integration of </em><strong><em>Google firebase (firestore to store the response) </em></strong><em>and </em><strong><em>Redhat Linux</em></strong><em> using </em><strong>Python — CGI Programming<em>.</em></strong></p><p><strong>Task 3 : Flutter App Development .</strong></p><p>1. Create an app that can run any linux command using API</p><p>2. Output will be saved in Firestore.</p><p>3. From Firestore, get this output and print on screen.</p><h3>What is Command line?</h3><p>The Linux command line is a text interface to your computer. Often referred to as the shell, terminal, console, prompt or various other names, it can give the appearance of being complex and confusing to use. To access the Command line of any Linux system we must have an access to the physical server to perform any operation on it.</p><p><strong>In this project article we will learn how to make app from which we can perform any Linux command remotely from our mobile. 😃</strong></p><p><strong>What is CGI Programming?</strong></p><p>The Common Gateway Interface, or CGI, is a set of standards that define how information is exchanged between the web server and a custom script. The CGI specs are currently maintained by the NCSA.</p><h3>What is CGI?</h3><ul><li>The Common Gateway Interface, or CGI, is a standard for external gateway programs to interface with information servers such as HTTP servers.</li></ul><h4><strong>Web Browsing</strong></h4><p>To understand the concept of CGI, let us see what happens when we click a hyper link to browse a particular web page or URL.</p><ul><li>Your browser contacts the HTTP web server and demands for the URL, i.e., filename.</li><li>Web Server parses the URL and looks for the filename. If it finds that file then sends it back to the browser, otherwise sends an error message indicating that you requested a wrong file.</li><li>Web browser takes response from web server and displays either the received file or error message.</li></ul><p>However, it is possible to set up the HTTP server so that whenever a file in a certain directory is requested that file is not sent back; instead it is executed as a program, and whatever that program outputs is sent back for your browser to display. This function is called the Common Gateway Interface or CGI and the programs are called CGI scripts. These CGI programs can be a Python Script, PERL Script, Shell Script, C or C++ program, etc.</p><p><strong>In this we can use Python instead of shell scripts for automation. Python provides methods to run shell commands, giving us the same functionality of those shells scripts. Learning how to run shell commands in Python opens the door for us to automate computer tasks in a structured and scalable way.</strong></p><p>To know more about cgi-programming refer this <a href="https://www.tutorialspoint.com/python/python_cgi_programming.htm"><strong>link</strong></a> :</p><h3><strong>Web Server Support and Configuration 😄</strong></h3><p>Before you proceed with CGI Programming, make sure that your Web Server supports CGI and it is configured to handle CGI Programs. All the CGI Programs to be executed by the HTTP server are kept in a pre-configured directory. This directory is called CGI Directory and by convention it is named as /var/www/cgi-bin. By convention, CGI files have extension as. <strong>cgi,</strong> but you can keep your files with python extension <strong>.py</strong> as well.</p><p>By default, the Linux server is configured to run only the scripts in the cgi-bin directory in /var/www. If you want to specify any other directory to run your CGI scripts, comment the following lines in the httpd.conf file −</p><pre>&lt;Directory &quot;/var/www/cgi-bin&quot;&gt;<br>   AllowOverride None<br>   Options ExecCGI<br>   Order allow,deny<br>   Allow from all<br>&lt;/Directory&gt;<br><br>&lt;Directory &quot;/var/www/cgi-bin&quot;&gt;<br>Options All<br>&lt;/Directory&gt;</pre><p>This file is kept in /var/www/cgi-bin directory and it has following content. Before running your CGI program, make sure you have change mode of file using <strong>chmod 755 linux.py</strong> UNIX command to make file executable.</p><pre>#!/usr/bin/python3</pre><pre>import cgi<br>import subprocess<br>print(&quot;content-type:text/html&quot;)<br>print()<br>mydata=cgi.FieldStorage()<br>output=subprocess.getoutput(&quot;sudo &quot; +mydata.getvalue(&quot;x&quot;))<br>print(output)</pre><h3>GET and POST Methods</h3><p>You must have come across many situations when you need to pass some information from your browser to web server and ultimately to your CGI Program. Most frequently, browser uses two methods two pass this information to web server. These methods are GET Method and POST Method.</p><h3>Passing Information using GET method</h3><p>The GET method sends the encoded user information appended to the page request. The page and the encoded information are separated by the ? character as follows −</p><pre>&quot;http://192.168.84.130/cgi-bin/docker.py?x=${mycmd}&quot;;</pre><pre>http://&lt;serverIP&gt;/cgi-bin/pythonfile.py?x=${mycmd}<br>//mycmd filed will take the command name which we have to execute.</pre><pre>To check the server ip address you can use ifconfig command.</pre><p>The GET method is the default method to pass information from browser to web server and it produces a long string that appears in your browser’s Location:box. Never use GET method if you have password or other sensitive information to pass to the server.</p><p>Note: Before you can access the server remotely you need to set firewall To know more about firewall refer this <a href="https://blog.resellerclub.com/a-step-by-step-guide-on-how-to-configure-firewall-in-linux/"><strong><em>link</em></strong></a><strong><em>.</em></strong></p><p>for this tutorial purpose i had disabled my firewall : To disable the firewall use command : <strong>systemctl stop firewalld</strong></p><p><strong>Now</strong> <strong>Check SELinux Status:</strong></p><p>The SELinux service is enabled by default on CentOS and most other RHEL-based systems. However, this might not be the case for your system.</p><p>Start by checking the status of SELinux on your system with the command:</p><pre>sestatus</pre><p>To disable SELinux temporarily, type in the following command in the terminal:</p><pre>sudo setenforce 0</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*8Z1ROHFABF5CuXT3hgnBVQ.png" /></figure><p>Now We will able to Perform Command operation on Linux remotely using http :</p><p>Now we will make an simple Interface flutter app to perform Linux commands.</p><p>To know how to Connect Firebase Firebase Storage Refer This article: <strong>https:/</strong><a href="https://firebase.flutter.dev/docs/firestore/usage/"><strong>/firebase.flutter.dev/docs/firestore/usage/</strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/735/1*7Xxz4u9V4NBUgL4vuWGmEg.png" /><figcaption><strong>This is a demonstration image : Enter any Command in Text filed and execute that command remotely.</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/739/1*bBkamRgAAd7gxkIDH9se2g.jpeg" /><figcaption><strong>Function that will execute and fetch the http response from the Linux server.</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/574/1*p-dl95tELQ-fn74XxfIWMw.jpeg" /><figcaption><strong>This function will send the save the command Execution Result in firestore storage</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/952/1*PJmGDCUavXWe__MzPvf61Q.jpeg" /><figcaption>Execute this function to retrieve the response back form Firebase storage.</figcaption></figure><p>Firebase Cloud Firestore Console.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A8d31BNeBLoqcZbgkanm0w.jpeg" /></figure><p>Thank you for reading the article hope you liked it . Github Link for flutter App : <a href="https://github.com/sparsh308/sparsh308-Flutter_Redhat_Firebase_integration">https://github.com/sparsh308/sparsh308-Flutter_Redhat_Firebase_integration</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6c495b00fd41" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Animation in Flutter (Task 3)]]></title>
            <link>https://sparsh308.medium.com/animation-in-flutter-task-3-ebcbf687dee0?source=rss-9593c0400ae3------2</link>
            <guid isPermaLink="false">https://medium.com/p/ebcbf687dee0</guid>
            <category><![CDATA[flutter-widget]]></category>
            <category><![CDATA[linuxworld]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[flutter-animation]]></category>
            <dc:creator><![CDATA[Sparsh]]></dc:creator>
            <pubDate>Wed, 30 Sep 2020 15:47:45 GMT</pubDate>
            <atom:updated>2020-10-19T09:19:05.371Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9N386KhoizX25JG6mU_nhA.gif" /></figure><h3>Animation in Flutter (Task 6)</h3><p>Well-designed animations make a UI feel more intuitive, contribute to the slick look and feel of a polished app, and improve the user experience. Flutter’s animation support makes it easy to implement a variety of animation types. Many widgets, especially <a href="https://flutter.dev/docs/development/ui/widgets/material">Material widgets</a>, come with the standard motion effects defined in their design spec, but it’s also possible to customize these effects.</p><h3>Choosing an approach</h3><p>There are different approaches you can take when creating animations in Flutter. Which approach is right for you?</p><h3>Animation types</h3><p>Generally, animations are either tween- or physics-based. The following sections explain what these terms mean, and point you to resources where you can learn more.</p><h3>Tween animation</h3><p>Short for <em>in-betweening</em>. In a tween animation, the beginning and ending points are defined, as well as a timeline, and a curve that defines the timing and speed of the transition. The framework calculates how to transition from the beginning point to the end point.</p><h3>Now Lets get started building simple rotate animation:</h3><h3>Animation</h3><p>The primary building block of the animation system is the <a href="https://api.flutter.dev/flutter/animation/Animation-class.html">Animation</a> class. An animation represents a value of a specific type that can change over the lifetime of the animation. Most widgets that perform an animation receive an Animation object as a parameter, from which they read the current value of the animation and to which they listen for changes to that value.</p><h3>Animation­Controller</h3><p>To create an animation, first create an <a href="https://api.flutter.dev/flutter/animation/AnimationController-class.html">AnimationController</a>. As well as being an animation itself, an AnimationController lets you control the animation. For example, you can tell the controller to play the animation <a href="https://api.flutter.dev/flutter/animation/AnimationController/forward.html">forward</a> or <a href="https://api.flutter.dev/flutter/animation/AnimationController/stop.html">stop</a> the animation. You can also <a href="https://api.flutter.dev/flutter/animation/AnimationController/fling.html">fling</a> animations, which uses a physical simulation, such as a spring, to drive the animation.</p><p>Once you’ve created an animation controller, you can start building other animations based on it. For example, you can create a <a href="https://api.flutter.dev/flutter/animation/ReverseAnimation-class.html">ReverseAnimation</a> that mirrors the original animation but runs in the opposite direction (from 1.0 to 0.0). Similarly, you can create a <a href="https://api.flutter.dev/flutter/animation/CurvedAnimation-class.html">CurvedAnimation</a> whose value is adjusted by a <a href="https://api.flutter.dev/flutter/animation/Curves-class.html">Curve</a>.</p><pre>@override</pre><pre>void initState() {</pre><pre><em>// TODO: implement initState</em></pre><pre>super.initState();</pre><pre>animationController = AnimationController(</pre><pre>vsync: this, duration: Duration(milliseconds: 1000));</pre><h3>Tweens</h3><p>To animate beyond the 0.0 to 1.0 interval, you can use a <a href="https://api.flutter.dev/flutter/animation/Tween-class.html">Tween&lt;T&gt;</a>, which interpolates between its <a href="https://api.flutter.dev/flutter/animation/Tween/begin.html">begin</a> and <a href="https://api.flutter.dev/flutter/animation/Tween/end.html">end</a> values. Many types have specific Tween subclasses that provide type-specific interpolation. For example, <a href="https://api.flutter.dev/flutter/animation/ColorTween-class.html">ColorTween</a> interpolates between colors and <a href="https://api.flutter.dev/flutter/animation/RectTween-class.html">RectTween</a> interpolates between rects. You can define your own interpolations by creating your own subclass of Tween and overriding its <a href="https://api.flutter.dev/flutter/animation/Tween/lerp.html">lerp</a> function.</p><pre>animation =</pre><pre>Tween&lt;double&gt;(begin: 0.0, end: 6.28).animate(animationController);</pre><pre>animationController.forward();//This will Initially start the animation after this we can check the status of animation using animation status listener. </pre><p>Now add a Animation listener. to control the animation.</p><pre>animation.addStatusListener((status) {</pre><pre>if (status == AnimationStatus.completed) {</pre><pre>animationController.reverse();</pre><pre>} else if (status == AnimationStatus.dismissed) {</pre><pre>animationController.fling();</pre><pre>}</pre><pre>});</pre><h3>Now add the widget on which we have to apply the animation .</h3><pre>@override</pre><pre>Widget build(BuildContext context) {</pre><pre>return Center(</pre><pre>child: AnimatedLogo(</pre><pre>animation: animation,</pre><pre>));</pre><pre>}</pre><pre>}</pre><pre>class AnimatedLogo extends AnimatedWidget {</pre><pre>final Tween&lt;double&gt; _sizeAnim = Tween&lt;double&gt;(begin: 0.5, end: 1.5);</pre><pre>AnimatedLogo({Key key, Animation animation})</pre><pre>: super(key: key, listenable: animation);</pre><pre>@override</pre><pre>Widget build(BuildContext context) {</pre><pre>final Animation animation = listenable;</pre><pre><em>// TODO: implement build</em></pre><pre>return Transform.rotate(</pre><pre>angle: animation.value,</pre><pre>child: Transform.scale(</pre><pre>scale: _sizeAnim.evaluate(animation),</pre><pre>child: Container(</pre><pre>width: 50,</pre><pre>height: 50,</pre><pre>child: Image.network(</pre><pre>&#39;https://www.mozilla.org/media/protocol/img/logos/firefox/logo-lg-high-res.7ba3ce88e665.png&#39;))));</pre><pre>}</pre><pre>}</pre><p>Final Result: Git hub link : <a href="https://github.com/sparsh308/Flutter-Animation-Example">https://github.com/sparsh308/Flutter-Animation-Example</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cnql4kr1XsxE1Km-iq0a8A.gif" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ebcbf687dee0" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>