0

Weekend Build: An Arduino based vROps NOC


Parts List:

LattePanda Windows 10 single board computer with integrated Arduino

http://www.lattepanda.com/

SainSmart I2C LCD2004 Serial LCD Display

https://www.sainsmart.com/sainsmart-iic-i2c-twi-serial-2004-20×4-lcd-module-shield-for-arduino-uno-mega-r3.html

Wire Jumpers

https://www.amazon.com/gp/product/B01EV70C78/ref=oh_aui_detailpage_o06_s00?ie=UTF8&psc=1

Power Supply

https://www.amazon.com/gp/product/B00MARDJZ4/ref=oh_aui_detailpage_o07_s01?ie=UTF8&psc=1

LattePanda Stand 3D Files


Hardware Connections:

Pinout-Development-Support

LCD Connection U2 Pin Number
GND 23
VCC 24
SDA 6
SCL 8

Software:

F Malpartida’s NewLiquidCrystal library

https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/Home

Arduino sketch to find the LCD’s I2C address

https://arduino-info.wikispaces.com/LCD-Blue-I2C

Arduino Sketch


//vROps Arduino Dashboard
//2017 Matt Bradford @VMSpot

#include <LiquidCrystal_I2C.h>

//Configure the I2C chip for the LCD display
#define I2C_ADDR 0x27 //I2C address of PCF8574A
#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7
LiquidCrystal_I2C
lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
String stringRead; //String used to store incoming Serial message
String ln1;
String ln2;
String ln3;
String ln4;
String ln5;
String ln6;
String ln7;
String ln8;
int x=1;

void setup() {
//Turn the Serial Protocol ON
Serial.begin(9600);

lcd.begin (20,4); //SainSmart LCD2004 is a 20x4 display

//LCD Backlight ON
lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
lcd.setBacklight(HIGH);

lcd.home (); //Go to LCD home
lcd.clear(); //Clear LCD text
}

void loop() {
if (Serial.available()) { //Check to see if data has been sent from the PC
stringRead = Serial.readString(); //Read the incoming serial string
stringRead.remove(stringRead.length()-1 ,1); //Remove the Serial StopBit
}

//Parse out the line numbers from the serial message and assign them to their respective lines

if (stringRead.substring(0,2) == "01"){
stringRead.remove(0,3);
ln1 = stringRead;
stringRead= "";
}
if (stringRead.substring(0,2) == "02"){
stringRead.remove(0,3);
ln2 = stringRead;
stringRead= "";
}

if (stringRead.substring(0,2) == "03"){
stringRead.remove(0,3);
ln3 = stringRead;
stringRead= "";
}

if (stringRead.substring(0,2) == "04"){
stringRead.remove(0,3);
ln4 = stringRead;
stringRead= "";
}

if (stringRead.substring(0,2) == "05"){
stringRead.remove(0,3);
ln5 = stringRead;
stringRead= "";
}

if (stringRead.substring(0,2) == "06"){
stringRead.remove(0,3);
ln6 = stringRead;
stringRead= "";
}

if (stringRead.substring(0,2) == "07"){
stringRead.remove(0,3);
ln7 = stringRead;
stringRead= "";
}

if (stringRead.substring(0,2) == "08"){
stringRead.remove(0,3);
ln8 = stringRead;
stringRead= "";
}

//Print the lines to the LCD and rotate pages

if (x == 1)
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print(ln1);
lcd.setCursor(0,1);
lcd.print(ln2);
lcd.setCursor(0,2);
lcd.print(ln3);
lcd.setCursor(0,3);
lcd.print(ln4);
}

if ( x == 30000)
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print(ln5);
lcd.setCursor(0,1);
lcd.print(ln6);
lcd.setCursor(0,2);
lcd.print(ln7);
lcd.setCursor(0,3);
lcd.print(ln8);
}

if (x == 35000)
{
x=0;
}

x=++x;
}

 

Powershell Script


#Enter your vCenter and vROps hosts here
$vrops = "vrops.vmspot.lan"
$vcenter = "vc1.vmspot.lan"

#Enter the resources you want to collect information on here
$resource1 = "esxi1.vmspot.lan"
$resource2 = "esxi2.vmspot.lan"
$resource3 = "SYN-DS01"

#Connect to vCenter and vROps instances
Write-Host "Enter your vROps Credentials"
Connect-OMServer $vrops
Write-Host "Enter your vCenter Credentials"
Connect-VIServer $vcenter

#Define the serial settings to communicate with Arduino
$port= new-Object System.IO.Ports.SerialPort COM5,9600,None,8

#Collect information for the resources defined above
function collect {
$ln01= get-omstat -resource $resource1 -key 'cpu|workload' | select -expandproperty Value -last 1
#$ln01 = [math]::Round($ln01)
$global:ln01 = "ESXi1 CPU Load: $ln01%"
$ln02 = get-omstat -resource $resource1 -key 'mem|workload' | select -expandproperty Value -last 1
$global:ln02 = "ESXi1 MEM Load: $ln02%"
$ln03= get-omstat -resource $resource2 -key 'cpu|workload' | select -expandproperty Value -last 1
#$ln03= [math]::Round($ln03)
$global:ln03 = "ESXi2 CPU Load: $ln03%"
$ln04 = get-omstat -resource $resource2 -key 'mem|workload' | select -expandproperty Value -last 1
$global:ln04 = "ESXi2 MEM Load: $ln04%"
$ln05 = get-omstat -resource $resource1 -key "badge|capacityRemaining" | select -ExpandProperty Value -last 1
$ln05 = [math]::Round($ln05)
$global:ln05 = "ESXi1 Remain: $ln05"
$ln06 = get-omstat -resource $resource2 -key "badge|capacityRemaining" | select -ExpandProperty Value -last 1
$ln06 = [math]::Round($ln06)
$global:ln06 = "ESXi2 Remain: $ln06"
$ln07 = get-vm | ?{$_.PowerState -eq "PoweredOn"} | measure | select -expandproperty Count
$global:ln07 = "Powered On VMs: $ln07"
$global:ln08 = Get-OMStat -resource $resource3 -from ([DateTime]::Now).AddMinutes(-5) -key "capacity|available_space" | select -expandproperty Value -last 1
$ln08= [math]::Round($ln08)
$global:ln08 = $resource3+" "+$ln08 +"GB Free"
}

#Send collected data to the Arduino
function send {
$port.open()
Write-Host"Port Open"
$port.WriteLine("01 $ln01")
Write-Host"01 $ln01"
start-sleep2
$port.WriteLine("02 $ln02")
Write-Host"02 $ln02"
start-sleep2
$port.WriteLine("03 $ln03")
Write-Host"03 $ln03"
start-sleep2
$port.WriteLine("04 $ln04")
Write-Host"04 $ln04"
start-sleep2
$port.WriteLine("05 $ln05")
Write-Host"05 $ln05"
start-sleep2
$port.WriteLine("06 $ln06")
Write-Host"06 $ln06"
start-sleep2
$port.WriteLine("07 $ln07")
Write-Host"07 $ln07"
start-sleep2
$port.WriteLine("08 $ln08")
Write-Host"08 $ln08"
$port.Close()
Write-Host"Port Closed"
}

cls
while ($true){
Write-Host "Collecting Data"
collect
send

#Wait five minutes before performing another collection
start-sleep 300
}

Matt Bradford

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.