<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Iago</title>
    <description>The latest articles on DEV Community by Iago (@iagows).</description>
    <link>https://dev.to/iagows</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1161617%2F6356319e-c7bb-43f8-9b28-3bbf48649610.jpeg</url>
      <title>DEV Community: Iago</title>
      <link>https://dev.to/iagows</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/iagows"/>
    <language>en</language>
    <item>
      <title>Arduino remotely controlled (part 3)</title>
      <dc:creator>Iago</dc:creator>
      <pubDate>Tue, 03 Oct 2023 23:14:44 +0000</pubDate>
      <link>https://dev.to/iagows/arduino-remotely-controlled-part-3-229j</link>
      <guid>https://dev.to/iagows/arduino-remotely-controlled-part-3-229j</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;In the &lt;a href="https://dev.to/iagows/arduino-remotely-controlled-part-2-1b1n"&gt;previous post&lt;/a&gt;, we created a server to talk with an Arduino.&lt;/p&gt;

&lt;p&gt;Now it's time to create a simple mobile application to interact with the server.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are the problems I want to solve?
&lt;/h2&gt;

&lt;p&gt;I don't want to interact with my Arduino using URLs. I want to interact with a nice (?) UI.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is the solution?
&lt;/h2&gt;

&lt;p&gt;Create an React Native + Expo application to connect and interact with the server.&lt;/p&gt;

&lt;h2&gt;
  
  
  Weak points
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;I'm not doing a very complex and fully working application. It's just a POC.&lt;/li&gt;
&lt;li&gt;Ideally each interaction with the 'slider' should take some milliseconds before calling the server to avoid multiple callings

&lt;ol&gt;
&lt;li&gt;Now I'm thinking of making a change into the Arduino library to make percent values change into steps to make it smooth.&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;
&lt;li&gt;I'm not storing/recovering the server IP into the application. I'm sure you can do it easily.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Intended public
&lt;/h2&gt;

&lt;p&gt;I expect you to have some knowledge of: Typescript, React, React Native and Expo.&lt;/p&gt;

&lt;h2&gt;
  
  
  Let's start
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Code
&lt;/h3&gt;

&lt;p&gt;I created tag into the &lt;a href="https://gitlab.com/arduino_io/iot_app/-/tree/3.0.5?ref_type=tags"&gt;app repository&lt;/a&gt;, so you just have to download and read the code.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is the code idea?
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;It waits for user input the server URL or IP&lt;/li&gt;
&lt;li&gt;Tests the connection&lt;/li&gt;
&lt;li&gt;Loads the server data&lt;/li&gt;
&lt;li&gt;Shows the hubs components

&lt;ol&gt;
&lt;li&gt;Waits for user interaction to send the value back to Arduino&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Results
&lt;/h2&gt;

&lt;p&gt;It's running in my old Android 7 smartphone. The screen is damaged and I had to do multiple touches to make the buttons work. I didn't want a long video, so I cropped some parts of it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--g8Cqx4dl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8dshaijuoh3ka2w4x77t.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--g8Cqx4dl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8dshaijuoh3ka2w4x77t.gif" alt="Testing the app and verifying the results" width="288" height="354"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Previous steps
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://dev.to/iagows/arduino-remote-io-1mc7"&gt;Create an Arduino library to remote communication&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/iagows/arduino-remotely-controlled-part-2-1b1n"&gt;Connect the Arduino to a server&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Last words
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;This project is far from complete.&lt;/li&gt;
&lt;li&gt;It's NOT intended to be used in production as is.&lt;/li&gt;
&lt;li&gt;It needs lots of refactoring (that I intend to do, and I'll keep the tags for everyone who's reading this tutorial)&lt;/li&gt;
&lt;li&gt;Maybe someday, after all refactoring, I'll connect my Arduino to an solid state relay and do some 220V tests (children, don't try this)&lt;/li&gt;
&lt;li&gt;If you did try my code, please let me know if it worked, any problems you faced and how you got around those issues&lt;/li&gt;
&lt;li&gt;And last but not least, if you got this far, thank you for your patience&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>arduino</category>
      <category>iot</category>
      <category>tutorial</category>
      <category>reactnative</category>
    </item>
    <item>
      <title>Arduino remotely controlled (part 2)</title>
      <dc:creator>Iago</dc:creator>
      <pubDate>Sat, 30 Sep 2023 19:16:21 +0000</pubDate>
      <link>https://dev.to/iagows/arduino-remotely-controlled-part-2-1b1n</link>
      <guid>https://dev.to/iagows/arduino-remotely-controlled-part-2-1b1n</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;In the &lt;a href="https://dev.to/iagows/arduino-remote-io-1mc7"&gt;previous post&lt;/a&gt;, we learned how to create an Arduino hub using the &lt;a href="https://www.arduino.cc/reference/en/libraries/simple-repository-io/"&gt;Simple Repository IO&lt;/a&gt; library.&lt;/p&gt;

