Fitbit Tracker Display

Bolded words will have definitions at the bottom of each section

STEP 1: Fitbit Authorization

Fitbit uses OAuth 2. There is a lot of documentation at https://dev.fitbit.com/docs/. You will need to make a fitbit dev account. Once you make the account, you will need to make an application. An application is basically a project that you are working on, and it asks you questions about what you are doing with the project (is it personal, or for a business). When making your application, it will ask you for the redirect URI (also labeled Callback URI). This and the name of your application are the two main parts. The other sections, you can more or less make up what you put in. It asks you for your organization and website just to be sure that it is real, so type in real websites for those sections, but they won’t be used. Click save, and your application will be made. You will also be given a client ID and client secret. These allow you to get an access code which you must trade in for an access token and refresh token.

Type this website into your browser (make sure to put in YOUR client id and redirect URI in place of {client ID} and {redirect URI} respectively):

https://www.fitbit.com/oauth2/authorize?response_type=code&client_id={client ID}&redirect_uri={redirect URI}&scope=activity

!!NOTE!! make sure that the redirect URI is URI encoded. Here is a website to encode your URI: http://www.url-encode-decode.com/

This will then bring you to a page that asks you to sign into fitbit and allow the application you made access to the person’s fitbit. Once you click allow, it will bring you to your redirect URI. The URL in your browser should be{redirect URI}/?code={string of numbers and letters here}#_=_ The string of numbers and letters is your access code. You will use this in the next step to get your access token and refresh token.

After granting access to the application and getting an access code, you will make a post command to get an access token which will be used to actually talk to the fitbit api and get information from the user’s activity data. Using HTTP requests, make a POST to https://api.fitbit.com/oauth2/token with headers.

Authorization: Basic {Base64 encoded string “client ID:client secret”}

Content-Type: application/x-www-form-urlencoded

The header “Content-Type” tells you the type of body that should be in the POST command. This is what the body should be

client_id={client ID}&grant_type=authorization_code&redirect_uri={uri encoded redirect uri}&code={authorization code that you got in the last step}

Just a note: the authorization code only lasts 10 min, so you must do this within 10 min of getting the authorization code. Once you make the post command, you will receive back a json string with an access token and a refresh token and user id (to be used later). The access token is used to make GET and POST commands to the fitbit website. It can only be used for 8 hours. Then you must use the refresh token to get a new access token (similar to how you used the access code to get the original access token and refresh token). The POST command to use the refresh token to get a new access token again to https://api.fitbit.com/oauth2/token with headers.

Authorization: Basic {Base64 encoded string “client ID:client secret”}

Content-Type: application/x-www-form-urlencoded

And only now the body is different, and it is

grant_type=refresh_token&refresh_token={refresh token}

This will send you a new access token which you can use for the next 8 hours and a new refresh token which you will have to use when the access token runs out again.

Definitions

redirect URI: A url that the person is redirected to once they have allowed the application access to their account. You can create your own redirect uri as a google site or a wordpress site.

access code: a string of letters and numbers for when a person has allowed your application to access their account. It is traded in for an access token. You should only have to get an access code once (unless you want to get information from a different user). From now on you should be able to use the refresh token to get a new access token.

access token: a string of numbers and letters that is used when making a GET or POST command to get information from the user’s activity data. It lasts 8 hours and then it is no longer valid.

refresh token: a string of numbers and letters that is used to get a new access token and refresh token. That way you do not need to get a new access code every 8 hours.

 

STEP 2: REST api calls to fitbit

Now that you have access to the fitbit api, you can start making GET requests in order to get the activity data. For this project all you need is the step count of each person. To get this it is just a GET command to https://api.fitbit.com/1/user/{user ID}/activities/date/today.json This will get you today’s current step count for that person. You need a header with the access token you got that matches the person whose user ID is in the GET command

Authorization: Bearer {access token}

This returns a long json string that you must parse in order to find the current steps. You can do this by searching for “steps”, taking the string after that, looking for “steps” again and take what’s after that, and search for “,”, and takes the number before that and after “steps”.

Definitions

user ID: a 6 letter/number code that identifies the user. You get this code in the response from the access code post and refresh token post (this user ID does not change).

STEP 3: Connecting to Thingworx

