<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>InfluxData Blog - Gene Hynson</title>
    <description>Posts by Gene Hynson on the InfluxData Blog</description>
    <link>https://www.influxdata.com/blog/author/gene-hynson/</link>
    <language>en-us</language>
    <lastBuildDate>Wed, 17 Nov 2021 04:00:47 -0700</lastBuildDate>
    <pubDate>Wed, 17 Nov 2021 04:00:47 -0700</pubDate>
    <ttl>1800</ttl>
    <item>
      <title>Monitoring Your Smart Home with InfluxDB and IFTTT</title>
      <description>&lt;p&gt;Do you have smart and IoT home devices switches, video cameras, doorbells, alarm systems or appliances? Do you want to monitor and send events from these devices to InfluxDB with zero coding? With IFTTT Webhooks, you can!&lt;/p&gt;

&lt;p&gt;Let’s dive in.&lt;/p&gt;

&lt;h2 id="what-is-ifttt"&gt;What is IFTTT?&lt;/h2&gt;

&lt;p&gt;IFTTT stands for “If This, Then That.” it’s a cloud service that allows you to connect IoT devices and services. It’s an incredibly powerful service that can help you automate your smart home.&lt;/p&gt;

&lt;p&gt;&lt;img class="aligncenter wp-image-260758" src="/images/legacy-uploads/Do-more-with-the-thngs-you-love.png" alt="Do more with the things you love" width="1200" height="546" /&gt;&lt;/p&gt;

&lt;p&gt;I’ve used IFTTT to:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Open my garage door when I get close to home&lt;/li&gt;
  &lt;li&gt;Turn on lights in my home with motion detection&lt;/li&gt;
  &lt;li&gt;Send my phone a notification when I’ve left the fridge door open too long&lt;/li&gt;
  &lt;li&gt;Start video camera recording when my home alarm is triggered.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;However, what if I want to do more things like:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Keep track of all the motion and sound events from my cameras&lt;/li&gt;
  &lt;li&gt;Or log fridge temperature over time&lt;/li&gt;
  &lt;li&gt;Learn which lights are left on the longest&lt;/li&gt;
  &lt;li&gt;Track how often the temperature in my home fluctuates&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;How do I do all these? That’s where InfluxDB comes in.&lt;/p&gt;

&lt;h2 id="what-is-influxdb"&gt;What is InfluxDB?&lt;/h2&gt;

&lt;p&gt;InfluxDB is a time-series database that allows you to track metrics and events from devices and services over time. InfluxDB accepts data in the form of &lt;a href="https://docs.influxdata.com/influxdb/cloud/reference/syntax/line-protocol/"&gt;Line Protocol&lt;/a&gt;. It’s built to scale and stream data from all your devices. InfluxDB is an &lt;a href="https://github.com/influxdata/influxdb"&gt;open source project&lt;/a&gt;. However, it also offers a free &lt;a href="https://cloud2.influxdata.com/signup"&gt;cloud service&lt;/a&gt; which I’m using for this exercise.&lt;/p&gt;

&lt;h2 id="more-than-monitoring-motion-and-sound-events-from-the-wyze-camera"&gt;More than monitoring motion and sound events from the Wyze Camera&lt;/h2&gt;

&lt;p&gt;The Wyze app lets me see my &lt;a href="https://wyze.com/wyze-cam.html?bundle=1"&gt;Wyze cams&lt;/a&gt;’ motion and sound events. But it doesn’t provide a way to combine the data and answer how often my cameras capture motion events each minute. To solve this, I will use IFTTT + InfluxDB integration for my Wyze cams.&lt;/p&gt;

&lt;p&gt;The best part is that this integration requires no code! Here’s how it works.&lt;/p&gt;

&lt;h2 id="creating-an-iftt-and-influxdb-integration"&gt;Creating an IFTT and InfluxDB integration&lt;/h2&gt;

&lt;p&gt;First, make an &lt;a href="https://ifttt.com/"&gt;IFTTT&lt;/a&gt; and &lt;a href="https://cloud2.influxdata.com/login"&gt;InfluxDB Cloud&lt;/a&gt; accounts. Both are free!&lt;/p&gt;