&lt;p&gt;Now it's time to make it talk with an server.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are the problems I want to solve?
&lt;/h2&gt;

&lt;p&gt;I want to create Arduino Hubs with actuators and sensors, but they must be controlled remotely.&lt;br&gt;
This will (?) ease my mind that wants to create something.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is the solution?
&lt;/h2&gt;

&lt;p&gt;After creating an Arduino library, I must create a server to do the remote communication.&lt;/p&gt;

&lt;h2&gt;
  
  
  Weak points
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;The server is intended to run on your LAN only

&lt;ol&gt;
&lt;li&gt;You can do changes to make it work on the WEB&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;
&lt;li&gt;
&lt;del&gt;I'll create an NPM library to make it easier to call the commands without duplicating code over your servers' code.&lt;/del&gt; Packages &lt;a href="https://www.npmjs.com/search?q=%40arduino_io"&gt;created&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;It relies on Multicast

&lt;ol&gt;
&lt;li&gt;I don't know your LAN configuration, but if you're here I hope you know how to handle that&lt;/li&gt;
&lt;li&gt;Right?&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Intended public
&lt;/h2&gt;

&lt;p&gt;I expect you to have some knowledge regarding: TCP, UDP, IP ranges, and Typescript (not only C/C++)&lt;/p&gt;

&lt;h2&gt;
  
  
  Let's start
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Library
&lt;/h3&gt;

&lt;p&gt;In your Arduino IDE install the &lt;a href="https://www.arduino.cc/reference/en/libraries/simple-repository-io/"&gt;Simple Repository IO&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Changing the wiring from previous post
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;What&lt;/th&gt;
&lt;th&gt;Amount&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Arduino*&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;breadboard&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;220 ohm resistor&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Led (built in)&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Led&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;I hope you have a WeMos D1 R1 compatible Arduino board or an Wi-Fi module compatible with &lt;code&gt;ESP8266WiFi&lt;/code&gt; and know how to wire it&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Pin D10 to resistor&lt;br&gt;
Resistor to LED&lt;br&gt;
LED to GND&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TWyLt2qH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o7etc657jiwhjil7v18c.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TWyLt2qH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o7etc657jiwhjil7v18c.jpg" alt="Wiring" width="800" height="369"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Code
&lt;/h2&gt;

&lt;p&gt;I created a tag so you can use the same version I used for this article.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://gitlab.com/arduino_io/hub/-/tree/3.0.5?ref_type=tags"&gt;Hub&lt;/a&gt; &amp;gt;&amp;gt; arduino code files

&lt;ol&gt;
&lt;li&gt;It starts defining the components (see last article to better understanding)&lt;/li&gt;
&lt;li&gt;Then it &lt;a href="https://en.wikipedia.org/wiki/Multicast"&gt;MULTICASTS&lt;/a&gt; a message via &lt;a href="https://en.wikipedia.org/wiki/User_Datagram_Protocol"&gt;UDP&lt;/a&gt;. Something like "I live, again"&lt;/li&gt;
&lt;li&gt;Wait for WiFi &lt;a href="https://en.wikipedia.org/wiki/Transmission_Control_Protocol"&gt;TCP&lt;/a&gt; messages with some command&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://gitlab.com/arduino_io/server/-/tree/3.0.5?ref_type=tags"&gt;Server&lt;/a&gt; &amp;gt;&amp;gt; typescript node server

&lt;ol&gt;
&lt;li&gt;It starts two servers&lt;/li&gt;
&lt;li&gt;UDP server to add hubs to its list&lt;/li&gt;
&lt;li&gt;TCP server to act as an API

&lt;ul&gt;
&lt;li&gt;each endpoint calls the Arduino&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Results
&lt;/h2&gt;