A beta version of a Thingworx library for LabVIEW just came out recently, and you should use that to make your device IoT enabled. Thingworx is a good place to store information that needs to be transferred between internet capable devices (such as a myRIO and computer in this project). For this project I used Thingworx to store the access codes and refresh tokens, because they changed so frequently, and the myRIO would lose them whenever you restarted the program.

Thingworx allows you to create “Things” that have “properties”. You can read/edit the value of properties using GET/POST commands (made easy by the Thingworx library). It would be good to try to become acquainted with Thingworx before going too deep into this project.

You will want to start a thing and make properties on it called “Current_Users” (list of the current users), “goal” (the office step count goal), “steps” (total number of steps). These are the basic properties that you want to have (more will be added later). You will also eventually want properties for each person’s individual access token and refresh token.

Definition

Thingworx: a cloud platform that stores information and can be accessed by internet capable devices.

STEP 4: Connecting an arduino to lights

For the cool light display, you will need to be able to control the lights and make them different colors. You can control the lights using an arduino and an external power source (7-9 volts).

First, you will need to download the Adafruit_Neopixel library. Open the strip test example.

Second you will need to hook up the LED strip to the arduino. You can do this using a breadboard. Connect the positive end of the external power source to one row on the breadboard and the negative end to a different row. You will need to connect the ground of the LED strip to the same row as the negative end of the external power source, and the positive wire of the LED strip to the row that has the positive end of the external power source. You will also need to ground the arduino with the same ground, so you will need a jumper that goes from a ground pin on the arduino to the row that has the negative of the external power source and the ground of the LED strip. Lastly connect the data wire of the LED strip to a PWM pin on the arduino (a pin that has a ~ before the number).

Make sure that the pin number variable in the code is the same as the pin number you plugged the LED strip data wire into. Then try running the code. Make sure you get this working and that the circuit setup is correct before moving on.

Once you have gotten that working, you can start writing your own code. Use the same structure as the example code. Since the LED strip that I used was 144 lights, I split the strip in 3rds, meaning that if the total step count was below a third of the whole goal, the lights would be red, if the total was between one to two thirds of the goal, the lights would be orange, and if the total was above two thirds of the goal, the lights would be green. As an indication that the total steps for the day was above the goal, all the lights would be purple.
Here is the code:

#include <Adafruit_NeoPixel.h>     //makes sure to include the neopixel library
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN            3           //the pin number of the data wire
#define NUMPIXELS      144    //the number of neopixels on the strip

// defines what pixels and strip mean
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

float goal = (type goal here);             //goal
float steps = (type current steps here);     //current steps

void setup() {
pixels.setBrightness(30);       //turns down brightness (the lights are very bright)
strip.begin();            // This initializes the NeoPixel lights (makes sure they are all off).
strip.show();
}

void loop() {
if(steps == 0){
for(int p = 0; p <= 144; p++){
pixels.setPixelColor(p, 0,0,0);   //resets the color of all the lights if the current total is zero
pixels.show();
}
}

if(goal > steps){
for(int i = 1; i <= 144; i++){    // checks what “percentage” you are at
if((float)i*(goal/144.0)> steps){
k = i -1;                    //tells you how many light should light up
break;
}
}

if(k<48){
for(int p = 0; p <= k; p++){
pixels.setPixelColor(p, 255,0,0);   //set the number of lights, and if < 48 lights => red
pixels.show();            // displays lights
}
}

if(k>48 && k<96){
for(int p = 0; p <= k; p++){
pixels.setPixelColor(p, 255,50,0);  //set the number of lights, and if < 96 lights => orange
pixels.show();
}
}

if(k>96){
for(int p = 0; p <= k; p++){
pixels.setPixelColor(p, 0,255,0);  //set the number of lights, and if >96 lights, => green
pixels.show();
}
}
}

else{
for(int n = 0; n <= 144; n++){
pixels.setPixelColor(n,128,0,128);   // when over goal, lights will be purple
pixels.show();
}
}
}
Note, pixel color is set like this:
pixels.setPixelColor(pixel number, red value, green value, blue value)

Change the values for goal and total and play around with it a bit to make sure that it works.