&lt;p&gt;Once you’ve done that, go into your IFTTT account and &lt;a href="https://ifttt.com/wyzecam"&gt;“Connect” Wyze&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Next, login to your InfluxDB Cloud account and create a bucket. A “bucket” is where you’ll store your time series data. You can create a bucket by visiting the &lt;strong&gt;Load Data&lt;/strong&gt; page and selecting the &lt;strong&gt;Buckets&lt;/strong&gt; tab. Name this bucket whatever you’d like. I called mine “wyze”.&lt;/p&gt;

&lt;p&gt;While you’re on this page, click the “API Tokens” tab. Create a new “read/write” token with write permissions to your newly created bucket. This token will give IFTTT permission to write to your InfluxDB bucket.&lt;/p&gt;

&lt;p&gt;&lt;img class="aligncenter wp-image-260761" src="/images/legacy-uploads/Generate-Read-Write-API-token.png" alt="Generate Read-Write API token" width="1200" height="882" /&gt;&lt;/p&gt;

&lt;p&gt;After you’ve created your new token, copy that token to your clipboard.&lt;/p&gt;

&lt;p&gt;Finally, you’ll need to find your InfluxDB Organization ID. Click the initial icon on the nav bar and select &lt;strong&gt;About&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;img class="aligncenter" src="/images/legacy-uploads/find-your-InfluxDB-Organization-ID.png" alt="Find your InfluxDB Organization ID" width="400" height="482" /&gt;&lt;/p&gt;

&lt;p&gt;You’ll find your Organization ID on this page. Copy that somewhere as well, so you can reference it later.&lt;/p&gt;

&lt;h2 id="creating-an-ifttt-integration"&gt;Creating an IFTTT integration&lt;/h2&gt;

&lt;p&gt;Alright, now the fun begins! Go back to IFTTT log in.&lt;/p&gt;

&lt;p&gt;Click the &lt;strong&gt;Create&lt;/strong&gt; button in the top right corner. You’ll then be presented with the “If this…”, “…then that” screen.&lt;/p&gt;

&lt;p&gt;Click “If this…” and then search for the Wyze service.&lt;/p&gt;

&lt;p&gt;&lt;img class="aligncenter wp-image-260765" src="/images/legacy-uploads/Create-your-own-if-this-then-that-img.png" alt="Create your own - if this - then that" width="670" height="444" /&gt;&lt;/p&gt;

&lt;p&gt;You’ll be presented with events you can subscribe to. In our case, we’re interested in the motion events from the cameras.&lt;/p&gt;

&lt;p&gt;Select &lt;strong&gt;Motion detected&lt;/strong&gt; and then choose &lt;strong&gt;Any camera&lt;/strong&gt; in the dropdown.&lt;/p&gt;

&lt;p&gt;After clicking &lt;strong&gt;Create Trigger&lt;/strong&gt;, you should see this screen. This means half your job is done!&lt;/p&gt;

&lt;p&gt;&lt;img class="aligncenter wp-image-260757" src="/images/legacy-uploads/Create-Trigger.png" alt="Create Trigger" width="670" height="450" /&gt;&lt;/p&gt;

&lt;p&gt;And now, you guessed it, click the &lt;strong&gt;…Then that&lt;/strong&gt; button!&lt;/p&gt;

&lt;h2 id="making-a-webhook-web-request"&gt;Making a Webhook web request&lt;/h2&gt;

&lt;p&gt;Now search for Webhooks, and choose &lt;strong&gt;Make a web request&lt;/strong&gt;. You should end up on a bright blue screen that looks like this:&lt;/p&gt;

&lt;p&gt;&lt;img class="aligncenter wp-image-260762" src="/images/legacy-uploads/Make-a-web-request.png" alt="Make a web request" width="500" height="486" /&gt;&lt;/p&gt;

