Stream IoT data into Excel

Published Nov 16 2021 10:06 AM 1,048 Views
Microsoft

JimBennett_5-1636164924652.png

 

There is a whole world of IoT services out there that allow you to connect your device and upload data to the cloud. From there you can make decisions on your data, run it through AI models, or visualize it with powerful dashboards.

 

But what if that's just too much? What if you just want to see the data in Excel?

 

This is a common case - especially in schools that are introducing physical computing to CS students. They often don't have the money, expertise, or firewall access to spin up cloud services to ingest data, and visualization services to show it. What they do often have is Excel - either running on PCs, Macs, Chromebooks or iPads, and usually want to connect a simple device to something, and plot data from it so students can work on projects.

 

JimBennett_0-1636164924651.png

 

One example is digital agriculture, which in schools is often a temperature sensor used to calculate growing degree days, or a soil moisture sensor, maybe combined with a relay and pump, to track if a plant needs water and if so automatically water it.

 

There are many devices and kits that can provide the physical computing side – such as Raspberry Pis, Arduinos, and sensor kits, but how can data be sent from these devices to Excel?

 

This post shows you how to stream data from an IoT device to Excel running on the web!

 

This post contains links to sample code that you can use with the FarmBeats for students kit, available from Seeed Studios.

 

Architecture

 

JimBennett_1-1636164924651.png

 

 

The architecture you can use for this is not that complex. As long as your IoT device has WiFi, you can expose a REST API over HTTPS that can be called by an Excel add-in. This API can then be used to read sensor data, or control actuators.

 

Let’s dive in a bit deeper. You can also find all the sample code for this in my GitHub repo.

 

IoT device with a REST API

 

The Excel add-in JavaScript API can make calls to REST endpoints, including those running on your local network. On your IoT device you can expose a REST API, and from this API return sensor data, or control actuators.

 

For example, if you are using a Raspberry Pi with a soil moisture sensor and a relay, you can create a Python/Flask app, and expose a REST API with 2 endpoints:

temperature/ - make a GET request to this endpoint to get the current reading for the temperature sensor

relay/ - make a POST request to this endpoint to turn the relay on or off, passing the desired state as a boolean in a JSON request body.

 

As a tip – reading from sensors can take time, and you probably want to avoid multiple concurrent reads to a sensor. A good way to do this is to have a thread that reads and caches sensor values every second or so. When a REST request comes in, read from the cache. This would also allow you to cache historic data, should you want to add an endpoint to get historic data captured when Excel isn’t connected.

 

The Excel add-in architecture also supports web sockets, so you can even expose streaming data over a web socket if you wish.

 

One thing you MUST do though, is use HTTPS. Excel add-ins will not work with HTTP, they require a secure endpoint using HTTPS. You can use ad-hoc self-signed certificates, such as by setting the SSL context in a Flask app to adhoc as described in this blog post. You also need to run using sudo to use SSL with a flask app on a Raspberry Pi.

 

You can find example code for a RaspberryPi that hosts a Flask app with REST endpoints, using the sensors from the FarmBeats for students kit in the farmbeats-server folder in my GitHub repo.

 

Excel add-ins

 

Excel has an add-in model that allows you to build add-ins using JavaScript or TypeScript. This allows you to write code that not only uses the Excel JavaScript API to interact with worksheets, but you can also use standard JavaScript code to do other things - such as interact with the REST endpoint on your IoT device.

 

The first step is to create an add-in. There is a handy generator tool to help with this, available on the Office Developer GitHub.

 

This tool is installed using NPM, then can be used to create add-ins for any Office app. For Excel, you can create 2 types of add-ins – Task Panes and Excel Functions.

 

JimBennett_2-1636164924651.png

 

 

Task Panes are panels that pop out when you select a button on the ribbon. These show HTML pages, with JavaScript or TypeScript code behind the scenes to respond to buttons being selected or other input.

 

JimBennett_3-1636164924652.png

 

