A Universal Windows App that mimics the web portal to a Windows 10 IoT Core device. Makes use of the web portal through REST and uses JSON to process the response for display. Can get ipconfig, processes, installed app, default app, OS info etc… All in an app.


Project on GitHub: https://github.com/djaus2/IoTSysInfo

Development Requirements: Windows 10, Visual Studio 2015 RTM, Windows 10 IoT device (eg Raspberry Pi 2)

 

Updates: This blog has been updated with more background information. Also Version 2.1 of the app has a new command that list all installed apps.  Version 2.2: Some code improvement that would slightly simplify adding additional commands.


Platforms for app:

Windows 10 IoT, Windows 10 Desktop, Windows 10 Phone(Version 2 of app)  [Phone’s not working yet. Scren resolution changes don’t work]

About

A Windows 10 IoT device has a web portal in which you can view various aspects of the running device. You can also set some aspects. The readable status items are accessed via the portal gain this access through REST calls from JavaScript. This app uses the same APIs and accesses them through REST. As the responses are in JSON format, the app recursively parses the response to generate the information to be displayed.  The app, being a Universal Windows app will run on all Windows 10 targets including the targeted IoT device and Windows 10 phone.

What the app doesn’t do:

It can’t change any settings as this requires web sockets rather than REST.  There is some discussion as to whether settings changes may require POSTs with parameters instead of sockets.  Looking at the JavaScript it seems that Web Sockets are used for changes I’d love to find out I’m wrong on this.

Versions

There are two versions, both using the same REST and JSON processing code. They differ on the UI interface in that the first version is simple interface meant for a standard desktop screen. The second is more complex in that the UI is divided into three sections and are subject to State Triggers. This version is meant for smaller screens as well as the desktop as the triggers can automatically hide parts of the UI which can be manually triggered for display.

The Take Home

This app shows you how you access various system attributes of a Windows 10 IoT device from a Universal Windows App running on the device or on another Windows 10 device (IoT, Phone or Desktop). It exemplifies REST calls and recursive JSON parsing.

Acknowledgement

The basis of this app (wrt REST and the Web Portal API) came for a blog by Bruce Eitman:

Windows 10 IoT Core: Getting the MAC Address from Raspberry Pi.


Using Version 1.0

The app can run on a Windows 10 desktop, Windows 10 Phone or Windows 10 IoT device, depending upon the CPU target used when building the app. But the subject of the app is always a Windows 10 IoT device as it exploits the web service that runs on those devices. Hence the app either runs in local or remote mode. If running in local mode, on a Raspberry Pi 2 for example, you set the target to localhost, the device name or its IPAddress. If running remotely though, you can’t use localhost of course. The port needs to be set to 8080 as per the web interface. You set the login credentials for on the device which default to those for when a device is first initiated. When press the button for whichever command you want to action. The result of the query appears in teh right-hand pane. eg:

 

image

Version 1.0 of the app (Click me)

In the above image of the app ipconfig has been run.

 

Arrays

With some commands where items are indexed, they can be expanded by clicking upon them to get details. For example, Devices returns a  large numbers of devices, each which has a large set of (the same) properties. For each, the initial query just displays the Name property of each device. By clicking on a particular device you get all of its properties. The same for Processes, Installed Packages and Providers. Ipconfig will return an array where there is more than one network adapter. This can be exemplified by plugging in a USB network adapter ( i use the one supplied with the Galileo board). In this case you initially just get a list of the nics. If you then click on one you get the interface’s details.

 

image

The target IoT device is configured in the top left of the UI, as circled in red.

The user credentials on are just below that as circled in blue.

image

The commands in the bottom left of the UI.

The Commands

  • ipconfig: As per ipconfig app
  • sysinfo: OS system information: Device name, OS build no, system hardware version
  • osapi: Slightly more detail to sysinfo
  • devices: a list of installed devices on the system
  • processes: a list of running processes on the system
  • default app: the one app that runs from start up.
  • providers: various Windows “services”
  • packages: installed apps (Added to version 2.1 of the app)
  • api: Can manually enter an api path to test

 

Async Cancel

image

Most calls in the app are async including the REST call. “In principle” you can cancel the REST call if its taking too long or set a timeout beforehand.
To set the time just vary the slider position, It seems that an incorrectly targeted REST call can’t be stopped in this manner though. It just eventually fails

 

REST API Calls

The REST calls use a URL made up of the target name or IPAddress, the port (8080) and an API path:

These API paths are of the form /API/Service/Info. There are determined by examining the JavaScript files that the various web port tab pages use.

The following are the APIs used in the app.

 

IpConfig

  /api/networking/ipconfig

SysInfo

  /api/iot/deviceinformation

OSAPI

  /api/os/info

Devices

  /api/devicemanager/devices

Processes

  /api/resourcemanager/processes

DefaultApp

  /api/iot/appx/getdefault

Packages

  /api/appx/installed  <- Add in Version 2.1

Providers

  /api/etw/providers

 

 

Where did these strings come from?

These query strings are gleaned from examining the JavaScript files that are referenced on the Web Portal pages. One script, WebRest.js is listed in full here:

http://embedded101.com/Blogs/David-Jones/entryid/683/Win-10-IoT-SysInfo-A-Windows-Universal-App-WebRest-js-

 

Further:

If you wish to experiment with these API paths, no that these paths are copied into the box just to the right of the [API] command button.
When the [API] button is pressed, whatever path is in that box is used and so you can test any API path you wish. Note also that below the [API] button is another textbox. This can be used to add any REST parameters.

 

Version 2.0

Version 2.0 has the same functionality as Version1.0. The underlying  “engine” is unchanged. It just a reworked UI that is more dynamic.

image

This version has the UI in three sections (Click me):

  • Commands
  • Settings
  • Query Output

In full screen on a desktop, all three panes show, by default. The first two can though be hidden by pressing

  • the Glyph symbol top left to hide the commands
  • the Settings icon above the (pink) settings pane
  • the icon above the query pane will clear it.

 

For smaller screens the Settings pane is hidden by default and for even smaller screen (say the phone) the commands are also hidden.

Note that the Glyph and Settings Icon are also used to show their panes when not showing..


Next: The REST and JSON processing: Win 10-IoT- SysInfo- A Universal Windows App (Part 2)- REST & JSON Code