&lt;p&gt;Here’s what we’re going to write in each field:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;URL: This will depend on which InfluxDB region you signed up for. You can find out out by copying the domain from your browser’s address bar after logging into InfluxDB Cloud. In my case, my region is &lt;a href="https://us-west-2-1.aws.cloud2.influxdata.com/"&gt;https://us-west-2-1.aws.cloud2.influxdata.com/&lt;/a&gt;. After finding your region, append &lt;code&gt;“/api/v2/write?orgID=[[your org id]]&amp;amp;bucket=[[your bucket name]]”&lt;/code&gt; to the URL&lt;/li&gt;
  &lt;li&gt;Method: Select “POST”&lt;/li&gt;
  &lt;li&gt;Content type: Select “text/plain”&lt;/li&gt;
  &lt;li&gt;Additional headers: Type “Authorization: Token [[your InfluxDB API token]]”&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Body: Type &lt;code&gt;activity,type=motion message=”{{MotionDetected}}”&lt;/code&gt;. The &lt;code&gt;and&lt;/code&gt; escape the messages so the double quotes are passed through &lt;code&gt;correctly.IFTTT&lt;/code&gt; will make an API request to InfluxDB Cloud using your API Token for authorization.&lt;/p&gt;

&lt;p&gt;In the body of the request, you’re sending some very basic &lt;a href="https://docs.influxdata.com/influxdb/cloud/reference/syntax/line-protocol/"&gt;Line Protocol&lt;/a&gt;. You’re setting “activity” as the measurement, the value “motion” to the field “type”, and you’re creating the tag “message” with the value of whatever comes from your Wyze camera. In this case, it’ll be the message “Motion detected on [[camera name]]”. because there is no timestamp in this line protocol, InfluxDB will automatically attach the current time when it receives your message.&lt;/p&gt;

&lt;p&gt;Smash that save button! You’re done! Do a happy dance in front of your Wyze cam to start sending those motion events to InfluxDB.&lt;/p&gt;

&lt;p&gt;&lt;img class="aligncenter wp-image-260763" src="/images/legacy-uploads/sending-motion-events-to-InfluxDB.png" alt="sending motion events to InfluxDB" width="670" height="405" /&gt;&lt;/p&gt;

&lt;p&gt;After you’ve collected some motion events, you can log back into InfluxDB to start analyzing. I’m going to create a Notebook in InfluxDB to explore this data. You can do the same by selecting the “Notebooks” option from the nav tree.&lt;/p&gt;

&lt;p&gt;InfluxDb will present you with the query builder and a couple of visualization panels below with a new Notebook.&lt;/p&gt;

&lt;p&gt;Select your bucket and the measurement “activity” in the query builder.&lt;/p&gt;

&lt;p&gt;Next, click the Run button at the top of the Notebook to run the query.&lt;/p&gt;

&lt;p&gt;&lt;img class="aligncenter wp-image-260755" src="/images/legacy-uploads/Build-a-Query.png" alt="Build a Query" width="1200" height="684" /&gt;&lt;/p&gt;

&lt;p&gt;You should see some data.&lt;/p&gt;

&lt;p&gt;&lt;img class="aligncenter wp-image-260764" src="/images/legacy-uploads/Validate-the-Data.png" alt="Validate the Data" width="1200" height="320" /&gt;&lt;/p&gt;

&lt;h2 id="writing-a-flux-query-for-motion-events"&gt;Writing a Flux query for motion events&lt;/h2&gt;

&lt;p&gt;I have two cameras: Door Cam and Pan Cam. I’d like to know which receives more motion events every 10 minutes. Here’s a Flux query I wrote that can help us visualize that:&lt;/p&gt;

&lt;pre&gt;&lt;code class="language-javascript"&gt;import "strings"
from(bucket: "wyze")
|&amp;gt; range(start: v.timeRangeStart, stop: v.timeRangeStop)
|&amp;gt; filter(fn: (r) =&amp;gt; r["_measurement"] == "activity")
|&amp;gt; filter(fn: (r) =&amp;gt; strings.containsStr(v: r["_value"], substr: "Door Cam"))
|&amp;gt; aggregateWindow(every: 10m, fn: count, createEmpty: false)
|&amp;gt; yield(name: "count")&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This Flux query finds all the events where the message “Motion detected on Door Cam” appears and compiles those events over a 10-minute window by counting the number of events that happened in that 10 minutes.&lt;/p&gt;