Excel Functions are functions in Excel, as the name suggests. You can call these in your spreadsheet the same way that you would call the built-in functions such as SUM and VLOOKUP. Under the hood, it calls functions in your add-in, and these functions can either return a single value, or start a background timer that returns values that update on a regular basis, updating the value in the cell.

 

Whichever one you use, your JavaScript or TypeScript code runs inside Excel, so if you are running Excel on the Web via Microsoft 365 for example, this code runs inside your browser locally, not on a server somewhere. This means it can access resources on your local network, such as your IoT device. Inside your button or function code you can then use the JavaScript fetch API to get or set values on your IoT device.

 

You can find example code in the excel-addin folder in my GitHub repo.

 

Wiring it all up

 

Once you have your add-in written, you need to test it all out. Instructions for running and testing your add-in are in the generator documentation.

 

One thing to be aware of is you need to be using Excel on the web, not the local app. This is due to the fun of HTTPS certificates. Unfortunately, there is no way for your IoT device to have a fully valid certificate – certificates are based on the URL of your REST API, and your device is running locally, so won’t have a proper public URL.

 

Excel running locally will refuse to access your REST API without a valid certificate, but on the web, you can get your browser to allow the ad-hoc certificate running on your IoT device. What you need to do is to first load one of the REST endpoints in your browser, then when you get a certificate warning, select the option to allow access. You only need to do this once per certificate and after this Excel in the browser will be able to access your IoT device. If you are using Flask for example, every time your Flask app restarts it generates a new certificate, so you will need to re-approve it after every restart.

 

JimBennett_4-1636164924652.png

 

Start by loading the REST API in a browser and approving the certificate.

 

Once done, open an Excel workbook in your browser, then load the manifest.xml file for your add-in. You will then be able to access any Task Panes or Excel Functions from your add-in.

 

JimBennett_5-1636164924652.png

 

You can access from any browser - running on a PC, Mac, Chromebook or iPad!

 

If you want to then publish your add-in rather than have it running locally, you will need to host the content somewhere, such as Azure storage. You can find the instructions in the Excel add-in documentation.

 

Where next?

 

You can check out sample code to do this in my GitHub repo. Also check out the Office add-ins documentation.

