Information Technology

Powered By Raspberry Pi-4, Hadoop, And Spark

__
<p>This article is a high-level overview of using Industrial Grade&nbsp;Vi&trade; IoT Sim Card&nbsp;to execute industrial/prototype-to-production PoCs rapidly.</p><p>Particle Electron, an out-of-the-box readily available hardware with a cloud bundle environment and Thingspeak open-source data visualization tool,&nbsp;can rapidly transform your ideas into a product using Vi Enterprise-grade IoT sim cards, meticulously crafted connectivity solution specifically for your organizational strategic objectives.</p><p><strong>Hardware components:</strong></p><ol><li>Particle Electron - 1</li><li>DHT22 Temperature Sensor Module -1</li></ol><p><strong>Software apps and online services:</strong></p><ol><li>ThingSpeak API for data visualization.</li></ol><p><strong>The setup:</strong></p><p>Now connect the sensor module DAT pin to D1, Vcc to 3.3v, and Gnd to Gnd of Particle Electron.</p><p>Let&rsquo;s go to&nbsp;particle.io setup, and in the Electron section, click on&nbsp;<strong>&ldquo;Setup my Electron.&rdquo;&nbsp;</strong></p><p><strong><img style="display: block; margin-left: auto; margin-right: auto;" src="https://kradminasset.s3.ap-south-1.amazonaws.com/ExpertViews/Brijesh+1.PNG" /></strong></p><p><strong>https://kradminasset.s3.ap-south-1.amazonaws.com/ExpertViews/Brijesh+.jpg</strong></p><p>To successfully connect to the Device Cloud with a non-Particle SIM, you need to flash your device with special firmware.&nbsp;</p><p><img style="display: block; margin-left: auto; margin-right: auto;" src="https://kradminasset.s3.ap-south-1.amazonaws.com/ExpertViews/Brijesh+2.PNG" width="368" height="563" /></p><p><img style="display: block; margin-left: auto; margin-right: auto;" src="https://kradminasset.s3.ap-south-1.amazonaws.com/ExpertViews/Brijesh+3.PNG" width="372" height="371" /></p><p>The Electron indicates its status with the color LED. At first, it will blink green while connecting to the cell tower. After a few minutes, it will breathe cyan.</p><p><strong><em>Electron breathing cyan means it&rsquo;s connected to the internet</em></strong></p><p><strong>The Visualization:</strong></p><p>We will use ThingSpeak to visualize the temperature and humidity.</p><p>Create an account at&nbsp;<strong>thingspeak.com&nbsp;</strong>and create a channel called &ldquo;Vi IoT Rapid PoC&rdquo; with 2 Fields called &ldquo;Temperature&rdquo; and &ldquo;Humidity.&rdquo;</p><p><img style="display: block; margin-left: auto; margin-right: auto;" src="https://kradminasset.s3.ap-south-1.amazonaws.com/ExpertViews/BRIJESH+4.PNG" width="391" height="602" /></p><p>Let&rsquo;s now move to write code for the Electron and to flash that code into the Electron.</p><p>After clicking through the Electron setup, you&rsquo;ll end up in the online integrated development environment (IDE), where you can program the Electron.</p><p>For this project, we will use an existing library to talk to the temperature sensor and send data to the Thingspeak portal for visualization.</p><p>After naming your app and hitting &ldquo;Save&rdquo; (the folder icon), click the bookmark icon on the left to open the library tab.</p><p>Search for the &ldquo;Adafruit_DHT_Particle&rdquo; library and click &ldquo;Include in-app.&rdquo;</p><p><img style="display: block; margin-left: auto; margin-right: auto;" src="https://kradminasset.s3.ap-south-1.amazonaws.com/ExpertViews/Brijesh+5.PNG" /></p><p><img style="display: block; margin-left: auto; margin-right: auto;" src="https://kradminasset.s3.ap-south-1.amazonaws.com/ExpertViews/Brijesh+6.PNG" /></p><p>Do the same for the &ldquo;ThingSpeak&rdquo; library, the one written by the ThingSpeak development team.</p><p>Here&rsquo;s the code that we&rsquo;ll be using for this project. The Electron samples the temperature and humidity, send the data to ThingSpeak, and sleep for 5 seconds to conserve battery power. When the Electron wakes up 5 seconds later, the code starts back from the beginning.</p><p>// This #include statement was automatically added by the Particle IDE.</p><p>#include &lt;ThingSpeak.h&gt;</p><p>&nbsp;</p><p>&nbsp;</p><p>// This #include statement was automatically added by the Particle IDE.</p><p>#include &lt;Adafruit_DHT_Particle.h&gt;</p><p>&nbsp;</p><p>// This #include statement was automatically added by the Particle IDE.</p><p>#include &lt;Adafruit_DHT_Particle.h&gt;</p><p>#include "Particle.h"</p><p>&nbsp;</p><p>// Set your 3rd-party SIM APN here</p><p>// https://docs.particle.io/reference/device-os/firmware/electron/#setcredentials-</p><p>STARTUP(cellular_credentials_set("********", "", "", NULL));</p><p>&nbsp;</p><p>// This example assumes the sensor to be plugged into CONN2</p><p>#define DHTPIN D1&nbsp; &nbsp; &nbsp;// what pin we're connected to</p><p>&nbsp;</p><p>// Here we define the type of sensor used</p><p>#define DHTTYPE DHT22&nbsp; &nbsp; &nbsp; &nbsp;// DHT11 or DHT22&nbsp;</p><p>&nbsp;</p><p>DHT dht(DHTPIN, DHTTYPE);</p><p>&nbsp;</p><p>/* Thingspeak */</p><p>TCPClient client;</p><p>unsigned long myChannelNumber = ***********;</p><p>const char * myWriteAPIKey = "****************";</p><p>&nbsp;</p><p>void setup() {</p><p>&nbsp;</p><p>&nbsp; &nbsp; // We open up a serial port to monitor the sensor values</p><p>&nbsp; &nbsp; Serial.begin(9600);&nbsp;</p><p>&nbsp; &nbsp; Serial.println("DHT22 test!");</p><p>&nbsp;</p><p>&nbsp; &nbsp; dht.begin();</p><p>&nbsp; &nbsp; ThingSpeak.begin(client);</p><p>}</p><p>void loop() {</p><p>&nbsp; &nbsp; // Wait a few seconds between measurements.</p><p>&nbsp; &nbsp; delay(5000);</p><p>&nbsp; &nbsp; // Reading temperature or humidity takes about 250 milliseconds!</p><p>&nbsp; &nbsp; // Sensor readings may also be up to 2 seconds&nbsp;</p><p>&nbsp; &nbsp; float h = dht.getHumidity();</p><p>&nbsp; &nbsp; // Read temperature as Celsius</p><p>&nbsp; &nbsp; float t = dht.getTempCelcius();</p><p>&nbsp; &nbsp; // Read temperature as Farenheit</p><p>&nbsp; &nbsp; float f = dht.getTempFarenheit();</p><p>&nbsp; &nbsp;&nbsp;</p><p>&nbsp; &nbsp; // Check if any reads failed and exit early (to try again).</p><p>&nbsp; &nbsp; if (isnan(h) || isnan(t) || isnan(f)) {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; Serial.println("Failed to read from Grove DHT sensor!");</p><p>&nbsp; &nbsp; &nbsp; &nbsp; return;</p><p>&nbsp; &nbsp; }</p><p>&nbsp; &nbsp; ThingSpeak.setField(1, (float)t);</p><p>&nbsp; &nbsp; ThingSpeak.setField(2, (float)h);</p><p>&nbsp;</p><p>&nbsp; &nbsp; // Write the fields that you've set all at once.</p><p>&nbsp; &nbsp; ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);</p><p>&nbsp;</p><p>&nbsp; &nbsp; // Give time for the message to reach ThingSpeak</p><p>&nbsp; &nbsp; delay(5000);</p><p>&nbsp; &nbsp;&nbsp;</p><p>&nbsp; &nbsp; // Print the data over serial</p><p>&nbsp; &nbsp; Serial.print("Humid: ");&nbsp;</p><p>&nbsp; &nbsp; Serial.print(h);</p><p>&nbsp; &nbsp; Serial.print("% - ");</p><p>&nbsp; &nbsp; Serial.print("Temp: ");&nbsp;</p><p>&nbsp; &nbsp; Serial.print(t);</p><p>&nbsp; &nbsp; Serial.print("*F ");</p><p>&nbsp; &nbsp; Serial.println(Time.timeStr());</p><p>&nbsp; &nbsp;</p><p>// Publish data to the Particle cloud.&nbsp;</p><p>&nbsp; &nbsp; // Remember that you'll consume data every time you publish to the cloud.</p><p>&nbsp; &nbsp; Particle.publish("temp", String (t));</p><p>&nbsp; &nbsp; Particle.publish("humi", String (h));</p><p>}</p><p>Make sure to put your ThingSpeak channel number, Vi IoT Sim Card APN, and write the API key from before into your copy of the code.</p><p>Let&rsquo;s hit the lightning bolt icon located at the top-left of the web IDE and flash the program into the Electron! You will get a warning that flashing over the air (OTA) uses a bit of data. At this point, it&rsquo;s OK to say &ldquo;Flash OTA anyway.&rdquo; The Electron will flash purple a few times and restart.</p><p>You should now see that the Electron goes to sleep after 6 seconds and your first data point appear in ThingSpeak.</p><p>After some time, you&rsquo;ll be able to see a nice graph of the temperature and humidity.</p><p>&nbsp;</p>
KR Expert - Brijesh Kumar Mishra