&lt;h2 id="adding-flux-query-into-your-notebook"&gt;Adding Flux query into your Notebook&lt;/h2&gt;

&lt;p&gt;You can add this query into your Notebook by clicking the + button at the bottom and selecting &lt;strong&gt;Script&lt;/strong&gt;. Then, paste the query.&lt;/p&gt;

&lt;p&gt;Next, click the + button again and select “Graph”.&lt;/p&gt;

&lt;p&gt;Finally, click the &lt;strong&gt;Run&lt;/strong&gt; button to rerun the whole Notebook again. You should see a visualization.&lt;/p&gt;

&lt;p&gt;If you don’t, make sure to check your time window at the top right of the Notebook — I have mine set to “Past 24 hours”. My visualization looks like this:&lt;/p&gt;

&lt;p&gt;&lt;img class="aligncenter wp-image-260759" src="/images/legacy-uploads/Door-Cam-activity.png" alt="Door Cam activity" width="1200" height="306" /&gt;&lt;/p&gt;

&lt;p&gt;The Door Cam sees at most two motion events every 10 minutes. If I repeat the same process and produce another visualization for the Pan Cam, it looks very similar. It seems more often than not, both cameras detect the same events. I should probably check to make sure there isn’t any overlap in their visible field.&lt;/p&gt;

&lt;p&gt;&lt;img class="aligncenter wp-image-260756" src="/images/legacy-uploads/check-there-is-not-any-overlap-in-their-visible-field.png" alt="check there is not any overlap in their visible field" width="1200" height="312" /&gt;&lt;/p&gt;

&lt;p&gt;And that’s it!&lt;/p&gt;

&lt;p&gt;I’ll leave you with a &lt;strong&gt;challenge&lt;/strong&gt;: repeat this exercise but also capture the “Sound detected” events from your Wyze cameras! You should be able to overlap both the motion and sound data in a visualization. You’ll see how often your cameras hear something when they also see something. Here’s a sneak peak of what that looks like for me from both of my cameras combined:&lt;/p&gt;

&lt;p&gt;&lt;img class="aligncenter wp-image-260754" src="/images/legacy-uploads/both-cameras-combined.png" alt="both cameras combined" width="1200" height="312" /&gt;&lt;/p&gt;

&lt;h2 id="try-it-out-yourself"&gt;Try it out yourself&lt;/h2&gt;
&lt;p&gt;The integration with Wyze demonstrated here is one of many potential integrations you can create with IFTTT and InfluxDB! IFTTT has other IFTTT services with hundreds of devices and services. ou can send data from any of them into InfluxDB using the IFTTT Webhooks as described above.&lt;/p&gt;

&lt;p&gt;Share your smart home projects with me by joining the &lt;a href="https://influxdata.com/slack"&gt;InfluxDB Community Slack&lt;/a&gt;. I’d love to see how you’re using IFTTT and InfluxDB to monitor your smart home&lt;/p&gt;

&lt;h2 id="faq"&gt;FAQ&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Does IFTTT work with Wyze?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Yes, Wyze &lt;a href="https://ifttt.com/wyzecam"&gt;works with IFTTT&lt;/a&gt;. All you need to do is go to the IFTTT app on your phone or through your desktop and search for WYZE. Once there, you can use any of the many applets Wyze has.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How do I add Wyze to IFTTT?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To start using IFTTT, you must first create an account. You can download the IFTTT app in &lt;a href="https://play.google.com/store/apps/details?id=com.ifttt.ifttt&amp;amp;utm_source=/&amp;amp;utm_medium=web"&gt;Google Play&lt;/a&gt; or the &lt;a href="https://itunes.apple.com/app/apple-store/id660944635?pt=1752682&amp;amp;ct=/&amp;amp;mt=8"&gt;App Store&lt;/a&gt;. Follow the prompts to make a user account.&lt;/p&gt;