Now that you know that that works, you want to be able to send commands via your computer’s serial port while the code is running on the arduino. This will eventually lead to the rio sending the serial commands to light up the lights. The serial port reads in characters, so you must concatenate them into a string, then parse the string into total and goal and then run the lights code based on that.
Here is the code:

#include <Adafruit_NeoPixel.h>         //makes sure to include the neopixel library
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN            3         //the pin number of the data wire
#define NUMPIXELS      144    //the number of neopixels on the strip

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

float goal; //goal
float steps; //current steps
int k;
bool reading = 0;
String data = “”;
int g;
String stepString;
String goalString;

void setup() {
pixels.setBrightness(30);       //turns down brightness (the lights are very bright)
strip.begin();            // This initializes the NeoPixel lights (makes sure they are all off).
strip.show();

Serial.begin(9600);        // opens serial port so the arduino can talk to rio

}

void stepCount(String input){     //function that parses “!#,#?” into numbers
for(int s = 0; s <= input.length(); s++){
if(input.charAt(s) == ‘,’){
g = s-1;
}
}

stepString = input.substring(0,g+1);
goalString = input.substring(g+2,input.length());
steps = stepString.toInt();
goal = goalString.toInt();
steps = steps/10;
goal = goal/10;
}

void loop() {
// read  string in the form “! step number, goal number ?”
if (Serial.available()) {        //check to see if data is sent through serial
char letter = Serial.read();
if(reading == 0){
if(letter == ‘!’){        //if it wasn’t reading the characters and it sees ! start reading
reading = 1;
}
}else{
if(letter == ‘?’){        //sees end of string
reading = 0;        //stops making a string
stepCount(data);    //parses string into goal and steps
lights();            //runs lights (from before)
Serial.print(steps);    //returns the step count (just so you can see that it works)
data = “”;        //resets the string to empty so it is ready for a new string
}else{
data = data + letter;        //makes the string using the characters coming in
}
}
}
}

void lights() {
Same code from before
}

You should test this out by typing into the COMM command on the arduino application. Type in “!{steps},{goal}?” where {steps} is the total steps for the day and {goal} is your test goal. Make sure all this is working consistently before moving on.

STEP 5: Connecting a myRIO to the Arduino

Now, you need to write labVIEW code that will tell the myRIO to talk to the arduino and tell it to light up its lights. You want to have the myRIO open its serial port, start a while loop that is sending the arduino information and when you want it to stop, it closes the serial port. You will want to have controls on the front panel of labVIEW so that you can continuously change the goal and current step values and see the lights change (the same thing you were doing in the COMM command in the last step). Your code and front panel should look something like this

STEP 6: Adding an LCD Screen

Since the goal can change pretty frequently, it is nice to have a display that can show what the current goal is and how many days the office has left to complete that goal. This is where it is nice to have an LCD screen that just says “goal: # [enter] days left: #”. This code is pretty simple. You need to put a string into a function that displays it on the LCD screen. The string needs to be a concatenated string of “goal:”,”{the goal}”, “days left:”, and “{the number of days left}”. This is easy to do in labVIEW, because there is a string concatenation function in labVIEW. The one tricky part of this is making it so that “goal: #” and “days left: #” are on different lines. The way to do this is is to find the length of the string “goal:#” and then add 16 minus that length number of spaces,  and then add “days left:” and “{number of days left}”. The who string is then fed into the function that displays the string on the LCD screen. Since you added the specific number of spaces, the length of the number for the goal doesn’t matter.

STEP 7: Putting it all together

It would be much easier to put all the steps together so that all you have to do is put in the person’s name and the access code you get from the redirect url when they allow your application access to their account.
You will want to make many sub vis that do specific tasks. I will talk through the sub vis in order of when they would be used.
(1) Turning access code into access token
Inputs: access code
Outputs: access token, refresh token, user ID
This sub vi should take the access code, make the POST command to the fitbit api with the hard coded values of the headers, then parse the json response and output the access token, refresh token and user ID.

(2) Adding the new user to thingworx
Inputs: access code, person’s name
This sub vi takes the access code, and puts it through (1). It also takes the person’s name and creates two properties in Thingworx with it “PersonsName_AccessToken” and “PersonsName_Refresh_Token” and saves the access token and refresh tokens to it respectively. It also adds the person’s name to the list of names in the property “CurrentUsers”
Code looks like this:

