I added this to the main sketch in the loop to see if see if that would work any differently:
if ((!connection) && (!attempted)){
comms.isAnyone();
attempted = true;
Serial.println("attempted to connect");
}
Here is comms:
#include "Arduino.h"
#include "Comms.h"
void Comms::piInit(){
static char input_line [MAX_INPUT];
static unsigned int input_pos = 0;
if (Serial1.available () > 0)
{
char inByte = Serial1.read ();
switch (inByte)
{
case '\n': // end of text
input_line [input_pos] = 0; // terminating null byte
// terminator reached! process input_line here ...
process_data (input_line);
// reset buffer for next time
input_pos = 0;
break;
case '\r': // discard carriage return
break;
default:
// keep adding if not full ... allow for terminating null byte
if (input_pos < (MAX_INPUT - 1))
input_line [input_pos++] = inByte;
break;
} // end of switch
} // end of incoming data
}
void Comms::process_data (char * data)
{
byte index = 0;
// for now just display it
Serial.println("here comes what was read: ");
Serial.println(data);
int i;
for (i = 0; i < strlen(data); i++){
//Looks for the ^ Char
if(data[i] == 94){
incoming = true;
}// end of if i = ^
else{
//Looks for the & Char
if(data[i] == 38){
}// end of if i = &
if((data[i] != 38) && (incoming)){
inChar = data[i]; // Read a character
inData[index] = inChar; // Store it
index++; // Increment where to write next
}
}// end of else
}// end of for
char tinData[20]; // Allocate some space for the string
char tinChar; // Where to store the character read
byte tindex = 0; // Index into array; where to store the character
String lantemp = String (inData[0]);
if(lantemp.equals("$")){
//need to read through inData here to get the IP
for (i = 0; i < strlen(inData); i++){
if(i>3){
tinChar = inData[i]; // Read a character
tinData[tindex] = tinChar; // Store it
//Serial.println(tinData[index
tindex++; // Increment where to write next
}// end i>3
}
String IP(tinData);
piIp = IP;
Serial.print("IP: ");
Serial.println(IP);
myGLCD.print("Pi IP: " + IP, LEFT,42);
menus.homeScrn();
}// end if = $
String temp = inData;
Serial.print("String Temp: ");
Serial.println(temp);
if(temp.equals("Power")){
piStatus = "Ready";
delay (50);
Serial1.println("ip");
menus.homeScrn();
connection = true;
//myGLCD.print("PI Status: "+piStatus, LEFT, 28);
}//end if inData.equals
inData[0] = '\0';
temp = "";
} // end of process_data
void Comms::serialGack(int port){
switch(port){
case 1:
if (Serial1.available () > 0) {
char inByte = Serial1.read ();
} // end of incoming data
break;
case 3:
if (Serial3.available () > 0) {
char inByte = Serial3.read ();
}
break;
}
}
void Comms::isAnyone(){
Serial1.println("VN");
delay(75);
}
What baffles me now is that in the Menus library this works:
if ((x>=150) && (x<=210)){
if (mnu == 1){
Serial1.println("RB");
Serial.println("Restart");
piStatus = "Restarting";
piIp = NULL;
mnu = 0;
homeScrn();
but Serial1.println("ST"); is still not working correctly.