<?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 Zach Young on Medium]]></title>
        <description><![CDATA[Stories by Zach Young on Medium]]></description>
        <link>https://medium.com/@zachyoung?source=rss-574b77db85ab------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*z3SXUt_VTqn7v3_dHD1JUw@2x.jpeg</url>
            <title>Stories by Zach Young on Medium</title>
            <link>https://medium.com/@zachyoung?source=rss-574b77db85ab------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 19:51:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@zachyoung/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[I Silenced My Doorbell. My Dog Appreciates It.]]></title>
            <link>https://medium.com/@zachyoung/i-silenced-my-doorbell-my-dog-appreciates-it-4f94da8b44ca?source=rss-574b77db85ab------2</link>
            <guid isPermaLink="false">https://medium.com/p/4f94da8b44ca</guid>
            <category><![CDATA[problem-solving]]></category>
            <category><![CDATA[esp32]]></category>
            <category><![CDATA[dogs]]></category>
            <category><![CDATA[iot]]></category>
            <category><![CDATA[arduino]]></category>
            <dc:creator><![CDATA[Zach Young]]></dc:creator>
            <pubDate>Fri, 09 May 2025 05:02:43 GMT</pubDate>
            <atom:updated>2025-05-09T05:07:53.383Z</atom:updated>
            <content:encoded><![CDATA[<p>How an ESP32, an ACS712 current sensor, and a quiet obsession led to peace and push notifications.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*WVH-VX53hygFka-N.jpeg" /></figure><h3>The Problem: A Loud World Needs Quieter Solutions</h3><p>Most doorbells are obnoxiously loud. It’s as if they were designed with a single purpose: to announce visitors with maximum acoustic disruption. For dog owners, this means instant chaos — barking, jumping, and general canine pandemonium every time someone arrives.</p><p>I wanted something different — something that didn’t send my dog into a frenzy every time someone dropped off a package. What I built was a “silent” doorbell: one that quietly notifies <em>me</em>, not the dog 🐶.</p><h3>Key Features</h3><ul><li><strong>Precise current detection</strong> using the ACS712 sensor to monitor doorbell button presses</li><li><strong>Adaptive calibration</strong> that automatically adjusts to environmental conditions</li><li><strong>Smart debounce logic</strong> to prevent false positives from electrical noise</li><li><strong>Telnet server</strong> for real-time remote monitoring and diagnostics</li><li><strong>OTA updates</strong> for seamless firmware deployment without opening the case</li><li><strong>HTTP webhook integration</strong> for triggering phone notifications via ntfy.sh</li></ul><h3>The Hardware Setup</h3><p>My solution centers around two main components:</p><ol><li><strong>ESP32</strong> — The brains of the operation, handling WiFi, detection logic, and notifications</li><li><strong>ACS712 current sensor</strong> — A clever little chip that can detect the tiny electrical current that flows when someone presses your doorbell button</li></ol><p>The ACS712 is particularly perfect for this application because it can detect current flow without interrupting the circuit — it simply “senses” the magnetic field created by current flowing through a wire. This means I didn’t need to cut any existing doorbell wires or disable the original system.</p><h3>How It Works</h3><p>On power-up, the ESP32 performs a baseline calibration, taking 100 samples from the ACS712 to determine the “resting” electrical signature of the doorbell circuit. It then calculates a dynamic threshold based on the statistical variance of these samples, allowing it to reliably distinguish between normal electrical noise and an actual doorbell press.</p><p>When someone presses the doorbell button, the current flow creates a distinct signature that the ESP32 detects. The system requires multiple consecutive readings above threshold to confirm a press (debouncing), then:</p><ol><li>Logs the event over Telnet for monitoring</li><li>Sends a POST request to ntfy.sh/doorbell_pressed</li><li>Triggers a silent push notification to my phone</li></ol><p>All of this happens without a single audible chime. My dog continues napping peacefully, and I remain perfectly informed about visitors.</p><h3>The Code</h3><p>Here’s the core detection logic that makes it all work:</p><pre>// Read current from the ACS712 sensor<br>float currentReading = readCurrentSensor();</pre><pre>// Check if current indicates a doorbell press<br>if (abs(currentReading - baselineCurrent) &gt; currentThreshold) {<br>  highReadCount++;<br>  <br>  // Confirm press with multiple readings (debounce)<br>  if (!triggered &amp;&amp; highReadCount &gt;= debounceSamples) {<br>    triggered = true;<br>    lastTriggerTime = millis();<br>    Serial.println(&quot;🚨 DOORBELL PRESSED! 🚨&quot;);<br>    <br>    // Send silent notification<br>    sendNotification();<br>  }<br>} else {<br>  // Reset counter when current returns to normal<br>  highReadCount = 0;<br>  <br>  // Reset for next detection after cooldown period<br>  if (triggered &amp;&amp; (millis() - lastTriggerTime &gt; cooldownPeriod)) {<br>    triggered = false;<br>    Serial.println(&quot;System ready for next press&quot;);<br>  }<br>}</pre><p>The notification function uses the free ntfy.sh service, which requires no account setup and works globally:</p><pre>void sendNotification() {<br>  HTTPClient http;<br>  String ntfyUrl = &quot;https://ntfy.sh/your_unique_doorbell_topic&quot;;<br>  <br>  http.begin(ntfyUrl);<br>  http.addHeader(&quot;Title&quot;, &quot;Doorbell Alert&quot;);<br>  http.addHeader(&quot;Priority&quot;, &quot;high&quot;);<br>  http.addHeader(&quot;Tags&quot;, &quot;bell,home,visitor&quot;);<br>  <br>  String message = &quot;Someone is at your door!&quot;;<br>  int httpCode = http.POST(message);<br>  <br>  // Log success/failure<br>  if (httpCode &gt; 0) {<br>    Serial.printf(&quot;Notification sent: %d\n&quot;, httpCode);<br>  } else {<br>    Serial.printf(&quot;Notification failed: %d\n&quot;, httpCode);<br>  }<br>  <br>  http.end();<br>}</pre><h3>The Bug Hunt: HTTP -1 and the ISP Culprit</h3><p>One day, during testing, the project mysteriously stopped sending notifications. The ESP32 was clearly detecting doorbell presses (confirmed via Telnet monitoring), but every HTTP POST request failed with a status code of <strong>-1</strong>.</p><p>This enigmatic error code sent me down a troubleshooting rabbit hole:</p><ol><li>First, I verified the ntfy.sh service was online using my laptop and phone</li><li>Next, I tried alternate notification services (Textbelt, Pushover) with identical results</li><li>I tested my code on another ESP32 with the same outcome</li><li>I checked network settings, rebuilt the firmware, and even reflashed the ESP32</li></ol><p>After hours of increasingly desperate debugging, I tried one last thing: connecting the ESP32 to a different network instead of my home WiFi. Suddenly, notifications worked flawlessly.</p><p>The culprit? <strong>T-Mobile Home Internet was silently blocking outbound HTTP requests from ESP32 devices</strong> as part of their network security policy. Once I switched to a more conventional ISP, everything worked perfectly.</p><p>Lesson learned: not all internet service is created equal — especially for IoT devices.</p><h3>The Results: Peace and Quiet</h3><p>The difference has been remarkable. Package deliveries, friends stopping by, and food delivery no longer trigger a canine cacophony. My dog now lounges undisturbed while I receive discreet notifications on my phone.</p><p>The entire system cost less than $10 in parts and took a weekend to build and debug. Compare that to commercial options like Ring (which start at $100 plus subscription fees) and the value proposition becomes clear.</p><p>The best part? My solution focuses exclusively on solving the dog-startling problem, without unnecessary complexity or privacy concerns. No cameras, no cloud subscriptions, no microphones — just a simple, effective notification system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OM4MBc39JRUovLf4UMd8eA.png" /></figure><h3>Next Steps: Future Improvements</h3><p>While the current system works beautifully, I’m considering a few enhancements:</p><ul><li><strong>Battery backup</strong> for power outage resilience</li><li><strong>Deep sleep mode</strong> for improved power efficiency</li><li><strong>Home Assistant integration</strong> for a more comprehensive smart home experience</li><li><strong>Multiple notification recipients</strong> so everyone in the household gets alerts</li></ul><h3>Final Thoughts</h3><p>This project exemplifies why I love building custom solutions: sometimes the perfect product for your specific need simply doesn’t exist in the market. Commercial smart doorbells focus on video, security, and two-way communication — features I didn’t need. What I needed was silence for my dog, and that’s exactly what I built.</p><p>The project also reinforces an important lesson in troubleshooting IoT devices: sometimes the problem isn’t your code or hardware, but the infrastructure connecting it to the wider world.</p><p>If you’re interested in the complete code and build instructions, I’ll be publishing the full project repository soon. In the meantime, my dog sends his quiet thanks for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4f94da8b44ca" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building an iMessage Discord Bot: A Journey of Workarounds]]></title>
            <link>https://blog.devgenius.io/building-an-imessage-discord-bot-on-macos-a-journey-of-workarounds-and-frustration-c4170bd75493?source=rss-574b77db85ab------2</link>
            <guid isPermaLink="false">https://medium.com/p/c4170bd75493</guid>
            <category><![CDATA[mac]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[discord]]></category>
            <dc:creator><![CDATA[Zach Young]]></dc:creator>
            <pubDate>Wed, 05 Feb 2025 05:39:45 GMT</pubDate>
            <atom:updated>2025-02-06T18:39:35.977Z</atom:updated>
            <content:encoded><![CDATA[<h3>Building an iMessage Discord Bot: A Journey of Workarounds and Frustration</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kWqrrRHNl1Jsoc0Q" /><figcaption>Photo by <a href="https://unsplash.com/@alexbemore?utm_source=medium&amp;utm_medium=referral">Alexander Shatov</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>As a developer, I enjoy automating tasks to make my life easier. So, when I had the idea to put together a Discord Bot that could send messages to my friends in our iMessage group chat to notify us when someone was online, I figured it would be straightforward. After all, sending SMS messages programmatically is a breeze with services like Twilio.</p><p>Unfortunately, Apple had other plans.</p><p><strong>The iMessage API That Doesn’t Exist</strong></p><p>For years, developers have requested an iMessage API, but Apple refuses to budge. Without an API, integrating iMessage into automated workflows — whether personal or business — is nearly impossible. While apps like WhatsApp and Telegram provide clear documentation and APIs for automation, iMessage remains stuck in Apple’s walled garden.</p><p>Without an API, developers like myself must resort to AppleScript or GUI automation, both of which come with serious limitations and reliability issues. These workarounds can break with macOS updates, require a constantly running macOS machine, and provide no <strong>official</strong> support.</p><p>For my use case — centralizing discord notifications — I needed a way to send iMessages when users joined or left a voice channel. Since Discord has a robust API, the logical workaround was to use a combination of a Node.js server and AppleScript.</p><p><strong>The Workaround: Using AppleScript</strong></p><p>To bypass Apple’s restrictions, I had to rely on AppleScript to send messages via iMessage. <em>AppleScript is an automation scripting language built into macOS, which allows limited control over native apps like Messages. While unreliable, it is the only way to programmatically send iMessages without manually interacting with the UI.</em></p><p>The setup involves running a Node.js server on my Mac, which listens for Discord events and triggers an AppleScript command to send an iMessage to a designated group chat.</p><p><strong>Requirements</strong></p><p>First and foremost — I do not recommend this approach for any critical applications. <em>More on that later</em>. But if you would like to create a bot like this for yourself, you will need the following:</p><ol><li>A <strong>Discord account</strong> and a new or existing server.</li><li>A<strong> Mac Running MacOS</strong> ( OS version may affect AppleScript functionality)</li><li><strong>Node.js</strong> installed (you can download <a href="https://nodejs.org/en/download/current">here</a>)</li><li>An <strong>Apple Account / Apple ID</strong> that can send iMessages.</li></ol><h3>Part I: <strong>Setting Up Your Discord Bot</strong></h3><p><strong>Creating a Discord Application and Retrieving a Bot Token</strong></p><p>Before writing the bot’s logic, we need to create a <strong>Discord Application</strong> and <strong>generate a bot token</strong> to allow it to interact with Discord servers.</p><p><strong>Step 1: Create a New Discord Application</strong></p><p>1. Go to the <a href="https://discord.com/developers/applications">Discord Developer Portal</a>.</p><p>2. Click <strong>“New Application”</strong> and give it a name (e.g., “iMessage Alerts”).</p><p>3. Click <strong>“Create”</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZKJTTPK5tPmOO67ig6djdA.png" /></figure><p><strong>Step 2: Create a Bot User</strong></p><p>1. Inside your new application, navigate to the <strong>“Bot”</strong> tab.</p><p>2. Click <strong>“Add Bot”</strong> and confirm.</p><p>4. Under <strong>“Privileged Gateway Intents”</strong>, enable:</p><p>• <strong>Presence Intent &amp; Server Members Intent</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9BdAdOAgUPE2td0FG0iNWA.png" /></figure><p><em>Enabling these permissions permits the bot to access information about members in the server and their online status. Mileage may vary on what permissions are right for your project. Additional info can be found </em><a href="https://gist.github.com/advaith1/e69bcc1cdd6d0087322734451f15aa2f"><em>here</em></a><em>.</em></p><p><strong>Step 3: Invite the Bot to Your Serve</strong></p><p>1. Go to the <strong>“OAuth2” → “URL Generator”</strong> section.</p><p>2. Under <strong>“Scopes”</strong>, check <strong>“bot”</strong>.</p><p>3. Under <strong>“Bot Permissions”</strong>, check:</p><p>• <strong>“Administrator”</strong> (only for demonstration, remove later and replace with fine-grain permissions)</p><p>4. Copy the <strong>generated URL</strong> and paste it into your browser.</p><p>5. Select the Discord server you want to add the bot to and click <strong>“Authorize”</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pyglqBAjINAypW39jRm3yw.png" /></figure><p><strong>Step 4: Get the Bot Token</strong></p><p>1. Under “Bot”, scroll down and click <strong>“Reset Token”</strong> (if one hasn’t been generated already).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IpbfvvJyO8F2LlMoWA1IYw.png" /></figure><p>2. <strong>Copy the bot token and hang on to it for now</strong>(this will be used in our index.js file).</p><p>3. <strong>DO NOT share this token</strong> — if someone else gets access to it, they can control your bot.</p><h3>Part II: <strong>Preparing Your Mac for Automation</strong></h3><p>This solution requires a physical <strong>mac</strong> running <strong>macOS</strong> with a valid <strong>Apple ID</strong> and registered <strong>iMessage</strong> account.</p><p>Double check your environment, make sure you are signed in to your mac with the Apple ID you wish to use and make sure iMessage is open/running and you can successfully send a message manually.</p><p>Additionally make sure you have <strong>AppleScript</strong> on your machine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/274/1*Nl4m_ybOOobEusuKWKipXA.png" /></figure><p><em>Note: I am running macOS Sequoia. I did notice issues running the same AppleScript script on an older machine.</em></p><p>Once you have validated the aforementioned, make sure you have a <a href="https://code.visualstudio.com/"><strong>text editor</strong></a> and <a href="https://nodejs.org/en/download/current"><strong>Node.js</strong></a> installed.</p><h3>Part III: <strong>Building the iMessage Bot</strong></h3><p><strong>Step 1: Initialize a Node.js Application</strong></p><p>Open up a terminal and create a new project folder:</p><pre>mkdir discord-imessage-bot<br>cd discord-imessage-bot<br>npm init -y</pre><p>This will create a barebones project.</p><p><strong>Step 2: Install Dependencies</strong></p><p>Navigate to that newly created project and open it in your prefered text editor. My flavor of choice is <a href="https://code.visualstudio.com/"><strong>VSCode</strong></a>.</p><p>Once you have the project open in your editor, we will begin by installing our dependencies. In this case, that will be just<strong> discord.js </strong>which can be installed with the following command:</p><pre>npm install discord.js</pre><p><strong>Step 3: Creating the AppleScript to Send iMessages</strong></p><p>Since Apple does not provide an iMessage API, I’m opting to use AppleScript to send messages via the macOS Messages app.</p><p>Create a new file called <strong>sendGroupMsg.scpt</strong> in your project folder and add the following code:</p><pre>on run {groupName, messageText}<br> tell application &quot;Messages&quot;<br>  set targetChat to first chat whose name is groupName<br>  send messageText to targetChat<br> end tell<br>end run</pre><p>This script looks for an iMessage group chat with the specified name and sends a message to it.</p><p>Make sure the name matches exactly how it appears in your Messages app. This is the unique identifier for AppleScript to match against to target the correct group chat.</p><p><strong><em>⚠ Important:</em></strong><em> The iMessage group name </em><strong><em>must match exactly</em></strong><em> how it appears in Messages. Changing the group name will break the script.</em></p><p><strong>Granting Permissions for AppleScript</strong></p><p>By default, macOS requires user permission for automation scripts to control applications. Follow these steps:</p><p>1. Open <strong>System Settings</strong> → <strong>Privacy &amp; Security</strong> → <strong>Automation</strong>.</p><p>2. Look for Terminal (or VS Code if you’re running the script from there).</p><p>3. Ensure <strong>Messages</strong> is checked under Terminal’s automation permissions.</p><p>If your script isn’t working, you may need to grant <strong>Full Disk Access</strong> to Terminal as well.</p><p><strong>Step 5: Setting Up the Discord Bot</strong></p><p>With our Node.js project initialized and discord.js installed, we need to create a basic bot that listens for voice channel events.</p><p>Create a new file called <strong>index.js</strong> and add the following code:</p><p><em>⚠ Important: In this guide, I’m omitting environment variables for simplicity. However, in a real production environment, use a package like </em><a href="https://www.npmjs.com/package/dotenv"><em>dotenv</em></a><em> to keep your credentials private and prevent exposing them in source control.</em></p><pre>const { Client, GatewayIntentBits } = require(&quot;discord.js&quot;);<br>const { exec } = require(&quot;child_process&quot;);<br><br>// Initialize the Discord bot with voice state intent<br>const client = new Client({ intents: [GatewayIntentBits.GuildVoiceStates] });<br>const DISCORD_BOT_TOKEN = &quot;YOUR_DISCORD_BOT_TOKEN&quot;;<br>const groupName = &quot;YOUR IMESSAGE GROUP NAME&quot;; // Change this to your iMessage group name<br><br>// Function to send an iMessage using AppleScript<br>function sendiMessage(groupName, message) {<br> const script = `osascript sendGroupMsg.scpt &quot;${groupName}&quot; &quot;${message}&quot;`;<br> exec(script, (error, stdout, stderr) =&gt; {<br>  if (error) {<br>   console.error(`Error sending iMessage: ${error.message}`);<br>   return;<br>  }<br>  if (stderr) {<br>   console.error(`AppleScript Error: ${stderr}`);<br>   return;<br>  }<br>  console.log(`iMessage sent to group &quot;${groupName}&quot;: ${stdout}`);<br> });<br>}<br><br>// Listen for users joining or leaving a voice channel<br>client.on(&quot;voiceStateUpdate&quot;, (oldState, newState) =&gt; {<br> const user = newState.member.user.username;<br> if (!oldState.channelId &amp;&amp; newState.channelId) {<br>  sendiMessage(groupName, `${user} joined the voice channel!`);<br> } else if (oldState.channelId &amp;&amp; !newState.channelId) {<br>  sendiMessage(groupName, `${user} left the voice channel!`);<br> }<br>});<br><br>client.login(DISCORD_BOT_TOKEN);</pre><p>This script initializes a basic Discord Bot that listens for voice channel activity. When a user joins or leaves a channel, the bot executes an AppleScript command to send an iMessage.</p><p><strong>Finally: Running the Bot</strong></p><p>Now that everything is set up, start the bot by running:</p><pre>node index.js</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/782/1*XSjiXspkj8In8TlH5cVa8g.png" /></figure><p>You can test your bot by joining the discord channel your bot is in and — if working — you should see a message show up in the targeted group chat!</p><p><strong>The Hardships: Why Apple Makes This So Difficult</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*88Jo0J17h5q7hNag" /><figcaption>Photo by <a href="https://unsplash.com/@quaritsch?utm_source=medium&amp;utm_medium=referral">Quaritsch Photography</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>If Apple provided an iMessage API, this project would have taken minutes. Instead, I had to:</p><ul><li><strong>Use AppleScript</strong>, a language that feels outdated and clunky for modern development.</li><li><strong>Keep a Mac running at all times</strong>, which is costly and unnecessary when an SMS solution could be run from any cloud server.</li><li><strong>Deal with iMessage inconsistencies</strong>, such as Apple occasionally throttling messages or AppleScript commands failing sporadically.</li></ul><p><strong>Considering AWS Mac EC2 Instances</strong></p><p>Since I didn’t want my personal Mac to be running 24/7, I looked into hosting this on AWS using a macOS EC2 instance. However, the pricing was steep:</p><ul><li><strong>mac1.metal (Intel-based)</strong>: $1.083 per hour (~$26/day, ~$9,490/year)</li><li><strong>mac2.metal (M1-based)</strong>: $0.65 per hour (~$15.60/day, ~$5,694/year)</li></ul><p>At these prices, keeping a Mac mini running at home made more sense. Still, it’s ridiculous that such an expensive cloud solution is needed just to automate sending iMessages.</p><p><strong>The Alternative: Just Use SMS</strong></p><p>If this was just about sending a message, SMS would have been the obvious solution. Services like Twilio, Plivo, or even Google’s Messages API allow for seamless SMS automation. But since iMessage is locked down, Apple forces users into these frustrating workarounds.</p><p><strong>Final Thoughts</strong></p><p>This project started as a fun experiment, but quickly became a <strong>lesson in frustration</strong>. If Apple provided an official iMessage API, this could be done in minutes — <strong>without a full Mac running 24/7</strong>.</p><p>If Apple ever <strong>releases an API</strong>, I’ll be the first to switch. But until then, <strong>this is the best we’ve got</strong>.</p><p>Have you tried automating iMessage? Found a better workaround? Let me know! 🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c4170bd75493" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/building-an-imessage-discord-bot-on-macos-a-journey-of-workarounds-and-frustration-c4170bd75493">Building an iMessage Discord Bot: A Journey of Workarounds</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Arduino based SMS alert system (Life Alert inspired)]]></title>
            <link>https://blog.devgenius.io/arduino-based-sms-alert-system-life-alert-inspired-88ad3dc5129a?source=rss-574b77db85ab------2</link>
            <guid isPermaLink="false">https://medium.com/p/88ad3dc5129a</guid>
            <category><![CDATA[esp8266]]></category>
            <category><![CDATA[twilio]]></category>
            <category><![CDATA[iot]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[arduino]]></category>
            <dc:creator><![CDATA[Zach Young]]></dc:creator>
            <pubDate>Tue, 30 Jun 2020 07:55:42 GMT</pubDate>
            <atom:updated>2020-07-15T08:00:55.177Z</atom:updated>
            <content:encoded><![CDATA[<h4><em>This project is an example of how to use an ESP8266, a LM393 based sound sensor, and the Twilio API to send SMS alerts when the sensor has been triggered.</em></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qjfopLQv6igEMWS3iFhV1w.jpeg" /></figure><p>I found the current <a href="https://www.twilio.com/docs/sms/tutorials/how-to-send-sms-messages-esp8266-cpp">tutorial</a> in Twilio’s documentation to be moderately confusing on how to get it functioning on an ESP8266. Consequently, I decided to document the process for incorporating Twilio’s API into my project so that anyone wanting to do the same has a clear understanding of how to accomplish it. But first, a little background on how this project came to be.</p><h3>Background</h3><p>To understand the usefulness of this project you must first understand the circumstances that necessitated its creation.</p><p>My brother has a high-function form of autism called <a href="https://www.health.harvard.edu/newsletter_article/aspergers-syndrome">Aspergers</a>. In many cases, including his, people with this disorder can have <a href="https://www.autism.org.uk/about/behaviour/meltdowns.aspx">meltdowns</a>. In recent months the frequency and intensity of his meltdowns have increased dramatically. So much so, that on several occasions he has injured himself without knowing it in the moment. Many times these occur in the middle of the night when my parents are asleep. And though these meltdowns are usually associated with running, jumping, and screaming, often times it does not wake them up. Being able to intervene and give him something to help him calm down has become essential to prevent him for hurting himself. But if my parents aren’t awake to do this, how can they intervene?</p><p>In comes what I’ve deemed “Life Alert”.</p><p>Just like the actual Life Alert, this sensor sends out a notification to alert someone when it has been triggered. In the case of this system, because his meltdowns are always associated with screaming, when the sound sensor is triggered at a certain decibel level then the ESP8266 sends out an SMS via Twilio, to my parents, to alert them so that they can intervene.</p><p><em>This project can be adapted to use whatever sensor fits your needs. The emphasis, however, will be on how to integrate Twilio into your project.</em></p><h3>Materials Needed</h3><p><em>(1) ESP8266 <br>(1) LM393 Analog Sound Sensor<br>(3) Female to Female Jumper Wires <br>(Alternatively you could use plain wire, solder, and a soldering iron)<br>(1) Micro USB cable<br>(1) 5V Power Adapter</em></p><h3>Setup</h3><p>I am assuming you already have the Arduino IDE installed, but if not you can find it <a href="https://www.arduino.cc/en/Main/Software">here</a>.</p><p><em>I am using the ESP8266 which will require some configuration to work with Arduino. If you are using a different board the process may be slightly different.</em></p><p>First you need to download and install the driver that allows for communication with the ESP8266 over usb. The driver required may be different depending on your specific version of the ESP8266, so refer to the documentation that came with yours to determine the specific driver. Mine uses the CP2102 driver which you can find <a href="https://www.silabs.com/products/development-tools/software/usb-to-uart-bridge-vcp-drivers">here</a>.</p><p>Next you’ll need to add the ESP8266 to your boards manager in the Arduino IDE. In the IDE navigate to <strong>Preferences</strong> &gt; <strong>Additional Boards Manager URLs </strong>and<strong> </strong>paste in the following: <a href="http://arduino.esp8266.com/stable/package_esp8266com_index.json"><strong>http://arduino.esp8266.com/stable/package_esp8266com_index.json</strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PvxIeTJ8xDbySYomhRvlYw.png" /></figure><p>Now open the Boards Manager by going to <strong>Tools &gt; Board &gt; Board Manager</strong> and search for “<em>ESP8266</em>” and install the one by <strong>ESP8266 Community</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AyDFtEdf_b-Ao5nUgLac5Q.png" /></figure><p>Now you should be all setup for when it’s time to upload the code.</p><h3>Twilio</h3><p>To integrate SMS notifications via the Twilio API you will need to create an <a href="https://www.twilio.com/try-twilio">account</a>. After doing so you’ll need to create a new project and verify a phone number. Next, you’ll need a phone number to send messages. Click <strong>Get Trial Number </strong>in your project’s dashboard and choose a phone number.</p><p>Now go ahead and download Twilio’s project files for the ESP8266. You can find them <a href="https://github.com/TwilioDevEd/twilio_esp8266_arduino_example">here</a>. Once downloaded, rename the folder from <strong>twilio_esp8266_arduino_example-master</strong> to <strong>twilio_esp8266_arduino_example </strong>. While the change seems trivial, it’s important so the Arduino IDE can read the files correctly. Now open it in the Arduino IDE by going to <strong>File &gt; Open </strong>and navigate to the folder you just renamed. Open the file titled <strong>twilio_esp8266_arduino_example.ino</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d8zepdSl-s5mvCcex2_5Pw.png" /></figure><p>This is where you can customize the project to your hearts content. From setting active and non-active time periods to making POST requests to a custom API to store logs. But for the sake of simplicity I will show how to send a notification when the sensor is triggered.</p><p>The first thing you will want to do is configure the Wi-Fi settings. Change the <strong>ssid </strong>and<strong> password </strong>variables to your network name and password. Next, we need a valid <strong>fingerprint</strong>. This was one that took me a minute to figure out but it’s easy to get. In Chrome, go to <strong>api.twilio.com. </strong>Click on the<strong> lock icon &gt; Certificate.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YgglRZVfWj8-4NDmZffxdw.png" /></figure><p>Expand the<strong> details </strong>dropdown in the modal and scroll to the very bottom where it says <strong>fingerprints </strong>and copy the the value for the <strong>SHA-1</strong> key.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Fp5jI1Oqr5rJMLZswXLc7g.png" /></figure><p>Now paste that key in the <strong>fingerprint </strong>variable in your sketch.</p><p>Head back over to your Twilio project’s dashboard. You’ll need the <strong>trial number</strong>, <strong>account sid</strong>, and <strong>auth token. </strong>Paste them into the<strong> from_number, account_sid, </strong>and<strong> auth_token </strong>variables respectively.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GGxNQCK_dpFkG8-KFt_hFw.png" /></figure><p>You’ll also want to provide a phone number in the <strong>to_number</strong> variable, to receive these text messages.</p><p><strong>NOTE: </strong><em>If you are using the trial version of Twilio for your project, only </em><strong>verified numbers</strong><em> can receive SMS messages. By default the number you used to sign up is already verified. If you wish to send messages to a number other than the one you signed up with, you will need to add that phone number to the </em><strong>verified numbers </strong>section of your project dashboard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3Z034TPBAoetVpaTcOGvww.png" /></figure><h3>Code</h3><p>For this example I am only demonstrating how to send messages, so I have gone ahead and removed any unnecessary code that doesn’t pertain to outgoing messages. The sketch can be found below.</p><p><em>If you are following along with an ESP8266 and sound sensor, you’ll want to connect the sensor to +3.3v, ground, and GPIO pin 4 (D2) on the ESP8266.</em></p><pre>/*<br> * Twilio SMS and MMS on ESP8266 Example.<br> */</pre><pre>#include &lt;ESP8266WiFi.h&gt;<br>#include &lt;WiFiClientSecure.h&gt;<br>#include &lt;ESP8266WebServer.h&gt;</pre><pre>#include &quot;twilio.hpp&quot;</pre><pre>// Use software serial for debugging?<br>#define USE_SOFTWARE_SERIAL 0</pre><pre>// Print debug messages over serial?<br>#define USE_SERIAL 1</pre><pre>// Your network SSID and password<br>const char* ssid = &quot;The_Sailboat&quot;;<br>const char* password = &quot;club848!&quot;;</pre><pre>// Find the api.twilio.com SHA1 fingerprint, this one was valid as <br>// of August 2019.<br>const char fingerprint[] = &quot;06 86 86 C0 A0 ED 02 20 7A 55 CC F0 75 BB CF 24 B1 D9 C0 49&quot;;</pre><pre>// Twilio account specific details, from <a href="https://twilio.com/console">https://twilio.com/console</a><br>// Please see the article: <br>// <a href="https://www.twilio.com/docs/guides/receive-and-reply-sms-and-mms-messages-esp8266-c-and-ngrok">https://www.twilio.com/docs/guides/receive-and-reply-sms-and-mms-messages-esp8266-c-and-ngrok</a></pre><pre>// If this device is deployed in the field you should only deploy a revocable<br>// key. This code is only suitable for prototyping or if you retain physical<br>// control of the installation.<br>const char* account_sid = &quot;ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&quot;;<br>const char* auth_token = &quot;Your AUTH TOKEN&quot;;</pre><pre>// Details for the SMS we&#39;ll send with Twilio.  Should be a number you own <br>// (check the console, link above).<br>String to_number    = &quot;+18005551212&quot;;<br>String from_number = &quot;+18005551212&quot;;<br>String message_body    = &quot;Hello from Twilio and the ESP8266!&quot;;</pre><pre>// The &#39;authorized number&#39; to text the ESP8266 for our example<br>//String master_number    = &quot;+18005551212&quot;;</pre><pre>// Optional - a url to an image.  See &#39;MediaUrl&#39; here: <br>// <a href="https://www.twilio.com/docs/api/rest/sending-messages">https://www.twilio.com/docs/api/rest/sending-messages</a><br>//String media_url = &quot;&quot;;</pre><pre>// Global twilio objects<br>Twilio *twilio;<br>ESP8266WebServer twilio_server(8000);</pre><pre>//  Optional software serial debugging<br>#if USE_SOFTWARE_SERIAL == 1<br>#include &lt;SoftwareSerial.h&gt;<br>// You&#39;ll need to set pin numbers to match your setup if you<br>// do use Software Serial<br>extern SoftwareSerial swSer(14, 4, false, 256);<br>#else<br>#define swSer Serial<br>#endif</pre><pre>//initialize sensor on GPIO pin 4<br>int micPin = 4;</pre><pre>/* Setup function for ESP8266 Twilio Example.<br> * Here we connect to a friendly wireless network, set the time, instantiate <br> * our twilio object, optionally set up software serial, then send a SMS <br> * or MMS message.<br> */<br>void setup() {<br>        WiFi.begin(ssid, password);<br>        twilio = new Twilio(account_sid, auth_token, fingerprint);</pre><pre>#if USE_SERIAL == 1<br>        swSer.begin(115200);<br>        while (WiFi.status() != WL_CONNECTED) {<br>                delay(1000);<br>                swSer.print(&quot;.&quot;);<br>        }<br>        swSer.println(&quot;&quot;);<br>        swSer.println(&quot;Connected to WiFi, IP address: &quot;);<br>        swSer.println(WiFi.localIP());<br>        #else<br>        while (WiFi.status() != WL_CONNECTED) delay(1000);<br>        #endif      <br>}<br>void loop() {<br>        //if sensor is triggered send a notification<br>        if (digitalRead(micPin) == LOW){<br>        // Response will be filled with connection info and Twilio API responses<br>        // from this initial SMS send.<br>        String response;<br>        twilio-&gt;send_message(<br>                to_number,<br>                from_number,<br>                message_body,<br>                response,<br>                media_url<br>        );<br>        swSer.println(response);<br>        delay(100);<br>        }<br>}</pre><p>And that’s it! This loop will continuously run and if it senses the <strong>micPin </strong>get triggered<strong> </strong><em>(go LOW) </em>then it will fire off a SMS message to the <strong>to_number</strong> you provided.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2qydzuOYRhyX_j3Vj6kC3g.png" /></figure><h3>Next Steps</h3><p>As previously noted, there are many ways to modify this project to make it fit your needs, but this is simply a boilerplate to get you up and running with Twilio so you can integrate into your own projects.</p><p>If there is any interest in creating a Full Stack application to log the data and display it I will create a <strong>Part 2 </strong>to this tutorial.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=88ad3dc5129a" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/arduino-based-sms-alert-system-life-alert-inspired-88ad3dc5129a">Arduino based SMS alert system (Life Alert inspired)</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>