&lt;p&gt;When calling &lt;code&gt;http://localhost:3000/Hub_A/write/led/true&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zlr_pkTs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3snr95dpxumtnp3cpf91.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zlr_pkTs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3snr95dpxumtnp3cpf91.jpg" alt="Led on" width="800" height="1732"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When calling &lt;code&gt;http://localhost:3000/Hub_A/write/led/false&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WBhMwaUW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pbphcxuxyev99wor0le1.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WBhMwaUW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pbphcxuxyev99wor0le1.jpg" alt="Led off" width="800" height="1732"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When the &lt;code&gt;pwm_led&lt;/code&gt; is set to 0 (zero) and calling &lt;code&gt;http://localhost:3000/write/Hub_A/pwm_led/100&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NcPZVWKc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kmwmj8mqa1h6p9tjxgsx.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NcPZVWKc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kmwmj8mqa1h6p9tjxgsx.gif" alt="Animated image of an led turning on" width="512" height="910"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Previous step
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://dev.to/iagows/arduino-remote-io-1mc7"&gt;Create an Arduino library to remote communication&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Next step
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://dev.to/iagows/arduino-remotely-controlled-part-3-229j"&gt;Create a React Native app to handle the data&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>arduino</category>
      <category>cpp</category>
      <category>iot</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Arduino remotely controlled</title>
      <dc:creator>Iago</dc:creator>
      <pubDate>Sat, 30 Sep 2023 14:11:39 +0000</pubDate>
      <link>https://dev.to/iagows/arduino-remote-io-1mc7</link>
      <guid>https://dev.to/iagows/arduino-remote-io-1mc7</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Hi all,&lt;/p&gt;

&lt;p&gt;This is my first post here and I hope I write many more.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are the problems I want to solve?
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;I want to create Arduino Hubs with actuators and sensors, but they must be controlled remotely.&lt;/li&gt;
&lt;li&gt;This will ease my mind that wants to create something&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  What is the solution?
&lt;/h2&gt;

&lt;p&gt;I created an Arduino library that can do the following:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;You assign pin, names and some typing for each actuator/sensor&lt;/li&gt;
&lt;li&gt;Every item is assigned to a CentralCommandUnit (CCU) that will handle everything from that point&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  What are the weak points?
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;It's in early stage

&lt;ol&gt;
&lt;li&gt;Sometimes I see a problem that must be fixed with breaking changes&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;

&lt;li&gt;Currently only works for &lt;code&gt;bool&lt;/code&gt; and &lt;code&gt;int&lt;/code&gt; values&lt;/li&gt;

&lt;/ol&gt;

&lt;h3&gt;
  
  
  Intended public
&lt;/h3&gt;

&lt;p&gt;Please keep in mind that the code here, even for a 'blink' code, is more verbose than it would be in a beginner project. So it's not for those who are starting with Arduino. You won't see &lt;code&gt;pinMode&lt;/code&gt;, &lt;code&gt;analogRead&lt;/code&gt;... because the library handles that.&lt;/p&gt;

&lt;h2&gt;
  
  
  Let's start
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Library
&lt;/h3&gt;

&lt;p&gt;In your Arduino IDE install the &lt;a href="https://www.arduino.cc/reference/en/libraries/simple-repository-io/" rel="noopener noreferrer"&gt;&lt;code&gt;Simple Repository IO&lt;/code&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Some wiring
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;What&lt;/th&gt;
&lt;th&gt;Amount&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Arduino&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Photo resistor&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;breadboard&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;220 ohm resistor&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Led (built in)&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Pin A0 connected to the resistor and photo resistor&lt;br&gt;
The other resistor leg connected to GND&lt;br&gt;
The other photo resistor leg connected to 5V&lt;/p&gt;