(3) Turning refresh token into access token
Inputs: refresh token
Outputs: access token, refresh token, user ID
This sub vi should take the refresh token, make the POST command to the fitbit api with the hard coded values of the headers, then parse the json response and output the access token, refresh token and user ID. (Very similar to (1), but making the POST to a different URL and with slightly different headers)

 

(4) Getting Steps From Fitbit
Inputs: access token, user ID
Outputs: step count
This one takes the user ID and adds it to the fitbit api base url that you use for making the GET command to. It also adds the access token to header. The code makes the GET command, parses the response and outputs the step count for that person.

(5) Lights
Inputs: serial port, steps, goal
Outputs: serial port
This sub vi is the vi that we wrote in a previous step where you can input the steps and goal and it has the RIO tell the arduino the numbers and the arduino lights up the lights. It outputs the serial port, so that you can have it in a chain with other vis that may need to open serial connections

(6) Screen Display
Inputs: days left, goal
This sub vi makes an LCD screen display the goal and the number of days left to complete the goal.
(7) Change Goal
This is a vi that runs on its own. You add the goal that you want and the number of days that the office has to complete that goal to controls on the front panel. It takes this information, and writes the new goal and days left to complete to thingworx, overriding the previous values. It also clears the total, so that it restarts the light display and count.

Once all the sub vis are made, you can start adding them into one big vi. Outside the while loop you want to start a thing and open the serial port. Then you will want to run a while loop that runs forever. In that loop you want to grab the list of names from the “CurrentUsers” property, parse through them and make an array of the names of people. Then send that through a for loop in order to read the “name_Refresh_Token” and send it through the refresh token sub vi and then overwrite the “name_Access_Token” and “name_Refresh_Token”. As well as creating an array of clusters which contain the access token and user ID. After going through the for loop, it goes into another for loop which runs once every minute for 450 minutes (7.5 hours). That way it uses the access token for 7.5 hours and then goes back to the beginning of the while loop and uses the refresh token and gets a new access code and keeps going.
Inside the for loop that runs for 7.5 hours, you want to have a for loop that goes through the array of clusters and sends each group of user ID and access token through the step count vi to get the steps. Then sum all the steps to get the total. Update the total in thingworx. Send the total into the lights vi. Also grab the goal from the “goal” property in thingworx and send that into the lights vi. Also send the goal to the screen display. Pull the “days_left” property value and send that into the screen display vi. Make sure to wire the array of clusters to the end of the for loop and change it into a shift register so that the next time it loops, it can send the access token and refresh token to the step vi again, and continue the cycle.

STEP 8: Making the box

Make sure that all the code works before making a polished box for it. I made the box by taping together 2 ⅛ thick pieces of 24×6 in wood. (6 in sides together to make a piece 48×6 in). If you have a laser engraver you can write the title of your step counter at the top along with motivational saying to the side of where the LED strip would be. You and also just do this in Sharpie. Place the LED strip on the wood with the wires that connect to the breadboard at the bottom. Cut a hole at the bottom that allows the wires to go through it so that you can have the rio, arduino and breadboard on the back of the wood. Also put the LCD wires through that hole and have the LCD screen on the front of the wood. Cut 2 12×2 in pieces and 4 6×2 in pieces and 2 5.75×2 in pieces. Lining the 6×12 in pieces with the corner of the back of the 48×6 in piece where the 6 in part is along the edge of the 48 in part, hot glue the piece down to create a 2 in wall. This wall will hold the 48×6 in wood away from the wall allowing the RIO, arduino and breadboard to be behind it without people see it, and without it resting on those pieces of hardware. Next to the 6×2 in piece, hot glue the 12×2 in piece (again lined up with the edge of the 6×48 piece). This creates more stability where the 2 6×24 in pieces meet. Then glue another 6×2 in piece next to that to create an entire side. Do this again on the other side. Now, the 5.75×2 in pieces should fit snuggly between those two side walls at the top and bottom. Glue those in. Add reinforcement where needed. Now you should have an open top box. Feel free to tape the RIO, arduino and breadboard inside the box.
Flip the box back over so that you are looking at the front. Tape down the LED strip where you want it (double sided tape works well).
Make a open box (5 faces missing the second 6×6 face)) whose outside dimensions are 6x6x1 in. This will hold the LDC screen. Cut a 3×1 in hole out from the middle of the 6×6 face. The LCD should fit right in. You may need to solder the back of the LCD screen and cut the prongs on the front to make it fit snuggly. Now glue that box to the front of the 48×6 in piece of wood, under the LED strip. Try to cover the hole you made for the wires to go through with the box.
Add screw eyes to the top, so that you can put string between the screw eyes and hang it from the wall. See pictures.

 

 

 

 

 

 

 

