Upload files to "uno-stats-monitor"
Initial version
This commit is contained in:
30
uno-stats-monitor/monitor_sender.sh
Normal file
30
uno-stats-monitor/monitor_sender.sh
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# UNO Monitor Sender
|
||||||
|
# kidacro@archamedis.net
|
||||||
|
#
|
||||||
|
|
||||||
|
# TTY Device to use
|
||||||
|
TTY="/dev/ttyACM0"
|
||||||
|
##########################################################
|
||||||
|
|
||||||
|
# Stats
|
||||||
|
# we are limited to 2 lines and 16 chars per line so, light stats & no labels
|
||||||
|
CLOAD=$(mpstat | awk '$3 ~ /CPU/ { for(i=1;i<=NF;i++) { if ($i ~ /%idle/) field=i } } $3 ~ /all/ { printf("%d%%",100 - $field) }')
|
||||||
|
CTEMP=$(sensors | grep TSI0_TEMP: | tr '°+' ' ' | awk '{print $2}' | paste -sd ', ')
|
||||||
|
MFREE=$(free -h | grep Mem | awk '{print $4}' | paste -sd ', ')
|
||||||
|
RFREE=$(df -h | grep /dev/nvme0n1p3 | awk '{print $4}' | paste -sd ', ')
|
||||||
|
LFREE=$(df -h | grep /dev/sda1 | awk '{print $4}' | paste -sd ', ')
|
||||||
|
SFREE=$(df -h | grep /dev/mapper/store0-lvol1 | awk '{print $4}' | paste -sd ', ')
|
||||||
|
|
||||||
|
# setup device
|
||||||
|
stty -F $TTY ispeed 9600 ospeed 9600 -ignpar cs8 -cstopb -echo -hupcl
|
||||||
|
|
||||||
|
# Line 1
|
||||||
|
LINE1="#1$CLOAD $CTEMP $MFREE@"
|
||||||
|
/usr/bin/echo "$LINE1" > $TTY # -ne
|
||||||
|
echo Sending to $TTY: $LINE1
|
||||||
|
|
||||||
|
# line 2
|
||||||
|
LINE2="#2$RFREE $LFREE $SFREE@"
|
||||||
|
/usr/bin/echo "$LINE2" > $TTY
|
||||||
|
echo Sending to $TTY: $LINE2
|
||||||
214
uno-stats-monitor/monitor_uno.ino
Normal file
214
uno-stats-monitor/monitor_uno.ino
Normal file
@@ -0,0 +1,214 @@
|
|||||||
|
/*
|
||||||
|
* UNO Monitor Receiver (4bit LCD Version)
|
||||||
|
* kidacro@archamedis.net
|
||||||
|
*
|
||||||
|
* Waits for input over serial connection and displays on LCD
|
||||||
|
*
|
||||||
|
* Input Schema:
|
||||||
|
* Start char is: '#'
|
||||||
|
* End char is: '@'
|
||||||
|
* 2nd char denotes which line number to use
|
||||||
|
*
|
||||||
|
* Example:
|
||||||
|
* Line 1: #1Archamedis Status@
|
||||||
|
* Line 2: #299% free / etc.@
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
// include the library code:
|
||||||
|
#include <LiquidCrystal.h>
|
||||||
|
|
||||||
|
// LCD Pinout:
|
||||||
|
// LCD RS pin to digital pin 12
|
||||||
|
// LCD Enable pin to digital pin 11
|
||||||
|
// LCD D4 pin to digital pin 5
|
||||||
|
// LCD D5 pin to digital pin 4
|
||||||
|
// LCD D6 pin to digital pin 3
|
||||||
|
// LCD D7 pin to digital pin 2
|
||||||
|
// LCD R/W pin to ground
|
||||||
|
// LCD VSS pin to ground
|
||||||
|
// LCD VCC pin to 5V
|
||||||
|
// 10K resistor:
|
||||||
|
// ends to +5V and ground
|
||||||
|
// wiper to LCD VO pin (pin 3)
|
||||||
|
|
||||||
|
// Variable Init
|
||||||
|
// LCD vars
|
||||||
|
// initialize the library by associating any needed LCD interface pin
|
||||||
|
// with the arduino pin number it is connected to
|
||||||
|
const int LCDRS = 12, LCDEN = 11, LCDD4 = 5, LCDD5 = 4, LCDD6 = 3, LCDD7 = 2;
|
||||||
|
int LCDLength = 16;
|
||||||
|
LiquidCrystal LCD(LCDRS, LCDEN, LCDD4, LCDD5, LCDD6, LCDD7);
|
||||||
|
|
||||||
|
// Serial vars
|
||||||
|
const byte numChars = 32;
|
||||||
|
char receivedChars[numChars]; // an array to store the received data
|
||||||
|
boolean newData = false;
|
||||||
|
|
||||||
|
// Debugging (serial console must be connected)
|
||||||
|
bool DEBUG = 1;
|
||||||
|
|
||||||
|
void LcdSetup(void) {
|
||||||
|
// set up the LCD's number of columns and rows:
|
||||||
|
LCD.begin(LCDLength, 2);
|
||||||
|
|
||||||
|
// Print a "waiting" message to the LCD.
|
||||||
|
LcdL1();
|
||||||
|
LCD.print("Starting Up...");
|
||||||
|
LcdL2();
|
||||||
|
LCD.print("Waiting for data");
|
||||||
|
}
|
||||||
|
|
||||||
|
void LcdCls(void) {
|
||||||
|
delay(10);
|
||||||
|
LCD.clear(); // The screen is empty
|
||||||
|
LcdL1(); // the cursor position is zeroed
|
||||||
|
delay(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LcdL1() {
|
||||||
|
delay(10);
|
||||||
|
LCD.setCursor(0, 0); // Define the cursor position as the 1st position of the 1st line
|
||||||
|
delay(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LcdL2() {
|
||||||
|
delay(10);
|
||||||
|
LCD.setCursor(0, 1); // Define the cursor position as the 1st position of the 2nd line
|
||||||
|
delay(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
// returns starting position of text
|
||||||
|
void LcdCenter(int mylen) {
|
||||||
|
int mypos = 0;
|
||||||
|
|
||||||
|
return mypos;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LcdWrite(String mymessage) {
|
||||||
|
int i = 0;
|
||||||
|
unsigned int mylen = mymessage.length();
|
||||||
|
|
||||||
|
// trunicate string to lcd line length
|
||||||
|
if(mylen > LCDLength) {
|
||||||
|
mylen = LCDLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Debug input and length
|
||||||
|
if(DEBUG) {
|
||||||
|
Serial.println("\n\nString: ");
|
||||||
|
Serial.println(mymessage);
|
||||||
|
Serial.println(mymessage.length());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Output string
|
||||||
|
//LCD.print(mymessage);
|
||||||
|
|
||||||
|
// Output character by character
|
||||||
|
for(i=0; i < mylen; i++) {
|
||||||
|
char c = mymessage[i];
|
||||||
|
if(c != '\b') {
|
||||||
|
delay(10);
|
||||||
|
LCD.print(c);
|
||||||
|
delay(10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void LcdWriteExample() {
|
||||||
|
LcdCls();
|
||||||
|
|
||||||
|
LcdL1();
|
||||||
|
LcdWrite("Archamedis Stats");
|
||||||
|
|
||||||
|
LcdL2();
|
||||||
|
LcdWrite("4.3ghz 89% 68C");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void recvWithStartEndMarkers() {
|
||||||
|
static boolean recvInProgress = false;
|
||||||
|
static byte ndx = 0;
|
||||||
|
char startMarker = '#';
|
||||||
|
char endMarker = '@';
|
||||||
|
char rc;
|
||||||
|
|
||||||
|
while (Serial.available() > 0 && newData == false) {
|
||||||
|
rc = Serial.read();
|
||||||
|
|
||||||
|
if(recvInProgress == true) {
|
||||||
|
if(rc != endMarker) {
|
||||||
|
receivedChars[ndx] = rc;
|
||||||
|
ndx++;
|
||||||
|
if (ndx >= numChars) {
|
||||||
|
ndx = numChars - 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
receivedChars[ndx] = '\0'; // terminate the string
|
||||||
|
recvInProgress = false;
|
||||||
|
ndx = 0;
|
||||||
|
newData = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else if(rc == startMarker) {
|
||||||
|
recvInProgress = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void showNewData() {
|
||||||
|
if(newData == true) {
|
||||||
|
if(DEBUG) {
|
||||||
|
Serial.print("This just in ... ");
|
||||||
|
Serial.println(receivedChars);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print on line 1 or 2
|
||||||
|
// dev: fucking c and its fixed arrays
|
||||||
|
// we have to define 1st character (line number) as BS and when printing, search for that BS character to skip printing that 1 character, grrr
|
||||||
|
if(receivedChars[0] == '1') {
|
||||||
|
LcdL1();
|
||||||
|
LcdWrite(" "); // 16 spaces for a blank line
|
||||||
|
LcdL1();
|
||||||
|
receivedChars[0] = '\b';
|
||||||
|
LcdWrite(receivedChars);
|
||||||
|
}
|
||||||
|
else if(receivedChars[0] == '2') {
|
||||||
|
LcdL2();
|
||||||
|
LcdWrite(" "); // 16 spaces for a blank line
|
||||||
|
LcdL2();
|
||||||
|
receivedChars[0] = '\b';
|
||||||
|
LcdWrite(receivedChars);
|
||||||
|
}
|
||||||
|
|
||||||
|
newData = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void setup (void) {
|
||||||
|
// Init LCD panel
|
||||||
|
LcdSetup();
|
||||||
|
|
||||||
|
// Init Debugging output
|
||||||
|
if(DEBUG) {
|
||||||
|
Serial.begin(9600);
|
||||||
|
while (!Serial) {
|
||||||
|
; // wait for serial port to connect. Needed for native USB port only
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Init normal operation
|
||||||
|
else {
|
||||||
|
Serial.begin(9600);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// main()
|
||||||
|
void loop (void) {
|
||||||
|
// process input
|
||||||
|
recvWithStartEndMarkers();
|
||||||
|
showNewData();
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user