&lt;p&gt;To link your Wyze account in IFTTT, &lt;a href="https://ifttt.com/wyzecam"&gt;search for Wyze&lt;/a&gt;. Press Connect. It will ask you to log in to your Wyze Account.&lt;/p&gt;

&lt;p&gt;The Wyze Applet:&lt;br /&gt;
Once you have an account in IFTT and have it connected to the Wyze App, you can start to work with the &lt;a href="https://ifttt.com/wyzecam"&gt;Wyze applets&lt;/a&gt;. You can get your feet wet, and try one applet to get comfortable. You can also search applets &lt;a href="https://ifttt.com/wyzecam"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Is Wyze owned by Amazon?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;No, Amazon doesn’t own it. Wyze Labs, Inc. and all its related marks and logos, is a U.S. company based in &lt;a href="https://en.wikipedia.org/wiki/Seattle"&gt;Seattle&lt;/a&gt;, &lt;a href="https://en.wikipedia.org/wiki/Washington_(state)"&gt;Washington&lt;/a&gt;. It was formed by four former Amazon employees –  Yun Zhang,  Dongsheng Song,  Elana Fishman, and Dave Crosby.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Can Wyze trigger Alexa?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Alexa (in Amazon echo devices) and related logos are trademarks of amazon.com inc. Wyze can trigger Alexa, but you’ll have to use the Voice Monkey Skill in Your Alexa App to make this happen. Click on &lt;a href="https://www.ads-links.com/how-to-use-wyze-cameras-to-trigger-an-alexa-routine/"&gt;this link for a tutorial&lt;/a&gt;.&lt;/p&gt;
</description>
      <pubDate>Wed, 17 Nov 2021 04:00:47 -0700</pubDate>
      <link>https://www.influxdata.com/blog/monitoring-smart-home-influxdb-ifttt/</link>
      <guid isPermaLink="true">https://www.influxdata.com/blog/monitoring-smart-home-influxdb-ifttt/</guid>
      <category>Product</category>
      <category>Use Cases</category>
      <category>Developer</category>
      <author>Gene Hynson (InfluxData)</author>
    </item>
    <item>
      <title>Out-of-this-world monitoring with InfluxDB and React</title>
      <description>&lt;p&gt;&lt;em&gt;Reprinted with permission. © IDG Communications, Inc., 2021. &lt;a href="https://www.infoworld.com/article/3609389/out-of-this-world-monitoring-with-influxdb-and-react.html"&gt;https://www.infoworld.com/article/3609389/out-of-this-world-monitoring-with-influxdb-and-react.html&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;During an InfluxData internal hackathon, I was looking to work on a project that would help me strengthen my &lt;a href="https://www.influxdata.com/time-series-platform/telegraf/"&gt;Telegraf&lt;/a&gt; and &lt;a href="https://www.influxdata.com/products/flux/"&gt;Flux&lt;/a&gt; skills. I also wanted to use InfluxData’s &lt;a href="https://github.com/influxdata/giraffe"&gt;Giraffe&lt;/a&gt; to visualize my project in a React application. After reading &lt;a href="https://www.influxdata.com/blog/tracking-the-international-space-station-using-influxdb/"&gt;Sean Brickley’s blog post&lt;/a&gt; on tracking the International Space Station with InfluxDB, I was inspired to build on this idea. So I landed on building a React application that could track the ISS’s position live and document its journey using &lt;a href="https://www.influxdata.com/products/influxdb/"&gt;InfluxDB&lt;/a&gt;, ExpressJS, Telegraf, and Giraffe.&lt;/p&gt;

&lt;p&gt;There are three primary components for this project:&lt;/p&gt;
&lt;ol&gt;
 	&lt;li&gt;The Telegraf config&lt;/li&gt;
 	&lt;li&gt;The ExpressJS API server&lt;/li&gt;
 	&lt;li&gt;The React application&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Let’s start with the Telegraf config.&lt;/p&gt;