Pointless Button

The purpose of this project is to chart how often in an hour a button is pressed if it is left in a room without instructions. The inspiration for this project was someone wondering if a button was labeled Pointless Button and left it with a group of people, how often would it be pressed? Well, what better thing to do than hook it up to a myRIO and chart the data on a graph gadget in ThingWorx.

Tools and Materials:

  • Button
  • myRIO
  • LabVIEW
  • ThingWorx Account
  • IoT Toolkit
  • Jumper Cables
  • Alligator Clips
  • Resistor
  • Breadboard

Step One:

In order to have access to ThingWorx, you need to sign up for an account.  You just need the account because your username acts as a directory for your Things.


Step Two:

At this point, we should take the time to wire the button to the myRIO. Take two jumper wires and put each in a different side channel and plug one into Pin A-33 (+3.3V) and the other into Pin A-12 (GND). Next place the resistor with one wire connected to ground.  Make sure that there are at least two pins next to the other node of the resistor.  Then take a jumper wire and put it next to the non-ground node of the resistor.  Plug the other end of this wire into Pin A-11 (Digital Input).  Then using alligator clips and jumper cables connect one lead of the button to the same node as the resistor and the other to a different node, which you will connect with an m-m jumper cable to the side channel hooked up to Pin A-33.  It is important to make sure that the button is wired such that it completes a short only when the button is pressed.

Step Three:

Next, you make sure you have installed the NI IoT Toolkit and then open LabVIEW and start a myRIO project.  Make sure that you select the myRIO if you have it plugged into your computer, or write in the myRIO’s IP address, should you choose to connect via WiFi.  Then create a VI.  There are two processes that work together in this VI.  The first process is creating a loop that will count the number of clicks in a certain period of time starting from zero.  A click is registered as an output of TRUE from Digital Input A-11.  When the loop restarts, it will output the total count for that period, reset to zero and start all over again.  The second process writes to ThingWorx.  All of the necessary SubVIs can be found under the IoT toolkit in the Functions Palette.  A new Thing is created with a chart gadget assigned to it and the value output by the counting loop is input to the Write to Thing.vi, which will set it to accepting floats.  It is important that the counting loop and the Write to Thing.vi are inside of a while loop so that values are continually read and written to ThingWorx.  Also, make sure that the property name is the same for the gadget.vi and the Write to Thing.vi.  See the screen capture of the final result below for reference.

Step Four:

Now it’s time to run the program.  Make sure that all of the files are saved and run the VI with the target being Main Application Instance. It will prompt you to log into ThingWorx and it will send you to the dashboard. You will see the graph gadget under the title that you gave it.

Be sure to save the URL. Now stop the program and change the target of the VI to be the myRIO and run it again. You can now leave the myRIO running and it will continually update the count on the dashboard.

Office Admin Desk Display

The purpose of this project is to make a box that displays how long someone will be away from their desk or office that they control via ThingWorx.  The inspiration for this project was an office administrator desiring a way to display remotely how long that they will be away from their desk or office or display a custom message.   The way that this project will work is that the user will be able to select a preset message or type in a custom message in a custom ThingWorx gadget from a computer and hopefully from a mobile device soon.  A myRIO will be running a VI that is constantly checking that gadget, processing the property value, and then appropriately displaying it with LEDs and an LCD screen.  In addition there will be two buttons on the box, one of which will allow the user to display a message along the lines of “I will return shortly” if they are away for a short enough time that it isn’t worth going through ThingWorx, while the other one will clear any message displayed so as to not distract the person while they are at their desk.

Tools and Materials:

  • myRIO
  • LabVIEW
  • ThingWorx Account
  • IoT Toolkit
  • 2 Buttons
  • Jumper Cables
  • Alligator Clips
  • Resistors
  • LEDs
  • Breadboard

