Project showcase
Streaming Data to Power BI from a Spin Bike

Streaming Data to Power BI from a Spin Bike © GPL3+

Stream your spin bike RPM data to Power BI for real time reporting and dashboarding.

  • 1,246 views
  • 2 comments
  • 6 respects

Components and supplies

Necessary tools and machines

Hy gluegun
Hot glue gun (generic)
09507 01
Soldering iron (generic)

Apps and online services

About this project

Project

This project was to educate people on the difference between static and streaming data. To do this we built the simple Arduino project with a reed switch to read the data. From there, we exported the data over the serial port where node.js listened to it and called a PowerShell script to post the data to a Power BI streaming data set. This allowed for a nice dashboard to be built on top of the data that we were collecting, with minimal coding.

Code

Arduino CodeArduino
This reads the reed switch data and posts it to the serial port
//Modified code from https://www.sparkfun.com/products/8642
const int REED_PIN = 2; // Pin connected to reed switch
void setup() 
{
  Serial.begin(9600);
  // Since the other end of the reed switch is connected to ground, we need
  // to pull-up the reed switch pin internally.
  pinMode(REED_PIN, INPUT_PULLUP);
}

void loop() 
{
  int proximity = digitalRead(REED_PIN); // Read the state of the switch
  if (proximity == LOW) // If the pin reads low, the switch is closed.
  {
    //Serial.println("Trigger");
    Serial.write(1);
  }
  else
  {
   //Serial.println("Opened");
   Serial.write(0);
  }
}
node.js codeJavaScript
This allows the the arduino's serial data to be read by the windows machine. From there a PowerShell script is called to post the data to Power BI. See code comments for details
var rpm = 0;
var secondsBetweenPosts = 1;
var state = 0;

var postRPM = function() {
    rpm = rpm *15; //Second in the minute 15 instead of 60 seems to be the trick
    console.log("Current RPM reading is: " + rpm);
    if(rpm > 0){
        var spawn = require("child_process").spawn,child;
        child = spawn("powershell.exe", ["-file","powerBI.ps1","-DATA",rpm]);
        child.stdin.end();
    }
    rpm = 0;
};

// How often to post to your cloud
setInterval(postRPM, secondsBetweenPosts * 1000);

var randomRPM = function() {
    rpm = rpm + Math.floor(Math.random() * 3) + 1;
};

// Autopilot for when testing is needed
// setInterval(randomRPM, 500);

// call every time that we need to add to the RPM count
var writeRPM = function() {
    rpm++;
};

// Lis the avaible ports
var SerialPort = require('serialport');
SerialPort.list(function(err, ports) {
    console.log('');
    console.log('The following ports are avaiable on this machine');
    console.log('------------------------------------------------');
    ports.forEach(function(port) {
        console.log(port.comName);
        console.log(port.pnpId);
        console.log(port.manufacturer);
    });
});

// The arduino is on COM6 for this computer your's may be different
var port = new SerialPort('COM6');

// open errors will be emitted as an error event 
port.on('error', function(err) {
    console.log('Error: ', err.message);
});

port.on('open', function() {
    console.log('Serial Port Opend - waiting for data...');
    port.on('data', function(data) {
        var valueTxt = data[0];
        if (valueTxt !== state) {
            if (valueTxt === 1) {
                writeRPM();
            }
            state = valueTxt; // reset state for new data
        }
    });
});
PowerShell codePowershell
This post the data to a Power BI streaming data set. You could probably do this in node.js, but this was quicker for our use case
param(
 [int]$DATA = ""
)
# Where should this data go?
$endpoint = "https://api.powerbi.com/beta/yourLinkHere"

# Initialise the Payload
$payload = @{}
$payload.Time = Get-Date -format s
$payload.Number = $DATA

# Send the event
Invoke-RestMethod -Method Post -Uri "$endpoint" -Body (ConvertTo-Json @($payload))

Schematics

Wiring
Hook up From:
https://learn.sparkfun.com/tutorials/reed-switch-hookup-guide
Example circuit bb 2 u0uyy4we9l

Comments

Team members

Danshrader
danshrader
  • 1 project
  • 1 follower
Default
santoshkanthety
  • 1 project
  • 0 followers

Additional contributors

  • Base code for the serial port by Spark Fun
  • Node package and documentation for listening to the serial port by serialport
  • Powershell base code for posting to powerbi by Power BI

Published on

May 26, 2017

Members who respect this project

PhotoDe69a62a2b35333cd5fa834c6f202b80 qq25e5259b25be25e72589258720160323205203 uugfypsuzu

and 4 others

See similar projects
you might like

Similar projects you might like

Programmable Pocket Power Supply with OLED Display

Project tutorial by Shahariar

  • 6,523 views
  • 6 comments
  • 32 respects

Arduino Environmental Monitoring

Project showcase by Prajay Basu

  • 13,766 views
  • 1 comment
  • 25 respects

Blaster with AWS Alexa Voice Control & IR Firing Power

Project tutorial by Tom

  • 3,539 views
  • 1 comment
  • 26 respects

Export Data from Arduino to Excel Sheet

Project showcase by ahmed ismail

  • 14,681 views
  • 1 comment
  • 7 respects

Bike Route Data Gatherer

Project tutorial by Paul Trebilcox-Ruiz

  • 9,200 views
  • 0 comments
  • 36 respects

Fingerscan: Music at Your Fingertips

Project showcase by touchmysound

  • 8,551 views
  • 6 comments
  • 27 respects
Add projectSign up / Login