%3CLINGO-SUB%20id%3D%22lingo-sub-2948955%22%20slang%3D%22en-US%22%3EStream%20IoT%20data%20into%20Excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2948955%22%20slang%3D%22en-US%22%3E%3CP%20align%3D%22center%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22JimBennett_5-1636164924652.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F324744i8B20D58E824D5E38%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22JimBennett_5-1636164924652.png%22%20alt%3D%22JimBennett_5-1636164924652.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThere%20is%20a%20whole%20world%20of%20IoT%20services%20out%20there%20that%20allow%20you%20to%20connect%20your%20device%20and%20upload%20data%20to%20the%20cloud.%20From%20there%20you%20can%20make%20decisions%20on%20your%20data%2C%20run%20it%20through%20AI%20models%2C%20or%20visualize%20it%20with%20powerful%20dashboards.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EBut%20what%20if%20that's%20just%20too%20much%3F%20What%20if%20you%20just%20want%20to%20see%20the%20data%20in%20Excel%3F%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThis%20is%20a%20common%20case%20-%20especially%20in%20schools%20that%20are%20introducing%20physical%20computing%20to%20CS%20students.%20They%20often%20don't%20have%20the%20money%2C%20expertise%2C%20or%20firewall%20access%20to%20spin%20up%20cloud%20services%20to%20ingest%20data%2C%20and%20visualization%20services%20to%20show%20it.%20What%20they%20do%20often%20have%20is%20Excel%20-%20either%20running%20on%20PCs%2C%20Macs%2C%20Chromebooks%20or%20iPads%2C%20and%20usually%20want%20to%20connect%20a%20simple%20device%20to%20something%2C%20and%20plot%20data%20from%20it%20so%20students%20can%20work%20on%20projects.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20align%3D%22center%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22JimBennett_0-1636164924651.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F324741i7840A126F51AD2B3%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22JimBennett_0-1636164924651.png%22%20alt%3D%22JimBennett_0-1636164924651.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EOne%20example%20is%20digital%20agriculture%2C%20which%20in%20schools%20is%20often%20a%20temperature%20sensor%20used%20to%20calculate%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FGrowing_degree-day%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Egrowing%20degree%20days%3C%2FA%3E%2C%20or%20a%20soil%20moisture%20sensor%2C%20maybe%20combined%20with%20a%20relay%20and%20pump%2C%20to%20track%20if%20a%20plant%20needs%20water%20and%20if%20so%20automatically%20water%20it.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThere%20are%20many%20devices%20and%20kits%20that%20can%20provide%20the%20physical%20computing%20side%20%E2%80%93%20such%20as%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fwww.raspberrypi.com%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3ERaspberry%20Pis%3C%2FA%3E%2C%20%3CA%20href%3D%22https%3A%2F%2Farduino.cc%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3EArduinos%3C%2FA%3E%2C%26nbsp%3Band%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fwiki.seeedstudio.com%2FGrove_Base_Hat_for_Raspberry_Pi%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Esensor%20kits%3C%2FA%3E%2C%20but%20how%20can%20data%20be%20sent%20from%20these%20devices%20to%20Excel%3F%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThis%20post%20shows%20you%20how%20to%20stream%20data%20from%20an%20IoT%20device%20to%20Excel%20running%20on%20the%20web!%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%3E%3CEM%3EThis%20post%20contains%20links%20to%20sample%20code%20that%20you%20can%20use%20with%20%3CA%20href%3D%22https%3A%2F%2Fwww.seeedstudio.com%2FGrove-Kit-with-Raspberry-Pi-4-designed-for-Microsoft-FarmBeats-for-Students-p-4872.html%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Ethe%20FarmBeats%20for%20students%20kit%3C%2FA%3E%2C%20available%20from%20%3CA%20href%3D%22https%3A%2F%2Fwww.seeedstudio.com%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3ESeeed%20Studios%3C%2FA%3E.%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--295988274%22%20id%3D%22toc-hId--293430088%22%3EArchitecture%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20align%3D%22center%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22JimBennett_1-1636164924651.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F324739i22D28EB658011166%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22JimBennett_1-1636164924651.png%22%20alt%3D%22JimBennett_1-1636164924651.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20architecture%20you%20can%20use%20for%20this%20is%20not%20that%20complex.%20As%20long%20as%20your%20IoT%20device%20has%20WiFi%2C%20you%20can%20expose%20a%20REST%20API%20over%20HTTPS%20that%20can%20be%20called%20by%20an%20Excel%20add-in.%20This%20API%20can%20then%20be%20used%20to%20read%20sensor%20data%2C%20or%20control%20actuators.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ELet%E2%80%99s%20dive%20in%20a%20bit%20deeper.%20You%20can%20also%20find%20all%20the%20sample%20code%20for%20this%20in%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fjimbobbennett%2Ffarmbeats-vnext-experimental%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Emy%20GitHub%20repo%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--2103442737%22%20id%3D%22toc-hId--2100884551%22%3EIoT%20device%20with%20a%20REST%20API%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20Excel%20add-in%20JavaScript%20API%20can%20make%20calls%20to%20REST%20endpoints%2C%20including%20those%20running%20on%20your%20local%20network.%20On%20your%20IoT%20device%20you%20can%20expose%20a%20REST%20API%2C%20and%20from%20this%20API%20return%20sensor%20data%2C%20or%20control%20actuators.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFor%20example%2C%20if%20you%20are%20using%20a%20Raspberry%20Pi%20with%20a%20soil%20moisture%20sensor%20and%20a%20relay%2C%20you%20can%20create%20a%20Python%2FFlask%20app%2C%20and%20expose%20a%20REST%20API%20with%202%20endpoints%3A%3CBR%20%2F%3E%3CBR%20%2F%3E%3CEM%3Etemperature%2F%3C%2FEM%3E%20-%20make%20a%20GET%20request%20to%20this%20endpoint%20to%20get%20the%20current%20reading%20for%20the%20temperature%20sensor%3C%2FP%3E%0A%3CP%3E%3CEM%3Erelay%2F%3C%2FEM%3E%20-%20make%20a%20POST%20request%20to%20this%20endpoint%20to%20turn%20the%20relay%20on%20or%20off%2C%20passing%20the%20desired%20state%20as%20a%20boolean%20in%20a%20JSON%20request%20body.%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%3E%3CEM%3EAs%20a%20tip%20%E2%80%93%20reading%20from%20sensors%20can%20take%20time%2C%20and%20you%20probably%20want%20to%20avoid%20multiple%20concurrent%20reads%20to%20a%20sensor.%20A%20good%20way%20to%20do%20this%20is%20to%20have%20a%20thread%20that%20reads%20and%20caches%20sensor%20values%20every%20second%20or%20so.%20When%20a%20REST%20request%20comes%20in%2C%20read%20from%20the%20cache.%20This%20would%20also%20allow%20you%20to%20cache%20historic%20data%2C%20should%20you%20want%20to%20add%20an%20endpoint%20to%20get%20historic%20data%20captured%20when%20Excel%20isn%E2%80%99t%20connected.%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20Excel%20add-in%20architecture%20also%20supports%20web%20sockets%2C%20so%20you%20can%20even%20expose%20streaming%20data%20over%20a%20web%20socket%20if%20you%20wish.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EOne%20thing%20you%20%3CSTRONG%3EMUST%3C%2FSTRONG%3E%20do%20though%2C%20is%20use%20HTTPS.%20Excel%20add-ins%20will%20not%20work%20with%20HTTP%2C%20they%20require%20a%20secure%20endpoint%20using%20HTTPS.%20You%20can%20use%20ad-hoc%20self-signed%20certificates%2C%20such%20as%20by%20setting%20the%20SSL%20context%20in%20a%20Flask%20app%20to%20%3CEM%3Eadhoc%3C%2FEM%3E%20%3CA%20href%3D%22https%3A%2F%2Fblog.miguelgrinberg.com%2Fpost%2Frunning-your-flask-application-over-https%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Eas%20described%20in%20this%20blog%20post%3C%2FA%3E.%20You%20also%20need%20to%20run%20using%20%3CEM%3Esudo%3C%2FEM%3E%20to%20use%20SSL%20with%20a%20flask%20app%20on%20a%20Raspberry%20Pi.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%20can%20find%20example%20code%20for%20a%20RaspberryPi%20that%20hosts%20a%20Flask%20app%20with%20REST%20endpoints%2C%20using%20the%20sensors%20from%20the%20FarmBeats%20for%20students%20kit%20in%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fjimbobbennett%2Ffarmbeats-vnext-experimental%2Ftree%2Fmain%2Ffarmbeats-server%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ethe%20farmbeats-server%20folder%20in%20my%20GitHub%20repo%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-384070096%22%20id%3D%22toc-hId-386628282%22%3EExcel%20add-ins%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EExcel%20has%20an%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Foffice%2Fdev%2Fadd-ins%2Fexcel%2Fexcel-add-ins-overview%3FWT.mc_id%3Dacademic-48592-jabenn%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Eadd-in%20model%3C%2FA%3E%26nbsp%3Bthat%20allows%20you%20to%20build%20add-ins%20using%20JavaScript%20or%20TypeScript.%20This%20allows%20you%20to%20write%20code%20that%20not%20only%20uses%20the%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Foffice%2Fdev%2Fadd-ins%2Freference%2Foverview%2Fexcel-add-ins-reference-overview%3FWT.mc_id%3Dacademic-48592-jabenn%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EExcel%20JavaScript%20API%3C%2FA%3E%26nbsp%3Bto%20interact%20with%20worksheets%2C%20but%20you%20can%20also%20use%20standard%20JavaScript%20code%20to%20do%20other%20things%20-%20such%20as%20interact%20with%20the%20REST%20endpoint%20on%20your%20IoT%20device.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20first%20step%20is%20to%20create%20an%20add-in.%20There%20is%20a%20handy%20generator%20tool%20to%20help%20with%20this%2C%20available%20on%20the%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FOfficeDev%2Fgenerator-office%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EOffice%20Developer%20GitHub%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThis%20tool%20is%20installed%20using%20NPM%2C%20then%20can%20be%20used%20to%20create%20add-ins%20for%20any%20Office%20app.%20For%20Excel%2C%20you%20can%20create%202%20types%20of%20add-ins%20%E2%80%93%20Task%20Panes%20and%20Excel%20Functions.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20align%3D%22center%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22JimBennett_2-1636164924651.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F324740iCA7469F3D2EA712F%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22JimBennett_2-1636164924651.png%22%20alt%3D%22JimBennett_2-1636164924651.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETask%20Panes%20are%20panels%20that%20pop%20out%20when%20you%20select%20a%20button%20on%20the%20ribbon.%20These%20show%20HTML%20pages%2C%20with%20JavaScript%20or%20TypeScript%20code%20behind%20the%20scenes%20to%20respond%20to%20buttons%20being%20selected%20or%20other%20input.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20align%3D%22center%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22JimBennett_3-1636164924652.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F324742iB52E43E81EA2C7CC%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22JimBennett_3-1636164924652.png%22%20alt%3D%22JimBennett_3-1636164924652.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EExcel%20Functions%20are%20functions%20in%20Excel%2C%20as%20the%20name%20suggests.%20You%20can%20call%20these%20in%20your%20spreadsheet%20the%20same%20way%20that%20you%20would%20call%20the%20built-in%20functions%20such%20as%20%3CSTRONG%3ESUM%3C%2FSTRONG%3E%20and%20%3CSTRONG%3EVLOOKUP%3C%2FSTRONG%3E.%20Under%20the%20hood%2C%20it%20calls%20functions%20in%20your%20add-in%2C%20and%20these%20functions%20can%20either%20return%20a%20single%20value%2C%20or%20start%20a%20background%20timer%20that%20returns%20values%20that%20update%20on%20a%20regular%20basis%2C%20updating%20the%20value%20in%20the%20cell.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWhichever%20one%20you%20use%2C%20your%20JavaScript%20or%20TypeScript%20code%20runs%20inside%20Excel%2C%20so%20if%20you%20are%20running%20Excel%20on%20the%20Web%20via%20Microsoft%20365%20for%20example%2C%20this%20code%20runs%20inside%20your%20browser%20locally%2C%20not%20on%20a%20server%20somewhere.%20This%20means%20it%20can%20access%20resources%20on%20your%20local%20network%2C%20such%20as%20your%20IoT%20device.%20Inside%20your%20button%20or%20function%20code%20you%20can%20then%20use%20the%20JavaScript%20fetch%20API%20to%20get%20or%20set%20values%20on%20your%20IoT%20device.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%20can%20find%20example%20code%20in%20the%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fjimbobbennett%2Ffarmbeats-vnext-experimental%2Ftree%2Fmain%2Fexcel-addin%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Eexcel-addin%20folder%20in%20my%20GitHub%20repo%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--1423384367%22%20id%3D%22toc-hId--1420826181%22%3EWiring%20it%20all%20up%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EOnce%20you%20have%20your%20add-in%20written%2C%20you%20need%20to%20test%20it%20all%20out.%20Instructions%20for%20running%20and%20testing%20your%20add-in%20are%20in%20the%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FOfficeDev%2Fgenerator-office%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Egenerator%20documentation%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EOne%20thing%20to%20be%20aware%20of%20is%20you%20need%20to%20be%20using%20Excel%20on%20the%20web%2C%20not%20the%20local%20app.%20This%20is%20due%20to%20the%20fun%20of%20HTTPS%20certificates.%20Unfortunately%2C%20there%20is%20no%20way%20for%20your%20IoT%20device%20to%20have%20a%20fully%20valid%20certificate%20%E2%80%93%20certificates%20are%20based%20on%20the%20URL%20of%20your%20REST%20API%2C%20and%20your%20device%20is%20running%20locally%2C%20so%20won%E2%80%99t%20have%20a%20proper%20public%20URL.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EExcel%20running%20locally%20will%20refuse%20to%20access%20your%20REST%20API%20without%20a%20valid%20certificate%2C%20but%20on%20the%20web%2C%20you%20can%20get%20your%20browser%20to%20allow%20the%20ad-hoc%20certificate%20running%20on%20your%20IoT%20device.%20What%20you%20need%20to%20do%20is%20to%20first%20load%20one%20of%20the%20REST%20endpoints%20in%20your%20browser%2C%20then%20when%20you%20get%20a%20certificate%20warning%2C%20select%20the%20option%20to%20allow%20access.%20You%20only%20need%20to%20do%20this%20once%20per%20certificate%20and%20after%20this%20Excel%20in%20the%20browser%20will%20be%20able%20to%20access%20your%20IoT%20device.%20If%20you%20are%20using%20Flask%20for%20example%2C%20every%20time%20your%20Flask%20app%20restarts%20it%20generates%20a%20new%20certificate%2C%20so%20you%20will%20need%20to%20re-approve%20it%20after%20every%20restart.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20align%3D%22center%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22JimBennett_4-1636164924652.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F324743i4B32C55FE16D277B%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22JimBennett_4-1636164924652.png%22%20alt%3D%22JimBennett_4-1636164924652.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EStart%20by%20loading%20the%20REST%20API%20in%20a%20browser%20and%20approving%20the%20certificate.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EOnce%20done%2C%20open%20an%20Excel%20workbook%20in%20your%20browser%2C%20then%20load%20the%20manifest.xml%20file%20for%20your%20add-in.%20You%20will%20then%20be%20able%20to%20access%20any%20Task%20Panes%20or%20Excel%20Functions%20from%20your%20add-in.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20align%3D%22center%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22JimBennett_5-1636164924652.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F324744i8B20D58E824D5E38%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22JimBennett_5-1636164924652.png%22%20alt%3D%22JimBennett_5-1636164924652.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%20can%20access%20from%20any%20browser%20-%20running%20on%20a%20PC%2C%20Mac%2C%20Chromebook%20or%20iPad!%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20you%20want%20to%20then%20publish%20your%20add-in%20rather%20than%20have%20it%20running%20locally%2C%20you%20will%20need%20to%20host%20the%20content%20somewhere%2C%20such%20as%20Azure%20storage.%20You%20can%20find%20the%20instructions%20in%20the%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Foffice%2Fdev%2Fadd-ins%2Fpublish%2Fpublish-add-in-vs-code%3FWT.mc_id%3Dacademic-48592-jabenn%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EExcel%20add-in%20documentation%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-1064128466%22%20id%3D%22toc-hId-1066686652%22%3EWhere%20next%3F%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%20can%20check%20out%20sample%20code%20to%20do%20this%20in%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fjimbobbennett%2Ffarmbeats-vnext-experimental%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Emy%20GitHub%20repo%3C%2FA%3E.%20Also%20check%20out%20the%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Foffice%2Fdev%2Fadd-ins%2F%3FWT.mc_id%3Dacademic-48592-jabenn%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EOffice%20add-ins%20documentation%3C%2FA%3E.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-2948955%22%20slang%3D%22en-US%22%3E%3CP%3ELearn%20how%20to%20stream%20data%20from%20an%20IoT%20device%20into%20Excel%20with%20an%20add-in%20and%20the%20Excel%20JS%20API!%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22JimBennett_5-1636164924652.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F324744i8B20D58E824D5E38%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22JimBennett_5-1636164924652.png%22%20alt%3D%22JimBennett_5-1636164924652.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2948955%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EInternet%20of%20Things%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EIoT%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Co-Authors
Version history
Last update:
‎Nov 16 2021 10:06 AM