Step One:

In order to have access to ThingWorx, you need to sign up for an account.  Your username acts as a directory for your Things.  For this project you will need to make a custom gadget that consists of two widgets, a radio button and a text box.  The custom gadget should be programmed such that there is only one property, whose value is assigned as the value of the text box.  Then the output value of the radio button should input into the text box.  The selectable messages on the radio button are set as custom button states.

Step Two:

At this point, we should take the time to wire the buttons, LEDs, and LCD Display to the myRIO.  Take two jumper wires and put each in a different side channel and plug one into Pin A-33 (+3.3V) and the other into Pin A-12 (GND). Next place the resistor with one wire connected to ground.  Make sure that there are at least two pins next to the other node of the resistor.  Then take a jumper wire and put it next to the non-ground node of the resistor.  Plug the other end of this wire into a digital input pin.  Then using alligator clips and jumper cables connect one lead of the button to the same node as the resistor and the other to a different node, which you will connect with an m-m jumper cable to the side channel hooked up to Pin A-33. It is important to make sure that the button is wired such that it completes a short only when the button is pressed.  Next, do the same for the other button.

Next, you need to wire the LEDs.  The LED should be wired such that the anode (the short side) is wired to ground.  Then wire one end of the resistor to the same node as the cathode of the LED with the other end connected to a different node of the breadboard.  Then to that different node, connect an m-f wire, with the other end connected to a digital output.  Do this again with the other LED.  Make sure that the LEDs are different colors.

Finally, you need to wire the LCD display.  This project could use either SPI or I2C protocol, however this project was designed using SPI.  Both require that certain pins are wired or soldered together and that certain pins are wired to the myRIO in a specific way.  The following picture can be used as reference.

Step Three:

Next, you make sure you have installed the NI IoT Toolkit and then open LabVIEW and start a myRIO project.  Make sure that you select the myRIO if you have it plugged into your computer, or write in the myRIO’s IP address, should you choose to connect via WiFi.  Then create a VI.  There are several processes that work together in this VI.  The overarching process is reading and writing to ThingWorx.  All of the necessary SubVIs can be found under the IoT toolkit in the Functions Palette.  A new Thing is created and needs to be configured to the custom gadget that was created in the first step.  You need to connect a Write to Thing.vi, a Read from Thing.vi, and an End Thing.vi.   Make sure that the property and gadget names are the same when appropriate.  It is important that the Read from Thing.vi and the Write to Thing.vi are inside of a while loop, so that values are continually read and/or written to ThingWorx.

The next process deals with the two buttons.  First find the Digital Input express VIs in the myRIO section of the Functions Palette and assign the appropriate pins.  To have access to the myRIO section, change the target of the VI to the myRIO.  Then the inputs actually need to be processed, which can be accomplished with a case statement with another nested inside.  The outer one should process the ‘clear’ button and should output an empty string constant to the Write to Thing.vi if TRUE.  The inner one should process the quick ‘I will be right back’ message, and should output some message if TRUE.  Otherwise nothing is output.

The third process deals with the processing the values output by the Read from Thing.vi, which either come from the buttons or from toggling the custom gadget within ThingWorx.  This operates on a case statement relying on string inputs rather than Boolean inputs like in the button process described in the previous paragraph.   The case statement needs to be ‘programmed’ so that if any of the preset messages are read from ThingWorx, then the message is displayed on the LCD Display and one of the LEDs are lit up.  For the LCD Display, as mentioned previously, use the SPI signal augmentation like the one found in the LCD Display Demo.  For the LED, you will need a Digital Output express VI that can be found in the same drop-down of the functions palette as the Digital Input express VI.  The other two cases should check for the responses from the two physical buttons.  These responses are the strings output by the button processing case statements described from the previous paragraph.  The response to the ‘I will be right back’ message should be to display the message on the LCD Display and turn on the other LED via another Digital Output express VI.  