&lt;p&gt;Let's use the built in led.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0w0w4mwjtfirgo8wlbt6.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0w0w4mwjtfirgo8wlbt6.jpg" alt="Wiring"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Code
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="c1"&gt;// imports&lt;/span&gt;
&lt;span class="cp"&gt;#include&lt;/span&gt; &lt;span class="cpf"&gt;"bool_component.h"&lt;/span&gt;&lt;span class="cp"&gt;
#include&lt;/span&gt; &lt;span class="cpf"&gt;"ccu.h"&lt;/span&gt;&lt;span class="cp"&gt;
#include&lt;/span&gt; &lt;span class="cpf"&gt;"command_factory.h"&lt;/span&gt;&lt;span class="cp"&gt;
#include&lt;/span&gt; &lt;span class="cpf"&gt;"percent_component.h"&lt;/span&gt;&lt;span class="cp"&gt;
#include&lt;/span&gt; &lt;span class="cpf"&gt;"Simple_Repository_IO.h"&lt;/span&gt;&lt;span class="cp"&gt;
&lt;/span&gt;
&lt;span class="c1"&gt;// for this library, we must know only the names&lt;/span&gt;
&lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="n"&gt;String&lt;/span&gt; &lt;span class="n"&gt;led&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"led"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="n"&gt;String&lt;/span&gt; &lt;span class="n"&gt;photoSensor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"photo"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// this one is responsible to execute commands&lt;/span&gt;
&lt;span class="n"&gt;CentralCommandUnit&lt;/span&gt; &lt;span class="n"&gt;ccu&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;setup&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// creating a new Repository with 2 items&lt;/span&gt;
  &lt;span class="n"&gt;Repository&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;hub&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;Repository&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"hub"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="c1"&gt;// LED_BUILTIN &amp;gt;&amp;gt; your IDE knows the builtin led for your Arduino board&lt;/span&gt;
  &lt;span class="c1"&gt;// BoolComponent &amp;gt;&amp;gt; this led will turn on or off. This seems to be a boolean for me :)&lt;/span&gt;
  &lt;span class="c1"&gt;// Component::IoType::OUT &amp;gt;&amp;gt; we are not reading values, we're showing them&lt;/span&gt;
  &lt;span class="n"&gt;BoolComponent&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;bc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;BoolComponent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;LED_BUILTIN&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;led&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Component&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;IoType&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;OUT&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="c1"&gt;// A0 &amp;gt;&amp;gt; analogic input pin&lt;/span&gt;
  &lt;span class="c1"&gt;// PercentComponent &amp;gt;&amp;gt; the value starts at 0 (zero - pitch dark) and goes to 100 ("praise the sun")&lt;/span&gt;
  &lt;span class="c1"&gt;// Component::IoType::IN &amp;gt;&amp;gt; we are reading values&lt;/span&gt;
  &lt;span class="n"&gt;PercentComponent&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;pc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;PercentComponent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;A0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;photoSensor&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Component&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;IoType&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;IN&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="c1"&gt;// adding to the repository&lt;/span&gt;
  &lt;span class="n"&gt;hub&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;put&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;bc&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="n"&gt;hub&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;put&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;pc&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="c1"&gt;// starting the Central Command Unit&lt;/span&gt;
  &lt;span class="n"&gt;ccu&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;setup&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hub&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="n"&gt;Serial&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;begin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;9600&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="c1"&gt;// ccu.execute &amp;gt;&amp;gt; tells the ccu to do some command&lt;/span&gt;
  &lt;span class="c1"&gt;// CommandFactory::describe() &amp;gt;&amp;gt; this is to create a JSON from your Arduino hub stored into the repository&lt;/span&gt;
  &lt;span class="n"&gt;String&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ccu&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;CommandFactory&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;describe&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
  &lt;span class="n"&gt;Serial&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Please, don't use this library as the example bellow&lt;/span&gt;
&lt;span class="c1"&gt;// This is an example to it running. In the next article, we'll send commands remotely&lt;/span&gt;
&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;loop&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// CommandFactory::read(photoSensor) &amp;gt;&amp;gt; asking the current value for the component with the name stored into the variable&lt;/span&gt;
  &lt;span class="n"&gt;String&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ccu&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;CommandFactory&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;read&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;photoSensor&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

  &lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="n"&gt;isBright&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;toInt&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="c1"&gt;// CommandFactory::write(led, !isBright) &amp;gt;&amp;gt; change the value of an 'output' component with that name&lt;/span&gt;
  &lt;span class="n"&gt;ccu&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;CommandFactory&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;write&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;led&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;isBright&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
  &lt;span class="n"&gt;delay&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Results
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Turn on the lights = led off&lt;/li&gt;
&lt;li&gt;Turn off the lights (or cover the photo resistor) = led on&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3bkxve3tja7w2zozwgks.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3bkxve3tja7w2zozwgks.gif" alt="On and Off"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Yes, the code is VERY verbose. But this library is for remote control the Arduino.&lt;/p&gt;

&lt;h2&gt;
  
  
  Next steps
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;a href="https://dev.to/iagows/arduino-remotely-controlled-part-2-1b1n"&gt;Connect the Arduino to a server&lt;/a&gt;

&lt;ol&gt;
&lt;li&gt;receive commands&lt;/li&gt;
&lt;li&gt;return data&lt;/li&gt;
&lt;li&gt;Create an API to get/set the hubs information&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;

&lt;li&gt;&lt;a href="https://dev.to/iagows/arduino-remotely-controlled-part-3-229j"&gt;Create a React Native app to handle the data&lt;/a&gt;&lt;/li&gt;

&lt;/ol&gt;

</description>
      <category>arduino</category>
      <category>cpp</category>
      <category>iot</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
