<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Thing Speak &#8211; IoT Expert</title>
	<atom:link href="https://iotexpert.com/category/iot-cloud/thing-speak/feed/" rel="self" type="application/rss+xml" />
	<link>https://iotexpert.com</link>
	<description>Engineering for the Internet of Things</description>
	<lastBuildDate>Thu, 30 Mar 2017 16:12:10 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://iotexpert.com/wp-content/uploads/2017/01/cropped-Avatar-32x32.jpg</url>
	<title>Thing Speak &#8211; IoT Expert</title>
	<link>https://iotexpert.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Particle Photon:  Elkhorn Creek Depth</title>
		<link>https://iotexpert.com/particle-photon-elkhorn-creek-depth/</link>
					<comments>https://iotexpert.com/particle-photon-elkhorn-creek-depth/#comments</comments>
		
		<dc:creator><![CDATA[Alan Hawse]]></dc:creator>
		<pubDate>Thu, 30 Mar 2017 16:12:10 +0000</pubDate>
				<category><![CDATA[Particle]]></category>
		<category><![CDATA[Particle Photon]]></category>
		<category><![CDATA[Thing Speak]]></category>
		<category><![CDATA[WIFI]]></category>
		<guid isPermaLink="false">https://iotexpert.com/?p=3296</guid>

					<description><![CDATA[Summary In the previous article I showed you all of the components of the Particle Photon Ecosystem.  All that is cool.  But what can you build?  I have written extensively about the Elkhorn Creek in my backyard, and the system that I built to monitor the water level.  As part of that series of articles I explained that [&#8230;]]]></description>
										<content:encoded><![CDATA[<h1>Summary</h1>
<p>In the previous article I showed you all of the components of the <a href="http://particle.io" target="_blank">Particle</a> Photon Ecosystem.  All that is cool.  But what can you build?  I have written extensively about the <a href="http://www.elkhorn-creek.org/creekServer/creekPlots/current.html" target="_blank">Elkhorn Creek</a> in my backyard, and the <a href="https://iotexpert.com/category/solutions/elkhorn-creek/" target="_blank">system</a> that I built to monitor the water level.  As part of that series of articles I explained that I have a 4-20ma current loop that turns pressure into water level read <a href="https://iotexpert.com/2016/01/25/the-elkhorn-creek/" target="_blank">here</a> .  In this article I will:</p>
<ul>
<li>Attach the Photon to my Creek System Current Loop</li>
<li>Write the Firmware in the Particle Cloud IDE to publish W</li>
<li>Send events to the Particle Cloud &amp; monitor</li>
<li>Use Webhooks to send the data to ThingSpeak.com</li>
</ul>
<h1>Attach Particle Photon to Creek System</h1>
<p>To interface to a 4-20mA current look you just attach it to a 51.1 ohm resistor to serve as a trans-impedence amplifier.  Here is the PSoC Creator schematic for the board:  Using this schematic, the system will generate a voltage between (51.1 Ohms * 4ma = 204.4mV) and (51.1Ohm * 20mA = 1022 mV).   This voltage can then be attached to an Analog To Digital Convertor, then converted digitally into a Pressure, then a water depth.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2016/02/creekOverallSchematic.png"><img fetchpriority="high" decoding="async" src="https://iotexpert.com/wp-content/uploads/2016/02/creekOverallSchematic.png" alt="" width="902" height="666" class="alignnone size-full wp-image-553" srcset="https://iotexpert.com/wp-content/uploads/2016/02/creekOverallSchematic.png 902w, https://iotexpert.com/wp-content/uploads/2016/02/creekOverallSchematic-600x443.png 600w, https://iotexpert.com/wp-content/uploads/2016/02/creekOverallSchematic-300x222.png 300w" sizes="(max-width: 902px) 100vw, 902px" /></a></p>
<p>I decided that the easiest thing to do with the Particle Photon was to attach the pin A0 to the highside input.  This was easy as I put a loop on the <a href="https://iotexpert.com/2016/02/07/the-creek-board-1-1/" target="_blank">Creek Board</a>.  The loop is labeled &#8220;PRES&#8221;.  The picture is a bit ugly as I was standing in the dark in the rafters of my barn.  Sorry.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/03/IMG_3990.jpg"><img decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/03/IMG_3990-e1490221901847.jpg" alt="Particle Photon attached to Elkhorn Creek Water Level 1.1" width="3024" height="4032" class="alignnone wp-image-3307 size-full" /></a></p>
<h1>Particle Photon Firmware</h1>
<p>When you look at the main loop of the firmware, lines 23-40 it does three things</p>
<ul>
<li>Reads the ADC voltage on Pin A0</li>
<li>Applies an Infinite Impulse Response Filter (IIR) with coefficients of 7/8 and 1/8.  This is low pass filter.</li>
<li>Turns the voltage into depth.  This is done by turning (4-20ma) into (0-15 psi) then PSI into Feet</li>
</ul>
<p>Then, on lines 34-39, I use the system time to figure out if it is time to publish again.  I publish every &#8220;INTERVAL&#8221;.</p>
<p>In order to test the Particle Cloud interface to the Photon, I setup all of the intermediate calculation of depth as &#8220;Particle.variable&#8221;s which allows me to inspect them remotely.</p>
<pre class="lang:c++ range:1-100 decode:true" title="Particle Photon Firmware">uint32_t nextTime; // when do you want to publish the data again
const uint32_t INTERVAL = (5*60*1000); // every 5 minutes in milliseconds
const double  MVPERCOUNT = (3330.0/4096.0); // 3300mv and 2^12 counts
uint32_t current;
uint32_t filter=0;
double depth;
double percent;
double psi;
double voltage;
double percentTemp;

void setup() {
    nextTime =  millis() + INTERVAL;
    // setup variables so that they can be polled
    Particle.variable("filter",filter);
    Particle.variable("adc",current);
    Particle.variable("percent",percent);
    Particle.variable("voltage",voltage);
    Particle.variable("psi",psi);
    Particle.variable("depth",depth);
}

void loop() {
   
   char buff[128];
   
    current = analogRead(A0);
    filter = ((filter&gt;&gt;3) * 7) + (current&gt;&gt;3); // IIR Filter with 7/8 and 1/8 coeffecients
    voltage  = ((double)filter) * MVPERCOUNT; // Convert ADC to Milivolts
    percent = ( voltage - (51.1*4.0) ) / (51.1 * (20.0-4.0)); // 51.1 ohm resistor... 4-20ma 
    psi = percent * 15.0; // Range of pressure sensor
    depth = psi / 0.53; // Magic 0.53psi per foot

   if(millis() &gt; nextTime)
   {
        sprintf(buff,"%.1f",depth);
        Particle.publish("CreekDepth",buff);
        nextTime = millis() + INTERVAL;
   }
}</pre>
<h1>Sending Events to the Particle Cloud &amp; Monitor</h1>
<p>Once I flashed the firmware with the very cool Over-The-Air Bootloader, I go to the Particle Console and click on my device.  As soon as I do that I see the &#8220;Particle.variable&#8221;s that I defined in the firmware.  One by one I press &#8220;get&#8221; and after a second the data is displayed on the screen.  I am not exactly sure how the exactly works, but it is cool.</p>
<h1><a href="https://iotexpert.com/wp-content/uploads/2017/03/consoleCloud.png"><img decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/03/consoleCloud.png" alt="Particle Cloud Device Console" width="1500" height="790" class="alignnone wp-image-3308 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/03/consoleCloud.png 1500w, https://iotexpert.com/wp-content/uploads/2017/03/consoleCloud-600x316.png 600w, https://iotexpert.com/wp-content/uploads/2017/03/consoleCloud-300x158.png 300w, https://iotexpert.com/wp-content/uploads/2017/03/consoleCloud-768x404.png 768w, https://iotexpert.com/wp-content/uploads/2017/03/consoleCloud-1024x539.png 1024w" sizes="(max-width: 1500px) 100vw, 1500px" /></a></h1>
<p>After inspecting the variables, I go the Logs page and look to see what the events are.  You can see that every 5 minutes (about) there is an event called &#8220;CreekDepth&#8221; with a -0.0 or so. That is good as it means that the Particle Photon is publishing regularly.  The answer is 0.0 (or about 0.0) as the Elkhorn Creek if not doing anything right now.  The other events are part of the web hook that I setup (and will talk about in the next section).</p>
<h1><a href="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-6.46.47-PM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-6.46.47-PM.png" alt="Particle Cloud Device Event Log" width="1483" height="1136" class="alignnone wp-image-3309 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-6.46.47-PM.png 1483w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-6.46.47-PM-600x460.png 600w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-6.46.47-PM-300x230.png 300w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-6.46.47-PM-768x588.png 768w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-22-at-6.46.47-PM-1024x784.png 1024w" sizes="auto, (max-width: 1483px) 100vw, 1483px" /></a></h1>
<h1>Using WebHooks to send data to ThingSpeak.com</h1>
<p>Unless I am missing something, the Particle Cloud does not store your actual data.  They do have a mechanism to take Events from your devices and trigger a &#8220;WebHook&#8221;.  This is basically a RESTFul API call to another cloud.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/03/webhooks-overview.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/03/webhooks-overview.png" alt="Particle Cloud Webhooks" width="800" height="431" class="alignnone size-full wp-image-3324" srcset="https://iotexpert.com/wp-content/uploads/2017/03/webhooks-overview.png 800w, https://iotexpert.com/wp-content/uploads/2017/03/webhooks-overview-600x323.png 600w, https://iotexpert.com/wp-content/uploads/2017/03/webhooks-overview-300x162.png 300w, https://iotexpert.com/wp-content/uploads/2017/03/webhooks-overview-768x414.png 768w" sizes="auto, (max-width: 800px) 100vw, 800px" /></a></p>
<p>They call these &#8220;integrations&#8221; and you configure them on the Console.  When you press &#8220;Integrations&#8221; you end up with this screen which gives you the option of editing a current webhook or creating a new one.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-23-at-6.00.05-AM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-23-at-6.00.05-AM.png" alt="Particle Cloud Integrations" width="1038" height="412" class="alignnone wp-image-3313 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-23-at-6.00.05-AM.png 1038w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-23-at-6.00.05-AM-600x238.png 600w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-23-at-6.00.05-AM-300x119.png 300w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-23-at-6.00.05-AM-768x305.png 768w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-23-at-6.00.05-AM-1024x406.png 1024w" sizes="auto, (max-width: 1038px) 100vw, 1038px" /></a></p>
<p>When you click on &#8220;new integration&#8221; it gives you the option of connecting to Google, Microsoft Azure or Webhook.  I havent tried Google or Azure so for this article Ill stick with a Webhook.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-23-at-5.58.37-AM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-23-at-5.58.37-AM.png" alt="Particle Cloud New Integration" width="1104" height="365" class="alignnone wp-image-3312 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-23-at-5.58.37-AM.png 1104w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-23-at-5.58.37-AM-600x198.png 600w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-23-at-5.58.37-AM-300x99.png 300w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-23-at-5.58.37-AM-768x254.png 768w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-23-at-5.58.37-AM-1024x339.png 1024w" sizes="auto, (max-width: 1104px) 100vw, 1104px" /></a></p>
<p>I started with a WebHook to the <a href="https://thingspeak.com" target="_blank">ThingSpeak</a> Cloud (because they show a nice <a href="https://docs.particle.io/guide/tools-and-features/webhooks/" target="_blank">example</a> in the documentation).  ThingSpeak is run by the <a href="https://www.mathworks.com" target="_blank">MathWorks</a> people (same as Matlab).  They call ThingSpeak &#8220;an open IoT with Matlab Analytics&#8221;.  OK sounds cool.  In order to use it to collect and display data I start by creating a new account.  Then I click on the &#8220;New Channel&#8221; button to create an &#8220;Elkhorn Creek Depth&#8221; channel.  On this screen I say that there will be only one field &#8220;CreekDepth&#8221;.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-23-at-6.21.36-AM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-23-at-6.21.36-AM.png" alt="ThingSpeak Create New Channel" width="663" height="551" class="alignnone wp-image-3314 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-23-at-6.21.36-AM.png 663w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-23-at-6.21.36-AM-600x499.png 600w, https://iotexpert.com/wp-content/uploads/2017/03/Screen-Shot-2017-03-23-at-6.21.36-AM-300x249.png 300w" sizes="auto, (max-width: 663px) 100vw, 663px" /></a></p>
<p>In order to write data into this channel you need to have the API keys which give your Restful API call the authority to write into the database.  Press &#8220;API Keys&#8221; and you will see this screen.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/03/new-channel.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/03/new-channel.png" alt="ThingSpeak Channel API Keys" width="1355" height="1125" class="alignnone wp-image-3318 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/03/new-channel.png 1355w, https://iotexpert.com/wp-content/uploads/2017/03/new-channel-600x498.png 600w, https://iotexpert.com/wp-content/uploads/2017/03/new-channel-300x249.png 300w, https://iotexpert.com/wp-content/uploads/2017/03/new-channel-768x638.png 768w, https://iotexpert.com/wp-content/uploads/2017/03/new-channel-1024x850.png 1024w" sizes="auto, (max-width: 1355px) 100vw, 1355px" /></a></p>
<p>Now that I have an active channel (and I know the channel number and API write key) I go back to the Particle Cloud Integrations tab and create a Webhook.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/03/webhook.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/03/webhook.png" alt="Particle Cloud Edit Integration" width="1310" height="1125" class="alignnone wp-image-3316 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/03/webhook.png 1310w, https://iotexpert.com/wp-content/uploads/2017/03/webhook-600x515.png 600w, https://iotexpert.com/wp-content/uploads/2017/03/webhook-300x258.png 300w, https://iotexpert.com/wp-content/uploads/2017/03/webhook-768x660.png 768w, https://iotexpert.com/wp-content/uploads/2017/03/webhook-1024x879.png 1024w" sizes="auto, (max-width: 1310px) 100vw, 1310px" /></a></p>
<p>Each time the &#8220;CreekDepth&#8221; event occurs, the Particle Cloud will do an API call to the ThingSpeak cloud and insert the new data.  On the ThingSpeak Cloud there is a chart of the data, and a handy-dandy way to insert the chart into your webpage.  Here it is for the Elkhorn Creek showing the last 6 hours of data which is flat at the time of this writing, but maybe when you read this page it will be raining in Kentucky and you will see something interesting.</p>
<h1><iframe loading="lazy" width="450" height="260" style="border: 1px solid #cccccc;" src="https://thingspeak.com/channels/246112/charts/1?bgcolor=%23ffffff&amp;color=%23d62020&amp;dynamic=true&amp;results=60&amp;type=line&amp;yaxismax=15&amp;yaxismin=0"></iframe></h1>
<p>I guess at this point I have a number of questions which I will leave to the future:</p>
<ul>
<li>Exactly what is the form of the request made to the ThingSpeak cloud?</li>
<li>What is the mapping between the event &#8211;&gt; API Request</li>
<li>What is the protocol for Particle.variables?</li>
<li>How does the Microsoft integration work?</li>
<li>How does the Google integration work?</li>
<li>How do I save power on the Photon?</li>
</ul>
<p>I suppose Ill leave these questions to future posts.  If you have other questions leave them as I comment and Ill take a crack at trying to figure them out.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://iotexpert.com/particle-photon-elkhorn-creek-depth/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
	</channel>
</rss>