After that, make sure to clear the LCD Display and the LEDs.  This should be done outside of the while loop with the error outputs and inputs of the express VIs connected (from any express VI within the while loop through all of the ones outside of the loop.  See the screen capture of the final result below for reference.

Step Four:

Now it’s time to run the program.  Make sure that the target of the VI is the myRIO and that you have the mash-up of the gadget open.  You should see the custom gadget in a tab on its own.  Be sure to save the URL.  You can now leave the myRIO running and your selection in the custom gadget and/or pressing of the buttons should be expressed on the LCD Display and the LEDs.

Skype Button

This project aimed to make two offices in two different buildings have the same convenient communication accessibilities as those next to each other. In particular, we developed this prototype to connect an advisor to his lab across a University campus. We have a photoresistor detect if light is over a certain threshold according to the ambience in the office, and if the lights are on, suggesting that he is in his office, the lab will have a display to read this information and can choose to send an alert, asking the advisor to Skype call the lab so students can ask a quick (or not so quick) question.

Code

Location A (lab)

Location B (advisor’s office)


Step 1: Connecting to Thingworx

We have two Things connecting to each other in this project through Thingworx. To get started, create two Things, one for Location A and one for Location B. We did this on LabVIEW through the Education IoT toolkit. Here, we have set up Button_Trial, and Lights on two different myRIO’s. Button_Trial also has a property, Switch. We use this property to read a button value when it is pressed on Location A’s hardware. Since the button switches from true to false quickly (pressing down switches to true, releasing makes the value false again), we made a subvi to make it act like a switch.

With this addition, when a value changes on a button from Location A, Location B will receive the alert until it is acted on, instead of being alerted once momentarily.

Step 2: Hardware 

  

Location A: This is where we placed the lab A’s device that has an LED attached to show if the professor is in his office or not (on for in, off for out), a button to request an alert, and an LCD screen display to show some feedback information. We connected this button, and screen display appropriately, and made the lights connect to the photoresistor information on Location B’s device.

Location B: This device is located in the advisor’s office. It has a photoresistor as a light sensor, two buttons for ignore and accept Skype request, an LCD display, and a buzzer and LED light to display the alert from Location A.

Skype call:

When Location B accepts the alert, the boolean value is sent to Thingworx, which then runs a vi on Location B’s computer to send a Skype call to Location A through B’s command line. Skype will prompt the advisor to make sure he wants to send the Skype call before it is sent out. The command line input pay vary according to your file location and Skype username you wish to call.

 

Introduction to the LabVIEW IoT Education Kit

Overview

This software package helps users read and write to the cloud using LabVIEW and ThingWorx to view connected devices called Things. First, create an account on the ThingWorx academic edition site with the access code ptcni2017.  Run the Getting Started VI.

Blink example

The first example in the Getting Started VI makes an LED blink in LabVIEW and on your ThingWorx dashboard. This VI blinks an LED on the front panel and reads and writes a boolean to the cloud. Drag this code snippet to a blank front panel and run this code.

This VI blinks an LED on the dashboard every 2 seconds.

This VI gets a boolean property from the cloud called Blink.  In the example, it sets the LED on the front panel to true or false.  All of the get property VIs have a glasses icon.

 

This VI sets a boolean property from the cloud called Blink.  In the example, it reads in a boolean value from LabVIEW true if the iteration number is even.  All of the set property VIs have a pencil icon.

 

This is a ThingWorx dashboard, which shoes a group of gadgets.  The dashboard is named Thingname_username at the URL displayed in Getting Started.  By default, when the VI is run on the computer in LabVIEW, the dashboard is called “ScratchPad”.  In this example, the username is “user”. This example shows a boolean gadget called Blink.

There are a variety of Thing properties we can interact with:

  • boolean
  • text
  • gauge
  • float
  • integer
  • timestamp

For each of these properties, you can read (get property VI) or write (set property VI) to the cloud.

Gadgets and Dashboards

This example sets up two gadgets, one float (Random) and one gauge (Integer), on a dashboard for Thing named Jack. The Start Thing VI opens a connection to Thingworx.  It passes a Thing (green wire) into the while loop and writes a private integer (that no other user can see) and a public float.  The private set property VIs are shaded gray. The URL for the dashboard is displayed on the front panel. When the stop button is pressed on the front panel, the Delete Thing VI is executed and the gadgets are deleted from the dashboard.

Note: Hitting the abort button on LabVIEW will not execute the Delete Thing VI.

Gauge and float example

This is the dashboard for the float and gauge example.

Examples