&lt;p&gt;Like Sean, I used a &lt;a href="http://open-notify.org/Open-Notify-API/ISS-Location-Now/"&gt;public API&lt;/a&gt; to get the current position of the ISS. My plan was to use Telegraf to poll this API, parse the coordinate data, and send this location information to InfluxDB. I used Telegraf’s &lt;a href="https://docs.influxdata.com/telegraf/v1.14/guides/using_http/#configure-the-http-input-plugin-in-your-telegraf-configuration-file"&gt;HTTP plug-in&lt;/a&gt; to achieve this. The next step was to parse the coordinate information from the JSON and convert the strings into floats. This can be accomplished with Telegraf’s &lt;a href="https://github.com/influxdata/telegraf/blob/release-1.14/plugins/processors/converter/README.md"&gt;Converter plug-in&lt;/a&gt;. And finally, I needed to send my location data to my InfluxDB cloud instance running in AWS. Naturally, this is easily done with Telegraf’s InfluxDB plug-in. Step one complete! Now we can run &lt;code class="language-bash"&gt;telegraf --config ./telegraf/iss.conf&lt;/code&gt; and start collecting the ISS’s location.&lt;/p&gt;

&lt;p&gt;Now that we are beginning to collect some data, the next step is querying it. I decided to build an API using ExpressJS and to query my InfluxDB instance using the &lt;a href="https://github.com/influxdata/influxdb-client-js"&gt;InfluxDB JS client&lt;/a&gt;. The goal here is to build an API that the React app can use to retrieve the location data that it will need to visualize the ISS’s flight path using Giraffe.&lt;/p&gt;

&lt;p&gt;First we need to connect to InfluxDB, and we can do that by passing our URL and token to the InfluxDB object. Since we’re going to use the client to run queries, we need to get the Query API object. If you wanted to get bucket information, for example, you would want to get the Bucket API object instead.&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-javascript"&gt;const influxDB = new InfluxDB({ url: baseURL, token: influxToken })
const queryApi = influxDB.getQueryApi(orgID)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Next, we can use the InfluxDB JS client to query our InfluxDB instance like so:&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-javascript"&gt;app.get('/iss, (_, res) =&amp;gt; {
 let csv = ''
 const issQuery = `todo`
 let clientQuery = flux``+issQuery
 queryApi.queryLines(clientQuery, {
   next(line) {
     csv = `${csv}${line}\n`;
   },
   error(error) {
     console.error(error)
     console.log('\nFinished /iss ERROR')
     res.end()
   },
   complete() {
     console.log('\nFinished /iss SUCCESS')
     res.end(JSON.stringify({ csv }))
   },
 })
})&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This route will use the Query API object from the InfluxDB client to execute our query (which we haven’t defined yet). We’ll use the &lt;em&gt;queryLines&lt;/em&gt; function to get our response back line by line. The resulting string will be a csv response that Giraffe can understand.&lt;/p&gt;

&lt;p&gt;Great! Now we just need a Flux query. I experimented with several queries to try and see which one I thought highlighted the ISS’s movement the best. If I simply grabbed all the data over the past several hours, the Giraffe plot might be too busy. If I focused on trying to grab the data for one full orbit, there is a weird problem to solve with drawing a circular, continuous line across a flat map. So I ended up deciding to draw the ISS’s current orbit, from west to east, meaning I grabbed all the data points from 0 degrees longitude to its current position. The ISS orbits every 93 minutes, so I limited my query within that range. Here’s what I came up with:&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-javascript"&gt;import "experimental/geo"
 currentPos = from(bucket: "iss")
 |&amp;gt; range(start: -1m)
 |&amp;gt; filter(fn: (r) =&amp;gt; r._field == "iss_position_longitude")
 |&amp;gt; tail(n: 1)
 |&amp;gt; findRecord(
   fn: (key) =&amp;gt; true,
   idx: 0
 )
 
 from(bucket: "iss")
 |&amp;gt; range(start: -93m)
 |&amp;gt; aggregateWindow(every: 3m, fn: min, createEmpty: false)
 |&amp;gt; geo.shapeData(latField: "iss_position_latitude", lonField: "iss_position_longitude", level: 14)
 |&amp;gt; filter(fn: (r) =&amp;gt; r.lon &amp;lt;= currentPos._value)
 |&amp;gt; geo.asTracks()&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The query starts by finding the current longitude position of the ISS, which would be the most recent record. Then we query for all the positional data, aggregated into three-minute windows where the longitude is less than the ISS’s current position. We use Flux’s experimental &lt;a href="https://docs.influxdata.com/influxdb/v2.0/reference/flux/stdlib/experimental/geo/"&gt;Geo&lt;/a&gt; package to shape the data and to return the positional data as a track.&lt;/p&gt;

