Simple: how do I use regex in Arduino?
Complicated:
I am having a problem with a simple program that I wrote to monitor the status of my computer (mac), and send it to the arduino through serial usb, and have it displayed though led's. The code on the mac side is fairly straight forwards and passes a letter (depending on the status item) followed by the binary status.
#!/bin/bash
#This script sends an agnlegement signal along with net, power, email, and temp data to the arduino
#power variable is $powerStat
#net variable is $netStat
#speed variable is $speedStat
#email variable is $emailStat
#temp variable is $tempStat
#power test
isFullyCharged=`ioreg -n AppleSmartBattery | grep FullyCharged | awk '{ print $5 }'`
isCharging=`ioreg -n AppleSmartBattery | grep IsCharging | awk '{ print $5 }'`
timeLeft=`ioreg -n AppleSmartBattery | grep TimeRemaining | awk '{ print $5 }'`
if [ $isFullyCharged = "Yes" ] ; then
powerStat=1
elif [ $isCharging = "Yes" ]; then
powerStat=1
else
powerStat=0
fi
#
#network test
networkTest=`ping -c 4 8.8.4.4 | grep -o "0.0"`
if [ $networkTest = "0.0" ] ; then
netStat=1
else
netStat=0
fi
#
#speed test
load=`uptime | grep -o ": ...." | grep -o "[0-9].[0-9][0-9]"`
cpuStat=`echo $load*100 | bc | grep -o "[0-9][0-9][0-9]"`
if [ "$cpuStat" -lt "400" ] ; then
speedStat=1
else
speedStat=1
fi
#
#email test
gmail=`gmail | grep -o "[0-9]"`
if [ "$gmail" -gt "0" ] ; then
emailStat=1
else
emailStat=0
fi
#
#temp test
temp=`temp | grep -o "[0-9][0-9]"`
if [ "$temp" -lt "85" ] ; then
tempStat=1
else
tempStat=0
fi
#
echo 'P'$powerStat'N'$netStat'L'$speedStat'E'$emailStat'T'$tempStat
The code on the arduino side is extremely basic as I am a beginner Arduino coder, and need help with the program.
int incomingByte = 0; // for incoming serial data
String readString;
int cont = 1;
void setup() {
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
}
void loop() {
while (Serial.available() && cont>0) {
delay(100);
if (Serial.available() >0) {
char c = Serial.read(); //gets one byte from serial buffer
readString += c; //makes the string readString
}
if (readString == '"P"[0-1]"N"[0-1]"L"[0-1]"E"[0-1]"T"[0-1]'){
Serial.println("happy arduino");
delay(100);
cont = 0;
break;
}
else if (readString == '"P"[0-9]'){
Serial.println("meh");
delay(100);
cont = 0;
notify("E", 1);
break;
}
else{
Serial.println("bad nick");
delay(100);
cont = 0;
notify("E", 1);
break;
}
}
Serial.flush();
readString = "";
cont = 1;
delay(100);
}
int notify(String a, int b){
String input;
}
Please try to give suggestions without being a scathingly mean trollgrammer. Please help...