<?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" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ Internet of Things - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ Internet of Things - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Tue, 02 Jun 2026 21:43:19 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/internet-of-things/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ How to Set Up Zigbee2MQTT with Docker for Home Automation ]]>
                </title>
                <description>
                    <![CDATA[ Zigbee2MQTT is an open-source tool that lets you manage all of your Zigbee devices locally, so you don’t need cloud services or multiple proprietary hubs. This gives you more control and flexibility, whether used on its own or integrated with platfor... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-set-up-zigbee2mqtt-with-docker/</link>
                <guid isPermaLink="false">673c8cdcb7f79bc9aa2f300f</guid>
                
                    <category>
                        <![CDATA[ Internet of Things ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Docker ]]>
                    </category>
                
                    <category>
                        <![CDATA[ iot ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Joyce Lin ]]>
                </dc:creator>
                <pubDate>Tue, 19 Nov 2024 13:04:28 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/res/hashnode/image/upload/v1731778246828/8371f4de-6771-4f57-9e2c-9c57ad651950.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p><a target="_blank" href="https://www.zigbee2mqtt.io/">Zigbee2MQTT</a> is an open-source tool that lets you manage all of your <a target="_blank" href="https://en.wikipedia.org/wiki/Zigbee">Zigbee</a> devices locally, so you don’t need cloud services or multiple proprietary hubs. This gives you more control and flexibility, whether used on its own or integrated with platforms like <a target="_blank" href="https://www.home-assistant.io/">Home Assistant</a> or <a target="_blank" href="https://nodered.org/">Node-RED</a>.</p>
<p>In this guide, I’ll show you how to set it up using <a target="_blank" href="https://www.docker.com/">Docker</a> for a streamlined, privacy-focused smart home. Docker provides an efficient way to run Zigbee2MQTT as a standalone service, offering a lightweight, modular setup – no Home Assistant required.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1731723376381/d983ba57-72ba-4e06-b994-c6b30ad36ca5.png" alt="Diagram showing the integration of Zigbee devices into a local network using Raspberry Pi" class="image--center mx-auto" width="1280" height="500" loading="lazy"></p>
<h2 id="heading-table-of-contents">Table of Contents</h2>
<ul>
<li><p><a class="post-section-overview" href="#heading-key-iot-concepts-in-this-tutorial">Key IoT Concepts in this Tutorial</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-what-youll-need">What You’ll Need</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-what-youll-do">What You’ll Do</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-how-to-prepare-your-environment">How to Prepare Your Environment</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-how-to-set-up-the-zigbee2mqtt-configuration">How to Set Up the Zigbee2MQTT Configuration</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-how-to-set-up-zigbee2mqtt-and-mqtt-broker-in-docker">How to Set up Zigbee2MQTT and MQTT Broker in Docker</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-launch-the-containers">Launch the Containers</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-pair-your-zigbee-devices">Pair Your Zigbee devices</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-how-to-create-an-automation-script">How to Create an Automation Script</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-whats-next">What’s Next?</a></p>
</li>
</ul>
<h2 id="heading-key-iot-concepts-in-this-tutorial">Key IoT Concepts in this Tutorial</h2>
<p>Here are the key concepts related to the Internet of Things (IoT) and smart homes that you’ll be working with:</p>
<ul>
<li><p><a target="_blank" href="https://en.wikipedia.org/wiki/Zigbee">Zigbee</a> is a wireless communication protocol used in smart home devices. It relies on a Zigbee coordinator to communicate with devices like lights, sensors, and switches within a local mesh network. This network allows devices to relay signals to extend coverage and reliability.</p>
</li>
<li><p><a target="_blank" href="https://en.wikipedia.org/wiki/MQTT">MQTT (Message Queuing Telemetry Transport)</a> is a lightweight messaging protocol for low-bandwidth and high-latency environments. It uses an MQTT broker to manage communication between devices using a publish/subscribe (pub/sub) model, where devices can either send or receive messages based on specific topics.</p>
</li>
<li><p><a target="_blank" href="https://www.zigbee2mqtt.io/">Zigbee2MQTT</a> is a bridge application that connects Zigbee devices to an MQTT broker. It translates Zigbee signals into MQTT messages, and vice versa. Zigbee2MQTT supports a wide range of devices from different manufacturers.</p>
</li>
</ul>
<h2 id="heading-what-youll-need"><strong>What You’ll Need</strong></h2>
<ol>
<li><p>A Zigbee coordinator connected to your network or device. I have an <a target="_blank" href="https://smlight.tech/product/slzb-06/">SLZB-06</a> ($65 USD) connected to my network.</p>
</li>
<li><p>A device capable of running Docker, such as a Raspberry Pi or Linux server. I flashed a Raspberry Pi 4 - Model B.</p>
</li>
</ol>
<h2 id="heading-how-to-prepare-your-environment"><strong>How to Prepare Your Environment</strong></h2>
<ol>
<li><p>SSH into your Pi using the following command in your terminal window, where <code>pi</code> is the username of your Raspberry Pi OS and <code>&lt;RaspberryPi_IP&gt;</code> is the IP address of your Raspberry Pi on your local network.</p>
<pre><code class="lang-bash"> ssh pi@&lt;RaspberryPi_IP&gt;
</code></pre>
</li>
<li><p>Install Docker by inputting the following command at the SSH prompt.</p>
<pre><code class="lang-bash"> curl -sSL https://get.docker.com | sh
</code></pre>
</li>
<li><p>Give permissions to the current logged in user. You may then need to close the SSH connection, and re-connect, if the permissions hasn’t taken effect.</p>
<pre><code class="lang-bash"> sudo usermod -aG docker <span class="hljs-variable">$USER</span>
</code></pre>
</li>
</ol>
<h2 id="heading-how-to-set-up-the-zigbee2mqtt-configuration">How to Set Up the Zigbee2MQTT Configuration</h2>
<ol>
<li><p>Create a new project directory, and also a <code>/data</code> directory to store configuration files and data persistently.</p>
<pre><code class="lang-bash"> mkdir -p ~/zigbee2mqtt/data
</code></pre>
</li>
<li><p>Create the configuration file.</p>
<pre><code class="lang-bash"> touch ~/zigbee2mqtt/data/configuration.yaml
</code></pre>
</li>
<li><p>Open file with your preferred text editor, like using <code>nano</code> as shown below.</p>
<pre><code class="lang-bash"> nano ~/zigbee2mqtt/data/configuration.yaml
</code></pre>
</li>
<li><p>Paste the following YAML code into the configuration file from the text editor interface.</p>
<pre><code class="lang-yaml"> <span class="hljs-attr">homeassistant:</span> <span class="hljs-literal">false</span>
 <span class="hljs-attr">permit_join:</span> <span class="hljs-literal">false</span>
 <span class="hljs-attr">mqtt:</span>
   <span class="hljs-attr">base_topic:</span> <span class="hljs-string">zigbee2mqtt</span>
   <span class="hljs-attr">server:</span> <span class="hljs-string">'mqtt://mqtt:1883'</span>
 <span class="hljs-attr">serial:</span>
   <span class="hljs-attr">port:</span> <span class="hljs-string">'tcp://&lt;IP_OF_ZIGBEE_COORDINATOR&gt;:&lt;PORT&gt;'</span>
 <span class="hljs-attr">frontend:</span>
   <span class="hljs-attr">port:</span> <span class="hljs-number">8080</span>
</code></pre>
</li>
<li><p>Update the following details within the <code>configuration.yaml</code> file, and save the changes.</p>
<ul>
<li><p><code>&lt;MQTT_BROKER_IP&gt;</code>: Your MQTT broker's IP or hostname.</p>
</li>
<li><p><code>port</code>: This value depends on how your Zigbee coordinator is connected:</p>
<ul>
<li><p>If your Zigbee coordinator is connected to the network, you can configure the <code>port</code> using TCP/IP as shown in the example above, for example <code>tcp://192.168.1.xxx:6638</code> where the SLZB-06 is located at <code>192.168.1.xxx</code> on the local network and <code>6638</code> is the default port for that Zigbee coordinator.</p>
</li>
<li><p>If the Zigbee coordinator is connected to your device, you can find the serial port (such as <code>/dev/ttyUSB0</code>) by running <code>ls /dev/tty*</code> before and after plugging in the adapter to your device.</p>
</li>
</ul>
</li>
</ul>
</li>
</ol>
<h2 id="heading-how-to-set-up-zigbee2mqtt-and-mqtt-broker-in-docker">How to Set up Zigbee2MQTT and MQTT Broker in Docker</h2>
<ol>
<li><p>In the root of your project directory, create a <code>docker-compose.yaml</code> file to set up the <a target="_blank" href="https://hub.docker.com/r/koenkk/zigbee2mqtt/">Zigbee2MQTT container</a> and <a target="_blank" href="https://hub.docker.com/_/eclipse-mosquitto">Eclipse Mosquitto broker container</a> to handle communication between Zigbee2MQTT and other services.</p>
<pre><code class="lang-yaml"> <span class="hljs-attr">services:</span>
   <span class="hljs-attr">zigbee2mqtt:</span>
     <span class="hljs-attr">container_name:</span> <span class="hljs-string">zigbee2mqtt</span>
     <span class="hljs-attr">image:</span> <span class="hljs-string">koenkk/zigbee2mqtt</span>
     <span class="hljs-attr">restart:</span> <span class="hljs-string">unless-stopped</span>
     <span class="hljs-attr">volumes:</span>
       <span class="hljs-bullet">-</span> <span class="hljs-string">./data:/app/data</span>
       <span class="hljs-bullet">-</span> <span class="hljs-string">/run/udev:/run/udev:ro</span>
     <span class="hljs-attr">ports:</span>
       <span class="hljs-comment"># Frontend port</span>
       <span class="hljs-bullet">-</span> <span class="hljs-number">8080</span><span class="hljs-string">:8080</span>
     <span class="hljs-attr">environment:</span>
       <span class="hljs-bullet">-</span> <span class="hljs-string">TZ=American/Los_Angeles</span>
   <span class="hljs-attr">mqtt:</span>
     <span class="hljs-attr">image:</span> <span class="hljs-string">eclipse-mosquitto:2.0</span>
     <span class="hljs-attr">restart:</span> <span class="hljs-string">unless-stopped</span>
     <span class="hljs-attr">volumes:</span>
       <span class="hljs-bullet">-</span> <span class="hljs-string">"./mosquitto:/mosquitto"</span>
     <span class="hljs-attr">ports:</span>
       <span class="hljs-bullet">-</span> <span class="hljs-string">"1883:1883"</span>
       <span class="hljs-bullet">-</span> <span class="hljs-string">"9001:9001"</span>
     <span class="hljs-attr">command:</span> <span class="hljs-string">"mosquitto -c /mosquitto-no-auth.conf"</span>
</code></pre>
</li>
<li><p>Update the <code>TZ</code> environment variable if you are located in a different time zone, and save any changes.</p>
</li>
</ol>
<h2 id="heading-launch-the-containers"><strong>Launch the Containers</strong></h2>
<ol>
<li><p>Run the containers.</p>
<pre><code class="lang-bash"> docker compose up -d
</code></pre>
</li>
<li><p>Test the setup by checking the logs to confirm Zigbee2MQTT is running without errors. And look for lines indicating successful connection to the MQTT broker and Zigbee network initialization.</p>
<pre><code class="lang-bash"> docker compose logs
</code></pre>
</li>
</ol>
<h2 id="heading-pair-your-zigbee-devices"><strong>Pair Your Zigbee devices</strong></h2>
<ol>
<li><p>Once Zigbee2MQTT is running smoothly, you can access the frontend at <code>http://&lt;your-device-IP&gt;:8080</code> from a web browser to pair and manage your Zigbee devices.</p>
</li>
<li><p>Enable pairing by clicking <strong>Permit Join (all)</strong>, and then pair your devices by putting them in pairing mode, for example holding down a reset button.</p>
</li>
<li><p>Finish pairing all the Zigbee devices that you wish to use in an automation. In the screenshot below, I have paired an Aqara button and Third Reality smart plug.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1731775615109/616320a6-77d0-4d14-813e-7dfde9fb8f0a.png" alt="Aqara button and Third Reality smart plug in the Zigbee2MQTT frontend" class="image--center mx-auto" width="2888" height="836" loading="lazy"></p>
</li>
<li><p>Give your devices a friendly name by using the pencil icon. Make sure to choose a unique name to avoid messaging conflicts in the following steps. For example, if you have 2 smart plugs, you can name them <code>smart-plug-bedroom</code> and <code>smart-plug-office</code>.</p>
</li>
</ol>
<p>MQTT brokers follow a pub/sub messaging pattern which involves the following:</p>
<ul>
<li><p><strong>Subscribing to MQTT topics</strong> like <code>zigbee2mqtt/aqara-button</code> to monitor device states like listening for button presses.</p>
</li>
<li><p><strong>Publishing to MQTT topics</strong> like <code>zigbee2mqtt/third-reality/set</code> to send commands to devices like a smart plug to turn on a light.</p>
</li>
</ul>
<p>A topic such as <code>zigbee2mqtt/third-reality/set</code> is broken down into 3 parts:</p>
<ul>
<li><p><code>zigbee2mqtt</code> refers to the base topic (default for Zigbee2MQTT is <code>zigbee2mqtt</code>).</p>
</li>
<li><p><code>third-reality</code> refers to a specific device or group using the friendly name shown in the Zigbee2MQTT frontend.</p>
</li>
<li><p><code>set</code> allows you to control the device or group using a JSON message such as <code>{"state": "TOGGLE"}</code>.</p>
</li>
</ul>
<ol>
<li><p>Input the following command to see the MQTT messages being published to Zigbee2MQTT.</p>
<pre><code class="lang-bash"> docker logs -f zigbee2mqtt
</code></pre>
</li>
<li><p>Complete an action on a Zigbee device, for example pushing a button, and make a note of which topics you want to utilize in your automation for the next steps. For example, in the screenshot of the logs below, there is an MQTT topic published called <code>zigbee2mqtt/Aqara</code> when the Aqara button is pressed.</p>
</li>
</ol>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1731550585620/2f043360-75e1-4ef8-9549-a6bfe576ceb0.png" alt="Logs from pressing the Agara button" class="image--center mx-auto" width="2162" height="86" loading="lazy"></p>
<h2 id="heading-how-to-create-an-automation-script"><strong>How to Create an Automation Script</strong></h2>
<p>To set up an automation, you can use an external system like Home Assistant or Node-RED, or use Zigbee2MQTT’s <a target="_blank" href="https://www.zigbee2mqtt.io/guide/configuration/more-config-options.html#external-converters">external converters</a> to respond to MQTT messages from the broker.</p>
<p>You won’t be doing that. Instead, let’s write a JavaScript script to handle this automation, to keep the functionality modular and independent.</p>
<ol>
<li><p>From the command line prompt of your terminal window, install the NodeSource setup script on your Raspberry Pi.</p>
<pre><code class="lang-bash"> curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
</code></pre>
</li>
<li><p>Install <a target="_blank" href="https://nodejs.org/en/download/package-manager">Node.js</a> to use as the runtime for your script.</p>
<pre><code class="lang-bash"> sudo apt install -y nodejs
</code></pre>
</li>
<li><p>Verify the installation went smoothly by showing the installed version.</p>
<pre><code class="lang-bash"> node -v
</code></pre>
</li>
<li><p>Install <a target="_blank" href="https://www.npmjs.com/package/mqtt">MQTT.js</a>, the MQTT client library for Node.js.</p>
<pre><code class="lang-bash"> npm install mqtt
</code></pre>
</li>
<li><p>Create a file called <code>automation.js</code> to contain the automation script. In this example, you can run the script on the Raspberry Pi. However, the file can be placed anywhere and doesn’t even need to run on the same device as the MQTT broker. As long as the program can connect to the MQTT broker over the local network, it will function correctly.</p>
<pre><code class="lang-bash"> touch automation.js
</code></pre>
</li>
<li><p>Open the file with your preferred text editor, like Nano shown here.</p>
<pre><code class="lang-bash"> nano automation.js
</code></pre>
</li>
<li><p>Paste the following code into the file.</p>
<pre><code class="lang-javascript"> <span class="hljs-keyword">const</span> mqtt = <span class="hljs-built_in">require</span>(<span class="hljs-string">'mqtt'</span>);

 <span class="hljs-comment">// MQTT broker connection details</span>
 <span class="hljs-keyword">const</span> MQTT_BROKER = <span class="hljs-string">'mqtt://localhost'</span>; <span class="hljs-comment">// Replace with your broker's address</span>
 <span class="hljs-keyword">const</span> BUTTON_TOPIC = <span class="hljs-string">'zigbee2mqtt/aqara-button'</span>; <span class="hljs-comment">// Replace with your button's topic</span>
 <span class="hljs-keyword">const</span> PLUG_TOPIC = <span class="hljs-string">'zigbee2mqtt/third-reality'</span>; <span class="hljs-comment">// Replace with your plug's topic</span>

 <span class="hljs-comment">// Connect to the MQTT broker</span>
 <span class="hljs-keyword">const</span> client = mqtt.connect(MQTT_BROKER);

 <span class="hljs-comment">// Handle connection events</span>
 client.on(<span class="hljs-string">'connect'</span>, <span class="hljs-function">() =&gt;</span> {
     <span class="hljs-built_in">console</span>.log(<span class="hljs-string">'Connected to MQTT broker'</span>);
     <span class="hljs-comment">// Subscribe to the button's topic</span>
     client.subscribe(BUTTON_TOPIC, <span class="hljs-function">(<span class="hljs-params">err</span>) =&gt;</span> {
         <span class="hljs-keyword">if</span> (!err) {
             <span class="hljs-built_in">console</span>.log(<span class="hljs-string">`Subscribed to topic: <span class="hljs-subst">${BUTTON_TOPIC}</span>`</span>);
         } <span class="hljs-keyword">else</span> {
             <span class="hljs-built_in">console</span>.error(<span class="hljs-string">`Failed to subscribe to topic: <span class="hljs-subst">${BUTTON_TOPIC}</span>`</span>, err);
         }
     });
 });

 <span class="hljs-comment">// Handle incoming messages</span>
 client.on(<span class="hljs-string">'message'</span>, <span class="hljs-function">(<span class="hljs-params">topic, message</span>) =&gt;</span> {
     <span class="hljs-keyword">if</span> (topic === BUTTON_TOPIC) {
         <span class="hljs-keyword">try</span> {
             <span class="hljs-keyword">const</span> payload = <span class="hljs-built_in">JSON</span>.parse(message.toString());
             <span class="hljs-built_in">console</span>.log(<span class="hljs-string">'Received message:'</span>, payload);
             <span class="hljs-keyword">const</span> desiredAction = payload.action;

             <span class="hljs-comment">// Check for possible actions</span>
             <span class="hljs-keyword">if</span> (desiredAction === <span class="hljs-string">'single'</span>) {
                 <span class="hljs-comment">// Send a message to the plug's topic to toggle the switch</span>
                 client.publish(<span class="hljs-string">`<span class="hljs-subst">${PLUG_TOPIC}</span>/set`</span>, <span class="hljs-built_in">JSON</span>.stringify({<span class="hljs-string">"state"</span>: <span class="hljs-string">"TOGGLE"</span>}));
                 <span class="hljs-built_in">console</span>.log(<span class="hljs-string">'Toggling the switch'</span>)
             } <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (desiredAction === <span class="hljs-string">'double'</span>) {
                 <span class="hljs-comment">// Send a message to the plug's topic to turn off the switch</span>
                 client.publish(<span class="hljs-string">`<span class="hljs-subst">${PLUG_TOPIC}</span>/set`</span>, <span class="hljs-built_in">JSON</span>.stringify({ <span class="hljs-attr">state</span>: <span class="hljs-string">'OFF'</span> }));
                 <span class="hljs-built_in">console</span>.log(<span class="hljs-string">'Turning off the switch'</span>)
             }
         } <span class="hljs-keyword">catch</span> (err) { 
             <span class="hljs-built_in">console</span>.error(<span class="hljs-string">'Failed to parse message:'</span>, err.message);
         }           

     }
 });

 <span class="hljs-comment">// Handle errors</span>
 client.on(<span class="hljs-string">'error'</span>, <span class="hljs-function">(<span class="hljs-params">err</span>) =&gt;</span> {
     <span class="hljs-built_in">console</span>.error(<span class="hljs-string">'MQTT error:'</span>, err);
 });
</code></pre>
<p> This script connects to the MQTT broker and subscribes to the button’s topic (<code>zigbee2mqtt/aqara-button</code>). When a message is received, it examines the payload. If the action is a single click (<code>single</code>), the script sends a toggle command (<code>{state: "TOGGLE"}</code>) to the plug’s topic (<code>zigbee2mqtt/third-reality/set</code>), toggling the plug’s state. A <code>double</code> action turns the plug off.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1731777295907/11549e51-c2f9-44cd-af73-a0ba97eeda1e.png" alt="MQTT pub/sub messaging pattern" class="image--center mx-auto" width="1280" height="500" loading="lazy"></p>
<p> Update the MQTT broker connection and topic details at the top of the script as needed to accommodate your own Zigbee devices, and save your changes.</p>
</li>
<li><p>Run the script from the terminal prompt.</p>
<pre><code class="lang-bash"> node automation.js
</code></pre>
</li>
<li><p>Test the setup by pressing the button. The script should log the button action and send a command to toggle on the smart plug. Check the MQTT broker logs if the light doesn’t turn on.</p>
</li>
<li><p>Optional*:* Once the script is working as expected, there are a few more optional steps to make sure the script restarts during reboots. Install a process manager like <a target="_blank" href="https://www.npmjs.com/package/pm2">PM2</a> from the command line prompt of the Raspberry Pi.</p>
<pre><code class="lang-bash">sudo npm install -g pm2
</code></pre>
</li>
<li><p>Start the script again.</p>
<pre><code class="lang-bash">pm2 start automation.js
</code></pre>
</li>
<li><p>Your app should now be daemonized, running in the background, and kept alive forever. Generate and configure a startup script to keep PM2 and your processes alive at every server restart.</p>
<pre><code class="lang-bash">pm2 startup
</code></pre>
</li>
<li><p>Copy and paste the command exactly as shown in the terminal output, and run the suggested command.</p>
</li>
<li><p>Save the process list so PM2 can restore it after a system reboot.</p>
<pre><code class="lang-bash">pm2 save
</code></pre>
</li>
</ol>
<h2 id="heading-whats-next"><strong>What’s Next?</strong></h2>
<p>Now that you’ve created a custom automation, there are more ways to grow your home automation setup.</p>
<ul>
<li><p><strong>Explore more Zigbee devices</strong>: Zigbee2MQTT supports <a target="_blank" href="https://www.zigbee2mqtt.io/supported-devices/">a wide range of devices</a> from various manufacturers.</p>
</li>
<li><p><strong>Add custom behaviors</strong>: Use Zigbee2MQTT’s <a target="_blank" href="https://www.zigbee2mqtt.io/guide/configuration/more-config-options.html#external-converters">external converters</a> to define unique functionality for both supported and unsupported devices.</p>
</li>
<li><p><strong>Scale your setup</strong>: This flexible, lightweight setup is good for beginners and power users alike, who don’t want to get locked into proprietary smart home platforms or cloud services.</p>
</li>
</ul>
<p>If you found this tutorial helpful, don’t forget to check out <a target="_blank" href="https://github.com/loopDelicious/home-automation/blob/main/README.md">my recommended Home Automation hardware</a> and <a target="_blank" href="https://www.youtube.com/@joycejetson">how-to videos on YouTube</a> for more inspiration!</p>
<p>You can watch the video version of this article here:</p>
<div class="embed-wrapper">
        <iframe width="560" height="315" src="https://www.youtube.com/embed/mGg_9FjDKHQ" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="YouTube video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen="" loading="lazy"></iframe></div>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Podcast: Hardware Engineering with Bruno Haid ]]>
                </title>
                <description>
                    <![CDATA[ On this week's episode of the freeCodeCamp Podcast, I interview hardware engineer and tech founder from Austria. We talk about growing up in the European countryside, his early passion for computers, and ultimately his move to San Francisco, where he... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/podcast-hardware-engineering-bruno-haid/</link>
                <guid isPermaLink="false">66b8d5148cd1c2aa053d499a</guid>
                
                    <category>
                        <![CDATA[ embedded systems ]]>
                    </category>
                
                    <category>
                        <![CDATA[ hardware ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Internet of Things ]]>
                    </category>
                
                    <category>
                        <![CDATA[ podcast ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Quincy Larson ]]>
                </dc:creator>
                <pubDate>Fri, 24 Nov 2023 21:17:27 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/11/signal-2023-11-24-141140_002_jpeg.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>On this week's episode of the freeCodeCamp Podcast, I interview hardware engineer and tech founder from Austria.</p>
<p>We talk about growing up in the European countryside, his early passion for computers, and ultimately his move to San Francisco, where he's founded several tech companies.</p>
<p>Bruno's super excited about embedded systems and custom hardware. He's building home appliances that incorporate open source software and open datasets.</p>
<p>We cover so many topics here. From Star Trek to the European Pirate Party.</p>
<p>I hope these weekly freeCodeCamp podcasts are firing you up about learning more about technology.</p>
<p>Be sure to follow The freeCodeCamp podcast in your favorite podcast app. And share this podcast with a friend. Let's inspire more folks to learn to code and build careers for themselves in tech.</p>
<p>You can listen to the podcast in Apple Podcasts, Spotify, or your favorite podcast app. You can also listen to the podcast below, right in your browser:</p>
<div class="embed-wrapper"><iframe src="https://play.libsyn.com/embed/episode/id/28783273/height/192/theme/modern/size/large/thumbnail/yes/custom-color/34345c/time-start/00:00:00/playlist-height/200/direction/backward/download/yes" height="192" width="100%" style="border:none" title="Embedded content" loading="lazy"></iframe></div>



<p>A couple interesting links from our discussion: </p>
<ul>
<li><a target="_blank" href="https://www.youtube.com/watch?v=PWeO5IkCssk">"Only Amiga" song from Comdex 1987</a></li>
<li><a target="_blank" href="https://www.youtube.com/watch?v=pWrioRji60A">Halt and Catch Fire TV Show trailer</a></li>
</ul>
<p>And here are some bonus photos from my time at Bruno's house in NYC:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/11/Bruno_s_office_jpeg.png" alt="Image" width="600" height="400" loading="lazy">
<em>Bruno at work in his office</em></p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/11/A_project_by_Bruno_jpeg.png" alt="Image" width="600" height="400" loading="lazy">
<em>A hardware project Bruno had prototyped in his bedroom. (This is the photo that I mentioned during the interview that I had snuck in to snap.)</em></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Digital Connectivity – How We Connect to the Internet and IoT Explained ]]>
                </title>
                <description>
                    <![CDATA[ Telephones changed the way we all talked to each other and went about our work (well, the way our great-grandparents did, at any rate). Information could now be communicated instantly, rather than being sent over slow, overland routes.  But that's ha... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/digital-connectivity-internet-and-iot-explained/</link>
                <guid isPermaLink="false">66b995d33cd81de09c96b28a</guid>
                
                    <category>
                        <![CDATA[ internet ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Internet of Things ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ David Clinton ]]>
                </dc:creator>
                <pubDate>Tue, 24 Jan 2023 17:08:41 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/01/pexels-andrea-piacquadio-935743.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Telephones changed the way we all talked to each other and went about our work (well, the way our great-grandparents did, at any rate). Information could now be communicated instantly, rather than being sent over slow, overland routes. </p>
<p>But that's hardly news to anyone these days. The modern network – best known through its internet iteration – similarly boosted communication, although this time it was the movement of data rather than voice that got a boost.</p>
<p>In the fifty years or so since the birth of the internet, it's been trusted with the movement, storage, and management of more and more of our data. </p>
<p>These changes have brought tremendous opportunities, risks, and pressures. Just getting connected is now a basic necessity. Managing all of our many connected devices and leveraging the ways we authenticate to extend our identities also present challenges. We'll discuss all that here.</p>
<p>This article was taken from the book, <a target="_blank" href="https://amzn.to/3FXXAfb">Keeping Up: Backgrounders to All the Big Technology Trends You Can't Afford to Ignore</a>. If you'd prefer to watch this chapter as a video, feel free to follow along here:</p>
<div class="embed-wrapper">
        <iframe width="560" height="315" src="https://www.youtube.com/embed/FnTCMZFe2ww" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="YouTube video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen="" loading="lazy"></iframe></div>
<h1 id="heading-how-we-connect-to-the-internet">How We Connect to the Internet</h1>
<p>These days, after food and shelter, pretty much the most basic resource of all is internet connectivity. If you can't access the internet, you'll find it difficult to do your banking, educate yourself, book travel arrangements, or even figure out exactly where you are. </p>
<p>It's not for nothing that widespread, reliable, and relatively fast internet access is critical for a region's general economic development.</p>
<p>Even though the internet was originally build as a decentralized, distributed network of resources, you still need to establish some kind of connection to access it. </p>
<p>The best connections are run by network carriers, known as <em>tier 1 networks.</em> Theses networks can reach all other networks through a peering arrangement that doesn't require payment for IP transit. You can think of these networks as the backbone of the internet, and their network infrastructure is its structure.</p>
<p>Examples of companies managing tier 1 networks include AT&amp;T and Verizon in the US, Tata Communications (India), and Deutsche Telekom (Germany). Those carriers will resell bandwidth to smaller internet service providers (ISPs) who, in turn, sell access to end users like you and me.</p>
<h2 id="heading-broadband-options">Broadband Options</h2>
<p>Individuals looking for broadband access in their homes or small businesses can usually choose between one of four access models:</p>
<ul>
<li><strong>Cable</strong>. Since they're already in the business of providing data to millions of homes over existing physical connections, cable TV providers can easily transmit internet over the same wires.</li>
<li><strong>Digital subscriber line (DSL)</strong>. A family of technologies that permit digital data across copper telephone lines, DSL can provide a roughly similar level of service as cable, but without the need for an underlying cable subscription. In fact, using a "dry copper" connection, you don't even need a telephone landline account.</li>
<li><strong>Fibre optics</strong>. Due to some arcane technical details (including the laws of physics), transmitting digital signals as infrared light can happen faster and require fewer repeaters than comparable electrical cables. A fibre optics internet connection could typically deliver transfer speeds of 10-40Gbit/s – a thousand times faster than currently standard rates using cable or DSL.</li>
<li><strong>Satellite</strong>. Running new cable through densely populated cities is expensive, but companies can quickly make their money back through the many access contracts they'll sign. But sparsely populated rural regions are much more difficult to service. Partly to fill a rural connectivity gap, a number of companies ambitiously working to launch constellations of thousands of orbiting satellites to provide universal internet coverage. As of this writing, SpaceX is furthest along with its project, having already successfully launched more than 500 satellites as part of the Starlink system.</li>
</ul>
<p>Besides those dominant technologies, there have been more than a few alternate connectivity solutions attempted. Some are experimental but promising, and others are a bit more speculative. </p>
<p>Google's Balloon Internet (known officially as Loon LLC), is an attempt to float fleets of high-altitude balloons providing a 1 Mbps signal to anyone within range on the ground. </p>
<p>Loon is designed to provide low-end broadband in hard-to-reach regions where reliable service has been difficult or even impossible. As of 2020, the project seems to be in a late experimental stage.</p>
<p>Broadband over power line (BPL) can take advantage of all the electrical grid that connects power authorities with homes and businesses to provide internet data. Ultimately, the technology delivers limited bandwidth because line noise causes significant data signal loss. </p>
<p>Data carrying power lines can also cause interference with high frequency radio communications. In the end, relatively low signal quality and strong competition from other technologies mean that BPL will probably never be widely adopted.</p>
<p>Networks using forms of wireless Internet service provider (WISP) can service homes and offices across larger geographic areas without the need to physically wire every building. Wired connections are installed in an area's center and, where necessary, connected backhauls are installed in elevated areas to strengthen the wireless signals aimed at consumers. </p>
<p>Existing radio towers or other tall structures can be used for the backhaul repeaters, making a WISP system relatively inexpensive to install.</p>
<p>Smaller-scaled wireless network co-ops can be shared locally using a neighborhood internet service provider (NISP) (using rooftop antennas) or a wireless mesh network (where network-connected devices act as peer nodes) to efficiently share a single physical connection.</p>
<p>Those systems are primarily designed to serve us where we live and work. But mobile data access is definitely also a thing. I'm sure you're already familiar with data plans that mobile phone companies can provide alongside their calling and texting services.</p>
<h2 id="heading-mobile-phone-data-access">Mobile Phone Data Access</h2>
<p>Cell connectivity is distributed through geographic areas (known as "cells") from individual radio transmitters spread throughout the cell. </p>
<p>Since the transmitters within each cell will use different radio frequencies than the cells around it, modern wireless technologies permit a seamless, automated "handover" as a user moves between cells.</p>
<p>The technologies used for wireless telephony have changed since the 80s, when what's now known as 1G ("First Generation") cell phones were introduced. To describe the evolution of cell phones in very general terms, we could say that:</p>
<ul>
<li><strong>1G</strong> phones carried only voice communications and had a maximum transfer speed of 2.4 Kbps.</li>
<li><strong>2G</strong> phones could carry Short Message Service (SMS) and Multimedia Messaging Service (MMS) messaging, which could include short videos and images.</li>
<li><strong>3G</strong> phones had much higher transfer rates (as high as 2 Mbps) than any variant of 2G and was therefore dubbed, "mobile broadband."</li>
<li><strong>4G</strong> phones could reach speeds as high as 100 Mbps, which permitted HD mobile TV, online gaming, and video conferencing.</li>
<li><strong>5G</strong> phones – when used on compatible networks – are expected to reach transfer speeds of up to 20 Gbps at a very low latency, permitting fully immersive virtual environments. Should the 5G rollout be successful (and, at the time of writing, this isn't yet clear), the range and limits of new service categories that could be deployed is not yet known.</li>
</ul>
<p>When it comes to planning a new venture, it's long been the accepted wisdom that there's no replacement for solid market research. Without knowing who your customers will be, where they live, and what they like, how can you properly serve them? </p>
<p>Well, now you can add to that list "how reliable and robust is their internet connectivity," because without digital access, they may never find you or be able to consume your service.</p>
<h1 id="heading-talking-to-the-internet-of-things">Talking to the Internet of Things</h1>
<p>Two recent changes are, more than anything else, responsible for the internet of things (IoT) ecosystem: the availability of cheap, embedded, single-board computers (like the Raspberry Pi) and cheap and always-on internet connectivity.</p>
<p>Those tiny single-boards – often smaller than a credit card – are easy to incorporate into just about anything you're planning to manufacture. </p>
<p>Such devices cost very little – sometimes just a few dollars a piece – and they're generally built to run fully-powered (and free) Linux distributions. And network availability means that the vast streams of data generated by all those on-board cameras, sensors, and other peripherals, can be automatically sent back "home" for processing and analysis.</p>
<h2 id="heading-the-dream-of-iot">The Dream of IoT</h2>
<p>Here are some ways that IoT applications are already actively changing business and consumer practices:</p>
<h3 id="heading-inventory-control">Inventory control</h3>
<p>The very first IoT device was – arguably at least – a Coca-Cola vending machine at Carnegie Mellon University. Back in the early 80s, the machine was modified to digitally report its ongoing inventory. </p>
<p>The simple idea that physical devices can monitor themselves and their surroundings, providing accurate, up-to-the-minute status reports to remote servers, lies at the heart of countless modern industrial solutions. </p>
<p>Modern retail, wholesale, logistics, and manufacturing operations now have constant access to their inventories, allowing them to understand trends and anticipate problems.</p>
<h3 id="heading-agriculture">Agriculture</h3>
<p>Increasingly, modern farming incorporates robotic irrigation, fertilization, planting, and even harvesting technologies. </p>
<p>All those robots running around your property are generating data and, from time to time, getting themselves into trouble. </p>
<p>Moving that data "back" to administration servers is critical for keeping track of what's going on, what might need fixing, and how your actual farm is performing. You can, therefore, expect that each of those devices will be part of someone's IoT.</p>
<h3 id="heading-military">Military</h3>
<p>Communication is key for military operations. But if even weapons, vehicles, and other equipment can communicate autonomously, and if there are servers dedicated to interpreting and acting on that communication, then you're already way ahead of the game. </p>
<p>Sensors connected to each of hundreds of components for, say, a fighter jet, can contribute to giving planners an unprecedented view of what's really going on.</p>
<h3 id="heading-smart-cities">Smart cities</h3>
<p>When sensors embedded in buildings, roads, public lighting, smartphones, and electrical systems are combined with data coming from traffic cameras and public departments, the potential for data-driven insights is huge. </p>
<p>Properly understood data can help cities manage their resources, utilities, and even traffic more efficiently, and better maintain their physical infrastructure.</p>
<h3 id="heading-smart-homes">Smart homes</h3>
<p>On a far smaller scale than smart cities, home appliances can be connected and monitored and controlled through smartphone apps or remote servers. </p>
<p>Smart home devices already include heating and cooling systems, light bulbs, robotic vacuum cleaners, garage doors, and security systems. Smart home devices can be controlled through phone apps but, in many cases, also through voice controlled devices like Amazon Echo (Alexa).</p>
<p>Conversations about IoT are always just one step away from <em>buzzwordism</em> – where words lose meaning and exaggeration becomes an acceptable lifestyle choice. </p>
<p>Not all IoT stuff is actually IoT. Or, to put it another way, not all IoT is worth talking about. But here's one good way to categorize a particular technology: if, hour after hour, something generates more data than any human being could possibly absorb, then it's probably an IoT device.</p>
<p>Effectively dealing with all that data can be a problem. And that's not the only potential for trouble in IoT land.</p>
<h2 id="heading-the-nightmare-of-iot">The Nightmare of IoT</h2>
<p>In the information technology world, as a general rule, the more active network connections you have in your infrastructure, the greater your risk of being successfully attacked. </p>
<p>That's because successful hacker intrusions usually come through badly configured or unpatched devices. The more public-facing devices you're exposing, the greater the chance one of them will have a serious vulnerability.</p>
<p>What kind of vulnerabilities are we talking about? Well, the US government's Common Vulnerabilities and Exposures database contains nearly 140,000 individual entries, each one representing a unique software weakness that could allow unauthorized access to and destruction of an IT system. </p>
<p>There are threats impacting all operating systems (Windows, Linux, macOS), all formats (server, PC, smartphone), and all ages (there are active threats going back to the 1990s). And many hundreds of new entries are added each month.</p>
<p>In that sense, IoT devices are no different than any other kind of computer. But there is one way that they're a whole lot worse. Because you don't normally directly interact with IoT devices on an OS level, and because they're often commodity items that are purchased and deployed by the dozens or thousands, you don't instinctively treat them like computers.</p>
<p>Most of us, as an example, are aware that we should create complex and unique passwords for our laptops and WiFi routers. But your fridge? Just plug it in and it'll be fine! The problem is that many IoT devices – like "smart" fridges – have their own embedded operating systems and, usually, their own network interfaces.</p>
<p>There's a good chance that anyone driving down your quiet residential street can scan for available networks, quickly identify the brand of IoT device you're using, assume that you haven't changed the authentication credentials from their factory defaults, and log in to your private network. </p>
<p>What makes things much worse is that many device manufacturers are still shipping their products with authentication credentials using some variation of admin/admin.</p>
<p>That's a big problem.</p>
<h1 id="heading-leveraging-federated-identities">Leveraging Federated Identities</h1>
<p>All this talk about the dangers presented by authentication and credentials should make you curious about how they can be used to generate some <em>good</em> connectivity stuff. </p>
<p>In a single word, that'd be <em>federation.</em> Identity federation is a technology for linking a single person's identity across multiple network services. Federation is what lets you log in to online gaming or web application sites using, say, your Google account credentials.</p>
<p>The upside of federation is that a single login can be all you'll need as you move between many of the online services you regularly use. That lets you reduce the risk of exposing your password through a vulnerable website. </p>
<p>Of course, it also increases the damage that can come from a serious data breach of the servers used by your federation provider.</p>
<p>Federation can be used to integrate with third party single sign-on (SSO) authentication systems, like Kerberos, the Lightweight Directory Access Protocol (LDAP), and Microsoft's Active Directory (AD). When used with cloud services, SSO systems can securely permit automated as-needed access to private account resources for consumers or processes.</p>
<p>Besides convenience, all this authentication goodness drives opportunities for secure remote collaboration on large, complex projects – itself a fast-growing trend.</p>
<p><em>YouTube videos of all ten chapters from this book <a target="_blank" href="https://www.youtube.com/playlist?list=PLSiZCpRYoTZ6UWl4xialvwLOKyHYYJUiC">are available here</a>. Lots more tech goodness - in the form of books, courses, and articles - <a target="_blank" href="https://bootstrap-it.com">can be had here</a>. And consider taking my <a target="_blank" href="https://www.udemy.com/user/david-clinton-12/">AWS, security, and container technology courses here</a>.</em></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ What is Raspberry Pi? Specs and Models (2021 Guide) ]]>
                </title>
                <description>
                    <![CDATA[ By Veronica Stork Introduction Are you curious about the IoT (Internet of Things?) Have you always wanted to try to make your own robot, smart mirror, or bird feeder camera? What about building a computer for a fraction of the cost of a commercially ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/what-is-raspberry-pi-specs-and-models-2021-guide/</link>
                <guid isPermaLink="false">66d46181787a2a3b05af4410</guid>
                
                    <category>
                        <![CDATA[ Internet of Things ]]>
                    </category>
                
                    <category>
                        <![CDATA[ iot ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Raspberry Pi ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Wed, 25 Aug 2021 16:17:20 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2021/08/Raspberry-Pi-2-Bare-FL-bigger.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Veronica Stork</p>
<h2 id="heading-introduction">Introduction</h2>
<p>Are you curious about the IoT (Internet of Things?) Have you always wanted to try to make your own robot, smart mirror, or bird feeder camera? What about building a computer for a fraction of the cost of a commercially available machine?</p>
<p>If you said yes to any of these questions, you might enjoy playing around with a Raspberry Pi. </p>
<p>In this article, I'll explain what a Raspberry Pi is (and what it’s not.) Then I'll show you some things you can use it for, and finally, I'll list all of the current models along with their specs.</p>
<h2 id="heading-what-is-raspberry-pi">What is Raspberry Pi?</h2>
<p>A Raspberry Pi is a single board computer (SBC) created in the United Kingdom by the <a target="_blank" href="https://www.raspberrypi.org/about/">Raspberry Pi Foundation</a>. It's a charity that "works to put the power of computing and digital making into the hands of people all over the world."</p>
<p>The first model of the Raspberry Pi was released in 2012, and as of 2021 there have been five generations of the boards. A microcontroller (more about that later), called the Pico was released in early 2021.</p>
<h3 id="heading-gpio-pins">GPIO Pins</h3>
<p>Something that sets the Pi apart from your average computer is the set of 40 GPIO (General Purpose Input Output) pins. </p>
<p>GPIO pins are pretty much exactly what they sound like. They are designed to input and output single bits. This means that you can use them to add all sorts of functionality to your Raspberry Pi using switches, buzzers, lights, sensors, and so on.</p>
<h3 id="heading-raspberry-pi-hats">Raspberry Pi HATs</h3>
<p>There are a number of add-on boards that you can attach to the Raspberry Pi using the GPIO pins. </p>
<p>Raspberry Pi HATs (Hardware Attached on Top) are add-on boards designed according to certain specifications. The Raspberry Pi can automatically detect and configure the HATs, making set-up easy.</p>
<p>There is a <em>huge</em> variety of HATs and other add-on boards that you can buy, but here are some notable ones:</p>
<ul>
<li><strong><a target="_blank" href="https://www.raspberrypi.org/products/poe-plus-hat/">PoE+ HAT</a></strong> – Power over Ethernet HAT</li>
<li><strong><a target="_blank" href="https://www.raspberrypi.org/products/sense-hat/">Sense HAT</a></strong> – Designed for the <a target="_blank" href="https://astro-pi.org/">Astro Pi mission</a>, the Sense HAT includes a gyroscope, an accelerometer, a magnetometer, and sensors for temperature, humidity, and Barometric pressure.  </li>
<li><strong><a target="_blank" href="https://shop.pimoroni.com/products/explorer-hat">Pimoroni Explorer HAT Pro</a></strong> – All-purpose board featuring touch pads, crocodile clip pads, and analog inputs</li>
<li><strong><a target="_blank" href="https://www.adafruit.com/product/2340">Adafruit Capacitive Touch HAT</a></strong> – Similar to a <a target="_blank" href="https://makeymakey.com/">Makey Makey</a>, this HAT allows you to use any conductive object to trigger events using Python.</li>
</ul>
<h3 id="heading-raspberry-pi-operating-systems">Raspberry Pi Operating Systems</h3>
<p>The Raspberry Pi often runs some form of Linux, but there are a ton of operating systems that you can use. </p>
<p>On the official website, you will find a list of <a target="_blank" href="https://www.raspberrypi.org/software/operating-systems/">operating system images</a> available for download. These include the official Raspberry Pi OS, Debian Buster, and Ubuntu (desktop, core, and server.) </p>
<p>You will also find RetroPie, a specialized gaming platform operating system, and LibreELEC, a lightweight Linux distribution specifically created for use with the open source media player <a target="_blank" href="https://kodi.tv/">Kodi</a>.</p>
<h3 id="heading-raspberry-pi-vs-arduino">Raspberry Pi VS Arduino</h3>
<p>You may have heard of Arduino boards and wondered what the difference is between them and the Raspberry Pi. </p>
<p>The main difference is that Pis (with the exception of the Pico and the RP2040) are full computers with operating systems. You can connect your Pi to a keyboard, mouse, and monitor and use it like you would use a Mac or PC. </p>
<p>The Arduino, on the other hand, is a microcontroller. It cannot function independently as a computer, but is programmed using a computer and then used to control things like cameras, lights, robots, and so on. </p>
<p>As the official Arduino website puts it: “Arduino boards are able to read inputs… and turn it into an output.”</p>
<h2 id="heading-what-is-the-raspberry-pi-used-for">What is the Raspberry Pi Used For?</h2>
<p>Search the internet and you will find a huge array of projects created using Raspberry Pis. </p>
<p>Common use cases include home automation, gaming consoles, servers, WiFi extenders, streaming devices, weather stations, and home computers. (Fun fact: much of this article was written on a Raspberry Pi.)</p>
<p>During the Covid-19 pandemic, Raspberry Pi's were even used to control <a target="_blank" href="https://www.engadget.com/raspberry-pi-ventilators-covid-19-163729140.html">ventilators</a> in some hard-hit areas.</p>
<h2 id="heading-raspberry-pi-models">Raspberry Pi Models</h2>
<p>All models of Raspberry Pi that are currently in production have 40 GPIO pins. </p>
<p>This list does not include the Raspberry Pi microcontrollers, the Pico and the RP2040. </p>
<p>You can find out where to purchase any of these boards on the <a target="_blank" href="https://www.raspberrypi.org/products/">Raspberry Pi website</a>.</p>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Model</td><td>Processor</td><td>RAM</td><td>Connectivity</td><td>USB</td><td>HDMI</td><td>Power</td><td>Price</td></tr>
</thead>
<tbody>
<tr>
<td>Zero</td><td>BCM2835</td><td>512MB</td><td>None</td><td>Micro USB OTG</td><td>Mini HDMI</td><td>Micro USB</td><td>$5</td></tr>
<tr>
<td>Zero W</td><td>BCM2835</td><td>512MB</td><td>802.11 b/g/n wireless LAN</td><td>Micro USB OTG</td><td>Mini HDMI</td><td>Micro USB</td><td>$10</td></tr>
<tr>
<td>Raspberry Pi 1 Model A+</td><td>BCM2835</td><td>512MB</td><td>None</td><td>1x USB 2.0</td><td>Full-size HDMI</td><td>Micro USB</td><td>$25</td></tr>
<tr>
<td>Raspberry Pi 1 Model B+</td><td>BCM2835</td><td>512MB</td><td>100 base ethernet</td><td>4x USB 2.0</td><td>Full-size HDMI</td><td>Micro USB</td><td>$30</td></tr>
<tr>
<td>Raspberry Pi 3 Model A+</td><td>BCM2837B0</td><td>512MB</td><td>dual-band wireless, Bluetooth 4.2</td><td>1x USB 2.0</td><td>Full-size HDMI</td><td>5V DC via Micro USB</td><td>$25</td></tr>
<tr>
<td>Raspberry Pi 3 Model B</td><td>BCM2837</td><td>1GB</td><td>ethernet, wireless, BLE</td><td>4x USB 2.0</td><td>Full-size HDMI</td><td>2.1A via Micro USB</td><td>$35</td></tr>
<tr>
<td>Raspberry Pi 3 Model B+</td><td>BCM2837B0</td><td>1GB</td><td>dual-band wireless, Bluetooth 4.2, BLE</td><td>4x USB 2.0</td><td>Full-size HDMI</td><td>5V DC via Micro USB &amp; Power-over-Ethernet (PoE)</td><td>$35</td></tr>
<tr>
<td>Raspberry Pi 4 Model B</td><td>BCM2711</td><td>2GB, 4GB, or 8GB</td><td>Gigabit ethernet, dual-band wireless, Bluetooth</td><td>2x USB 3.0 &amp; 2x USB 2.0</td><td>2x micro HDMI</td><td>5V DC via USB-C</td><td>$35, $55, $75</td></tr>
<tr>
<td>Raspberry Pi 400</td><td>BCM2711</td><td>4GB</td><td>Gigabit ethernet, dual-band wireless, Bluetooth</td><td>2x USB 3.0 &amp; 1x USB 2.0</td><td>2x micro HDMI</td><td>5V DC via USB</td><td>$70</td></tr>
</tbody>
</table>
</div><h2 id="heading-conclusion">Conclusion</h2>
<p>The Raspberry Pi is an affordable way to explore electronics, hardware, and computer programming. It can be used for a huge variety of projects, from the very silly (like a <a target="_blank" href="https://www.raspberrypi.org/blog/hamsters-all-the-way-down/">hamster powered hamster drawing machine</a>) to the very important (like <a target="_blank" href="https://www.raspberrypi.org/blog/building-computer-labs-in-western-africa/">computer labs</a> in developing nations.)</p>
<p>Now that you know the basics, why don't you go out and make something? Whether you hook a Capacitive Touch HAT up to your Raspberry Pi and turn it into a banana piano or install Linux on it and use it to do your homework, I hope you have a great time creating something cool and useful.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ An Introduction to the Internet of Things ]]>
                </title>
                <description>
                    <![CDATA[ By Pier Paolo Ippolito Introduction During the last few years, Internet of Things (IoT) devices have started becoming a more and more important component in our daily lives. Some common applications for IoT devices are: Smart Home (eg. smart lamps) ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/introduction-to-iot-internet-of-things/</link>
                <guid isPermaLink="false">66d4608f37bd2215d1e245a8</guid>
                
                    <category>
                        <![CDATA[ Internet of Things ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Machine Learning ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Mon, 26 Aug 2019 17:08:40 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2019/08/internet_of_things_iot.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Pier Paolo Ippolito</p>
<h2 id="heading-introduction">Introduction</h2>
<p>During the last few years, Internet of Things (IoT) devices have started becoming a more and more important component in our daily lives. Some common applications for IoT devices are:</p>
<ul>
<li>Smart Home (eg. smart lamps)</li>
<li>Wearables (eg. smart-watches)</li>
<li>Autonomous vehicles</li>
<li>Smart cities</li>
<li>Smart Retail</li>
</ul>
<p>According to Wikipedia, IoT devices are defined as:</p>
<blockquote>
<p>"The <strong>Internet of things</strong> (<strong>IoT</strong>) is the extension of Internet connectivity into physical devices and everyday objects. Embedded with electronics, Internet connectivity, and other forms of hardware (such as sensors), these devices can communicate and interact with others over the Internet, and they can be remotely monitored and controlled "                                                                                                        –   Wikipedia [1]</p>
</blockquote>
<p>One of the most interesting characteristics of IoT devices is that they are able to produce large amounts of data. This can be particularly used in applications such as Artificial Intelligence and Machine Learning.</p>
<p>Most of IoT devices can produce in fact a great variety of Time Series data which are of huge interest in Artificial Intelligence.</p>
<p>According to a study carried out by <a target="_blank" href="https://www.globaldata.com/">Global Data</a>, the IoT market is projected to reach $318bn new worth by 2023 (in constantly rise compared to the previous years).</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/08/IoT-grow-chart.png" alt="Image" width="600" height="400" loading="lazy">
<em>Figure 1: IoT markets projections [2].</em></p>
<p>These projections are confirmed by the increased interest of companies such as Google and Microsoft to invest in IoT cloud platforms.</p>
<h2 id="heading-how-do-iot-devices-work">How do IoT devices work?</h2>
<p>An IoT system is compromised of four main components:</p>
<ol>
<li><strong>Sensors:</strong> enables the devices to collect data from the environment surrounding the device (eg. velocity, GPS coordinates, temperature, etc...). </li>
<li><strong>Connectivity:</strong> successively the data collected is sent to the cloud (through either WiFi or Bluetooth connection).</li>
<li><strong>Data Processing:</strong> once the data is received by the cloud infrastructure, it can then be processed (eg. check if the data received adhere to the requirements and if its not alert the user).</li>
<li><strong>User Interface:</strong> Once the data is processed, the results are then given to the and user. </li>
</ol>
<p>As a simple workflow example, let's consider a security system in a house. </p>
<p>Our IoT device will check if there are any intruders in our house using a Computer Vision system (<strong>Sensors</strong>). The video recordings of the house are then sent to the cloud to see if there are any intruders or not (<strong>Connectivity</strong>). Successively, the data is processed in the cloud (<strong>Data Processing</strong>) and if some intruders are detected we get alerted (<strong>User Interface</strong>). </p>
<p>An IoT system could be able to alert us in many different ways (eg. phone call/message or App notification) and in some cases we could be able to control remotely the system itself (eg. lock the house doors). </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/08/how-iot-works-summary.001.png" alt="Image" width="600" height="400" loading="lazy">
<em>Figure 2: Main Components of an IoT System [3]</em></p>
<h2 id="heading-internet-of-things-cloud-platforms">Internet of Things cloud platforms</h2>
<p>I will now introduce you to some of the most interesting IoT cloud platforms which can be used for analysing and controlling IoT devices. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/08/1_go7sTFOGN2fJGgYrI3E-FA.png" alt="Image" width="600" height="400" loading="lazy">
<em>Figure 3: IoT Cloud Platforms [4]</em></p>
<h3 id="heading-google-cloud-internet-of-things">Google Cloud Internet of Things</h3>
<p>Google Cloud is currently one of the main Cloud solutions provider on the market. Some of the packages offered by Google Cloud for IoT implementations are:</p>
<ul>
<li><strong>Cloud IoT Core:</strong> is used to set up the device(s) and establish a secure connection between them. </li>
<li><strong>Cloud Machine Learning Engine:</strong> it allows users to create Machine Learning models from the data gathered by the IoT devices in order to increase and monitor performances.</li>
<li><strong>Cloud Pub/Sub:</strong> provides real time analytics of the IoT devices.</li>
</ul>
<h3 id="heading-azure-internet-of-things">Azure Internet of Things</h3>
<p>Microsoft Azure is another really important cloud services provider. Azure is able to deliver both pre-customized and fully customizable solutions. In this way, Azure is able to provide solutions for both beginners and experts in IoT. Microsoft Azure enables to easily scale IoT systems to include devices from different manufacturers and also provides analytics and Machine Learning services support.</p>
<h3 id="heading-amazon-web-services-aws">Amazon Web Services (AWS)</h3>
<p>AWS is one of the most popular solution for cloud based services. AWS can enable to perform IoT projects from end to end and making use of the four following packages:</p>
<ul>
<li><strong>AWS IoT Core:</strong> is the basic package which can be used to set up IoT devices. Using IoT Core we can integrate different devices to communicate each other over a secured connection making possible to exchange data through cloud storage.</li>
<li><strong>AWS IoT Analytics:</strong> is used to process and analyse all the data produced by IoT devices. Once all the data is stored using a semi-structured format (eg. JSON, CSV) it can be then used for Machine Learning purposes (eg. monitor and optimise the interaction between IoT devices).</li>
<li><strong>AWS IoT Device Defender:</strong> is used to construct and personalise the security mechanisms of IoT devices (such as choosing device authentication and data encryption). </li>
<li><strong>AWS IoT Device Management:</strong> enables to easily integrate new IoT devices to an environment and monitor/update their functionalities.</li>
</ul>
<h2 id="heading-conclusion">Conclusion</h2>
<p>Internet of Things devices are definitely going to play a really important role in future technology advancements. Although there are still the same issues that have to be addressed. In fact, one of the main concerns about IoT devices can be cyber-security. </p>
<p>Because most IoT devices make use of a cloud centre to store their data and to collect useful information from the internet, that makes them vulnerable from Hackers attacks (creating a single point of failure). </p>
<p>In order to resolve this problem, could be either possible to increase the encryption standards (slowing down the transfer of data) or makes use of Artificial Intelligence security powered techniques such as <a target="_blank" href="https://towardsdatascience.com/ai-differential-privacy-and-federated-learning-523146d46b85">Differential Privacy and Federated Learning</a>.</p>
<p>In case a Hacker would be able to access control of an IoT device (or an entire group) there would be two main risks associated with it:</p>
<ul>
<li>The Hacker would be able to access and steal sensitive data of the IoT device users.</li>
<li>The Hacker could be able to take remote control of the device itself.</li>
</ul>
<p>In addition to the cloud services provided before, also the following ones can be considered a valid alternative: <a target="_blank" href="https://cloudplatform.sap.com/capabilities/product-info.SAP-Cloud-Platform-Internet-of-Things.48b79cfa-3d49-4a42-9249-e589696691ae.html">SAP</a>, <a target="_blank" href="https://www.oracle.com/uk/internet-of-things/">Oracle Internet of Things</a>, <a target="_blank" href="https://www.cisco.com/c/en/us/solutions/service-provider/iot-cloud-connect/index.html">Cisco IoT Cloud Connect</a>, <a target="_blank" href="https://www.ibm.com/uk-en/internet-of-things">IBM Watson Internet of Things</a>, etc...</p>
<h2 id="heading-contacts">Contacts</h2>
<p>If you want to keep updated with my latest articles and projects <a target="_blank" href="https://medium.com/@pierpaoloippolito28?source=post_page---------------------------">follow</a> me and subscribe to my <a target="_blank" href="http://eepurl.com/gwO-Dr?source=post_page---------------------------">mailing list</a>. These are some of my contacts details:</p>
<ul>
<li><a target="_blank" href="https://uk.linkedin.com/in/pier-paolo-ippolito-202917146?source=post_page---------------------------">Linkedin</a></li>
<li><a target="_blank" href="https://pierpaolo28.github.io/blog/?source=post_page---------------------------">Personal Blog</a></li>
<li><a target="_blank" href="https://pierpaolo28.github.io/?source=post_page---------------------------">Personal Website</a></li>
<li><a target="_blank" href="https://towardsdatascience.com/@pierpaoloippolito28?source=post_page---------------------------">Medium Profile</a></li>
<li><a target="_blank" href="https://github.com/pierpaolo28?source=post_page---------------------------">GitHub</a></li>
<li><a target="_blank" href="https://www.kaggle.com/pierpaolo28?source=post_page---------------------------">Kaggle</a></li>
</ul>
<p>Cover photo <a target="_blank" href="https://foreignpolicyi.org/blockchain-and-cryptocrypto-solution/">from this article</a>.</p>
<h2 id="heading-bibliography">Bibliography</h2>
<p>[1] Wikipedia, Internet of Things. Accessed at: <a target="_blank" href="https://en.wikipedia.org/wiki/Internet_of_things">https://en.wikipedia.org/wiki/Internet_of_things</a></p>
<p>[2] Global IoT market to reach $318 billion by 2023, says GlobalData. Michelle Froese, Windpower Engineering &amp; Development. Accessed at: <a target="_blank" href="https://www.windpowerengineering.com/business-news-projects/global-iot-market-to-reach-318-billion-by-2023-says-globaldata/">https://www.windpowerengineering.com/business-news-projects/global-iot-market-to-reach-318-billion-by-2023-says-globaldata/</a></p>
<p>[3] Anni Junnila, HOW IOT WORKS – SUMMARY – TRACKINNO BLOG. Accessed at: <a target="_blank" href="https://trackinno.com/2018/08/09/how-iot-works-part-4-user-interface/how-iot-works-summary-001/">https://trackinno.com/2018/08/09/how-iot-works-part-4-user-interface/how-iot-works-summary-001/</a></p>
<p>[4] Overview of the best IOT platforms. Tips for selecting the right cloud solution in 2019. Anna Davydova, Edsson. Accessed at: <a target="_blank" href="https://www.edsson.com/en/blog/article?id=iot-platforms">https://www.edsson.com/en/blog/article?id=iot-platforms</a></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Internet of Things prototyping with Firebase: how to do more with less ]]>
                </title>
                <description>
                    <![CDATA[ By Bayrem Gharssellaoui IoT is all about connecting devices, or “things” as you may call them, to the internet and then analyzing data collected from these devices in order to extract an added value. In this article you’ll discover how to benefit fro... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/iot-prototyping-with-firebase-doing-more-with-less-2f5c746dac8b/</link>
                <guid isPermaLink="false">66c35874c7095d76345eaf9e</guid>
                
                    <category>
                        <![CDATA[ arduino ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Firebase ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Internet of Things ]]>
                    </category>
                
                    <category>
                        <![CDATA[ iot ]]>
                    </category>
                
                    <category>
                        <![CDATA[ platformio ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Sat, 19 Jan 2019 13:23:15 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*ttEuxmPhOI8obezR7bn6tg.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Bayrem Gharssellaoui</p>
<p>IoT is all about connecting devices, or “things” as you may call them, to the internet and then analyzing data collected from these devices in order to extract an added value. In this article you’ll discover how to benefit from <a target="_blank" href="https://firebase.google.com/">Firebase</a> when working on an IoT project and how it can help you develop IoT prototypes much faster and easier than traditional methods. You will also develop your own IoT project and host it in Firebase.</p>
<h3 id="heading-before-firebase-realtime-database">Before Firebase Realtime Database</h3>
<p>Most of <a target="_blank" href="http://kaizoku.azurewebsites.net/">my IoT projects</a> require some way of communication between the different endpoints. These endpoints can be anything from devices and services to applications, and eventually data needs to be stored somewhere for further processing and analyzing.</p>
<p>So let’s say you want to build an IoT system where a device will measure temperature and humidity values from sensors and send them to a database service to store them. Then you want to have a web application that will fetch these values and display them in a dashboard. Quite simple, right…?</p>
<p>The easy and lightweight way to go about this is to setup an <a target="_blank" href="https://www.hivemq.com/mqtt-essentials/">MQTT</a> broker that will act as a hub and reroute all incoming messages <strong>published</strong> from the device to all <strong>subscribed</strong> clients like the web application in this case.</p>
<p>Now the question here is how can the web application display the data? Meaning will it be displaying messages coming from the broker directly or will it be fetching data from a database service?</p>
<p>Let’s say that you want the app to do both things: display data coming from the broker in realtime <strong>and</strong> fetch data from the database. In this case you can think of 2 ways (actually there are many different ways) to achieve this:</p>
<p><strong>First solution:</strong></p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*5NM__yb36ftzOmIvLtBc-A.png" alt="Image" width="800" height="449" loading="lazy"></p>
<p>Using this architecture the device will first publish its data to the broker then it will send an HTTP request to the database web-service to save the data. For this solution the device needs to implement 2 clients: an MQTT and an HTTP client.</p>
<p><strong>Second solution:</strong></p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*qOsO6-Hupd-Eidwdw66X-Q.png" alt="Image" width="800" height="449" loading="lazy"></p>
<p>The other way to go about this is that the device will send or publish its data to the broker, then the broker (as expected) will reroute this message to all connected subscribers like the web app. But this time there’s another subscriber connected which represents an API Engine that will accept this data and send it to the database web-service to be stored.</p>
<p>As you may have noticed in this solution, the HTTP client is decoupled from the device and implemented as a backend service. This way you make the device program much lighter. This is an important thing to keep in mind when developing on constrained IoT devices where resources like CPU and memory are limited.</p>
<p>Still, this solution required some additional work in developing the back-end service that will act as a persistence layer.</p>
<p>So is there much easier way of doing this?</p>
<h3 id="heading-firebase-to-the-rescue">Firebase to the rescue</h3>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*dFAUA_U6XtcCVDSDrd1eIQ.gif" alt="Image" width="800" height="600" loading="lazy"></p>
<p>As you may have seen above, things can get quite complex quite easily. For someone like me who wants to get up and running quickly when working on a prototype, that can take some extra time. That’s why, in this part of the article, you’ll see how Firebase can make your life easier and save you a lot of time when developing an IoT prototype.</p>
<p>Firebase offers many cloud services that ranges from authentication, storage, and cloud functions to hosting your web application. In this article you’ll use 2 services: Realtime Database and Hosting.</p>
<p>Let’s start with <strong>Firebase Realtime Database</strong>. The first thing that comes to mind when reading this service name is: okay so I know what a database is but what does it mean to be realtime here?</p>
<p>Well according to Wikipedia:</p>
<blockquote>
<p>A <strong>real-time database</strong> is a database system which uses <a target="_blank" href="https://en.wikipedia.org/wiki/Real-time_computing">real-time processing</a> to handle workloads whose state is constantly changing. This differs from traditional databases containing persistent data, mostly unaffected by time</p>
</blockquote>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*uWzVNx2DCXbVc0xnxbSYwg.gif" alt="Image" width="800" height="575" loading="lazy"></p>
<p>In the case of Firebase Realtime Database, clients will be connected to the database and will maintain an open bidirectional connection via <a target="_blank" href="https://blog.teamtreehouse.com/an-introduction-to-websockets">websockets</a>. Then if any client pushes data to the database it will be triggered and (in this case) inform all connected clients that it has been changed by sending them the newly saved data.</p>
<p>This way of working may remind you of the MQTT broker and how it reacts when it receives a message from a publisher and sends it to all subscribers. The difference this time is the addition of the data persistent part, which is the database. So as you can see here, you don’t need to route messages yourself using other protocols — Firebase Realtime Database will take care of that plus performing its normal database function. Amazing isn’t it?</p>
<p>Returning to the IoT system mentioned earlier, you can now connect the device to the Firebase Realtime Database and make it push data periodically to the database. On the other part of the system you have a web application which will be connected to the same service as the device and will receive new data whenever there is a change in the database.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*zyS---O8Po4Gz1tVUYS4QQ.png" alt="Image" width="800" height="449" loading="lazy"></p>
<p>But what about <strong>hosting</strong> the web application?</p>
<p>Firebase offers a hosting service that you can use to host your app rather than managing your own web server and dealing with deployment and networking configurations. The good thing is that it is free (yet limited) and pretty easy to use.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*VESaHfq7jgk8aeDyH2kFgg.png" alt="Image" width="512" height="512" loading="lazy"></p>
<p>Now for the part you all have been waiting for. In this demo you’ll use the example discussed throughout this article and bring it to life.</p>
<p>If you remember, the IoT system is made of <strong>2 endpoints</strong>: the first one is the <strong>IoT device</strong> which is responsible for sending temperature and humidity data to the Firebase Realtime Database. This in turn will communicate with the second endpoint — the <strong>web application</strong> — that will read the data and display it on a nice dashboard.</p>
<p>I’ll break this project into <strong>3 steps</strong> so it becomes easier to follow.</p>
<h3 id="heading-1-setting-up-firebase-realtime-database">1. Setting up Firebase Realtime Database</h3>
<p>There is nothing special about this step. You just need to go to your <a target="_blank" href="https://console.firebase.google.com/">firebase console</a> and create a new project. After your project is ready, go to the database section and make sure to create a Realtime Database <strong>not a cloud Firestore Database.</strong> Select start in test mode and proceed as you’ll be using this database only for testing and prototyping and not for production solutions (so you can ignore the red warning). Now the database should be ready for use.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*E-ny9SQDLjUGOiEn1ows8w.png" alt="Image" width="800" height="415" loading="lazy"></p>
<h3 id="heading-2-developing-the-iot-device-application">2. Developing the IoT device application</h3>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*ttEuxmPhOI8obezR7bn6tg.jpeg" alt="Image" width="800" height="529" loading="lazy"></p>
<p>When talking about embedded systems development, you often hear terms like low level programming, assembly, registers, memory management and so on. These terms and concepts are related to the hardware specifics you’re working with and can change from one to another.</p>
<p>That’s why, when prototyping ideas, you don’t have time to dig deep into these specifics and study them in details because you’ll be dealing at the same time with other high level languages and thus other ways of thinking about code. So instead you should have a clear overall idea about the architecture and characteristics of the device and how to use them.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*YQyb-Sopev0IYL9nRv1J-Q.gif" alt="Image" width="480" height="258" loading="lazy"></p>
<p>Luckily for you there is a platform that was made specially for prototyping and abstracting all the low level functionalities of hardware. Yes I’m talking about the famous <strong>Arduino</strong>.</p>
<p><a target="_blank" href="https://www.arduino.cc/"><strong>Arduino - Home</strong></a><br><a target="_blank" href="https://www.arduino.cc/">_Open-source electronic prototyping platform enabling users to create interactive electronic objects._www.arduino.cc</a></p>
<p>Note here that when I’m talking about Arduino, I’m referring to the <strong>Arduino Framework</strong> with its IDE, compilers, and libraries — not the board.</p>
<p>So you will be using Arduino to program the board, but what board you ask? Well, you need a board that is able to interface with sensors and measure physical values like temperature. It should also be able to connect to the internet in order to send this data to the database. Finally, it should be able to be programmed using the Arduino framework.</p>
<p>There are a variety of boards on the market that can achieve these tasks. Some of them are Arduino boards and others are Arduino-compatible boards.</p>
<p>In this demo you will use the famous <strong>NodeMCU,</strong> an Arduino compatible board. It’s based on the <strong>ESP8266</strong> SoC, a chipset produced by the Shanghai-based Chinese manufacturer, Espressif Systems. This board is attractive for developers, as single units can be bought for as little as $3.</p>
<h4 id="heading-our-gear">Our Gear</h4>
<p>Although the Arduino platform offers an IDE for programming and uploading code to boards, it’s not very friendly to developers as it does not provide any intelliSense features or debugging functionalities. That’s why, for most my IoT projects, I use an environment called <strong>PlatformIO.</strong></p>
<p><a target="_blank" href="https://platformio.org/"><strong>PlatformIO: An open source ecosystem for IoT development</strong></a><br><a target="_blank" href="https://platformio.org/">_Cross-platform build system and library manager. Cross-platform IDE and unified debugger. Remote unit testing and…_platformio.org</a></p>
<p>It’s an open source ecosystem for IoT development, and guess what? It supports the Arduino Framework. So you can use it to write Arduino code, compile it, and upload it to the board. Finally the cool thing about PlatformIO is that it comes as an <strong>extension</strong> that you can use inside <strong>Atom</strong> or <strong>VScode</strong> so you can use it alongside the other functionalities of your IDE (Atom or VScode). I highly recommend watching these 2 YouTube video tutorials to setup and get familiar with the environment.</p>
<p>Enough talk — let’s get started:</p>
<h4 id="heading-developing-firmware-for-nodemcu">Developing Firmware for NodeMCU</h4>
<p><a target="_blank" href="https://github.com/kaizoku-619/firebase_nodemcu"><strong>kaizoku-619/firebase_nodemcu</strong></a><br><a target="_blank" href="https://github.com/kaizoku-619/firebase_nodemcu">_Arduino Firebase Nodemcu client developed sending DHT11 data to Firebase Realtime Database …_github.com</a></p>
<p>Before diving into developing the firmware, let’s talk about the electronics setup.</p>
<p>If you remember from the example earlier, the IoT device will measure temperature and humidity values from a sensor and send them to the cloud. In this case that means the <strong>NodeMCU</strong> will read temperature and humidity values from <strong>DHT11</strong> sensor module and send them to Firebase. The <strong>DHT11</strong> module will be used here because it’s cheap and doesn’t require any additional electronic components to function.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*B6nyhGw-sarcmZgLA2etXg.png" alt="Image" width="800" height="329" loading="lazy">
<em>Wiring Diagram</em></p>
<p>As you can see from the wiring diagram above, DHT11 is connected to the board with 3 wires <strong>GND</strong>, <strong>3.3V</strong> and <strong>Data signal</strong> in the middle. Connect the data pin to one of the <strong>Dx</strong> pins on the board and you’re done with wiring.</p>
<p>Now that the wiring is done you can start coding the firmware using PlatformIO.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*DIOV2vSxZKjRO6WgP2nzjA.gif" alt="Image" width="500" height="300" loading="lazy">
<em>We’re not writing Go but I like the GIF</em></p>
<p>But before you dig into writing code directly, let’s stop for a moment and think about what the program should do.</p>
<p>So the first thing the device needs to do is to connect to the internet. To do that it needs to <strong>connect to the WiFi</strong> access point. Once online, it needs to <strong>open a connection with Firebase.</strong> After that the device will <strong>read temperature and humidity</strong> values from the sensor and finally <strong>publish the data</strong>.</p>
<p>Here is an ordered list of tasks:</p>
<p><em>(Note that the world <strong>task</strong> is used here to refer to a functionality of a bloc of code and not a task in realtime OS like FreeRTOS tasks.)</em></p>
<p><strong>1. Connect to WiFi</strong><br><strong>2. Open connection with Firebase</strong><br><strong>3. Read sensor values</strong><br><strong>3. Publish values to Firebase</strong></p>
<p>Let’s start with the first task:</p>
<ul>
<li><strong>Connect to WiFi:</strong></li>
</ul>
<p>This function begins with printing the <strong>SSID</strong> (AP name) and setting the NodeMCU into station mode rather than AP mode. Then it keeps loading until it connects to the AP. SSID and <strong>PASSWORD</strong> are 2 constants defined in another file as you’ll see later.</p>
<ul>
<li><strong>Open connection with Firebase:</strong></li>
</ul>
<p>This function is very straightforward: it takes 2 parameters <strong>FIREBASE_HOST</strong> and <strong>FIREBASE_AUTH.</strong> These are also 2 constants defined in another file.</p>
<ul>
<li><strong>Read sensor values:</strong></li>
</ul>
<p>You start by defining 2 constants for the <strong>DHT</strong> sensor type and pin. After that you create a DHT object by passing these 2 constants to the DHT constructor. Finally you use the object methods <strong>readHumidity()</strong> and <strong>readTemperature()</strong> to read humidity and temperature respectively.</p>
<ul>
<li><strong>Publish values to Firebase:</strong></li>
</ul>
<p>Here, the <strong>pushInt()</strong> method of Firebase class is used to push an integer to Firebase and in case of an error, print it.</p>
<p>And now you’re done with the tasks! All that’s left is to put these tasks together in a clean arduino sketch.</p>
<p>Start by creating a new project in PlatformIO as shown here:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*xwXxvU1FbJBSS6yypAiKHA.png" alt="Image" width="800" height="449" loading="lazy"></p>
<p>Next you need to <strong>install the libraries</strong> needed for the project. Note that in this case you will install the libraries <strong>locally,</strong> meaning they’re only available for this project. This is a best practice if you decided one day to use another version of the library in another project.</p>
<p>Go to the PlatformIO home page → Libraries and search for firebase. FirebaseArduino will show up, so click on it. But <strong>don’t click install button</strong>, instead click on the <strong>…</strong> next to install and choose the project to install the library into. Then finally click install. Repeat this process for the <strong>DHT</strong> library.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*gyXxo1VKPLWcqfHlkV_oLQ.png" alt="Image" width="800" height="449" loading="lazy"></p>
<p>Copy this code in the <strong>main.cpp</strong> file:</p>
<p>Remember the file containing the credentials for the WiFi and Firebase? Go to the include folder and create a new file <strong>Creds.h</strong> and copy this code to it. Don’t forget to <strong>change</strong> the code according to <strong>your credentials</strong>.</p>
<p>And there you go! Upload the firmware to <strong>NodeMCU</strong> and your device should be able to send data to <strong>Firebase Realtime Database</strong>.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*Dx4qV5dLbGQoNYcwYifa5w.png" alt="Image" width="800" height="449" loading="lazy"></p>
<h3 id="heading-3-developing-and-hosting-the-web-application">3. Developing and hosting the web application</h3>
<p><a target="_blank" href="https://github.com/kaizoku-619/firebase_iot_web"><strong>kaizoku-619/firebase_iot_web</strong></a><br><a target="_blank" href="https://github.com/kaizoku-619/firebase_iot_web">_Firebase web application client connected to Firebase Realtime database fetching sensor values …_github.com</a></p>
<p>Now that the IoT device is ready and pushing data to the Realtime Database, you can move to the other endpoint in the system, the web application. It will receive data from Firebase and display it on a dashboard.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*Rjf3-ZGcqjg_TUPOPmllOw.png" alt="Image" width="800" height="449" loading="lazy"></p>
<p>You will start by developing the app locally and eventually deploying it.</p>
<p>Start by setting up the project.</p>
<h4 id="heading-installing-firebase-cli"><strong>Installing Firebase CLI:</strong></h4>
<p>The <strong>Firebase CLI</strong> (command line interface) requires <strong>Node.js</strong> and <strong>npm</strong> (the Node Package Manager). Once they are installed you proceed to install the Firebase CLI using npm by running:</p>
<pre><code>npm install -g firebase-tools
</code></pre><p>You can follow the video to complete the project setup.</p>
<p>Once project setup is done your directory should look something like this:</p>
<pre><code>├── database.rules.json├── firebase.json└── public   ├── <span class="hljs-number">404.</span>html   └── index.html
</code></pre><p>Start by building the <strong>dashboard UI.</strong> This will be the <strong>index.html</strong> file. Open the file and change it to look like this:</p>
<p>This is a simple <strong>HTML</strong> page designed using <a target="_blank" href="https://fezvrasta.github.io/bootstrap-material-design/">Bootstrap Material Design</a>. It consists of <strong>2 Card</strong> elements, one for displaying Humidity and the other for displaying Temperature.</p>
<p>As for the Firebase part here, first you import the firebase dependency in the script tag inside the head tag. Finally when the page finishes loading, it calls <strong>app.js</strong>.</p>
<p>Now that the Dashboard UI is ready you can move on to <strong>app.js</strong> where you implement the firebase connection and your business logic. In the same directory create a new file called <strong>app.js</strong> and copy this code:</p>
<p>The script starts by creating a configuration object. The best way is to copy it directly from the firebase project in the firebase console. To do that, navigate to your firebase console and go to the firebase project settings. Then scroll down and click on the <strong>&lt;</strong>;/&gt; icon as shown here:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*UOd3xtXrWw291dCIP2I1zw.gif" alt="Image" width="800" height="450" loading="lazy"></p>
<p>I guess the rest of the code is self explanatory with the comments.</p>
<p>Now your app should be ready and you can test it locally with the following command:</p>
<pre><code>firebase serve
</code></pre><p><img src="https://cdn-media-1.freecodecamp.org/images/1*ZGnT6vNho7_lNuQNvcokBw.gif" alt="Image" width="600" height="337" loading="lazy"></p>
<p>Note that on startup the app will fetch the last temperature and humidity values from the database. Great! The app is working locally, but up until now it’s working only inside your localhost and can’t be accessed from the outside world. This means that it’s time to host it on the web using <strong>Firebase Hosting.</strong></p>
<p>But before you deploy it there is just one last thing you need to do. Go to the <strong>database.rules.json</strong> file and change the read and write rules to “<strong>true</strong>”. This method is not advised for production, as it is not secure, but it’s fine for demonstration purposes here.</p>
<p>With that done you are ready for deployment:</p>
<pre><code>firebase deploy
</code></pre><p><img src="https://cdn-media-1.freecodecamp.org/images/1*RUWH_VUFf_EJ2JVeUk6xWA.gif" alt="Image" width="600" height="337" loading="lazy"></p>
<p>There you go! If you’ve made it this far, by now you should have a live web application deployed and up and running.</p>
<h3 id="heading-putting-it-all-together">Putting it all together</h3>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*NRl95CtTxUi8Os7D_WKgAA.gif" alt="Image" width="500" height="226" loading="lazy"></p>
<p>It’s time to put everything together and test the system. Plug in the <strong>NodeMCU</strong> to your PC and upload the sketch if you haven’t already:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*neyIQF00mBE02W9aOw4ptg.gif" alt="Image" width="600" height="337" loading="lazy"></p>
<p>Open up the web app and the firebase database and watch it change in realtime with the values sent by the device.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*1JIi7SbvkC6LAePZiuRtjA.gif" alt="Image" width="600" height="337" loading="lazy"></p>
<p>Now open up the <strong>serial monitor</strong> and watch the data pushed from the device to the web app. Note that you can open the console in the browser to watch the received values. Here I use <a target="_blank" href="https://linux.die.net/man/1/gtkterm">Gtk Serial port terminal</a> with a baud-rate of 115200 bps, but you can use the integrated <strong>PlatformIO</strong> Serial Monitor or any other tool of your choice.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*oPKH60n5_9kQfIIdtx_Hjg.gif" alt="Image" width="600" height="337" loading="lazy"></p>
<h3 id="heading-troubleshooting">Troubleshooting</h3>
<p>I faced a problem while developing the application on the <strong>ESP8266</strong> (and it took me sometime to figure out). Even when everything was configured correctly (WiFi Connection, Firebase Host, Secret Key), the ESP8266 <strong>couldn’t connect to Firebase.</strong> This was caused by the <strong>wrong Fingerprint</strong> inside <strong>FirebaseHttpClient.h</strong> file in the Firebase library. You need to replace it with your own fingerprint. If you installed the library locally using <strong>PlatformIO</strong> then you can find the file in this path:</p>
<pre><code>your_project_folder/.piolibdeps/FirebaseArduino_ID1259/src/
</code></pre><p>To <strong>generate</strong> a fingerprint, go to this website and copy your Firebase host link without the https part and click on Fingerprint Site (mine is:<br>medium-iot-project.firebaseio.com):</p>
<p><a target="_blank" href="https://www.grc.com/fingerprints.htm"><strong>GRC | SSL TLS HTTPS Web Server Certificate Fingerprints</strong></a><br><a target="_blank" href="https://www.grc.com/fingerprints.htm">_GRC's HTTPS Web Server Certificate Fingerprint Service_www.grc.com</a></p>
<p>This will generate a fingerprint for your site, so go ahead and copy it in place of the old <strong>kFirebaseFingerprint[]</strong> value inside the <strong>FirebaseHttpClient.h</strong> file. That should fix the problem.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*TuJignt5v3mYTnybtktJnw.gif" alt="Image" width="471" height="200" loading="lazy"></p>
<h3 id="heading-conclusion">Conclusion</h3>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*HC62qJvM12Ey_u_CKA3uNQ.gif" alt="Image" width="498" height="211" loading="lazy"></p>
<p>Congratulations if you’ve made it this far!</p>
<p>We’ve only scratched the surface here. The Internet of Things is all about experimenting and exploring, so I encourage you to not stop here and keep learning by making mistakes and finding bugs in your code. But above all don’t forget to have fun along your learning journey.</p>
<h3 id="heading-references">References</h3>
<p><a target="_blank" href="https://firebase.google.com/docs/database/"><strong>Firebase Realtime Database | Firebase Realtime Database | Firebase</strong></a><br><a target="_blank" href="https://firebase.google.com/docs/database/">_Store and sync data with our NoSQL cloud database. Data is synced across all clients in realtime, and remains available…_firebase.google.com</a><a target="_blank" href="https://platformio.org/"><strong>PlatformIO: An open source ecosystem for IoT development</strong></a><br><a target="_blank" href="https://platformio.org/">_Cross-platform build system and library manager. Cross-platform IDE and unified debugger. Remote unit testing and…_platformio.org</a><a target="_blank" href="https://www.arduino.cc/"><strong>Arduino - Home</strong></a><br><a target="_blank" href="https://www.arduino.cc/">_Open-source electronic prototyping platform enabling users to create interactive electronic objects._www.arduino.cc</a><a target="_blank" href="https://fezvrasta.github.io/bootstrap-material-design/"><strong>Bootstrap Material Design</strong></a><br><a target="_blank" href="https://fezvrasta.github.io/bootstrap-material-design/">_The most popular HTML, CSS, and JS Material Design library in the world._fezvrasta.github.io</a><a target="_blank" href="https://github.com/esp8266/Arduino"><strong>esp8266/Arduino</strong></a><br><a target="_blank" href="https://github.com/esp8266/Arduino">_ESP8266 core for Arduino. Contribute to esp8266/Arduino development by creating an account on GitHub._github.com</a><a target="_blank" href="https://github.com/FirebaseExtended/firebase-arduino"><strong>FirebaseExtended/firebase-arduino</strong></a><br><a target="_blank" href="https://github.com/FirebaseExtended/firebase-arduino">_Arduino samples for Firebase. Contribute to FirebaseExtended/firebase-arduino development by creating an account on…_github.com</a><a target="_blank" href="https://www.grc.com/fingerprints.htm"><strong>GRC | SSL TLS HTTPS Web Server Certificate Fingerprints</strong></a><br><a target="_blank" href="https://www.grc.com/fingerprints.htm">_GRC's HTTPS Web Server Certificate Fingerprint Service_www.grc.com</a></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to build the most robust and secure home automation system ]]>
                </title>
                <description>
                    <![CDATA[ By Amir Off In this article, I’ll discuss how I built a Smart Home Automation System with Angular and Node.js on a Raspberry Pi without relying on any external cloud services. Intro Over the last few days, I spent some nights designing and developing... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/the-most-robust-and-secure-home-automation-system-6d0ddbb39f29/</link>
                <guid isPermaLink="false">66c361d95c8b3e001e067e67</guid>
                
                    <category>
                        <![CDATA[ Internet of Things ]]>
                    </category>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Node.js ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Raspberry Pi ]]>
                    </category>
                
                    <category>
                        <![CDATA[ technology ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Sat, 29 Sep 2018 11:55:28 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*ekrneFlaBAAqotbwcJ0pDA.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Amir Off</p>
<p><em>In this article, I’ll discuss how I built a Smart Home Automation System with Angular and Node.js on a Raspberry Pi without relying on any external cloud services.</em></p>
<h3 id="heading-intro">Intro</h3>
<p>Over the last few days, I spent some nights designing and developing a home automation system based on JavaScript, with the use of Angular and Node.js. And, like with any other project, the planning involved some deep research on the internet.</p>
<p>It turned out that there are plenty of fish in the sea —plenty of solutions on how to implement a home automation system. Some offer paid services in “the cloud” and others explain how to build your own using a technology called MQTT.</p>
<p>None of the solutions made any sense to me. All options were either expensive, or had inconvenient implementations or even security flaws.</p>
<p>But, before we go any further, let’s explain what MQTT is. MQTT stands for <strong>MQ Telemetry Transport</strong>. It is a publish/subscribe, extremely simple and lightweight messaging protocol. MQTT is designed for constrained devices and low-bandwidth, high-latency, or unreliable networks.</p>
<p>The design principles are to minimise network bandwidth and device resource requirements whilst attempting to ensure reliability and some degree of assurance of delivery. These principles also turn out to make the protocol <a target="_blank" href="http://mqtt.org">ideal for</a> the emerging “machine-to-machine” (M2M) or “Internet of Things” world of connected devices, and for mobile applications where bandwidth and battery power are at a premium.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/mNpCeEZHwF1UuwYj01abd-sbVPrKW-4yy8-t" alt="Image" width="800" height="460" loading="lazy">
<em>MQTT Publish/Subscribe Architecture (Image source: <a target="_blank" href="www.hivemq.com">HiveMQ.com</a>)</em></p>
<p>Why wasn’t I convinced about using MQTT, or by any of the solutions I found on the internet? Two reasons:</p>
<ol>
<li>While the MQTT technology seems very convenient for IoT devices, I still thought it was unnecessary. The system which I will be showing in the following tutorial operates in the same medium where the IoT devices live. All benefits that MQTT has for being “fast” and having “low-bandwidth” become irrelevant. Plus there’s all the hassle that is involved in its implementation and all the extra overhead with the additional npm packages that are required for it to work in a JavaScript environment. Instead, I will be using generic JavaScript and Node.js libraries only, nothing more!</li>
<li>What about the security part? Well, I’m not a big fan of “the cloud” or cloud computing in general. In some cases it can be very beneficial, but in most cases it’s just unnecessary. Think about it: why would you have a service that is required for controlling your home appliances to be hosted somewhere else in “the cloud” and not in your own network?</li>
</ol>
<p><img src="https://cdn-media-1.freecodecamp.org/images/6PYFXtvRMHaKIfhgJC68Ux7p5uJMqe5K1wE4" alt="Image" width="442" height="583" loading="lazy">
_Comic by [Geek and Poke](http://geekandpoke.typepad.com/geekandpoke/2009/11/good-consultants.html" rel="noopener" target="<em>blank" title=")</em></p>
<p>One might think that “the cloud” provides the ability to access your home appliances from anywhere in the world via the internet.</p>
<p>But think about this: when your home network doesn’t have internet connection, “the cloud” becomes redundant. More importantly, you can still make your home automation system accessible from the internet using port-forwarding even if it’s hosted on your local network.</p>
<p>This is when it “clicked” for me, and I thought about hosting the whole system on a Raspberry Pi and keeping it in my local network.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/IkTlTjziky8EUtdFX8G4BCVGwMa9aijqLZh7" alt="Image" width="800" height="600" loading="lazy">
<em>A Raspberry Pi 3 Model B</em></p>
<h3 id="heading-the-technology">The technology</h3>
<ol>
<li><strong>Software:</strong> The reason why I chose Angular and Node.js is because they’re based on JavaScript and I’m already familiar with it. After all, I wanted to design and develop a progressive web app that communicates with my IoT devices via HTTP — and JavaScript offered all the functionality that I needed.</li>
<li><strong>Hardware:</strong> The system works with microcontrollers like the Arduino Uno/Mega/Du/MKR1000, Adafruit HUZZAH CC3000, and any other microcontroller with a WiFi connection. I am using the <a target="_blank" href="https://medium.com/p/deb7bd1841c1?source=user_profile---------3------------------"><strong>ESP8266</strong></a> as a base component for my home automation system. It’s a low-cost WiFi microchip with microcontroller capability. It has everything I need and for a cheap price! Lastly, we need to host the system somewhere on our local network — so what’s better than the Raspberry Pi?</li>
</ol>
<p>This won’t be a coding tutorial where I dive deep into coding, since this project is open-source and I will be publishing everything on GitHub. I will only demonstrate how to implement your own home automation system and will be going through each step. If you’re a developer please <a target="_blank" href="https://github.com/ameer157/smarthaus"><strong>fork</strong></a> the repository and get involved in improving it.</p>
<h3 id="heading-the-setup">The setup</h3>
<p>I estimate that it will take about 40 minutes to finish this whole setup plus any time spent online searching for solutions for installation errors.</p>
<h4 id="heading-what-is-needed"><strong>What is needed?</strong></h4>
<p>A Raspberry Pi is required. In my example I’m using a Raspberry Pi 3, but it should work with most versions. The components needed are:</p>
<ol>
<li>Raspberry Pi board</li>
<li>MicroSD card (A class 10 with 16 GB or higher is recommended)</li>
<li>A USB MicroSD card reader or SD card adapter</li>
<li>HDMI monitor and a USB keyboard (only required temporarily for the first boot of the Raspberry Pi)</li>
<li>Ethernet cable (not needed for Raspberry Pi 3 as it has built in WiFi)</li>
</ol>
<h4 id="heading-installing-raspbian-os-on-the-raspberry-pi">Installing Raspbian OS on the Raspberry Pi</h4>
<p>Raspbian is a free operating system based on Debian Linux, and it is optimized for Raspberry Pi.</p>
<p><strong>I recommend</strong> the headless “LITE” version. It has no desktop environment or any graphical user interface, and it’s remotely accessible from a computer or device on the same network via SSH. We’re keeping things simple since this is the only way we are going to access the Raspberry Pi. The LITE version has all the functionality we’re looking for.</p>
<ol>
<li>Download <a target="_blank" href="https://www.raspberrypi.org/downloads/raspbian/"><strong>the latest</strong></a> Raspbian image from the official Raspberry Pi website.</li>
<li>Flash the Raspbian OS image to the SD card with <a target="_blank" href="https://etcher.io/"><strong>Etcher</strong></a> or any other OS image burning software of your choice.</li>
</ol>
<h4 id="heading-setting-up-the-raspberry-pi">Setting up the Raspberry Pi</h4>
<p>To get the Raspberry Pi ready to boot we need to:</p>
<ol>
<li>Insert the MicroSD card into the Raspberry Pi</li>
<li>Connect the USB keyboard and the HDMI cable</li>
<li>Connect the Ethernet cable or if you have a Raspberry Pi 3 and want to use WiFi you should set up the network in the next section</li>
</ol>
<p>When the Raspberry Pi has finished booting up, log in using username <code>pi</code> and password <code>raspberry</code></p>
<h4 id="heading-enabling-wifi-and-connecting-to-the-network">Enabling WiFi and connecting to the network</h4>
<p><strong>Skip this step</strong> if you chose to connect with an Ethernet cable.</p>
<ol>
<li>Open the “wpa-supplicant” configuration file</li>
</ol>
<pre><code>$ sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
</code></pre><ol start="2">
<li>add the following at the bottom of the file while adding your wifi name and password:</li>
</ol>
<pre><code>network={
</code></pre><pre><code>   ssid=<span class="hljs-string">"your_networks_name"</span>   psk=<span class="hljs-string">"your_networks_password"</span>
</code></pre><pre><code>}
</code></pre><p><strong>3.</strong> Press <code>Ctrl+X</code> to save the code. Confirm with <code>Y</code> then <code>Enter</code></p>
<p><strong>4.</strong> Reboot the Raspberry Pi with the following command:</p>
<pre><code>$ sudo reboot
</code></pre><h4 id="heading-enabling-ssh-and-changing-the-username-and-password"><strong>Enabling SSH and changing the username and password</strong></h4>
<p>Now that the Raspberry Pi is connected to the internet, it’s recommended to change the default password.</p>
<ol>
<li>Open the Raspberry Pi configuration tool and click the second option “Change User Password” and follow the instructions</li>
</ol>
<pre><code>$ sudo raspi-config
</code></pre><p><img src="https://cdn-media-1.freecodecamp.org/images/dtaG9lRXQkYqmnIqANMtcZOb0IoxB9sfhDmz" alt="Image" width="800" height="241" loading="lazy"></p>
<p><strong>2.</strong> Select option 5 “Interfacing Options” then activate SSH</p>
<p><strong>3.</strong> Reboot the Raspberry Pi. When it’s up, you have SSH enabled and it’s ready to be accessed remotely from your desktop computer</p>
<pre><code>$ sudo reboot
</code></pre><h4 id="heading-configuring-remote-access-to-the-raspberry-pi">Configuring remote access to the Raspberry Pi</h4>
<p>Now, finally, the part when we install the required software on the Raspberry Pi. This part can be executed directly on the Pi through the terminal using a HDMI monitor and a USB keyboard. For convenience — and since we enable remote SSH connection — we’re going to connect from another desktop environment. This is the best and easiest way to remotely access and control the Pi whenever changes and configurations are needed.</p>
<p>So, basically, this is how you can access the command line interface of a Raspberry Pi remotely from another computer or any device on the same network using SSH. This can be done in two ways:</p>
<ol>
<li>Using the Command Prompt or PowerShell (I’m using Windows on a Desktop computer), replace with your username and IP address</li>
</ol>
<pre><code>$ ssh username@ipaddress
</code></pre><p>If you <strong>do not know</strong> the IP address, type “<code>hostname -I"</code> in the Raspberry Pi command line.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/p9TrkcLo-EaANTz2-5xivbif9p3RXm5wIGYA" alt="Image" width="918" height="547" loading="lazy"></p>
<p><strong>2.</strong> The second method is using a client program like <a target="_blank" href="https://www.putty.org/"><strong>PuTTY</strong></a> or any <a target="_blank" href="https://www.google.co.il/search?q=ssh+client"><strong>other</strong></a> functioning client SSH software. Here’s an easy <a target="_blank" href="https://www.raspberrypi.org/documentation/remote-access/ssh/windows.md"><strong>guide</strong></a> for using PuTTY.</p>
<h4 id="heading-installing-the-required-software-on-the-raspberry-pi">Installing the required software on the Raspberry Pi</h4>
<p>Before installing anything, it’s recommended to update the Raspberry Pi’s operating system and packages. Doing this regularly will keep it up-to-date.</p>
<ol>
<li>Update the system packages list using the following command:</li>
</ol>
<pre><code>$ sudo apt-get update
</code></pre><p><strong>2.</strong> Upgrade all your installed packages to their latest version:</p>
<pre><code>$ sudo apt-get dist-upgrade
</code></pre><p><strong>3.</strong> Download and install the latest version of Node.js:</p>
<pre><code><span class="hljs-comment">// To download$ curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -</span>
</code></pre><pre><code><span class="hljs-comment">// To install$ sudo apt-get install -y nodejs</span>
</code></pre><pre><code><span class="hljs-comment">// Check if the installation was successful:$ node -v</span>
</code></pre><p><strong>4.</strong> Install the Angular CLI globally:</p>
<pre><code>$ npm install -g @angular/cli
</code></pre><p><strong>5.</strong> Install the Git version-control system:</p>
<pre><code>$ sudo apt-get install git
</code></pre><h4 id="heading-installing-the-database-mongodb">Installing the database (MongoDB)</h4>
<p>We need a database for storing the registered users and their credentials. Here are the required steps:</p>
<ol>
<li>Install MongoDB</li>
</ol>
<pre><code>$ sudo apt-get install mongodb
</code></pre><ol start="2">
<li>Start the MongoDB process</li>
</ol>
<pre><code>$ sudo service mongodb start
</code></pre><ol start="3">
<li>Start the mongo Shell</li>
</ol>
<pre><code>$ mongo
</code></pre><ol start="3">
<li>Create a database called “smarthaus”</li>
</ol>
<pre><code>$ use smarthaus
</code></pre><p>In MongoDB, default database is test. If you didn’t create any database, then collections will be stored in test database.</p>
<h4 id="heading-installing-smart-haus">Installing Smart Haus</h4>
<p><strong>1.</strong> Check the current work directory using this command:</p>
<pre><code>$ pwd
</code></pre><pre><code><span class="hljs-comment">/* It will probably print "/home/pi"   where "pi" is the current user directory */</span>
</code></pre><p><strong>It’s recommended</strong> to clone the project’s repository under the pi’s user directory but you can navigate somewhere else if you’re sure.</p>
<p><strong>2.</strong> Clone the repository from:</p>
<pre><code>$ git clone https:<span class="hljs-comment">//github.com/ameer157/smarthaus.git</span>
</code></pre><p>Make sure to navigate inside the directory using:</p>
<pre><code>$ cd smarthaus
</code></pre><p>Before installing any npm packages using “npm install” please refer to the <a target="_blank" href="https://docs.npmjs.com/getting-started/fixing-npm-permissions#option-two-change-npms-default-directory"><strong>npm guide to fix permissions</strong></a> to learn how to fix any “<strong>EACCESS</strong> ”errors you might face during installation. This is <strong>very important</strong> since it will prevent any npm permission errors, and allows you to install packages globally without using sudo. Using sudo with npm is not recommended and <a target="_blank" href="https://medium.com/@ExplosionPills/dont-use-sudo-with-npm-still-66e609f5f92"><strong>should be avoided</strong></a>.</p>
<p><strong>3.</strong> Install all the required packages for the project:</p>
<pre><code>$ npm install
</code></pre><p><img src="https://cdn-media-1.freecodecamp.org/images/iCw2rJLK34PWv0B-UGGeoWcwO8i10-mgY2FI" alt="Image" width="961" height="576" loading="lazy"></p>
<h4 id="heading-starting-the-nodejs-server">Starting the Node.js server</h4>
<p>Before starting the server we need to build the project using the Angular CLI tool. And lastly, we configure the Raspberry Pi so that it runs the server whenever it boots up.</p>
<ol>
<li>Build the project using:</li>
</ol>
<pre><code>$ ng build --prod
</code></pre><p><strong>2.</strong> Edit the <code>rc.local</code> file using <code>nano</code>:</p>
<pre><code>$ sudo nano /etc/rc.local
</code></pre><p><strong>3.</strong> Add the following on the line before <code>exit 0</code> then exit and save the file:</p>
<pre><code>su pi -c <span class="hljs-string">'cd /home/pi/smarthaus/backend &amp;&amp; sudo node server.js &gt; log.txt &amp;'</span>
</code></pre><p><img src="https://cdn-media-1.freecodecamp.org/images/jHBDN5kBPqJ6oiWY269MJ1o0dAe7TlEPrL7X" alt="Image" width="800" height="501" loading="lazy"></p>
<p>The Node.js server is now ready! It will run on every system boot up and save logs in under the same directory in a “log.txt” file.</p>
<p>Let’s run it now and see if it works using this command:</p>
<pre><code>$ sudo node server
</code></pre><p>The system in now accessible from any device on your network via the Raspberry Pi’s IP address.</p>
<p>Please go ahead and <a target="_blank" href="https://github.com/ameer157/smarthaus"><strong>fork</strong></a> this project and get involved in developing the missing parts ?</p>
<h3 id="heading-the-end">The end</h3>
<p>We got ourselves a working home automation system running safely on a Raspberry Pi in our local network without the use of “the cloud” or somebody else’s server.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/3JIKPjo9dQos9Ua-10JPxsJnQPVt4PvH1EJF" alt="Image" width="566" height="306" loading="lazy"></p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/BdA31vbNfgwI0goItUDCZLdNlAv7XF5akvsu" alt="Image" width="566" height="306" loading="lazy">
<em>Real-time device status synchronization</em></p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/TAQatUFW1P3nbEaFN5v3Lm495VfROtRNnkKo" alt="Image" width="693" height="411" loading="lazy"></p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/tULxNb2WIueLALx-z-A5D6AMPMtw8h0hJ2Tw" alt="Image" width="566" height="306" loading="lazy">
<em>Adding a new device synchronising data on-demand</em></p>
<p>My Raspberry Pi sitting next to my <a target="_blank" href="http://bit.ly/2OiO1Pm"><strong>Fingbox</strong></a> and router in the living room ?</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/UbJPvVTIOvQXwBXNclgpBCxqWVFnUqtbocMZ" alt="Image" width="800" height="600" loading="lazy">
<em>Rick and Morty providing tech support ??</em></p>
<p>I hope you enjoyed reading,<br>Please <a target="_blank" href="https://medium.com/@ameer157"><strong>follow</strong></a> and <strong>share</strong> for more tech stuff ??</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/dc-iMjp94vVUVYzJKTYxFuVd8UYPENjRMPTH" alt="Image" width="146" height="174" loading="lazy"></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to measure temperature and send it to AWS IoT using a Raspberry Pi ]]>
                </title>
                <description>
                    <![CDATA[ By Leo Kyrpychenko What if you want to self-correct the temperature in your office? Or what if you are curious to understand your office environment using IoT sensors? If this sounds interesting to you, please read on. To begin with, we need to set u... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-measure-temperature-and-send-it-to-aws-iot-using-a-raspberry-pi-d6f7b196ec35/</link>
                <guid isPermaLink="false">66d46012d1ffc3d3eb89de18</guid>
                
                    <category>
                        <![CDATA[ AWS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Internet of Things ]]>
                    </category>
                
                    <category>
                        <![CDATA[ General Programming ]]>
                    </category>
                
                    <category>
                        <![CDATA[ tech  ]]>
                    </category>
                
                    <category>
                        <![CDATA[ TypeScript ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Mon, 10 Sep 2018 15:51:03 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*luZBAP5jAeQXIoKDlm2Lqg.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Leo Kyrpychenko</p>
<p>What if you want to self-correct the temperature in your office? Or what if you are curious to understand your office environment using IoT sensors?</p>
<p>If this sounds interesting to you, please read on.</p>
<p>To begin with, we need to set up a temperature reading sensor. We connect it to an Arduino which connects to a RaspberryPi.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*luZBAP5jAeQXIoKDlm2Lqg.jpeg" alt="Image" width="799" height="1066" loading="lazy"></p>
<p>The next step is to set up AWS IoT SDK on your Raspberry Pi.</p>
<h4 id="heading-setup-the-thing">Setup the Thing</h4>
<ol>
<li>Create a thing in AWS IoT:</li>
</ol>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*HMoK-8MpdziO3p1KgUu1WQ.png" alt="Image" width="800" height="581" loading="lazy"></p>
<ol start="2">
<li>Create a single thing to begin with:</li>
</ol>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*Zkpo9cALdjh6y_91NkYlgQ.png" alt="Image" width="800" height="472" loading="lazy"></p>
<ol start="3">
<li>Create a thing of a particular type. We are using RaspberryPi here (the types are made up by you).</li>
</ol>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*wpws9o3IaQd1QrhZerkgxw.png" alt="Image" width="800" height="1034" loading="lazy"></p>
<p>4.Create a certificate for your Thing to communicate with AWS:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*kvhutJBA_nZMl4tCRYlPhw.png" alt="Image" width="800" height="501" loading="lazy"></p>
<ol start="5">
<li>Download the certificates, a root certificate authority (CA), activate the Thing, and attach the policy.</li>
</ol>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*IlIegdjeWhnlsCPsk2CR9A.png" alt="Image" width="800" height="541" loading="lazy"></p>
<ol start="6">
<li>The policy code is here. It may seem a bit permissive, but it is OK for the demo App.</li>
</ol>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*mY-mP_JRKku7qBxk-PkTVg.png" alt="Image" width="800" height="518" loading="lazy"></p>
<h4 id="heading-setup-your-raspberrypi">Setup your RaspberryPi</h4>
<p>Before you start the setup, please copy all certificates and all root CA files over to the RaspberryPI (scp might help you). You also need to install Node.js if you don’t have it already.</p>
<p>You will also need to install the AWS IoT device SDK.</p>
<pre><code class="lang-bash">sudo apt-get update
sudo apt-get upgrade
sudo apt-get install nodejs

openssl x509 -<span class="hljs-keyword">in</span> ./CA-roots/VeriSign-Class\ 3-Public-Primary-Certification-Authority-G5.pem -inform PEM -out root-CA.crt
chmod 775 root-CA.crt

npm install aws-iot-device-sdk
</code></pre>
<p>Here is the code that reads the data from the serial port and sends temperature readings using the AWS IoT device SDK. The code is based on the examples from Amazon.</p>
<pre><code class="lang-js"><span class="hljs-meta">'use strict'</span>;

<span class="hljs-built_in">console</span>.log(<span class="hljs-string">'Running...'</span>);

<span class="hljs-keyword">const</span> SerialPort = <span class="hljs-built_in">require</span>(<span class="hljs-string">'serialport'</span>);
<span class="hljs-keyword">const</span> Readline = <span class="hljs-built_in">require</span>(<span class="hljs-string">'@serialport/parser-readline'</span>)

<span class="hljs-keyword">const</span> portName = <span class="hljs-string">'/dev/ttyACM0'</span>;
<span class="hljs-keyword">const</span> port = <span class="hljs-keyword">new</span> SerialPort(portName, <span class="hljs-function">(<span class="hljs-params">err</span>) =&gt;</span> {
    <span class="hljs-keyword">if</span> (err) {
        <span class="hljs-keyword">return</span> <span class="hljs-built_in">console</span>.log(<span class="hljs-string">'Error: '</span>, err.message);
    }
});

<span class="hljs-keyword">const</span> deviceModule = <span class="hljs-built_in">require</span>(<span class="hljs-string">'aws-iot-device-sdk'</span>).device;

<span class="hljs-keyword">const</span> parser = port.pipe(<span class="hljs-keyword">new</span> Readline({ <span class="hljs-attr">delimiter</span>: <span class="hljs-string">'\r\n'</span> }));
<span class="hljs-keyword">const</span> rePattern = <span class="hljs-keyword">new</span> <span class="hljs-built_in">RegExp</span>(<span class="hljs-regexp">/C: (.+)F:(.+)/</span>);

parser.on(<span class="hljs-string">'data'</span>, <span class="hljs-function">(<span class="hljs-params">data</span>) =&gt;</span> {
    <span class="hljs-keyword">const</span> arrMatches = data.match(rePattern);

    <span class="hljs-keyword">if</span>(arrMatches &amp;&amp; arrMatches.length &gt;= <span class="hljs-number">1</span>) {
        <span class="hljs-keyword">const</span> readingInC = arrMatches[<span class="hljs-number">1</span>].trim();
        <span class="hljs-built_in">console</span>.log(readingInC);

        sendDataToTheNube(readingInC);
    }
});

<span class="hljs-keyword">const</span> defaults = {
    <span class="hljs-attr">protocol</span>: <span class="hljs-string">'mqtts'</span>,
    <span class="hljs-attr">privateKey</span>: <span class="hljs-string">'./iot/f5b0580f5c-private.pem.key'</span>,
    <span class="hljs-attr">clientCert</span>: <span class="hljs-string">'./iot/f5b0580f5c-certificate.pem.crt'</span>,
    <span class="hljs-attr">caCert</span>: <span class="hljs-string">'./iot/root-CA.crt'</span>,
    <span class="hljs-attr">testMode</span>: <span class="hljs-number">1</span>,
    <span class="hljs-comment">/* milliseconds */</span>
    <span class="hljs-attr">baseReconnectTimeMs</span>: <span class="hljs-number">4000</span>,
    <span class="hljs-comment">/* seconds */</span>
    <span class="hljs-attr">keepAlive</span>: <span class="hljs-number">300</span>,
    <span class="hljs-comment">/* milliseconds */</span>
    <span class="hljs-attr">delay</span>: <span class="hljs-number">4000</span>,
    <span class="hljs-attr">thingName</span>: <span class="hljs-string">'cuttlefish-hub-01'</span>,
    <span class="hljs-attr">clientId</span>: <span class="hljs-string">'nouser'</span> + (<span class="hljs-built_in">Math</span>.floor((<span class="hljs-built_in">Math</span>.random() * <span class="hljs-number">100000</span>) + <span class="hljs-number">1</span>)),
    <span class="hljs-attr">Debug</span>: <span class="hljs-literal">false</span>,
    <span class="hljs-attr">Host</span>: <span class="hljs-string">'a7773lj8lvoid9a.iot.ap-southeast-2.amazonaws.com'</span>,
    <span class="hljs-attr">region</span>: <span class="hljs-string">'ap-southeast-2'</span>
};

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">sendDataToTheNube</span>(<span class="hljs-params">readingInC</span>) </span>{
    <span class="hljs-keyword">const</span> device = deviceModule({
          <span class="hljs-attr">keyPath</span>: defaults.privateKey,
          <span class="hljs-attr">certPath</span>: defaults.clientCert,
          <span class="hljs-attr">caPath</span>: defaults.caCert,
          <span class="hljs-attr">clientId</span>: defaults.clientId,
          <span class="hljs-attr">region</span>: defaults.region,
          <span class="hljs-attr">baseReconnectTimeMs</span>: defaults.baseReconnectTimeMs,
          <span class="hljs-attr">keepalive</span>: defaults.keepAlive,
          <span class="hljs-attr">protocol</span>: defaults.Protocol,
          <span class="hljs-attr">port</span>: defaults.Port,
          <span class="hljs-attr">host</span>: defaults.Host,
          <span class="hljs-attr">debug</span>: defaults.Debug
    });

    device.publish(<span class="hljs-string">`temperature/<span class="hljs-subst">${defaults.thingName}</span>`</span>, <span class="hljs-built_in">JSON</span>.stringify({
        <span class="hljs-attr">temperature</span>: readingInC
    }));
}
</code></pre>
<p>So now what can you do with that data?</p>
<p>You can write a Lambda that enqueues the data for processing. It may look like this:</p>
<pre><code class="lang-js"><span class="hljs-built_in">require</span>(<span class="hljs-string">"source-map-support"</span>).install();

<span class="hljs-keyword">import</span> { Callback, Handler } <span class="hljs-keyword">from</span> <span class="hljs-string">"aws-lambda"</span>;
<span class="hljs-keyword">import</span> { baseHandler } <span class="hljs-keyword">from</span> <span class="hljs-string">"../shared/lambda"</span>;
<span class="hljs-keyword">import</span> logger <span class="hljs-keyword">from</span> <span class="hljs-string">"../shared/logger"</span>;
<span class="hljs-keyword">import</span> {Models} <span class="hljs-keyword">from</span> <span class="hljs-string">"../shared/models"</span>;
<span class="hljs-keyword">import</span> {QueueWriter} <span class="hljs-keyword">from</span> <span class="hljs-string">"./queue-writer"</span>;

<span class="hljs-keyword">const</span> handler: Handler = baseHandler(<span class="hljs-function">(<span class="hljs-params">event: any, callback: Callback</span>) =&gt;</span> {
    logger.json(<span class="hljs-string">"Event:"</span>, event);

    <span class="hljs-keyword">const</span> writer = <span class="hljs-keyword">new</span> QueueWriter();

    <span class="hljs-keyword">const</span> { temperature, sensorId } = event;

    <span class="hljs-keyword">const</span> reading: Models.Readings.TemperatureReading = {
        temperature,
        sensorId,
    };

    writer.enqueue(reading)
        .then(<span class="hljs-function">() =&gt;</span> callback())
        .catch(callback);
});

<span class="hljs-keyword">export</span> { handler };
</code></pre>
<p>And your serverless.com file may look like this:</p>
<pre><code class="lang-yaml"><span class="hljs-attr">functions:</span>
    <span class="hljs-attr">sensorReadings:</span>
        <span class="hljs-attr">name:</span> <span class="hljs-string">${self:provider.stage}-${self:service}-sensor-readings</span>
        <span class="hljs-attr">handler:</span> <span class="hljs-string">sensor-readings/index.handler</span>
        <span class="hljs-attr">description:</span> <span class="hljs-string">Gets</span> <span class="hljs-string">triggered</span> <span class="hljs-string">by</span> <span class="hljs-string">AWS</span> <span class="hljs-string">IoT</span>
        <span class="hljs-attr">timeout:</span> <span class="hljs-number">180</span>
        <span class="hljs-attr">environment:</span>
            <span class="hljs-attr">READING_QUEUE_NAME:</span> <span class="hljs-string">${self:provider.stage}_${self:custom.productName}_reading</span>
            <span class="hljs-attr">READING_DL_QUEUE_NAME:</span> <span class="hljs-string">${self:provider.stage}_${self:custom.productName}_reading_dl</span>
        <span class="hljs-attr">tags:</span>
            <span class="hljs-attr">service:</span> <span class="hljs-string">${self:service}</span>
        <span class="hljs-attr">events:</span>
             <span class="hljs-bullet">-</span> <span class="hljs-attr">iot:</span>
                <span class="hljs-attr">sql:</span> <span class="hljs-string">"SELECT * FROM '#'"</span>
</code></pre>
<p>I hope this post has saved you some time setting up your device. Thanks for reading!</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Beginner’s Guide to Raspberry Pi ]]>
                </title>
                <description>
                    <![CDATA[ By Sean Choi It’s the little things that count. Raspberry Pi 3 Model B+ Many question what the term Internet of Things (IoT) means or what it actually represents. In simple terms, IoT is a term for categorizing anything that can connect to the Inter... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/beginners-guide-to-raspberry-pi-6e55080fdaaf/</link>
                <guid isPermaLink="false">66c3456d9972b7c5c7624e12</guid>
                
                    <category>
                        <![CDATA[ education ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Internet of Things ]]>
                    </category>
                
                    <category>
                        <![CDATA[ General Programming ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Raspberry Pi ]]>
                    </category>
                
                    <category>
                        <![CDATA[ technology ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Fri, 23 Mar 2018 22:26:53 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*rD9cweBR5NdgFg-l8koTOQ.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Sean Choi</p>
<h4 id="heading-its-the-little-things-that-count">It’s the little things that count.</h4>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*rD9cweBR5NdgFg-l8koTOQ.png" alt="Image" width="800" height="527" loading="lazy">
<em>Raspberry Pi 3 Model B+</em></p>
<p>Many question what the term <em>Internet of Things (IoT)</em> means or what it actually represents. In simple terms, <em>IoT</em> is a term for categorizing anything that can connect to the Internet. This includes your Alexa, HomePod, Android watch, Samsung smart refrigerator and many more. Even if you realize that IoT is a term meant to describe a group of little devices that connect to the Internet that talk to each other, it is still rather unclear how these little devices actually do what they do.</p>
<p>In contrast, everyone knows generally what a Macbook or a computer does and what they are capable of doing. Interestingly, the internals of these IoT devices are very similar to the computers that we use everyday, which includes a processing unit, memory, network and/or bluetooth module and some other sensors.</p>
<p>What many people don’t realize is how easy it is to make your own <em>IoT</em> device using a small computer. In fact, you might wonder if there even exists a readily available, cheap, and powerful small computer. The good news is that it actually <strong>exists</strong> and it’s <strong>really</strong> <strong>powerful.</strong></p>
<h3 id="heading-raspberry-pi-is-exactly-that">Raspberry Pi is EXACTLY That.</h3>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*GzvXMi0Yw0nq3tMRkoSyWQ.png" alt="Image" width="574" height="391" loading="lazy">
<em>Raspberry Pi 3 (raspberrypi.org)</em></p>
<p><a target="_blank" href="https://amzn.to/2PLBxk1">Raspberry Pi</a> is a small computer that fits snugly in your hand. Don’t be fooled by it’s size and just look at the hardware specs for the latest (3+) generation Raspberry Pi.</p>
<ul>
<li>1.4 GHz 64-bit quad-core <a target="_blank" href="https://en.wikipedia.org/wiki/ARM_Cortex-A53">ARM Cortex-A53</a>, 1GB RAM</li>
<li>2.4/5Ghz dual band 802.11ac Wireless LAN, 10/100/1000Mbps Ethernet</li>
<li>Bluetooth 4.2</li>
<li>4 USB ports, Full HDMI port, Combined 3.5mm audio jack and composite video port, 40 GPIO pins</li>
<li>Micro SD card slot, VideoCore IV 3D graphics core, Camera interface (CSI), Display interface (DSI),</li>
</ul>
<p>As you can see, this little beast houses a Quad-Core CPU, fast wireless, bluetooth module and enough RAM to do most things you do on your computer. Better yet, <a target="_blank" href="https://amzn.to/2PLBxk1">this only costs $35</a>, or about a reasonable dinner out (or <a target="_blank" href="https://sf.eater.com/2017/5/23/15677684/avocado-toast-prices-menu-costs-san-francisco">3 avocado toasts in SF</a>).</p>
<p>Raspberry Pis have an interesting naming convention. They are categorized by a combination of model name and generation. The model names include A, A+, B, B+, Zero and Compute Module (Compute Module is intended mainly for industrial applications, so we won’t touch on it in this article).</p>
<p>Each model is differentiated by available connectors and the size of the main board. There are various generations built so far, which are largely categorized by numbers from 1 to 3. Each generation is mainly differentiated by the chip performance. The latest and the most powerful version is called <em>Raspberry Pi 3+ Model B+</em>.</p>
<p>As a reference, here are some images that show what parts are available in each of the models.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*sgjYyv_QE0J8ZHyh48mCiQ.png" alt="Image" width="720" height="400" loading="lazy">
<em>Raspberry Pi Model Zero</em></p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*Zm0VfWGhkxG_wJPyMTXvNA.png" alt="Image" width="311" height="211" loading="lazy"></p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*E4pQ7ipQ7hGuMt2kstmORQ.png" alt="Image" width="311" height="211" loading="lazy">
<em>Raspberry Pi 1 Model A (left), Raspberry Pi 1 Model A+ revision 1.1 (right)</em></p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*t0OXJ9YgOHEDDPYn63yPxg.png" alt="Image" width="311" height="211" loading="lazy"></p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*fdW23Z7okJlTkNMyqqT9vQ.png" alt="Image" width="311" height="211" loading="lazy"></p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*NjVZqwr3uKVZu_nd1f5d3g.png" alt="Image" width="316" height="211" loading="lazy">
<em>Raspberry Pi 1 Model B (left), Raspberry Pi 1,2 Model B+ (middle), Raspberry Pi 3Model B+ (right)</em></p>
<p>Each model has it’s own tradeoffs. For example, Raspberry Pi Model Zero is the smallest of them all and consumes only 100 mA (0.5W) of power on average. (An average desktop houses a 200~1400W power supply). But, it only houses a single-core CPU, has lower RAM, and lacks a full HDMI port.</p>
<p>However, its smaller size allows it to fit into more spaces, which makes it useful for building devices that are space- and power-constrained. So, having multiple models to choose from increases your options for your project.</p>
<h3 id="heading-what-software-does-it-run">What software does it run?</h3>
<p>Unfortunately, Raspberry Pi does not run Mac OS X or Windows. Instead, it runs a version of Linux called <a target="_blank" href="https://www.raspberrypi.org/downloads/raspberry-pi-desktop/">Raspbian</a>. You can choose to install Raspbian on a micro SD card yourself with NOOBS installer, or purchase a pre-loaded micro SD card like one seen <a target="_blank" href="http://amzn.to/2DO09P0">here</a>. Once you plug in the micro SD card with Raspbian installed and turn on the Raspberry Pi, you get the following loading screen:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*HBm9igWAM0uNQJdViGyGag.jpeg" alt="Image" width="800" height="431" loading="lazy">
_Raspbian loading screen. Image from [https://alternativeto.net/software/raspbian/](https://alternativeto.net/software/raspbian/" rel="noopener" target="<em>blank" title=")</em></p>
<p>As you can see, the desktop looks just like a regular desktop on your large PC. By default, you get a web browser, terminal, image viewer, calculator and many more features.</p>
<p>Raspbian also lets you install tons of software from it’s own open source software repository at no cost. The process of installing a software is also quite simple. You can utilize the <em>apt-get</em> command, a popular Linux command to install software from various repositories, to install any available software.</p>
<p>For example,<code>sudo apt-get install scratch2</code> will install the popular <a target="_blank" href="https://scratch.mit.edu/">scratch programming language</a>. Browse around various repositories and StackOverflow, and you will soon realize you can do just about anything with these devices.</p>
<h3 id="heading-what-can-you-actually-do-with-this">What can you ACTUALLY do with this?</h3>
<p>Ok, so now you have a small computer that runs a bunch of free software. What can you actually do with it? Well, here’s an easy and fun Python project that I have implemented with a group of middle school students as part of a coding class.</p>
<p>Using a <a target="_blank" href="https://amzn.to/2NCMdwd">Raspberry Pi compatible temperature/humidity/pressure sensor with LED screen</a>, I taught the concept of randomness using random colors on the LED screen rather than numbers. My students loved how they could visually and physically interact with their own code. You can see the video of the project here:</p>
<p>Using the same device, we also built a calculator, gaming device, weather station and much more. I found them a very useful and cost efficient way to teach introductory programming to young students. I plan to cover the details of my curriculums in an article some other time.</p>
<p>One of my colleagues at Stanford built a customized Raspberry Pi secured espresso machine to protect our precious coffee. The idea is somewhat similar to a Raspberry Pi secured door lock as seen <a target="_blank" href="https://www.youtube.com/watch?v=bAcK80fm1_0">here</a>.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*6oZ2WsV6LCygftHXzgbcig.jpeg" alt="Image" width="800" height="450" loading="lazy">
<em>Raspberry Pi secured door lock by HackerHouse</em></p>
<p>There are many, many articles on using a Raspberry Pi to build fun and useful IoT devices. Here are some list of them I found: <a target="_blank" href="https://pimylifeup.com/raspberry-pi-security-camera/">Raspberry Pi Security Camera</a>, <a target="_blank" href="https://www.makeuseof.com/tag/kodi-raspberry-pi-media-center/">Raspberry Pi Media Center</a>, <a target="_blank" href="https://projects.raspberrypi.org/en/codeclub">Raspberry Pi Code Club</a>.</p>
<h3 id="heading-wrapping-up">Wrapping up</h3>
<p>I hope this article gives some basic insights on what Raspberry Pis are, how they are built and what they are used for. Also, I hope this article somewhat demystifies what IoT really means.</p>
<p>In essence, IoT is a movement to connect millions of little things using the Internet, and Raspberry Pi is one of the ways to power those little things. I truly believe that the future lies in IoT and I hope everyone try to participate in bringing it a step closer to us.</p>
<blockquote>
<p>It’s the little things that count, hundreds of ’em.</p>
<p>— Cliff Shaw.</p>
</blockquote>
<p><em>This is my first article on Medium! Any comment for corrections, improvements and applauses is greatly appreciated!</em></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to run Grafana with DeviceHive ]]>
                </title>
                <description>
                    <![CDATA[ By Nikolay Khabarov DeviceHive is an IoT platform which has plenty of different components. The Grafana plugin is one of them. This plugin can gather data from a DeviceHive server and display it with different dashboards using the very popular tool —... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-run-grafana-with-devicehive-b2f57fe998a8/</link>
                <guid isPermaLink="false">66c3543a5f85c1948b3fabb8</guid>
                
                    <category>
                        <![CDATA[ Grafana ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Internet of Things ]]>
                    </category>
                
                    <category>
                        <![CDATA[ iot ]]>
                    </category>
                
                    <category>
                        <![CDATA[ open source ]]>
                    </category>
                
                    <category>
                        <![CDATA[ technology ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Wed, 29 Nov 2017 21:44:43 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/0*Vam37zski44iqI5J.gif" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Nikolay Khabarov</p>
<p><a target="_blank" href="https://devicehive.com/?utm_source=medium&amp;utm_medium=social&amp;utm_campaign=d-spring-2018">DeviceHive</a> is an IoT platform which has plenty of different components. The Grafana plugin is one of them. This plugin can gather data from a DeviceHive server and display it with different dashboards using the very popular tool — Grafana. This article explains how to create a Grafana dashboard with DeviceHive. As an example, this uses the ESP8266 chip analog pin to visualise the voltage on it.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/nOECJ-zXVy1bAnBBNhEDO3mo7ZehFbSXHG6r" alt="Image" width="800" height="169" loading="lazy"></p>
<h3 id="heading-data">Data</h3>
<p>To display anything on a dashboard we need data. In terms of a DeviceHive server, data can be provided via ‘commands’ and ‘notifications’. Commands are typically used to deliver any messages to a device which the device should execute while ‘notifications’ are the opposite, devices notify their subscribers about certain events. ‘Commands’ and ‘notifications’ are basically simple JSON messages.</p>
<p>Both of these two entities can be used to plot graphs, display static text, a gauge, table or any other Grafana components. For this article we will generate notifications using special DeviceHive firmware for the ESP8266 chip. This firmware allows the chip to connect directly to a DeviceHive server using its protocol and has plenty of <a target="_blank" href="https://github.com/devicehive/esp8266-firmware/blob/develop/DeviceHiveESP8266.md">documented commands</a> which can be issued from the server side.</p>
<h3 id="heading-generating-notifications-with-esp8266-firmware">Generating notifications with ESP8266 firmware</h3>
<p>The binaries for the DeviceHive firmware are available <a target="_blank" href="https://github.com/devicehive/esp8266-firmware/releases">here</a>. Download the latest version and flash this firmware to your chip. The release archive contains documentation on how to do that, but if you have a ‘nodemcu’-like board you just need to connect the board via a microUSB cable to your computer and run the ‘esp-flasher’ util from the release archive for your operating system and wait until it flashes the board. Having flashed the board, there is a need to configure the chip which Wi-Fi network, DeviceHive server, and credential it should use. There are two ways to do that: using a posix-like terminal with the ‘esp-terminal’ util or wirelessly as described <a target="_blank" href="https://github.com/devicehive/esp8266-firmware/blob/develop/DeviceHiveESP8266.md#wireless-configuring">here</a>.</p>
<p>There is a <a target="_blank" href="https://playground.devicehive.com/?utm_source=medium&amp;utm_medium=social&amp;utm_campaign=d-spring-2018">free playground service</a>, which can be used for absolutely free to try a DeviceHive server. After your chip is connected to your server or playground, go to the server admin panel, find your ESP8266 device in the device list and issue the ‘adc/int’ command with the parameters ‘{“0”: 500}’.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/rpg8hn6zzqcOAuNC0aVxEPQmJQM2rSpD79zu" alt="Image" width="800" height="216" loading="lazy"></p>
<p>This command causes the esp8266 to report every 500ms the voltage on ADC input #0(the only ESP8266 has). After switching to ‘notifications’ there should be screen like:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/fW573XDzKshEDdhmbSvyuh6ok-uV8Vs5rkXn" alt="Image" width="800" height="454" loading="lazy"></p>
<p>That is the voltage on the chip’s input pin. And this kind of data is suitable for us to display with Grafana: notifications contain data (parameters in our case), notifications come continuously, and all DeviceHive’s notifications always have a timestamp. Having an analogue sensor connected to this pin it is possible to display this data with Grafana.</p>
<h3 id="heading-installing-the-devicehive-grafana-plugin-to-grafana">Installing the DeviceHive Grafana plugin to Grafana</h3>
<p>Grafana can be used as a local service or as a hosted service. To install Grafana locally, please, refer to the “<a target="_blank" href="http://docs.grafana.org/installation/">Official documentation. Grafana installation</a>”.</p>
<p>You can find how to install plugins in the “<a target="_blank" href="http://docs.grafana.org/plugins/installation/">Official documentation. Plugin installation</a>”.</p>
<p>To install DeviceHive datasource via grafana-cli you can use the following command:</p>
<p><code>$ grafana-cli plugins install devicehive-devicehive-datasource</code></p>
<p>If you want to install the plugin manually, you should perform the following steps:</p>
<p>Prerequisites, these packages should be installed:</p>
<ul>
<li>Grafana &gt;= 4.6</li>
<li>NodeJs &gt;= 8 (optional)</li>
<li>NPM &gt;= 5 (optional)</li>
<li>Grunt (<code>npm install -g grunt</code>) (optional)</li>
</ul>
<p>Also you should have permissions to copy data to the Plugins folder (you could set it in <code>grafana.ini</code> in <code>Paths-&gt;plug</code>ins).</p>
<ol>
<li>Clone this repo to the Plugins folder — <code>git clone [https://github.com/devicehive/devicehive-grafana-datasource.git](https://github.com/devicehive/devicehive-grafana-datasource.git;)</code><a target="_blank" href="https://github.com/devicehive/devicehive-grafana-datasource.git;">;</a></li>
<li>Next steps are optional (in case if you want to rebuild datasource sources code):<br>2.1 Go into folder — <code>cd devicehive-grafana-datasource</code>;<br>2.2 Install all packages — <code>npm install</code>;<br>2.3 Build plugin — <code>npm run build</code>;</li>
<li>Restart Grafana server</li>
<li>Open Grafana in browser;</li>
<li>Open the side menu by clicking the Grafana icon in the top header;</li>
<li>In the side menu click <code>Data Sources</code>;</li>
<li>Click the <code>+ Add data source</code> in the top header;</li>
<li>Select <code>DeviceHive</code> from the <code>Type</code> dropdown;</li>
<li>Configure the datasource.</li>
</ol>
<p>After installation you will be able to see the DeviceHive datasource plugin in the installed plugins list (look at the picture below).</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/AzonaJcVOdW9Hk3FCwUttkuiPJ9C7eWLQB1C" alt="Image" width="800" height="395" loading="lazy"></p>
<h3 id="heading-adding-grafana-datasource">Adding Grafana datasource</h3>
<p>To add DeviceHive datasource, you should perform the following steps:</p>
<ol>
<li>Open the side menu by clicking the Grafana icon in the top header;</li>
<li>In the side menu click <code>Data Sources</code>;</li>
<li>Click the <code>+ Add data source</code> in the top header;</li>
<li>Select <code>DeviceHive</code> from the <code>Type</code> dropdown;</li>
</ol>
<p>Look at the picture below:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/qc1uOouwh6YxgGqfdsQIZEDP1eYpxl2ecySv" alt="Image" width="800" height="361" loading="lazy"></p>
<p>To configure the DeviceHive datasource you should fill on the following fields:</p>
<p>Server URL (is the path to the DeviceHive WebSocket server. For the playground this is ws://playground.devicehive.com/api/websocket)<br>Device ID (unique identifier of the DeviceHive device)<br>Login/Password or AccessToken — credentials to pass authentication</p>
<p>Also, you are able to specify the RefreshToken for auto refreshing the AccessToken</p>
<p>On the picture below you can observe the configuration workflow:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/5gXrxTalhd08rH2yVadrRIuNobmWhTTVaSnu" alt="Image" width="800" height="649" loading="lazy"></p>
<p>After adding and configuring a DeviceHive datasource, it should exist in the datasource list as in the picture below:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/Axn57tNj1KkdGbqIsrstGx7Oa66jk7U7x6qL" alt="Image" width="800" height="325" loading="lazy"></p>
<h3 id="heading-create-new-dashboard">Create new dashboard</h3>
<p>To create a new dashboard you should just click on the “New” button in the sidebar panel as shown in the picture below:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/UxyJ0vnK8ijGBQ3Wc2JtnQIg2GX9GqF6l0DP" alt="Image" width="472" height="413" loading="lazy"></p>
<p>In this article we will show examples on the Graph panel, so, click on the Graph button:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/zRKDMidgaJZq8GeifLHTEacB2NlspwNzOxxf" alt="Image" width="660" height="468" loading="lazy"></p>
<p>After that you will be able to see line chart on your dashboard:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/5jyxzmU-kWVQnXJ6ffNtKFSDWMA7n57xJCaH" alt="Image" width="800" height="180" loading="lazy"></p>
<h3 id="heading-displaying-notificationscommands-with-grafanas-graph">Displaying notifications/commands with Grafana’s graph</h3>
<p>Notification and commands are DeviceHive entities:<br>Command: represents a message dispatched by clients for devices<br>Notification: represents a message dispatched by devices for clients</p>
<p>By default, a Notification or Command message provides the field named “parameters” in which a user can pass their own data.</p>
<p>At the start of this article we configured the ESP8266 device to send notifications with data that represents the state on analogue pin#0 of the chip. In the picture below you are able to observe how to configure the Grafana graph panel to make it show the data on the line chart:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/X5Z5ZHUPRVDhfCKxt4b6hcZ8gYbuxxJJJJC3" alt="Image" width="800" height="336" loading="lazy"></p>
<h3 id="heading-displaying-annotations-on-grafanas-graph">Displaying annotations on Grafana’s graph</h3>
<p>Annotations provide a way to mark points on the graph with rich events. When you hover over an annotation you can get an event description and event tags. The text field can include links to other systems with more detail.<br>More information about annotations you can find by following this <a target="_blank" href="http://docs.grafana.org/reference/annotations/">link</a>.</p>
<p>The picture below shows how to configure annotations powered by a DeviceHive datasource.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/Lw2KYjUe7Q24ya19OuQzVxTLReW6u-Lz5EkL" alt="Image" width="800" height="241" loading="lazy"></p>
<h3 id="heading-advanced-graph-tuning">Advanced graph tuning</h3>
<p>After clicking on the “Add converter” button you will be able to select a converter.<br>A converter is the simple function that transforms a value in some way.</p>
<p>For now, DeviceHive datasources support the following types of converters:</p>
<ul>
<li>Scale — multiplies by a given value</li>
<li>Offset — adds a given value</li>
<li>Unit converter — converts value between different units of below mentioned measurement types:</li>
<li>Temperature (‘c’ — Celsius, ‘f’ — Fahrenheit, ‘k’ — Kelvin)</li>
<li>Length (‘m’ — Meter, ‘mi’ — Mile, ‘yd’ — Yard, ‘ft’ — Feet, ‘in’ — Inch)</li>
<li>Weight (‘kg’ — Kilogram, ‘lb’ — Pound, ‘oz’ — Ounces)</li>
<li>Volume (‘l’ — Liter, ‘gal’ — Gallon, ‘pt’ — Pint)</li>
</ul>
<p><img src="https://cdn-media-1.freecodecamp.org/images/Vtz9svdJWA6c77zySGGgT8DVarEmy1NZQXCe" alt="Image" width="752" height="146" loading="lazy"></p>
<p>An example of this functionality is shown in the picture below.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/RxgzyoJ0xAMYgNGz9WDj-RqextPoxDbGgvd0" alt="Image" width="800" height="284" loading="lazy"></p>
<h3 id="heading-conclusion">Conclusion</h3>
<p>Grafana is a perfect tool to visualise data. It is very flexible and provides many different features to make visualisation in a way thay you like. Grafana can use many data sources from a wide range of software solutions and DeviceHive is one of them. The sample which we described in this article is very simple. Using these principles it is possible to create more advanced graphs and we hope it will be helpful for you. Using Grafana and DeviceHive you can build your own IoT visualisation solutions and moreover you can modify both projects as you wish since Grafana and DeviceHive are open source software.</p>
<p>_Written in collaboration with Igor Trambovetskiy, Senior Developer at <a target="_blank" href="https://devicehive.com/?utm_source=medium&amp;utm_medium=social&amp;utm_campaign=d-spring-2018">DeviceHive</a>._</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How you can use Python to build your own CNC controller and 3D printer ]]>
                </title>
                <description>
                    <![CDATA[ By Nikolay Khabarov This article discusses the process I used to build the first ever CNC machine controller implementation on pure Python. Computer numerical control (CNC) machine controllers are typically implemented using the C or C++ programming ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-build-a-3-d-printer-using-cnc-controller-in-python-bd3cd5e28516/</link>
                <guid isPermaLink="false">66c34f489972b7c5c7624e8e</guid>
                
                    <category>
                        <![CDATA[ Internet of Things ]]>
                    </category>
                
                    <category>
                        <![CDATA[ General Programming ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Python ]]>
                    </category>
                
                    <category>
                        <![CDATA[ tech  ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Thu, 05 Oct 2017 15:06:00 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*H-6cuBQ6gIL2dyhpocFWRQ.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Nikolay Khabarov</p>
<p>This article discusses the process I used to build the first ever CNC machine controller implementation on pure Python.</p>
<p>Computer numerical control (CNC) machine controllers are typically implemented using the C or C++ programming language. They run on OS-less or real-time operating systems with simple microcontrollers.</p>
<p>In this article, I’ll describe how to build a CNC controller — a 3D printer in particular — using modern ARM boards (Raspberry Pi) with a modern high level language (Python).</p>
<p>Such a modern approach opens a wide range of integration options with other cutting edge technologies, solutions, and infrastructures. This makes the whole project developer-friendly.</p>
<h3 id="heading-about-the-project">About the Project</h3>
<p>Modern ARM boards typically use Linux as a reference operating system. This gives us access to the entire Linux infrastructure with all the Linux software packages. We can host a web server on a board, use Bluetooth connectivity, use <a target="_blank" href="http://opencv.org/">OpenCV</a> for image recognition, and build a cluster of boards, among other things.</p>
<p>These are well-known tasks that can be implemented on ARM boards, and they can be really useful for custom CNC machines. For example, auto-positioning using compuvision can be very handy for some machines.</p>
<p>Linux is not a real-time operating system. This means we can’t generate pulses with the required timings to control stepper motors directly from the board pins with running software, even as a kernel module. So, how can we use steppers and high-level Linux features? We can use two chips — one microcontroller with a classic CNC implementation, and an ARM board connected to this microcontroller via UART (universal asynchronous receiver-transmitter).</p>
<p>What if there are no suitable firmware features for this microcontroller? What if we need to control additional axes that are not implemented in the microcontroller? Any modifications to the existing C/C++ firmware will require plenty of development time and efforts. Let’s see if we can make it easier and even save money on microcontrollers by simply removing them.</p>
<h3 id="heading-pycnc">PyCNC</h3>
<p><a target="_blank" href="https://github.com/Nikolay-Kha/PyCNC">PyCNC</a> is a free open-source high-performance G-code interpreter and CNC/3D-printer controller. It can run on various Linux-powered, ARM-based boards, such as Raspberry Pi, Odroid, Beaglebone, and others. This gives you the flexibility to pick any board and use everything that Linux offers. And you can keep the entire G-code runtime on one board without the need for a separate microcontroller for real-time operation.</p>
<p>Choosing Python as the main programming language significantly reduces the code base compared to C/C++ projects. It also reduces the boilerplate and microcontroller-specific code, and makes the project accessible to a wider audience.</p>
<h3 id="heading-how-it-works">How it works</h3>
<p>The project uses DMA (Direct Memory Access) on the chip hardware module. It simply copies the GPIO (General Purpose Input Output) states buffer allocated in RAM to the actual GPIO registers. This copying process is synchronized by the system clock and works completely independently from the CPU cores. Thus, a sequence of pulses for the stepper motor’s axis is generated in memory and then the DMA precisely sends them out.</p>
<p>Let’s dig deeper into the code to understand the basics and how to access hardware modules from Python.</p>
<h3 id="heading-gpio">GPIO</h3>
<p>A General Purpose Input Output module controls pin states. Each pin can have low or high state. When we program the micro-controller, we usually use SDK (software development kit) defined variables to write to that pin. For example, to enable a high state for pins 1 and 3:</p>
<pre><code>PORTA = (<span class="hljs-number">1</span> &lt;&lt; PIN1) | (<span class="hljs-number">1</span> &lt;&lt; PIN3)
</code></pre><p>If you look in the SDK, you will find the declaration of this variable, and it will look similar to:</p>
<pre><code>#define PORTA (*(volatile uint8_t *)(<span class="hljs-number">0x12345678</span>))
</code></pre><p>It’s just a pointer. It doesn’t point to the location in RAM, but to the address of the physical processor. The actual GPIO module is located at this address.</p>
<p>To manage pins, we can write and read data. Raspberry Pi’s ARM processor is not an exception, and it has the same module. To control pins, we can write/read data. We can find the addresses and data structures in the <a target="_blank" href="https://www.raspberrypi.org/app/uploads/2012/02/BCM2835-ARM-Peripherals.pdf">official documentation</a> for processor peripherals.</p>
<p>When we run a process in the user’s runtime, the process starts in the virtual address space. The actual peripheral is accessible directly. But we can still access real physical addresses with <code>_‘/dev/mem’_</code> device.</p>
<p>Here is some simple code in Python that controls a pin’s state using this approach:</p>
<p>Let’s break it down line by line:</p>
<p><strong>Lines 1–6</strong>: headers, imports.</p>
<p><strong>Line 7</strong>: open <code>_‘/dev/mem’_</code> device access to the physical address.</p>
<p><strong>Line 8</strong>: we use the <a target="_blank" href="http://man7.org/linux/man-pages/man2/mmap.2.html">mmap</a> system call to map a file (though in our case, this file represents physical memory) into the process’s virtual memory. We specify the length and offset of the map area. For the length, we take the page size. And the offset is <code>0x3F200000</code>.</p>
<p>The documentation says that the <strong>bus</strong> address <code>0x7E200000</code> contains GPIO registers, and we need to specify the <strong>physical</strong> address. The documentation says (page 6, paragraph 1.2.3) that the <code>0x7E000000</code> bus address is mapped to the <code>0x20000000</code> physical address, but this documentation is for Raspberry 1.  </p>
<p>Please note that all module bus addresses are the same for Raspberry Pi 1–3, but this map was changed to <code>0x3F000000</code> for RPi 2 and 3. So, the address here is <code>0x3F200000</code>. For Raspberry Pi 1, change it to <code>0x20200000</code>.</p>
<p>After this, we can write to our process’s virtual memory, but it actually writes to the GPIO module.</p>
<p><strong>Line 9</strong>: close the file handle, since we don’t need to store it.</p>
<p><strong>Lines 11–14</strong>: we read and write to our map with the <code>0x08</code> offset. According to the documentation, it is the GPFSEL2 GPIO Function Select 2 register. And this register controls pin functions.</p>
<p>We set (clear all, then set with the OR operator) 3 bits with the 3rd bit set to <code>001</code>. This value means that the pin works as an output. There are many pins and possible modes for them. This is why the register for modes is divided into several registers, where each contains the modes for 10 pins.</p>
<p><strong>Lines 16 and 22</strong>: set up the ‘Ctrl+C’ interruption handler.</p>
<p><strong>Line 17</strong>: infinite loop.</p>
<p><strong>Line 18</strong>: set the pin to the <strong>high</strong> state by writing to the GPSET0 register.</p>
<p>Please note, Raspberry Pi doesn’t have registers like PORTA (AVR microcontrollers) have. We can’t write the whole GPIO state of all pins. There are just <strong>set</strong> and <strong>clear</strong> registers which are used to set and clear specified with bitwise mask pins.</p>
<p><strong>Lines 19 and 21</strong>: delay</p>
<p><strong>Line 20</strong>: set pin to low state with the GPCLR0 register.</p>
<p><strong>Lines 25 and 26</strong>: switch pin to default, input state. Close the memory map.</p>
<p>This code should be run with superuser privileges. Name the file <code>‘gpio.py’</code> and run it with <code>‘sudo python gpio.py’</code>. If you have a LED connected to pin 21, it will blink.</p>
<h3 id="heading-dma">DMA</h3>
<p>Direct Memory Access is a special module that is designed to copy memory blocks from one area to another. We will copy data from the memory buffer to the GPIO module. First of all, we need a solid area in physical RAM that will be copied.</p>
<p>There are few possible solutions:</p>
<ol>
<li>We can create a simple kernel driver that will allocate, lock, and report to us the address of this memory.</li>
<li>In some implementations, virtual memory is allocated and uses <code>‘/proc/self/pagemap’</code> to convert the address to the physical one. I wouldn't recommend this approach, especially when we need to allocate big area. Any virtually allocated memory (even locked, see the <a target="_blank" href="https://www.kernel.org/doc/Documentation/vm/unevictable-lru.txt">kernel documentation</a>) can be moved to the physical area.</li>
<li>All Raspberry Pi have a <code>‘/dev/vcio’</code> device, which is a part of the graphic driver and can allocate physical memory for us. An official <a target="_blank" href="https://github.com/raspberrypi/userland/blob/master/host_applications/linux/apps/hello_pi/hello_fft/mailbox.c">example</a> shows how to do it. And we can use it instead of creating our own.</li>
</ol>
<p>The DMA module itself is just a set of registers that are located somewhere at a physical address. We can control this module via these registers. Basically, there are source, destination, and control registers. Let’s check some simple code that shows how to use the DMA modules to manage the GPIO.</p>
<p>Since additional code is required to allocate physical memory with <code>‘/dev/vcio’</code>, we will use a <a target="_blank" href="https://github.com/Nikolay-Kha/PyCNC/blob/master/cnc/hal_raspberry/rpgpio_private.py">file</a> with an existing CMA PhysicalMemory class implementation. We will also use the PhysicalMemory class, which performs the trick with memap from the previous sample.</p>
<p>Let’s break it down line by line:</p>
<p><strong>Lines 1–3</strong>: headers, imports.</p>
<p><strong>Lines 5–6</strong>: constants with the channel DMA number and GPIO pin that we will use.</p>
<p><strong>Lines 8–15</strong>: initialize the specified GPIO pin as an output, and light it up for a half second for visual control. In fact, it’s the same thing we did in the previous example, written in a more pythonic way.</p>
<p><strong>Line 17</strong>: allocates <code>64</code> bytes in physical memory.</p>
<p><strong>Line 18</strong>: creates special structures — control blocks for the DMA module. The following lines break the structure of this block. Each field has a length of <code>32</code> bit.</p>
<p><strong>Line 19</strong>: transfers information flags. You can find a full description of each flag on page 50 of the official documentation.</p>
<p><strong>Line 20</strong>: source address. This address must be a bus address, so we call <code>_get_bus_address()_</code>. The DMA control block must be aligned by 32 bytes, but the size of <strong>this block</strong> is <code>24</code> bytes. So we have 8 bytes, which we use as storage.</p>
<p><strong>Line 21</strong>: destination address. In our case, it’s the address of the SET register of the GPIO module.</p>
<p><strong>Line 22</strong>: transmission length — <code>4</code> bytes.</p>
<p><strong>Line 23</strong>: stride. We do not use this feature, set <code>0</code>.</p>
<p><strong>Line 24</strong>: address of the next control block, in our case, next 32 bytes.</p>
<p><strong>Line 25</strong>: padding. But since we used this address as a data source, put a bit, which should trigger GPIO.</p>
<p><strong>Line 26</strong>: padding.</p>
<p><strong>Lines 28–37</strong>: fill in the second DMA control block. The difference is that we write to CLEAR GPIO register and set our first block as a next control block to loop the transmission.</p>
<p><strong>Lines 38–39</strong>: write control blocks to physical memory.</p>
<p><strong>Line 41</strong>: get the DMA module object with the selected channel.</p>
<p><strong>Lines 42–43</strong>: reset the DMA module.</p>
<p><strong>Line 44</strong>: specify the address of the first block.</p>
<p><strong>Line 45</strong>: run the DMA module.</p>
<p><strong>Lines 49–52</strong>: clean up. Stop the DMA module and switch the GPIO pin to the default state.</p>
<p>Let’s connect the oscilloscope to the specified pin and run this application (do not forget about sudo privileges). We will observe ~1.5 MHz square pulses:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/ZxBtfiQNWX7SffPshqWST0ZhvMx82iqjCUia" alt="Image" width="640" height="480" loading="lazy"></p>
<h3 id="heading-dma-challenges">DMA challenges</h3>
<p>There are several things that you should take into consideration before building a real CNC machine.</p>
<p>First, the size of the DMA buffer can be hundreds of megabytes.</p>
<p>Second, the DMA module is designed for a fast data copying. If several DMA channels are working, we can go beyond the memory bandwidth, and buffer will be copied with delays that can cause jitters in the output pulses. So, it’s better to have some synchronization mechanism.</p>
<p>To overcome this, I created a special design for control blocks:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/E5J6HMgMMLODKP13TjtWXyZ9Vv7zl54llWur" alt="Image" width="800" height="241" loading="lazy"></p>
<p>The oscillogram at the top of the image shows the desired GPIO states. The blocks below represent the DMA control blocks that generate this waveform. “Delay 1” specifies the pulse length, and “Delay 2” is the pause length between pulses. With this approach, the buffer size depends only on the number of pulses.</p>
<p>For example, for a machine with 200mm travel length and 400 pulses per mm, each pulse would take 128 bytes (4 control blocks per 32 bytes), and the total size will be ~9.8MB. We would have more than one axis, but most of the pulses would occur at the same time. And it would be dozens of megabytes, not hundreds.</p>
<p>I solved the second challenge, related to synchronization, by introducing temporary delays through the control blocks. The DMA module has a special feature: it can wait for a special ready signal from the module where it writes data. The most suitable module for us is the PWM (pulse width modulation) module, which will also help us with synchronization.</p>
<p>The PWM module can serialize the data and send it with fixed speed. In this mode, it generates a ready signal for the FIFO (first in, first out) buffer of the PWM module. So, let’s write data to the PWM module and use it only for synchronization.</p>
<p>Basically, we would need to enable a special flag in the perceptual mapping of the transfer information flag, and then run the PWM module with the desired frequency. The implementation is quite long — you can <a target="_blank" href="https://github.com/Nikolay-Kha/PyCNC/blob/master/cnc/hal_raspberry/rpgpio.py">study</a> it yourself.</p>
<p>Instead, let’s create some simple code that can use the existing module to generate precise pulses.</p>
<pre><code><span class="hljs-keyword">import</span> rpgpio
</code></pre><pre><code>PIN=<span class="hljs-number">21</span>PINMASK = <span class="hljs-number">1</span> &lt;&lt; PINPULSE_LENGTH_US = <span class="hljs-number">1000</span>PULSE_DELAY_US = <span class="hljs-number">1000</span>DELAY_US = <span class="hljs-number">2000</span> g = rpgpio.GPIO()g.init(PIN, rpgpio.GPIO.MODE_OUTPUT) dma = rpgpio.DMAGPIO()<span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> range(<span class="hljs-number">1</span>, <span class="hljs-number">6</span>): <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> range(<span class="hljs-number">0</span>, i): dma.add_pulse(PINMASK, PULSE_LENGTH_US) dma.add_delay(PULSE_DELAY_US) dma.add_delay(DELAY_US)dma.run(True) raw_input(“Press Enter to stop”)dma.stop()g.init(PIN, rpgpio.GPIO.MODE_INPUT_NOPULL)
</code></pre><p>The code is pretty simple, and there is no need to break it down. If you run this code and connect an oscilloscope, you will see:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/zPJ37jLULml7544lV8qBJK3bGY-U-Zb42TlM" alt="Image" width="640" height="480" loading="lazy"></p>
<p>And now we can create real G-code interpreter and control stepper motors. But wait! It is already implemented <a target="_blank" href="https://github.com/Nikolay-Kha/PyCNC">here</a>. You can use this project, as it’s distributed under the MIT license.</p>
<h3 id="heading-hardware">Hardware</h3>
<p>The Python project can be adopted for your purposes. But in order to inspire you, I will describe the original hardware implementation of this project — a 3D printer. It basically contains the following components:</p>
<ol>
<li>Raspberry Pi 3</li>
<li><a target="_blank" href="http://reprap.org/wiki/RAMPS_1.4">RAMPSv1.4 board</a></li>
<li>4 A4988 or DRV8825 module</li>
<li>RepRap Prusa i3 frame with equipment (end-stops, motors, heaters, and sensors)</li>
<li>12V 15A power supply unit</li>
<li>LM2596S DC-DC step down converter module</li>
<li>MAX4420 chip</li>
<li>ADS1115 analog to digital converter module</li>
<li>UDMA133 IDE ribbon cable</li>
<li>Acrylic glass</li>
<li>PCB stands</li>
<li>Set of connectors with 2.54mm step</li>
</ol>
<p>The 40-pin IDE ribbon cable is suitable for the Raspberry Pi 40 pins connector, but the opposite end requires some work. Cut off the existing connector from the opposite end and crimp connectors to the cable wires.</p>
<p>The RAMPSv1.4 board was originally designed for connection to the <a target="_blank" href="https://www.arduino.cc/en/Main/arduinoBoardMega">Arduino</a> Mega connector, so there is no easy way to connect this board to the Raspberry Pi. The following method allows you to simplify the boards connection. You will need to connect less than 40 wires.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/EN-JNl9sm5cJ68bdtcKITvmDRyc9RM6p0h79" alt="Image" width="800" height="585" loading="lazy">
<em>PyCNC reference connection</em></p>
<p>I hope this connection diagram is fairly simple and easily duplicated. It’s better to connect some pins (2nd extruder, servos) for future use, even if they are not currently needed.</p>
<p>You might be wondering — why do we need the MAX4420 chip? The Raspberry Pi pins provide 3.3V for the GPIO outputs, and the pins can provide very small current. It’s not enough to switch the MOSFET (Metal Oxide Semiconductor Field Effect Transistor) gate. In addition, one of the MOSFETs works under the 10A load of a bed heater. As a result, with a direct connection to a Raspberry Pi, this transistor will overheat. Therefore, it is better to connect a special MOSFET driver between the highly loaded MOSFET and Raspberry Pi. It can switch the MOSFET in a an efficient way and reduce its heating.</p>
<p>The ADS1115 is an Analog to Digital Converter (ADC). Since Raspberry Pi doesn’t have an embedded ADC module, I used an external one to measure the temperature from the 100k Ohm thermistors. The RAMPSv1.4 module already has a voltage divider for the thermistors. The LM2596S step down converter must be adjusted to a 5V output, and it is used to power the Raspberry Pi board itself.</p>
<p>Now it can be mounted on the 3D printer frame and the RAMPSv1.4 board should be connected to the equipped frame.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/Wa2vq72NhEoEqS2hxcPkXSyk7yv5lz2G2EN5" alt="Image" width="800" height="533" loading="lazy"></p>
<p>That’s it. The 3D printer is assembled, and you can copy the source code to the Raspberry Pi and run it. <code>sudo ./pycnc</code> will run it in an interactive G-Code shell. <code>sudo ./pycnc filename.gcode</code> will run a G Code file. Check the <a target="_blank" href="https://github.com/Nikolay-Kha/PyCNC/blob/master/extra/sample-Slic3r-config.ini">ready config</a> for <a target="_blank" href="http://slic3r.org/">Slic3r</a>.</p>
<p>And in <a target="_blank" href="https://www.youtube.com/watch?v=41wdmmztTNA">this video</a>, you can see how it actually works.</p>
<p>If you found this article useful, please give me some claps so more people see it. Thanks!</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/AzJ9Gt6Nl3OfLXNoiI1Oxp45I8EU0Hxdsbr-" alt="Image" width="71" height="93" loading="lazy"></p>
<p>_IoT is all about prototyping ideas quickly. To make it possible we developed <a target="_blank" href="https://devicehive.com/?utm_source=medium&amp;utm_medium=social&amp;utm_campaign=d-spring-2018">DeviceHive</a>, an open source IoT/M2M platform. DeviceHive provides a solid foundation and building blocks to create any IoT/M2M solution, bridging the gap between embedded development, cloud platforms, big data &amp; client apps._</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/UA7ESnWpENlYCxEvgEiV3ENq60vytsMCzgzF" alt="Image" width="224" height="85" loading="lazy"></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How I built a Smart Mirror, with a little help from my daughter and her grandpa ]]>
                </title>
                <description>
                    <![CDATA[ By Coding with Cookie This month I built a smart mirror with my dad and daughter. This project spanned across three generations. The idea started a few years ago with the novelty of a smart mirror. But before I was going invest the time and money to ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/crafting-a-smart-mirror-with-my-dad-and-daughter-c3bdd151fefd/</link>
                <guid isPermaLink="false">66c347ef12c88d894ffd1f62</guid>
                
                    <category>
                        <![CDATA[ Internet of Things ]]>
                    </category>
                
                    <category>
                        <![CDATA[ life ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Raspberry Pi ]]>
                    </category>
                
                    <category>
                        <![CDATA[ smart home ]]>
                    </category>
                
                    <category>
                        <![CDATA[ technology ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Mon, 21 Aug 2017 04:31:11 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*0MC93WQzKqFGisGM2WisVQ.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Coding with Cookie</p>
<p>This month I built a smart mirror with my dad and daughter. This project spanned across three generations.</p>
<p>The idea started a few years ago with the novelty of a smart mirror. But before I was going invest the time and money to make one, I needed a practical reason to build one. Recently that reason presented itself.</p>
<p>In our kitchen we have a whiteboard where we list out our dinner plans for the week and I wanted to upgrade it. I submitted a presentation idea for the smart mirror at local tech conference. My smart mirror presentation was <a target="_blank" href="https://seattle.codecamp.us/Session/Details/217">selected</a>. This accelerated my timeline.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/DeTO06lHtTL-b0AmprtydowA3tWFIwc4dern" alt="Image" width="800" height="449" loading="lazy">
<em>Programming the Smart Mirror with my Daughter</em></p>
<p>I needed help with the design of the smart mirror frame</p>
<p>since I live in the digital world designing software that lives in the cloud. My dad is a Mechanical Engineer who lives in the physical world designing the planes we fly though the clouds everyday. While talking with my dad one evening, he suggested to create some initial sketches of the mirror.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/VYfIYuOgsKPTY5nsFkZmxPsY83hYF2SFfNkd" alt="Image" width="799" height="1066" loading="lazy">
<em>Initial Design of Smart Mirror</em></p>
<p>After a few more conversations with my dad and several design revisions, we settled on a simple box design for the frame. My dad knew more about woodworking than I did, and he had a few suggestions for me.</p>
<p>Like using cabinet draw sides for the sides of the frame as they already came with a groove to hold the glass. And using <a target="_blank" href="https://en.wikipedia.org/wiki/French_cleat">french cleats</a> to secure the mirror to the wall. This also allowed it to be easily removed for transport.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/eq70lB300bPWUI2zzdVaTePyHuCQWh0CaEDa" alt="Image" width="800" height="600" loading="lazy">
<em>Revised Design of the Smart Mirror</em></p>
<p>My wife was a huge support in this endeavor. She helped by sorting through dozens of televisions looking for the right price and features. The size had to be large enough for our kitchen, but not too large to make transporting a hassle. Finally she was able to get a television from Best Buy that had everything I was looking for. And the best part was that it was on sale.</p>
<p>The most noticeable part of the smart mirror is the reflective mirror. Most household mirrors are made from glass. But the biggest downside to using glass is that it’s fragile and doesn’t transport well. I chose plastic as it’s lighter, more transparent, and more durable.</p>
<p>It’s nice to talk to experts and I live in Seattle which has a great local <a target="_blank" href="https://www.tapplastics.com/">plastic supplier</a>. They were excellent and able to help me select the correct plastic. They suggested acrylic and we even tested the mirror film I had acquired on a sample they had. And this was not the first smart mirror they had supplied the plastic for so I knew I was on the right track.</p>
<p>The choice was simple when it came to deciding where to assemble the frame. My dad has a new workshop and all the tools we needed and I have a garage and a single toolbox. Once I had acquired the wood, acrylic, and mirror film, I went over to my dad’s workshop to assemble the frame.</p>
<p>I thought it would take 4–5 hours. But it took around 15 hours to assemble the mirror. That may be due to refining the design as we were making the mirror. It may also be due to me asking a lot of questions, like why glue this instead of screw that. Or it was due to having a good time with my dad. Looking back it was a combination of all the above.</p>
<p>Over three separate days we cut, glued, nailed, and screwed the frame together. It would hold the television, acrylic mirror, and Raspberry Pi.</p>
<p>Several power tools were used including a table saw, chop saw, and nail gun so my daughter didn’t help with that part. But she was able to help with the final assembly when the acrylic mirror was inserted. She was even able to use the power drill to screw in the top during the final assembly.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/image/not-found.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>My Daughter using a Power Drill to Screw in the Top of the Mirror</em></p>
<p>With all the woodworking completed, my daughter and I started wiring everything together. As pink is her favorite color, it was obvious that the only choice was to 3D print the Raspberry Pi case in pink.</p>
<p>We put the Raspberry Pi into the pink case and attached it to the back of the TV via adhesive Velcro.</p>
<p>By using Velcro, the Raspberry Pi can be disconnected. Thus I can show the size of the computer transforming the mirror into a smart mirror.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/Kv-0LGWfO0ueT1o-xHr6C-znSspCJIJMBuX8" alt="Image" width="800" height="600" loading="lazy">
<em>3D Printed Pink Raspberry Pi Case</em></p>
<p>Modern televisions usually include a USB port, and the one my wife found did indeed have one. I tested it out the USB Port on the TV and it was able to supply enough power to the Raspberry Pi. This meant that the TV Power cord was the only cable I needed to plug into the wall outlet.</p>
<p>Then we plugged the USB and HDMI cables into both the Raspberry Pi and TV and we were ready to go.</p>
<p>With the on board WiFi I connected the smart mirror to the internet without any other wires. And when the power is out it will still work as a traditional non-smart mirror.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/image/not-found.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>My Daughter and I Connecting all the Wires on the Back of the Smart Mirror</em></p>
<p>When you are 4, typing on a keyboard and coding are cool. We’ll see how she feels when she’s 14.</p>
<p>My daughter got to help a lot on the software part of the smart mirror. Since her spelling abilities end with her name, she was able to type that and was very excited when she saw it on the smart mirror.</p>
<p>To get her name to appear, we used HTML. To keep it simple a static HTML page with inline styling via Chrome, fullscreen <code>F11</code>, was all we had to do to get it working. The background needs to be as dark as possible to minimize the light coming though the mirror.</p>
<p>When the screen is off or completely black it appears as a common mirror. The text and graphics need to be as bright as possible to show through, transforming it into a smart mirror. On my mirror I was able to find a film with 5% transparency.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/a-EnHz7xBvtQyA7VmWtqAGQOnGUwSV3DTJNx" alt="Image" width="799" height="1066" loading="lazy">
<em>Installing the Acrylic Mirror into the Frame</em></p>
<p>In reviewing my mirror thus far, I would do a few things different next time. First, I would get a slimmer television. Right now the mirror frame is 4.5 inches deep, which is deep enough that you notice, but not so deep that it’s obtrusive.</p>
<p>Next, I would order acrylic with the mirror film already installed. My dad and I were able to install the film in 20 min, but this resulted in several small bubbles. Most likely due to a few small pieces of dust trapped between the film and acrylic.</p>
<p>Also, I would add a more stylized front. If you take a look at the corners of my smart mirror, you will see all the layers of plywood. This could be hidden with some nice wood to more resemble a picture frame.</p>
<p>Finally, I would add a small gap between the TV and acrylic. Currently, the acrylic is helping to support the TV. This is putting pressure on the acrylic causing it to bend slightly. This results in a slight distortion of the mirror.</p>
<p>Building the Smart Mirror has been a great experience and if you have any questions please <a target="_blank" href="https://codingwithcookie.com/contact/">reach out</a>.</p>
<p>The next project that my daughter and I are working on is wiring some sensors in the kitchen to track the temperature in the refrigerator and freezer. I’m hoping to get her more involved with this and future projects as she is excited to help and wire the sensors on a breadboard.</p>
<p>I look forward to sharing that story with you once she and I have completed it.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/8xBLYzrWXyZMltzMYYVKY5C2ARAcu9nHZlZ9" alt="Image" width="799" height="1066" loading="lazy"></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Hardware Fundamentals: what exactly is a microcontroller? ]]>
                </title>
                <description>
                    <![CDATA[ By Taron Foxworth At the fundamental level, a microcontroller is a just tiny computer. Being a “tiny computer” doesn’t really tell us much, though. So let’s go deeper. Many people associate microcontrollers with Arduino. But it’s important to point o... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/hardware-fundamentals-what-exactly-is-a-microcontroller-8a502a3650dc/</link>
                <guid isPermaLink="false">66c34c23a7aea9fc97bdfb42</guid>
                
                    <category>
                        <![CDATA[ arduino ]]>
                    </category>
                
                    <category>
                        <![CDATA[ hardware ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Internet of Things ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Makers ]]>
                    </category>
                
                    <category>
                        <![CDATA[ technology ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Mon, 24 Apr 2017 13:18:27 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*WKKNCMKqg6yEkowj28CHng.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Taron Foxworth</p>
<p>At the fundamental level, a microcontroller is a just tiny computer.</p>
<p>Being a “tiny computer” doesn’t really tell us much, though. So let’s go deeper. Many people associate microcontrollers with Arduino. But it’s important to point out that <strong>Arduino is not a microcontroller</strong>. Arduino is a complete platform which spans across software and hardware.</p>
<p>Arduino makes devices like the <a target="_blank" href="https://www.arduino.cc/en/Main/arduinoBoardUno">Arduino Uno</a>:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*GT8uC4hwFJfFb818C5g7LA.jpeg" alt="Image" width="800" height="534" loading="lazy">
<em>Arduino Uno</em></p>
<p>The Arduino Uno is not a microcontroller, either. It’s a breakout board based on the <a target="_blank" href="http://www.microchip.com/wwwproducts/en/ATmega328P">Atmel ATmega328P microcontroller</a>.</p>
<p>Here is what the Atmel microcontroller looks like:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*dGZ5XWLj4osrGlUf79mW1w.png" alt="Image" width="800" height="578" loading="lazy"></p>
<p>If you were to have just the Atmel microcontroller in hand, as a beginner, it wouldn’t be very useful. This is where the breakout board comes in.</p>
<p>The breakout board “breaks out” the pins on the microcontroller into a larger device (like the Arduino Uno). This larger device makes the microcontroller easier to use.</p>
<p>For the Arduino Uno, the breakout board gives you the ability to insert a USB cord, give it power, program the device, and more.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*jmPJwZqvF1QqNR0Xr_rmCw.jpeg" alt="Image" width="500" height="375" loading="lazy">
_[Image credit](https://www.hackster.io/hmkim/remote-controlled-8x8-led-matrix-e2b79a?ref=part&amp;ref_id=8233&amp;offset=18" rel="noopener" target="<em>blank" title=")</em></p>
<p>Without the breakout board, for a beginner, this would be a daunting task. This problem is the very reason that Arduino exists — to make it super easy for you to learn about hardware.</p>
<h3 id="heading-ah-so-its-like-the-raspberry-pi">Ah, So it’s like the Raspberry Pi?</h3>
<p>Well, not entirely. Both the Arduino and the Raspberry Pi are still computers by definition. But the Raspberry Pi is considered a <a target="_blank" href="http://maxembedded.com/2013/07/introduction-to-single-board-computing/">single-board computer</a>. A single-board computer is <a target="_blank" href="https://en.wikipedia.org/wiki/Single-board_computer">a full computer built on a single circuit board</a>.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*iK9lfwT4cpJsY4lWQ2ul0Q.jpeg" alt="Image" width="800" height="800" loading="lazy">
<em>A Raspberry Pi</em></p>
<p>Your laptop is also technically a single-board computer — just a powerful one. The Raspberry Pi is a simple version of the same hardware in your laptop. Just as your laptop runs an operating system (Windows, Mac, or Linux), the Raspberry Pi runs a Linux operating system.</p>
<p>Now, back to Microcontrollers. Microcontrollers can’t run an operating system. Microcontrollers also don’t have the same amount of computing power or resources as most single-board computers.</p>
<p>A microcontroller will run just one program repeatedly — not a full operating system. We can see this in Arduino programs because they only need two functions: <code>Setup</code> and <code>loop</code>. <code>Setup</code> will run once and <code>loop</code> will run indefinitely.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*2zfsMFC_vB9OMA81Hl5ITA.png" alt="Image" width="460" height="475" loading="lazy">
<em>Setup and Loop</em></p>
<h3 id="heading-so-whats-a-microcontroller">So, what’s a microcontroller?</h3>
<p>A microcontroller is a small computer with low-memory and programmable input/output peripherals.</p>
<h4 id="heading-inputsoutputs">Inputs/Outputs</h4>
<p>As you probably know, everything with a computer eventually starts with binary (0 or 1).</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*GFnxrpbOLyCUBuhnwxIHNA.png" alt="Image" width="800" height="517" loading="lazy"></p>
<p>An input means that the microcontroller will read binary. An example input would be a sensor.</p>
<p>An output means that the microcontroller will send binary. An example output would be to control a motor or LED.</p>
<h3 id="heading-why-do-we-need-microcontrollers">Why do we need microcontrollers?</h3>
<p>Well, these were “computers” before we arrived at the idea of the computers you know today. Microcontrollers stuck around because some computing tasks are incredibly trivial and require simple logic. For example, flipping a switch or controlling small components — like a LED light — don’t require the same resources we need for day-to-day tasks like sending an email.</p>
<p>We use them today because their low-powered and low memory makes them low-cost. Microcontrollers are part of the reason the <a target="_blank" href="https://en.wikipedia.org/wiki/Internet_of_things">Internet of Things</a> is possible and successful today.</p>
<h3 id="heading-how-do-i-get-one">How do I get one?</h3>
<p>Which microcontroller you’ll want to get depends on which problem you want to solve. If you are doing something simple — turning things on and off, or reading a sensor — pretty much any microcontroller will do.</p>
<p>If you want to play games or have more complex ideas, you’ll need more compute power, so you’ll need to move up to single-board computers, like the Raspberry Pi.</p>
<p><a target="_blank" href="https://www.adafruit.com/">Adafruit</a> and <a target="_blank" href="https://www.sparkfun.com/">Sparkfun</a> both have TONS of kits and hardware that are all amazing. You can also make use of their tutorials.</p>
<p><a target="_blank" href="https://losant.com">Losant</a> also has some cool <a target="_blank" href="https://docs.losant.com/getting-started/losant-iot-dev-kits/builder-kit/">kits</a> available. You could build your own <a target="_blank" href="https://docs.losant.com/getting-started/losant-iot-dev-kits/door-sensor-kit/">door sensor</a> — to be notified when a door is left open for too long.</p>
<p>If you don’t have a specific problem you want to solve, just grab some hardware and play around with it.</p>
<p>Here are some things you can buy to get started:</p>
<h4 id="heading-1-a-board-called-the-nodemcuhttpamznto2oyaluf">1. A board called the <a target="_blank" href="http://amzn.to/2oyalUf">NodeMCU</a>.</h4>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*lVu30df4maR8KAoG1vKDlg.jpeg" alt="Image" width="800" height="532" loading="lazy">
<em>Node MCU</em></p>
<p>The <a target="_blank" href="http://amzn.to/2p3YDEu">NodeMCU</a> is a board based on the ESP8266 microcontroller. This board is special because it’s cheap and WiFi enabled. It will only run you about $8.79 on Amazon and is even less on Ebay.</p>
<p>Not all microcontrollers are WiFi-enabled. The fact that this one is opens the door to a number of projects you can build with this device. For example, you can collect data and send it to the cloud ☁️.</p>
<h4 id="heading-2-youll-need-some-sensorshttpamznto2ocln7o">2. You’ll need some <a target="_blank" href="http://amzn.to/2ocLN7O">Sensors</a></h4>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*tJrDBAK3Gi1gd3EucYqsnw.jpeg" alt="Image" width="800" height="800" loading="lazy">
<em>Bread Board</em></p>
<p>You can’t have hardware without sensors. Sensors give you the ability to detect the environment and the world around you. They’re also a great tool for learning.</p>
<h4 id="heading-3-youll-need-a-breadboardhttpamznto2oul4zw-amp-jumper-wireshttpamznto2p0stym">3. You’ll need a <a target="_blank" href="http://amzn.to/2oul4zW">Breadboard</a> &amp; <a target="_blank" href="http://amzn.to/2p0stYM">Jumper Wires</a>:</h4>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*hzlbvjGieO28VE7VKbFFZw.jpeg" alt="Image" width="800" height="684" loading="lazy"></p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*-Ts_mndGd90p9JEImUouDQ.jpeg" alt="Image" width="800" height="600" loading="lazy"></p>
<p>To connect a sensor and the microcontroller together, you’ll have to plug them into the Breadboard and use the Jumper wires to connect them.</p>
<p>Remember: everything is cheaper on <a target="_blank" href="http://ebay.com/">eBay</a> and <a target="_blank" href="https://www.aliexpress.com/">AliExpress</a>. You’ll just have to wait a couple weeks for shipping</p>
<h3 id="heading-what-should-i-build">What should I build?</h3>
<p>Again — and I can’t stress this enough — it’s way easier to start with a project in mind. Now that you understand what a microcontroller is and how to get one, take a different look at the world around you. What can you control? What can you automate? Once you start to answer those questions, you’ll find a project.</p>
<p>While thinking of projects, <a target="_blank" href="https://www.hackster.io/">Hackster</a> is your best friend. Hackster has a ton of <a target="_blank" href="https://www.hackster.io/esp">ESP8266 projects</a> and some cool Arduino projects:</p>
<p>For example, you can live out a childhood dream.</p>
<p>You can even build robots.</p>
<p>The point is, you just need an idea.</p>
<p>Sometimes programming the real world is more fun than programming virtual ones.</p>
<h3 id="heading-whats-next">What’s next?</h3>
<p>Microcontrollers are only the beginning. You have a world of hardware to explore. Happy Hacking ??</p>
<h4 id="heading-further-reading">Further reading:</h4>
<p><a target="_blank" href="http://forefront.io/a/beginners-guide-to-arduino/"><strong>The Absolute Beginner's Guide to Arduino</strong></a><br><a target="_blank" href="http://forefront.io/a/beginners-guide-to-arduino/">_Over the Christmas break from work I wanted to learn something new. I've been eyeing up Arduino for some time now, and…_forefront.io</a></p>
<p><a target="_blank" href="https://twitter.com/anaptfox"><em>Taron Foxworth</em></a> <em>is a hardware hacker and the Developer Evangelist at <a target="_blank" href="https://www.losant.com">Losant</a>. His goal is to translate technology for people to learn, love, and be inspired.</em></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Hardware fundamentals: how pull-down and pull-up resistors work ]]>
                </title>
                <description>
                    <![CDATA[ By Taron Foxworth If you’ve ever wired up a button to an Arduino, you’ve come across this diagram: At first, this can be confusing. My first thoughts: “Why do I need a resistor? I just want to it to tell me whether the button is being pressed.” Afte... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/a-simple-explanation-of-pull-down-and-pull-up-resistors-660b308f116a/</link>
                <guid isPermaLink="false">66c3433c0bafa8455505c667</guid>
                
                    <category>
                        <![CDATA[ arduino ]]>
                    </category>
                
                    <category>
                        <![CDATA[ hardware ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Internet of Things ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Makers ]]>
                    </category>
                
                    <category>
                        <![CDATA[ technology ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Fri, 17 Mar 2017 19:40:27 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*SMTqmqkvw4LnRckc2Wj9RQ.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Taron Foxworth</p>
<p>If you’ve ever wired up a button to an Arduino, you’ve come across this diagram:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/5z3GVJwnEtxRQZnrIeMa6806A0l45ZDHoLLc" alt="Image" width="729" height="283" loading="lazy"></p>
<p>At first, this can be confusing. My first thoughts: “Why do I need a resistor? I just want to it to tell me whether the button is being pressed.”</p>
<p>After a lot of reading, there wasn’t a simple explanation.</p>
<h3 id="heading-whats-going-on-here">What’s going on here</h3>
<p><img src="https://cdn-media-1.freecodecamp.org/images/lnCBI4aQPD72ryakAoXRZOOIscOKzO1TN8T-" alt="Image" width="316" height="316" loading="lazy">
<em>Diagram 1</em></p>
<p>In that button — AKA a switch—the wires are shaped in the form of an “H”. But the middle isn’t connected — or the circuit isn’t connected — until we press the button.</p>
<p>In reality, we want to read from the Arduino a <code>0</code> when nothing is connected and a <code>1</code> when the button is pressed.</p>
<p>On the Arduino, this is called General Purpose Input Output (<a target="_blank" href="https://en.wikipedia.org/wiki/General-purpose_input/output">GPIO</a>).</p>
<p>So, we can do something like this:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/ei-WY10bPEXDJh5eHRZ8VW0K1Xp0E-fWPQz5" alt="Image" width="316" height="343" loading="lazy">
<em>Diagram 2</em></p>
<p>We connect positive (5v, 3.3V, or VCC) to the left side of the circuit.</p>
<p>Now, when the button is pressed, the GPIO will read a <code>1</code>, and all is good.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/WjBnoryrJcaJusAFgohNgpnKrR0mKXYI7fmd" alt="Image" width="316" height="343" loading="lazy">
<em>Diagram 3</em></p>
<p>Well, no. Let’s take a look at Diagram 2 again:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1T7hhKBigZliDdNhgut-kKK8KMmgId1jEAEv" alt="Image" width="316" height="343" loading="lazy">
<em>Diagram 2</em></p>
<p>We wanted a <code>0</code> when nothing is connected, but how can you guarantee this? Currently, there is no way to guarantee the GPIO to be <code>0</code>.</p>
<p>There is also electromagnetic frequencies in the air that could draw your GPIO to <code>0</code> or <code>1</code>. It could even fluctuate between the two! This way, we can’t be positive it’s a <code>0</code> (I’m so bad at puns). This is also known as a logical <code>0</code>.</p>
<p>One way to get a logical <code>0</code> is to tie the pin to Ground:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/mZLL1wlSMz6ReTNeJZDAQMaIOVnkOTrg5qqY" alt="Image" width="316" height="365" loading="lazy"></p>
<p>Yay! So, now it’s a guaranteed logical zero. While pushing the button, it’s going to be <code>1</code> now. Right?</p>
<p>Well, No.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/sMUiXkmyybe-DrcMuYHb0IqpU3FFLtTYm-uy" alt="Image" width="316" height="365" loading="lazy"></p>
<p>You just created a <a target="_blank" href="https://en.wikipedia.org/wiki/Short_circuit">short circuit</a>. ?</p>
<p>This is where the resistor comes in. To avoid a short circuit, we need to add resistance to our circuit. The resistor keeps things under control.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/T3HTmawK4YN37wNqYke-QQdh5EVmFnNY8nec" alt="Image" width="316" height="408" loading="lazy"></p>
<p><a target="_blank" href="http://ecmweb.com/content/path-least-resistance">Electricity will take the path of least resistance.</a> Your GPIO will now register a <code>1</code> when the button is pressed. Like so:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/yLtF3UnfFhhhZ4Kjdqg81d4MvXqVDsYuCclh" alt="Image" width="316" height="408" loading="lazy"></p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/msnI0gnXpKvs5h6JuTVHExkeAWJuzxyl7J2x" alt="Image" width="500" height="375" loading="lazy"></p>
<p>Woo Hoo! Now we’re working with something.</p>
<p>Now let’s look at the opposite: pull-up resistors. It’s the same thing but in reverse. While the button is not pressed, the GPIO will register a <code>1</code>. When you pressed the button, the GPIO will be <code>0</code>.</p>
<p>While not pressed, we have the GPIO connected to positive ( VCC ). So, any current that is there will be pulled-up so that the GPIO registers a logical <code>1</code>.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/zUGnUEh9axrnFyaWOvkUNt1B5uCZxQBewETh" alt="Image" width="316" height="422" loading="lazy"></p>
<p>It’s important to note here that, electricity always wants to go to Ground. So, when we press the button, the current that’s flowing will flow to Ground. Thus, any current that would have been going to the GPIO goes with it, leaving the GPIO at a logical <code>0</code>.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/4NW0bqGqmZbUolmRv4LObF5qR8fccQ1z9zl0" alt="Image" width="316" height="433" loading="lazy"></p>
<p>? The End.</p>
<h4 id="heading-why-did-i-write-this">Why did I write this?</h4>
<p>I joined <a target="_blank" href="https://losant.com">Losant</a> in September of 2016 with no hardware experience. Every single hardware starter kit gives you a button with no explanation of this concept. Hopefully, this helps your light bulb go off too. ?</p>
<p>This only scratched the surface. If you want to dig deeper, check out these resources:</p>
<p><a target="_blank" href="https://learn.sparkfun.com/tutorials/pull-up-resistors"><strong>Pull-up Resistors - learn.sparkfun.com</strong></a><br><a target="_blank" href="https://learn.sparkfun.com/tutorials/pull-up-resistors">_Another thing to point out is that the larger the resistance for the pull-up, the slower the pin is to respond to…_learn.sparkfun.com</a></p>
<p>I love feedback. So, please let me know if this could be improved. <strong>If I totally missed the ball on this, <a target="_blank" href="http://twitter.com/anaptfox">let me know</a>!</strong> I would love to make it better for others.</p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