&lt;p&gt;OK now on to the fun part — drawing the graph! I’m just going to cover the highlights, so feel free to check out the details of the implementation &lt;a href="https://github.com/genehynson/telegraf-giraffe-iss"&gt;in the repo&lt;/a&gt;. Basically, we have a React application that is using InfluxData’s Giraffe visualization library. Giraffe recently added Geo plots with the ability to plot markers and tracks (check out the &lt;a href="https://influxdata.github.io/giraffe/?path=/story/geo--tracks"&gt;Storybook&lt;/a&gt; to play around with them). Our React application will query our API every 30 seconds or so to retrieve the latest data. We’ll use the &lt;em&gt;fromFlux function&lt;/em&gt; to parse the response into a table that Giraffe can consume. As you can see from the Storybook, there are a lot of knobs you can tweak with the Geo plot. One important parameter is &lt;em&gt;tileServerConfiguration&lt;/em&gt;, which tells Giraffe where to get the map images. I used &lt;a href="https://www.openstreetmap.org/"&gt;OpenStreetMap&lt;/a&gt; and provided Giraffe the following object so it knows how to retrieve the correct map tiles:&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-javascript"&gt;const osmTileServerConfiguration = {
 tileServerUrl: 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;At this point, all the pieces are falling together! I added a checkbox into my UI to add the markers as an optional layer and also provided the ability to query for historical data of a custom time range.&lt;/p&gt;

&lt;p&gt;&lt;img class="alignnone size-full wp-image-254131" src="/images/legacy-uploads/international-space-station-influxdb-telegraf.png" alt="Plotting the International Space Station's Orbit Live Using Telegraf, InfluxDB, and Giraffe" width="1600" height="1349" /&gt;&lt;/p&gt;

&lt;p&gt;And there we have it — the ISS’s location updated live as it travels around the globe! Feel free to &lt;a href="https://github.com/genehynson/telegraf-giraffe-iss"&gt;check out the source code&lt;/a&gt; and play with it yourself. Let me know if you find other Flux queries that produce interesting visualizations of this data.&lt;/p&gt;

&lt;p&gt;As Sean mentioned in his post, the Geo features shown here are still experimental, but we’re working hard to get them ready for production. Stay tuned for more exciting updates in this space (pun intended)! If you’re working on a fun InfluxDB project like Sean and you need help please reach out on our &lt;a href="https://community.influxdata.com/"&gt;community forum&lt;/a&gt; or Slack. We’d love to answer your questions and learn about what you’re doing with InfluxDB.&lt;/p&gt;
</description>
      <pubDate>Tue, 06 Apr 2021 04:00:39 -0700</pubDate>
      <link>https://www.influxdata.com/blog/plotting-international-space-stations-orbit-live-using-telegraf-influxdb-giraffe/</link>
      <guid isPermaLink="true">https://www.influxdata.com/blog/plotting-international-space-stations-orbit-live-using-telegraf-influxdb-giraffe/</guid>
      <category>Product</category>
      <category>Use Cases</category>
      <category>Developer</category>
      <author>Gene Hynson (InfluxData)</author>
    </item>
  </channel>
</rss>
