Forum Rule: Always post complete source code & details to reproduce any issue!
Page 2 of 2 FirstFirst 1 2
Results 26 to 43 of 43

Thread: My Ethernet woes...

  1. #26
    Member
    Join Date
    Jan 2014
    Location
    Seattle, WA
    Posts
    25
    As I have stated before, I have a test set that works, so I put a scope on the Slave Select pins on that one. Pin 10, nice 3v pattern. Digital 4, the SD pin Nothing. No signal (not a constant 0 volts, more like open) . Mind you, this one works and has worked well for a few days of continuous writes and reads.

    I finally got it down to the fact that it was the SD card not starting. I changed the order in which things start and how (and whether or not) I set a SS pin. I finally got it to work by doing this:
    Code:
      //SD Card setup and Initialization
      pinMode(10,OUTPUT);     //setup to disable 5200 during SD statrup
      Ethernet.begin(mac, ip, gateway, gateway, subnet);
      digitalWrite(10,HIGH);
      pinMode(4, OUTPUT);    //SS line for SD card, 
      digitalWrite(10,HIGH);  //Enet disable
      SD.begin(4);
      digitalWrite(10,LOW);  //Enet disable
      server.begin();
    I had to put the Ethernet first and then pull everything (prints, checks etc) out to get the SD to start, I'll try and add some things back in and see exactly where it breaks.

    When I scope pin 10, looks like a digital signal, 3v, quick rise etc. It's rising and falling pretty often. When I do the same to digital 4, there's nothing. No signal. basically looks like it's not set at all (i.e. it's not held at 0 or 3v) just bobbles around in the mv range. My program does a write to the SD once a second for about 500 characters, and reads from the server probably 50 times a second, so I should have seen it move.
    It's written 400 records in a row and I've downloaded about 5mb of data and it's still running. I've got test data that'll run over 30 hours that I can QA each record, I'll let you know how it goes.

    I somehow think this shouldn't be working, and what I did just gets me past initialization, but that the real problem is still there, I just haven't found the conditions for it yet.


    My probe is on the teensy pin, not the wiz pin, just to eliminate a connection problem there.

    Thanks for your help so far.

    edit: when I took out the digital writes (any combination of them HIGH, LOW) it didn't work.

    another edit: now written 3000 records and 50 file downloads through the wiz. no issues yet!
    Last edited by mikeleslie; 03-05-2014 at 09:39 AM.

  2. #27
    Senior Member
    Join Date
    Jan 2013
    Posts
    966
    When I do the same to digital 4, there's nothing. No signal. basically looks like it's not set at all (i.e. it's not held at 0 or 3v) just bobbles around in the mv range.
    That is rather strange!
    Last edited by Headroom; 03-05-2014 at 10:38 AM.

  3. #28
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,576
    Quote Originally Posted by mikeleslie View Post
    here's the weird part, under some circumstances they both work, although both will not start in the same boot. I can start the wiz, change the code, start it again they both work at the same time....sometimes.
    I'm going to look into this today. You're using the WIZ820io with PJRC's adaptor board, right? If your hardware is somehow different now, please tell me exactly what you have hooked up, so I can duplicate your setup.

    Should I start with the code you posted on reply #12 ?

  4. #29
    Senior Member
    Join Date
    Jun 2013
    Location
    So. Calif
    Posts
    2,828
    Quote Originally Posted by mikeleslie View Post
    Code:
      //SD Card setup and Initialization
      pinMode(10,OUTPUT);     //setup to disable 5200 during SD statrup
      Ethernet.begin(mac, ip, gateway, gateway, subnet);
      digitalWrite(10,HIGH);
      pinMode(4, OUTPUT);    //SS line for SD card, 
      digitalWrite(10,HIGH);  //Enet disable
      SD.begin(4);
      digitalWrite(10,LOW);  //Enet disable
      server.begin();
    The final digitalWrite() sets Ethernet's SS true but comment may be wrong. Seems like that line of code is supposed to be handled by the Ethernet lib

  5. #30
    Member
    Join Date
    Jan 2014
    Location
    Seattle, WA
    Posts
    25
    Yep:
    green teensy 3.1 just got it late last week shipped direct from you with the PRJC adaptor.
    WIZ820io from Mouser, labeled WIZ820i0 R1.0
    Teensyduino 1.18 with all the libraries loaded
    Arduino 1.05-r2
    Tinygps++ library added, no others added.

    I have a MAX3232 attached to serial 1 and 3, but I get the same results with it "standalone" i.e just the teensy with the adaptor and wiznet

    feel free to contact me direct if you have any questions.


    up to 11,000 SD writes and 40 large file downloads without issue

    Here's the working code:

    Code:
    
    //////////////////////////////////////////////////////////////////////////////////
    //     1.1.2 removed rtc, 
    //     1.1.3 added 2 commas in non bms record.  added bms updates to web server mlaas and mlarr records
    //     1.1.4 added dynamic file names based on coledate from exp1 record
    //////////////////////////////////////////////////////////////////////////////////
    
     //#include <spi4teensy3.h>
     #include <SPI.h>
     #include <SD.h>
     #include <DS1307RTC.h>
     #include <Time.h>
     #include <Wire.h>
     #include <Ethernet.h>
     #include <utility/w5100.h>
     #define ethernetON
     #define ServerDEBUG
     
     //Ethernet Setup Info
     byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xEC };
     IPAddress ip( 192,168,0,10 );    // AJ1 Network
     IPAddress gateway( 192,168,0,254 );  //blue TP-Link Router, AJ1
     IPAddress subnet( 255,255,255,0 );
     EthernetServer server(80);
    
     const char legalChars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890/.-_~";
     unsigned int requestNumber = 0;
    
     const int chipSelect = 4; //sd card cs pin  
     String logFileExt = ".csv";
     String logFileString;
     char logFile[] = "logfi.csv"; //file name to store into
    
          
     //ColeTime Variables
     float ColeTimeSecond;
     int ColeTimeYear;
     long fakeSecond;
     int LeapDays = 0;
    
     //SD file write intermediate records
     String expRecord1 = ("");
     String expRecord2 = (",,,,,,,,,,,,,,,,,,,,,,"); // 22 commas
     String expRecord3 = ("");
     String expRecord  = ("");
     unsigned long ExpDelay = 0;
     int ExpReady = 0;
    
     //Serial input read strings 
     String inData;
     char inChar=-1;
     String inData2;char inChar2=-1;
     String inData3;
     char inChar3 =-1;
    
    
    void setup()
     {
      // Serial Ports Setup
      Serial.begin(19200);  // USB Monitoring Port
      Serial1.begin(4800);  //  input from Sensor module, includes all Insturment input
      //Serial2.begin(19200); //  EXP records from BMS module
      Serial3.begin(38400); // Output to other systems
      
      //Begin Sensor Initialization
      #ifdef ServerDEBUG
      Serial.println("DEBUG ON");
      delay(3000);
      #endif  
      delay(2000); //wait
      
      //announce yourself to the modules  ///
      Serial.println ("  Distribution Module Version 1.1.4 SD, SensorPac S1-4800, NO RTC,  ETHERNET BMS S2-19200,  S3-38400");
      Serial1.println("  Distribution Module Version 1.1.4 SD, SensorPac S1-4800, NO RTC,  ETHERNET BMS S2-19200,  S3-38400");
      Serial3.println("  Distribution Module Version 1.1.4 SD, SensorPac S1-4800, NO RTC,  ETHERNET BMS S2-19200, S3-38400");
      
      //SD Card setup and Initialization
      pinMode(10,OUTPUT);     //setup to disable 5200 during SD statrup
      Ethernet.begin(mac, ip, gateway, gateway, subnet);
      digitalWrite(10,HIGH);
      pinMode(4, OUTPUT);    //CS line for SD card, disables ethernet
      digitalWrite(10,HIGH);  //Enet disable
      SD.begin(4);
      digitalWrite(10,LOW);  //Enet disable
      Serial.print("SD Setup Sucessful. Ethernet Setup Begins......");
      #ifdef ethernetON
      server.begin();
      Serial.println(F("Server Ready"));
      #endif
      int loopCount = 0;
     }   //end of setup
    
    void loop() 
    //This loop checks the server for activity and reads from the sensors on Serial1, BMS module on Serial2, and SD write Records on Serial3 outputs a combined stream to port 3, writes logs to the SD card.
       {
         //check for network client activity
         #ifdef ethernetON
         checkServer();
         #endif
         //Combined II Sensor port IN
         while (Serial1.available() > 0)     //Port 1 Has NKE Instruments, remove HDG, ZDA, GLL MTA, VWR and VTG from output stream as the data conflicts with the GPS data. 
        {
            char recieved = Serial1.read();
            inData += recieved; 
            if (recieved == '\n') // Process message when new line character is recieved
            {                       
               #ifdef ServerDEBUG 
                 Serial.print("port  1: ");     
               #endif  
               Serial.print(inData);   //send all messages to USB
               Serial3.print(inData);  //send all messages to Output
               //Serial2.print(inData);  
               //Serial1.print(inData);      
               inData = "";             // Clear recieved buffer
           }    //end  /N EOL line processing
        }    //end while port available
    
        //BMS 3v Transfer Port
        while (Serial2.available() > 0)
            {
            char recieved2 = Serial2.read();
            inData2 += recieved2;
            if (recieved2 == '\n') // Process message when new line character is recieved
            {    
              //#ifdef ServerDEBUG  
                Serial.print("port  2: "); 
                Serial.print(inData2);    
             // #endif
                if (inData2.substring(1,6) =="MEXP2")                              //Read the Expedition Sentence
                      {
                      int poundloc =  inData2.indexOf(',#');
                      int poundloc2 = inData2.indexOf('#', poundloc+1);
                      String exp02 =  inData2.substring(poundloc+1,poundloc2);
                      expRecord2 = exp02;
                    }           
             else  // forward all other sentences
                    {
                     Serial.print(inData2);                                    //send all remaining messages to USB
                     Serial3.print(inData2);                                   //send all remaining messages to output port                 
                     } //end sentence print  
             inData2 = "";                                             // Clear recieved buffer
           }
         }
            
        //expedition record Port in, Vesper port out  
         while (Serial3.available() > 0)     //Port 3 Has Expedition data records only 
        {
            char recieved3 = Serial3.read();
            inData3 += recieved3; 
            if (recieved3 == '\n') // Process message when new line character is recieved
            { 
               #ifdef ServerDEBUG
                 Serial.print("port  3: ");  
                 Serial.print(inData3);            
                #endif
    
               if (inData3.substring(1,6) =="MEXP1") //Read the first Expedition Record
               {       
                 int poundloc = inData3.indexOf(',#');
                 int poundloc2 = inData3.indexOf('#', poundloc+1);
                 String exp01 = inData3.substring(poundloc+1,poundloc2);
                 String cDate = exp01.substring(0,5);
                 logFileString = cDate+ logFileExt;
                 #ifdef ServerDEBUG
                 Serial.print("**********************************************date***********************");
                 Serial.println(logFileString);
                 #endif
                 expRecord1 = exp01;
               }
               else if (inData3.substring(1,6) =="MEXP3") //Trigger for  Expedition Record Write
               { 
                 int poundloc = inData3.indexOf(',#');
                 int poundloc2 = inData3.indexOf('#', poundloc+1);
                 String exp03 = inData3.substring(poundloc+1,poundloc2);
                 expRecord3 = exp03;
                 inData3 = "";                                           // Clear recieved buffer 
                 #ifdef ServerDEBUG
                 Serial.print("ExpReady Count ");
                 Serial.println(ExpReady);
                 #endif
                 if (ExpReady >= 3)
                   {
                    
                     LogExpeditionInfo();
                   }
                }
                 //Serial.print(inData3);                                   //send all remaining messages to USB
                 //Serial3.print(inData3);                                  //send all remaining messages to output port
                 //Serial1.print(inData3);                                  //send all remaining messages to II port
              ExpReady = ExpReady+1;
              inData3 = "";                                           // Clear recieved buffer 
             }        
       } //end port read  
     }//end main loop 
    
    void LogExpeditionInfo()
        { 
         expRecord = expRecord1+expRecord2+expRecord3; //combine the 3 records
         logFileString.toCharArray(logFile,13);
         File dataFile = SD.open(logFile, FILE_WRITE);      
         dataFile.println(expRecord);  
         dataFile.close(); 
       #ifdef ServerDEBUG
         Serial.print(logFile);
         Serial.println("  Written to SD*************************************************************************");
         Serial.println(expRecord);
       #endif
        expRecord = "";
        expRecord1 = "";
        //expRecord2 = "";
        expRecord3 = "";
       
       }
    
    void checkServer() {
    
      EthernetClient client = server.available();
      if(client) {
        boolean currentLineIsBlank = true;
        boolean currentLineIsGet = true;
        int tCount = 0;
        char tBuf[64];
        int r,t;
        char *pch;
        char methodBuffer[8];
        char requestBuffer[48];
        char pageBuffer[48];
        char paramBuffer[48];
        char protocolBuffer[9];
        char fileName[32];
        char fileType[4];
        int clientCount = 0;
    
        requestNumber++;
    #ifdef ServerDEBUG
        Serial.print(F("\r\nClient request #"));
        Serial.print(requestNumber);
        Serial.print(F(": "));
    #endif
    
        // this controls the timeout
        int loopCount = 0;
    
        while (client.connected()) {
          while(client.available()) {
            // if packet, reset loopCount
    //        loopCount = 0;
            char c = client.read();
    
            if(currentLineIsGet && tCount < 63)
            {
              tBuf[tCount] = c;
              tCount++;
              tBuf[tCount] = 0;          
            }
    
            if (c == '\n' && currentLineIsBlank) {
    #ifdef ServerDEBUG
              Serial.print(tBuf);
    #endif
    //          Serial.print(F("POST data: "));
              while(client.available()) client.read();
    
              int scanCount = sscanf(tBuf,"%7s %47s %8s",methodBuffer,requestBuffer,protocolBuffer);
    
              if(scanCount != 3) {
    
    #ifdef ServerDEBUG
                Serial.println(F("bad request"));
    #endif
                sendBadRequest(client);
                return;
              }
    
              char* pch = strtok(requestBuffer,"?");
              if(pch != NULL) {
                strncpy(fileName,pch,31);
                strncpy(tBuf,pch,31);
    
                pch = strtok(NULL,"?");
                if(pch != NULL) {
                  strcpy(paramBuffer,pch);
                }            
                else paramBuffer[0] = 0;            
              }
    
              strtoupper(requestBuffer);
              strtoupper(tBuf);
    
              for(int x = 0; x < strlen(requestBuffer); x++) {
                if(strchr(legalChars,requestBuffer[x]) == NULL) {
                  Serial.println(F("bad character"));  
                  sendBadRequest(client);
                  return;
                }            
              }
    
    #ifdef ServerDEBUG
              Serial.print(F("file = "));
              Serial.println(requestBuffer);
    #endif
              pch = strtok(tBuf,".");
    
              if(pch != NULL) {
                pch = strtok(NULL,".");
    
                if(pch != NULL) strncpy(fileType,pch,4);
                else fileType[0] = 0;
    
    //#ifdef ServerDEBUG
                Serial.print(F("file type = "));
                Serial.println(fileType);
                if(fileType == "LOG") {ExpReady = 0; Serial.println("trapped LOG");} // 
    //#endif
               }
    
    #ifdef ServerDEBUG
              Serial.print(F("method = "));
              Serial.println(methodBuffer);
    #endif
              if(strcmp(methodBuffer,"GET") != 0 && strcmp(methodBuffer,"HEAD") != 0) {
                sendBadRequest(client);
                return;
              }
    
    #ifdef ServerDEBUG
              Serial.print(F("params = "));
              Serial.println(paramBuffer);
    
              Serial.print(F("protocol = "));
              Serial.println(protocolBuffer);
    #endif          
    
              // if dynamic page name 
              if(strcmp(requestBuffer,"/MYTEST.PHP") == 0) {
    #ifdef ServerDEBUG
                Serial.println(F("dynamic page"));            
    #endif
              }
              else {
                if(strcmp(fileName,"/") == 0) {
                  strcpy(fileName,"/INDEX.HTM");
                  strcpy(fileType,"HTM");
    
    #ifdef ServerDEBUG
                  Serial.print(F("Home page "));            
    #endif
                }
    
    #ifdef ServerDEBUG
                Serial.println(F("SD file"));            
    #endif
                if(strlen(fileName) > 30) {
    #ifdef ServerDEBUG
                  Serial.println(F("filename too long"));
    #endif
                  sendBadRequest(client);
    
                  return;
                }
                else if(strlen(fileType) > 3 || strlen(fileType) < 1) {
    
    #ifdef ServerDEBUG
                  Serial.println(F("file type invalid size"));
    #endif
                  sendBadRequest(client);
                  return;
                }
                else {
    #ifdef ServerDEBUG
                  Serial.println(F("filename format ok"));
    #endif
                  if(SD.exists(fileName)) { 
    #ifdef ServerDEBUG
     
                    Serial.print(F("file found.."));                
    #endif
    
                    File myFile = SD.open(fileName); 
                   ExpReady = 0; 
    
                    if(!myFile) {
    #ifdef ServerDEBUG
                      Serial.println(F("open error"));
    #endif
                      sendFileNotFound(client);
                      return;
                    }
    #ifdef ServerDEBUG
                    else Serial.print(F("opened.."));
    #endif
    
                    strcpy_P(tBuf,PSTR("HTTP/1.0 200 OK\r\nContent-Type: "));
    //                client.write(tBuf);
    //                client.print(F("HTTP/1.0 200 OK\r\nContent-Type: "));
    
                    // send Content-Type
                    if(strcmp(fileType,"HTM") == 0) strcat_P(tBuf,PSTR("text/html"));
                    else if(strcmp(fileType,"PHP") == 0) strcat_P(tBuf,PSTR("text/html"));
                    else if(strcmp(fileType,"TXT") == 0) strcat_P(tBuf,PSTR("text/plain"));
                    else if(strcmp(fileType,"CSS") == 0) strcat_P(tBuf,PSTR("text/css"));
                    else if(strcmp(fileType,"GIF") == 0) strcat_P(tBuf,PSTR("image/gif"));
                    else if(strcmp(fileType,"JPG") == 0) strcat_P(tBuf,PSTR("image/jpeg"));
                    else if(strcmp(fileType,"JS") == 0) strcat_P(tBuf,PSTR("application/javascript"));
                    else if(strcmp(fileType,"ICO") == 0) strcat_P(tBuf,PSTR("image/x-icon"));
                    else if(strcmp(fileType,"PNG") == 0) strcat_P(tBuf,PSTR("image/png"));
                    else if(strcmp(fileType,"PDF") == 0) strcat_P(tBuf,PSTR("application/pdf"));
                    else if(strcmp(fileType,"ZIP") == 0) strcat_P(tBuf,PSTR("application/zip"));
                    else strcat_P(tBuf,PSTR("text/plain"));
    
                    strcat_P(tBuf,PSTR("\r\nConnection: close\r\n\r\n"));
                    client.write(tBuf);
    
                    if(strcmp(methodBuffer,"GET") == 0)  {
    #ifdef ServerDEBUG
                      Serial.print(F("send.."));
    #endif
    
                      while(myFile.available()) {
                        tBuf[clientCount] = myFile.read();
                        clientCount++;
                        tBuf[clientCount] = 0;
    
                        if(clientCount > 63) {
                          client.write((byte*)tBuf,64);
                          clientCount = 0;
                        }
    
                      }
                      if(clientCount > 0) {
                        client.write((byte*)tBuf,clientCount);
                      }
                    }
    
                    myFile.close();              
    #ifdef ServerDEBUG
                    Serial.println(F("closed"));
    #endif
                    client.stop();                
    #ifdef ServerDEBUG
                    Serial.println(F("disconnected"));
    #endif
                    return;
                  }
                  else {
    #ifdef ServerDEBUG
                    Serial.println(F("File not found"));
    #endif
                    sendFileNotFound(client);
                    return;
                  }
    
                }
              }
    
              pch = strtok(paramBuffer,"&");
    
              while(pch != NULL)
              {
                if(strncmp(pch,"t=",2) == 0)
                {
                  t = atoi(pch+2);
                  Serial.print("$MLAAC,"); Serial.print(t);  Serial.println(",*23" );   //modifies bat capacity remaining       
    #ifdef ServerDEBUG
                  Serial.print("t=");
                  Serial.println(t,DEC);             
    #endif
                }
    
                if(strncmp(pch,"r=",2) == 0)
                {
                  r = atoi(pch+2);
                  Serial.print("$MLARR,"); Serial.print(r);  Serial.println(",*23" );   //modifies bat capacity remaining       
    
    #ifdef ServerDEBUG
                  Serial.print("r=");              
                  Serial.println(r,DEC);
    #endif
                }
    
    
                pch = strtok(NULL,"& ");
              }
    #ifdef ServerDEBUG
              Serial.println(F("Sending response"));
    #endif
              client.print(F("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n"));
    
              if(strcmp(methodBuffer,"GET") == 0) {
    
                strcpy_P(tBuf,PSTR("<html><head><script type=\"text/javascript\">"));
                client.write(tBuf);
                strcpy_P(tBuf,PSTR("function show_alert() {alert(\"are you sure\");}"));
                client.write(tBuf);
                strcpy_P(tBuf,PSTR("</script></head>"));
                client.write(tBuf);
    
                strcpy_P(tBuf,PSTR("<body><H1>BMS MODIFICATION PAGE</H1><form method=GET onSubmit=\"show_alert()\">"));
                client.write(tBuf);
                strcpy_P(tBuf,PSTR("AVAILABLE: <input type=text name=t><br>"));
                client.write(tBuf);
                strcpy_P(tBuf,PSTR("RATE: <input type=text name=r><br><input type=submit></form></body></html>"));
                client.write(tBuf);
              }
    
              client.stop();
            }
            else if (c == '\n') {
              currentLineIsBlank = true;
              currentLineIsGet = false;
            } 
            else if (c != '\r') {
              currentLineIsBlank = false;
            }
          }
    
          loopCount++;
    
          // if 1000ms has passed since last packet
          if(loopCount > 1000) {
            // close connection
            client.stop();
    #ifdef ServerDEBUG
            Serial.println("\r\nTimeout");
    #endif
          }
    
          // delay 1ms for timeout timing
          delay(1);
        }
    #ifdef ServerDEBUG
        Serial.println(F("disconnected"));
    #endif
      }
    }
    
    void sendFileNotFound(EthernetClient thisClient) {
      char tBuf[64];
      strcpy_P(tBuf,PSTR("HTTP/1.0 404 File Not Found\r\n"));
      thisClient.write(tBuf);
      strcpy_P(tBuf,PSTR("Content-Type: text/html\r\nConnection: close\r\n\r\n"));
      thisClient.write(tBuf);
      strcpy_P(tBuf,PSTR("<html><body><H1>FILE NOT FOUND</H1></body></html>"));
      thisClient.write(tBuf);
      thisClient.stop();  
    #ifdef ServerDEBUG
      Serial.println(F("disconnected"));
    #endif
    }
    
    void sendBadRequest(EthernetClient thisClient) {
      char tBuf[64];
      strcpy_P(tBuf,PSTR("HTTP/1.0 400 Bad Request\r\n"));
      thisClient.write(tBuf);
      strcpy_P(tBuf,PSTR("Content-Type: text/html\r\nConnection: close\r\n\r\n"));
      thisClient.write(tBuf);
      strcpy_P(tBuf,PSTR("<html><body><H1>BAD REQUEST</H1></body></html>"));
      thisClient.write(tBuf);
      thisClient.stop();  
    #ifdef ServerDEBUG
      Serial.println(F("disconnected"));
    #endif
    }
    
    void  strtoupper(char* aBuf) {
    
      for(int x = 0; x<strlen(aBuf);x++) {
        aBuf[x] = toupper(aBuf[x]);
      }
    }
    
    byte socketStat[MAX_SOCK_NUM];
    
    void ShowSockStatus()
    {
      for (int i = 0; i < MAX_SOCK_NUM; i++) {
        Serial.print(F("Socket#"));
        Serial.print(i);
        uint8_t s = W5100.readSnSR(i);
        socketStat[i] = s;
        Serial.print(F(":0x"));
        Serial.print(s,16);
        Serial.print(F(" "));
        Serial.print(W5100.readSnPORT(i));
        Serial.print(F(" D:"));
        uint8_t dip[4];
        W5100.readSnDIPR(i, dip);
        for (int j=0; j<4; j++) {
          Serial.print(dip[j],10);
          if (j<3) Serial.print(".");
        }
        Serial.print(F("("));
        Serial.print(W5100.readSnDPORT(i));
        Serial.println(F(")"));
      }
    }
    Last edited by mikeleslie; 03-05-2014 at 04:18 PM. Reason: added code

  6. #31
    Member
    Join Date
    Jan 2014
    Location
    Seattle, WA
    Posts
    25
    yea, sorry about the comments, I didn't change them as I was messing around with it last night

  7. #32
    w5100.cpp uint8_t casting issue with the Ethernet webserver EXAMPLE.

    I am at r1.06 Arduino. Teensy 3.2,teenseyduino 1.30 throws these at me for code that would compile for a long time....

    Is there an issue with R1.06 or do I need to make some addidional input I am using the webserver example and I stiil get the bottom error.


    where am I missing something?

    C:\Program Files (x86)\Arduino\libraries\Ethernet\utility\w5100.cpp : In member function 'void W5100Class::read_data(SOCKET, volatile uint8_t*, volatile uint8_t*, uint16_t)':
    C:\Program Files (x86)\Arduino\libraries\Ethernet\utility\w5100.cpp :115:24: error: cast from 'volatile uint8_t* {aka volatile unsigned char*}' to 'uint16_t {aka short unsigned int}' loses precision [-fpermissive]
    src_mask = (uint16_t)src & RMASK;
    Last edited by 1bit; 10-30-2016 at 06:52 PM. Reason: added teenseyduino version 1.30

  8. #33
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    5,679
    That's not a example from Teensyduino, right ?
    That path : "C:\Program Files (x86)\Arduino\libraries\Ethernet\" does not look right for a teensy

  9. #34

    I am at r1.06 Arduino. Teensy 3.2 ,teensyduino 1.30, w5100.cpp:115:24: error: cast

    Could you comment on this:: "
    I am at r1.06 Arduino. Teensy 3.2 ,teensyduino 1.30 throws these at me for code that would compile for a long time....

    Is there an issue with R1.06 or do I need to make some additional input I am using the webserver example and I stiil get the bottom error.


    where am I missing something?

    C:\Program Files (x86)\Arduino\libraries\Ethernet\utility\w5100.cpp : In member function 'void W5100Class::read_data(SOCKET, volatile uint8_t*, volatile uint8_t*, uint16_t)':
    C:\Program Files (x86)\Arduino\libraries\Ethernet\utility\w5100.cpp :115:24: error: cast from 'volatile uint8_t* {aka volatile unsigned char*}' to 'uint16_t {aka short unsigned int}' loses precision [-fpermissive]
    src_mask = (uint16_t)src & RMASK;
    "

    Should I change to a different setup?

  10. #35
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    5,679
    All i see, is that this path: C:\Program Files (x86)\Arduino\libraries\Ethernet\ is NOT a teensy library.
    Seems to be a issue with your setup, somehow.

    Are you compiling for a Teensy ? :-)

    Upgrade to newest Aduino and Teensyduino..
    Last edited by Frank B; 10-30-2016 at 07:59 PM.

  11. #36
    @ Frank B... Thanks...I AM NEW here...I might try uninstalling and reinstalling again....maybe installed in a wacky place for teensyduino and 3.1/3.2...but I compile for this code on other IDE just fine without Teensyduino installed it is the example from the pull down menu. I select board type (Teensy3.2/3.1) and load directly from Ethernet example web server on IDE.

  12. #37
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    5,679
    Well, it compiles for me, without errors.
    It uses the library from Arduino\hardware\teensy\avr\libraries\Ethernet
    You see the difference ?

    When installing teensyduino, make sure to install all the libraries. It might bepossibile that you did not do that .. or something else.

  13. #38
    @ Frank B.....I did install ALL the teensy stuff ...I will install arduino 1.6.5....there is no Ethernet library on the checkbox list for teensy 1.30 install on my copy....maybe I should get a different one....from PJRC. the most recent beta??

    Anyway I installed 1.3.1 beta #2 and Arduino IDE 1.6.12 and my whole thing (not just the example compiles fine)
    Last edited by 1bit; 10-30-2016 at 10:25 PM.

  14. #39
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    5,424
    Actually I don't see it either on the list, however when I install Teensyduino, I do see it installed on my machine:
    In my case I see it at: C:\arduino-1.6.12\hardware\teensy\avr\libraries\Ethernet

  15. #40
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    5,679
    Yes, and under "examples". Not ?

  16. #41
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    5,424
    Hi Frank,

    Oops, I can see my answer could be read multiple ways. What I meant to say was the Teensuduino installer did not list Ethernet as an optional library to install, So it probably ALWAYS installs the library as after each install I have it installed in the standard Teensy location... And Yes, Ethernet on my machine does show up under Examples.

    I have opened up the example Webserver which compiles fine for my machine with Arduino 16.12 and beta2...

  17. #42
    I got my whole, and I do mean all of my old application to compile just fine....now that I have every thing upgraded....I am also using Mudbus and HX711 libraries that I just installed. I did use the ADS1115 too....I will now install my other i2c libraries.....yeeha. I want to put a FONA on this setup...

  18. #43
    Member
    Join Date
    Jan 2014
    Location
    Seattle, WA
    Posts
    25
    I got this all working "mostly" last year, but I had continuing issues with the server refusing connections if I used the back button on the browser before it finished loading a page. (many of my pages read from the SD and just dump the contents) The sketch writes to the SD card every second or so.
    I was all excited when I saw that Paul was tinkering in the Ethernet library looking to fix some issues. I replaced the library with the one on GitHub, but alas, no difference.
    I don't have any problems with initialization and it reliably comes up after power up
    Only the wiznet stops. The teensy keeps working, and writing to the SD.
    Thoughts?
    Arduino 1.6.11
    Teensyduino 1.3.0
    Teensy 3.2, PJRC SD adaptor with 820 on top.

    #include <Ethernet.h>
    #include <SD.h>
    #include <SPI.h>
    #include <Wire.h>
    #include <TinyGPS++.h>
    #include <DS1307RTC.h>
    #include <Time.h>
    #include <Adafruit_BMP085.h>
    #include <Adafruit_DotStar.h>

    ////Version Number for splash//////
    String verstring = " Integrated Sensor, Logging, Route forwarding, Web Services and Forms, Flight Detection, voltage monitoring, Polar Tables, Dot Display, Tack Scoring & Polar Record Identification 1.3.3b ";
    int versionArray[36] = {
    255, 255, 255, 255, 0, 255, 255, 0, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
    };
    /////////

    //////Dotstar Setup////////////
    #define NUMPIXELS 20 // Number of LEDs in strip
    #define DATAPIN 15 //11 Data Pin
    #define CLOCKPIN 14 //13 Clock Pin
    Adafruit_DotStar strip = Adafruit_DotStar(NUMPIXELS, DATAPIN, CLOCKPIN, DOTSTAR_BRG);
    /////////

    //Declare the server port now//////
    EthernetServer server(80);
    const char legalChars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890/.-_~";
    unsigned int requestNumber = 0;
    int displayPageType = 0;
    int displayColorMode = 0;
    /////////

    //////SD card Setup/////////////
    const int chipSelect = 4; //sd card cs pin
    String logFileExt = ".csv";
    String logFileString;
    String logFileStringPrev;
    char logFile[] = "logfil.csv"; //file name to store into
    char ExpFile[] = "logfil.csv";
    char ipAdrVar[] ="192 ,168 , 0, 8";
    char logFileName = 'logfile.txt';
    int includeDate = 0;
    File myFile;
    int exINT = 15;
    float exFloat = 1.12345;
    boolean exBoolean = true;
    long exLong = 2123456789;
    /////////

    ///fix for defines not working properly //
    #define nop() __asm volatile ("nop")
    #if 1
    nop();
    #endif
    /////////

    /////////////DEFINES////////////
    ///////INSTRUMENT - SELECT ONE/////////
    #define instBG //use if the instrument type is B&G (no VTG correction)
    //#define instNKE //use if the instrument type is NKE (neeeds VTG HDM correction)
    ///////////DEBUG MESSAGES///////////////
    //#define CSVDEBUG //use if you want general verbose data to console
    //#define expDEBUG
    //#define serverDEBUG //use if you want general verbose data to console
    //#define distanceDEBUG //use if you want to add distance forward calcs to the console
    //#define guageDEBUG //use this if you want to add guage loss details to the console
    //#define TackScore //use if this is a tackscore device compile.
    #define EPO // use if this is a EPO device compile
    /////////
    int expCtr2 = 1;
    ///I2C DEVICE ADDRESSES/////////
    #define DEVICE (0x53) // tilt sensor addressDevice address as specified in data sheet
    /////////
    int vctr = 0; //counter for voltageXDR strings
    int sctr = 0; //counter for voltageXDR strings
    ///Status Light Setup///////////
    int neoMinTargetFloor = 70; //set range range of display (eg..80 represents 80 to 100 % of target/
    int centerPixel = 12; //pixel to use as the 100% target
    int pixelRange = 20; //100-neomintargetfloor
    float pickPixelMult = 0; //speed range per pixel
    float avgTrgtPixel = 0;
    int neoActual = 0;
    int neoActualT = 0;
    int whichPixelT = 0;
    int whichPixelR = 0;
    int whichPixelG = 0;
    int whichPixelB = 0;
    int neoPixel = 0;
    int prevPixelT = 0;
    int numpixels = 20;
    int dotBrightess = 5;
    int whichPixelROld = 0;
    int whichPixelGOld = 0;
    int whichPixelBOld = 0;
    int whichPixelROlder = 0;
    int whichPixelGOlder = 0;
    int whichPixelBOlder = 0;
    int pixelIndex = 0;
    int flightGain = 200;
    int dotReset = 0;
    int warningRoll = 45;
    int cautionRoll = 35;
    int flightRoll = 0;
    float dotTargetMin = 50;
    int pixelDiag = 0;
    int dotMode = 1; //1 = target speed, 2= polar mode
    int PixelArrayG[36] = {
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
    };
    int PixelArrayR[36] = {
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
    };
    int PixelArrayB[36] = {
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
    };
    /////////
    float lat2f = 0.000000;
    float lat2 = 0;
    String latDDTmp ;
    String latMMfinal ;
    ///Voltge Monitoring Setup /////
    int v12Signal = A6;
    //float v12Multiplier = .006091357421875;
    float v12Multiplier = .006152737421875;
    float v12Actual = 0;
    float v1290Threshold = 13.8;
    float v1280Threshold = 13.6;
    float v1270Threshold = 13.4;
    float v1260Threshold = 13.2;
    float v1250Threshold = 13.0;
    float v1240Threshold = 12.9;
    float v1230Threshold = 12.8;
    float v1220Threshold = 12.7;
    float v1210Threshold = 12.3;
    float v120Threshold = 12.0;
    float v12Pct = 0;
    //float v1270Threshold = 13.7;
    int v24Signal = A7;
    float v24Multiplier = .01215;
    float v24Actual = 0;
    float v2490Threshold = 26.5;
    float v2480Threshold = 26.4;
    float v2470Threshold = 26.3;
    float v2460Threshold = 26.2;
    float v2450Threshold = 26.0;
    float v2440Threshold = 25.9;
    float v2430Threshold = 25.7;
    float v2420Threshold = 25.6;
    float v2410Threshold = 25.2;
    float v240Threshold = 24.9;
    float v24Pct = 0;
    ///NMEA0183 STRUCTURES//////////
    ///////////NMEA CRC builder vars///////////
    //int XDRSail = 500;
    int XDRCounter = 0;
    int XDRCounter2 = 0;
    const byte buff_len = 90;
    char CRCbuffer[buff_len];
    unsigned long NMEAin = 0L;
    ////////// NMEA0183 output strings ////////
    String sp = " ";
    String delim = ",";
    String splat = "*";
    String msg = "";
    /////////NMEA183 inbound check vars ///////
    int charcount = 0;
    String starcheck = "*"; //Sentence End Indicator
    String hdrcheck = "$II"; //Sentece Talker Type
    //String hdrcheck = "$EC"; //Sentece Talker Type
    ////////NMEA0183 BWC Sentence Vars/////////
    String markMag; //mark bearing magnetic
    int markInt = 0; //Bearing to Mark in degrees magnetic*100
    String markDist; //mark Distance
    int markDistInt = 0; //distance*100 to active mark
    float markDistFloat = 0; //distance to active mark
    /////////NMEA inbound read Strings ////////
    String inData; //Serial1 inbound string
    char inChar = -1; //Serial1 inbound character
    String inData2; //Serial2 inbound string
    char inChar2 = -1; //Serial2 inbound character
    String inData3; //Serial3 inbound string
    char inChar3 = -1; //Serial3 inbound character
    /////NMEA0183 Inbound Fields //////////////
    TinyGPSPlus gps;
    //H5000 Types
    TinyGPSCustom cog(gps, "ECVTG", 3); // COG, VTG 3RD ELEMENT, Course Over Ground
    TinyGPSCustom sog(gps, "ECVTG", 5); // SOG, VTG 5th ELEMENT, Speed Over Ground
    TinyGPSCustom twd(gps, "ECMWD", 3); // TWD, MWD 3RD ELEMENT, True Wind Direction
    TinyGPSCustom tws(gps, "ECMWD", 5); // TWS, MwD 5th ELEMENT, True Wind Speed
    TinyGPSCustom twa(gps, "ECVWT", 1); // TWA, VWT 1st ELEMENT, True Wind Angle
    TinyGPSCustom hdm(gps, "ECHDM", 1); // HDM, HDM 1st ELEMENT, mag heading
    TinyGPSCustom hdg(gps, "ECVHW", 3); // HDG, VHW 3RD ELEMENT, mag Heading
    TinyGPSCustom bsp(gps, "ECVHW", 5); // BSP, VHW 5th ELEMENT, Boatspeed
    TinyGPSCustom aws(gps, "ECVWR", 3); // AWS, VWR 3rd ELEMENT, Apparent Wind Speed
    TinyGPSCustom dbt(gps, "ECDBT", 1); // DBT, DBT 1st ELEMENT, Depth Below Transducer
    TinyGPSCustom totlog(gps, "ECVLW", 1); //
    TinyGPSCustom currlog(gps, "ECVLW", 3); //
    TinyGPSCustom rot (gps, "ECROT", 1); // ROT, ROT 1st ELEMENT, Rate of Turn in degrees per second
    TinyGPSCustom rud (gps, "ECXDR", 18); // RUDDER, XDR 18th ELEMENT, Rudder position in degrees

    //TinyGPSCustom aws(gps, "IIVWR", 3); // AWS, VWR 3rd ELEMENT, Apparent Wind Speed
    //TinyGPSCustom twa (gps, "IIVWT", 1); // TWA, VWT 1st ELEMENT, True Wind Angle NKE and B&G //change to MWV
    TinyGPSCustom mtw(gps, "ECMTW", 1); // MTW, MTW 1st ELEMENT, Water Temp NKE, B&G

    int targetSpeedAVG = 0; //0 sets to actual speed, 1 sets to targets
    String RorL; //conversion character for wind direction Right or Left of bow
    String awa; // Apparent Wind Angle
    String gpstime; //time from GPS
    float lng2; //Longitude in HH.mmmm format
    int twaInt = 0; //True Wind Angle *100
    int twsInt = 0; //True Wind Speed *100
    float twsFloat2 = 0; //True Wind Speed fractional for exp records
    int awaInt = 0; //AWA*100 in degrees
    int bspInt = 0; //Boatspeed*100 in Kts
    long cogMag = 0; //COG in degrees MAG
    int sogInt = 0; //SOG*100
    int cogInt = 0; //Course Over Ground inDegrees
    String sogTmp = 0; //Speed Over Ground as a string
    String bspTmp = 0; //Boatspeed as a string
    int dbspInt = 0; //difference between BSP and SOG in 1/100 kt
    int hdmInt = 0; //Magnetic Heading in degrees
    int leeway = 0; //Leeway in degreees
    int dhdmInt = 0; //difference between heading and COG
    int awaPrev = 0;
    int twaPrev = 0;
    int magVar = 0; //Magnetic Variation derived by GPS or manually input
    int volts = 0; //v12 System Voltage
    int awsInt = 0;
    //////////

    ///////polar record check setup/////
    float TWSUpperBoundary = 0;
    float TWAUpperBoundary = 0;
    float TWALowerBoundary = 0;
    float TWSLowerBoundary = 0;
    int ValidPolarRecCtr = 0;
    int IsPolarRec = 0;
    ///////////configurables ///////////
    float TWSRange = 2.0; //allowable range of TWS to qualify as stable
    float TWARange = 2.0; //allowable range of TWA to qualify as stable
    int ValidPolarRecMin = 5; //number of sequential records which meet the TWxRange requirements
    //////////

    ///////tackscore setup///////////
    int postCounterInit = 50; //determine how many cycles after the tack to track loss. (B&G H2000 should be 20, for 38 secconds. NKE and Expedition should be 30)
    int tackIndex = 9; //current array index to load /started at 15 ///changedd to 9 for B&G //15 for expedition //sets the number of cycles prior to a tack to track loss. This + postcounierinit create the total cycles..
    int prevTackIndex = 8; //prevoius index // started at 14 //always -1 from ti
    int tackPoint = 0; //index to the tack trigger
    int postCounter = 0; //number of records to count post tack, remainder will be per tack
    long targetDist = 0; //benchmark distance traveled
    long targetAngle = 30;
    int tackScore = 9; //rating for the tack.
    int ktConv = 1688; //kts to feet conversion factor
    long duration = 1; //time between BSP measurments
    long prevMillis = millis();// counter for time between sentences
    int currBoard = 0; //are we on port(0) or starboard(1)
    int avgDistCounter = 0; //array index for distance averageing
    int avgAngleCounter = 0; //array index for AWA averaging
    long avgDist = 0; //average distance per period pre tack
    long avgSpeed = 000; //average distance per period pre tack
    int avgAngle = 20;
    long targetSpeed = 0;
    long preDistTot = 0; //distance covered for period seconds prior to the tack
    long preTimeTot = 0; //time covered for period seconds prior to the tack
    long preLaneTot = 0; //distance to weather/ leward before tack
    long tackDist = 0; //distance covered for the 15 seconds after the tack
    long tackTime = 0; //time covered for the 15 seconds after the tack
    long tackLane = 0; //
    int deltaAngle = 0;
    long distLost = 0; //distance lost in the tack
    long angleLost = 0;
    long laneLost = 0;
    int activeTack = 0;
    int targetBSPOld = 0;
    int targetBSPAvg = 0;
    int targetBSP = 0;
    long finalForward = 0;
    int finalGage = 1;
    long tempLane = 0;
    int finalLane = 0;
    int targetTWA = 0;
    int heelArray[36] = {
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
    };
    long sinArray[38] = {
    0, 174, 348, 523, 697, 871, 1045, 1219, 1392, 1564, 1736, 1908, 2079, 2249, 2419, 2588, 2756, 2924, 3090, 3256, 3420, 3584, 3746, 3907, 4067, 4383, 4539, 4694, 4848, 5000, 5150, 5300, 5446, 5591, 5735, 6100, 6500, 7200
    };
    int bspArray[36] = {
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
    };
    int awaArray[36] = {
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
    };
    int twaArray[36] = {
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
    };
    int hdmArray[36] = {
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
    };
    int distArray[36] = {
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
    };
    long laneArray[36] = {
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
    };
    int RorLArray[36] = {
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
    };
    int timeArray[36] = {
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
    };
    ///////////FUJIN Target Tables//////
    //true wind speed comment for spreadhseet inport,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17 ,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,3 4,35,36,37,
    long targetBSPArrayUP[38] = {0, 100, 200, 300, 410, 490, 570, 645, 720, 770, 820, 865, 910, 965, 1030, 1070, 1100, 1225, 1350, 1380, 1410, 1430, 1450, 1430, 1410, 1440, 1480, 1530, 1580, 1600, 1620, 1620, 1620, 1620, 1620, 1620, 1620, 1620};
    int targetTWAArrayUP[38] = {45, 49, 49, 49, 49, 49, 48, 47, 47, 46, 45, 44, 44, 45, 45, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49};
    long targetBSPArrayDN[38] = {0, 100, 200, 300, 460, 565, 670, 750, 810, 860, 910, 1000, 1070, 1220, 1350, 1520, 1700, 1925, 2150, 2200, 2230, 2360, 2480, 2540, 2590, 2640, 2730, 2810, 2870, 2920, 3030, 3100, 3210, 3280, 3300, 3365, 3400, 3510};
    int targetTWAArrayDN[38] = {130, 130, 133, 138, 134, 135, 136, 138, 140, 142, 143, 141, 140, 138, 136, 134, 133, 132, 131, 132, 134, 135, 136, 138, 140, 140, 140, 141, 141, 141, 141, 141, 141, 135, 141, 135, 145, 145};
    //////////

    ///////////////big table /////
    int cosArray[92] = {
    10000, 9998, 9994, 9986, 9976, 9962, 9945, 9925, 9903, 9877, 9848, 9816, 9781, 9744, 9703, 9659, 9613, 9563, 9511, 9455, 9397, 9336, 9272, 9205, 9135, 9063, 8988, 8910, 8829, 8746, 8660, 8572, 8480, 8387, 8290, 8192, 8090, 7986, 7880, 7771, 7660, 7547, 7431, 7314, 7193, 7071, 6947, 6820, 6691, 6561, 6428, 6293, 6157, 6018, 5878, 5736, 5592, 5446, 5299, 5150, 5000, 4848, 4695, 4540, 4384, 4226, 4067, 3907, 3746, 3584, 3420, 3256, 3090, 2924, 2756, 2588, 2419, 2250, 2079, 1908, 1736, 1564, 1392, 1219, 1045, 872, 698, 523, 349, 175, 0
    };
    int polarSpeed = 1;
    float polarBsp = 0;
    float polarBspAvg = 0;
    int ploarBspInt = 0;
    float polarArray [36][182];
    ///////////

    ////////////serial attached display variables//////////
    int displayMode = 0;
    boolean topButton = 0;
    int maxDisplays = 3;
    int statMsg = 0;
    int XDRMsg = 1;
    int reEntry = 0;
    //

    /////////tuneables read from SD file SETTINGS.TXT//
    String settingHeader = "upstg"; //header to check if serial input is a update to the settings file
    int baroffset = 0; //baro pressure offset. each 100 is 1 or reading //newer sensor
    int twsCorrectorUP = 100; //upwind tagget windspeed factor (as a percent)
    int twsCorrectorDN = 100; //downind tagget windspeed factor (as a percent)
    int targetSpeedMultiplier = 100; //target boatspeed factor (as a percent)
    int heelCorrector = 0; //corrector for install alighnement on heel sensor
    int pitchCorrector = 0; //corrector for install alignment for pitch sensor
    //

    /////////system configuration option defaults. changes are read from SD file SETTINGS.TXT during setup.//
    int NMEAPlay = 1; //echo the input stream to console
    int Expedition = 1; //write expedition records (use in conjunction with directlog for SD logging)
    int expFreq = 2; //number of data cycles per expedition record write
    int Sensor = 0; //use the external sensors (must be on for barometer)
    int Barometer = 0; //use the barometer
    int paddleSelector = 2; //enable the selector relay
    int flightDetector = 0; //enable the saildrive pressure transucers
    int directLog = 1; //create expedition records and write them directly to the SD card
    int startNo = 1; //default system restart number for the syslog file
    int tackScoreData = 1; // turn on tackscore sentences. Reduces the number of pressure and pitch readings as we run out of 0183 room on serial1
    int localDisplay = 0; //turn on the display attached to Serial2. Serial2 is disabled if the serverON=1;
    int serverON = 1; //enable the web server
    int nmeaSimulator = 0; //reads nmae0183 data from SD card instead of from Serial1. turns off expedition, sensors, directlog and paddleselector.
    int wiFly = 0; //reads nmea0183 data from SD card instead of from Serial1. turns off expedition, sensors, directlog and paddleselector.
    int dotTrgtAvg = 1; //simple averge for dot target display
    int flightHost = 1; //is this system a host for flight mode or a dot client
    int v24Record = 1; // 24v voltage recording
    int v12Record = 1; // 12v voltage recording
    int NMEALog = 0; ///////// enables writing S1 NMEA source to SD
    float boardHeight = 0; // Just what the tin says it is
    float travPos = -2; // Just what the tin says it is
    String activeSail = "500"; // Just what the tin says it is
    int activeSailCode = 500; //
    int s3PIXComm = 0; //turn on S3 comm for PIX sentences
    int s1PIXComm = 0; //turn on S1 comm for PIX sentences
    int s0PIXComm = 0; //turn on console comm for PIX sentences
    int s1NMEAComm = 1;
    int s3NMEAComm = 1; //turn on s3 OUT for NMEA
    int PIXGenerate = 0; //generate PIX Sentences, don't forget to select ports
    int s0XDRComm = 0;
    int s1XDRComm = 0;
    int s3XDRComm = 1;
    ////

    /////////////// Microsoft time format for expedition record variables.//
    //Defaults for hen RTC fails ///
    long LeapDays = -1; //corrector for number of leap days since 1900 (-1000 is a test value)
    long Day = 02; //Default value for day
    long Month = 03; //default value for month, SET TO ZERO to trigger Expedition COLE time set from GPS on start
    long Year = 2014;
    float Hour = 18;
    float Minute = 00;
    float Second = 01;
    int secondinc = 11;
    long fakeSecond = 0;
    long fakeSecondPrev = 0;
    /// Time Conversion Multipliers for RTC values///
    float ctsHours = 41666.6667; //ColeTime fractional per hour
    float ctsMinutes = 694.4444; //Cole Time fractional per minute
    float ctsSeconds = 11.579; //Cole Time fractional per Second
    long ColeTimeYear = 0; //resultant year component
    double ColeTimeSecond = 0; // resultant time component
    ///

    /// Expedition write record variables /////////
    String expRecord2 = (",,,,,,,,,,,,,,,,,"); // 17 commas accomidates 5 tackdistfields
    unsigned long ExpDelay = 0;
    int ExpReady = 0;
    ///

    ///flight sensor setup///////
    int isReadyToFly = 0; //Indicates whether flight is capable
    int isReadyMode = 1; //mode for evaluating flight (1=bsp,2=tws,3=both,4=either)
    int isReadyToFlyFlag = 0; //sets IRTF condition loop
    int isInFlight = 0; // final determinor for flight
    int isInFlightRange = 200; //allowable difference in pressure before inflight is set
    int bspFlightMin = 2000; //minimum speed for flight detection in 1/100th of a kt
    int twsFlightMin = 2000; //minimum windspeed for flight in 1/10 kt
    int isReadyToFlySignal = 23; //Signal line to Pressures Sensor indicating flight conditions
    int isInFlightSignal = 22; //Signal Line from Pressure Sensor indicating flight
    int flightPressCorrector = 9400; //corrects the ATMOS sesor to equal the Drive Sesnor statically
    int flightPressDrive = 0; //pressure in drive tube
    int flightPressDiff = 0; //difference between drive and atmos (D-A)
    int flightPressAtmos = 0; //pressure std atmosphere
    //int flightGain = 0; //allowable difference in the 2 pressure sensors
    int BMPSelector = 20; //pin for BMP mux
    //int neoMinTargetRange = 20; //Total range of display (eg..20 represents 80 to 100 % of target
    ////

    /////IMU Variables/////////
    //Barometer and Temp Sensor Values///
    short temperature;
    short tempold;
    long pressure = 100000;
    long pressureold = 100000;
    // Use these for altitude conversions
    const float p0 = 102725; // Pressure at sea level (Pa)
    float altitude;

    ///////////////ADXL045 accelerometer startup values//
    byte _buff[6];
    char POWER_CTL = 0x2D; //Power Control Register
    char DATA_FORMAT = 0x31;
    char DATAX0 = 0x32; //X-Axis Data 0
    char DATAX1 = 0x33; //X-Axis Data 1
    char DATAY0 = 0x34; //Y-Axis Data 0
    char DATAY1 = 0x35; //Y-Axis Data 1
    char DATAZ0 = 0x36; //Z-Axis Data 0
    char DATAZ1 = 0x37; //Z-Axis Data 1
    int16_t xold; //averaging value for x
    int16_t yold; //averaging value for y
    int16_t zold; // offset value for z
    int16_t x; //heel variable
    int16_t y; //pitch
    int16_t z; //wave height
    double pitch;
    double roll;
    //// Declare the BMP object////////
    Adafruit_BMP085 bmp;
    //////

    ////BUTTON OBJECT////////////
    //bButton button = Button(3, BUTTON_PULLDOWN); // Declare the Button object
    ///////

    void setup() {
    ///UART Port Initialization and setup//////////
    Serial.begin(57600); // Console output
    Serial1.begin(4800); // primary NMEA input and output port
    //Serial2.begin(19200); // display (if attached)
    Serial3.begin(4800); //output port to SD logging server
    ///
    delay(2000);
    /////I/O Pin setup for flight, paddle and voltage monitoring ////
    if (flightHost == 1) pinMode(23, OUTPUT); //Ready to Fly Signal to Drive Pressure Monitor
    digitalWrite(23, LOW); //Default to LOW
    if (paddleSelector != 1) pinMode(22, INPUT); //Is In Flight Signal from Drive Pressure Monitor
    else pinMode(22, OUTPUT);
    if (v12Record == 1)pinMode(v12Signal, INPUT); //v12 monitor from voltage divider.
    if (v24Record == 1) pinMode(v24Signal, INPUT); //v24 monitor from voltage divider
    if (flightDetector == 1) pinMode(BMPSelector, OUTPUT); //MUX selector pin for BMP's
    //

    //Dot Array start ////////
    //strip.begin(); // Initialize pins for output
    //strip.show(); // Turn all LEDs off ASAP
    ///

    /////I/O Pin setup, Enet Reset and SD Select Initializationp//
    pinMode(9, OUTPUT);
    digitalWrite(9, LOW); // begin reset the WIZ820io
    pinMode(10, OUTPUT); //setup CS for 5100
    digitalWrite(10, HIGH); //Enet disable
    pinMode(4, OUTPUT);
    digitalWrite(4, HIGH); // de-select the SD Card
    digitalWrite(9, HIGH); // end reset pulse
    //

    ///IP setup///////////////
    byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xEC };
    // IPAddress ip( 192,168,5,10 ); // AJ5 Network(hamachi main router)
    // IPAddress ip( 192,168,9,10 ); // AJ9 Network(new blue TPLink//
    // IPAddress gateway( 192,168,5,254 ); // hamachi tplink router
    IPAddress ip( 192, 168, 8, 10 ); // GC114 White Router//
    IPAddress gateway( 192, 168, 8, 1 ); // GC114 ROUTER
    IPAddress subnet( 255, 255, 0, 0 );
    const char legalChars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890/.-_~";
    unsigned int requestNumber = 0;
    //

    //////SD Card Start////
    SD.begin(4);
    digitalWrite(10, LOW); //Enet disable
    //

    //////ethernet start //
    if (serverON == 1)
    {
    Ethernet.begin(mac, ip, gateway, gateway, subnet);
    server.begin();
    int loopCount = 0;
    }
    ///

    ///Get Configurables from SD card////////////
    delay(1000);
    Serial.print(verstring);
    Serial.println(" Reading Setup Paramaters from SD card. to view anytime type rdstg into console ");
    HumanTime();
    delay(1000);
    //logStart();
    delay(1000);
    readSDSettings();
    logConfig();
    logStart();
    //if (localDisplay == 1) displayStart() ;
    if (paddleSelector == 1) Serial.print(" Boatspeed paddle selector is ON. port sensor is failover digital 22 on relay 1 digital 23 on relay 2 ,");
    if (paddleSelector == 2) Serial.print(" Remote flight signals are ON digital 22 and dgital 23,");
    if (NMEAPlay == 1) Serial.print(" NMEA Play to console is ON, ");
    if (Sensor == 1) Serial.print(" Heel/Pitch sensor is ON, ");
    if (Expedition == 1) Serial.print(" Expedition Record out S3 is ON, ");
    #ifdef CSVDEBUG
    Serial.print(" CSV output diagnostic mode is ON,");
    #endif
    #ifdef DEBUG
    Serial.print(" Expedition formatted record output to console is ON, ");
    #endif
    #ifdef serverDEBUG
    Serial.print(" General Debug verbose mode is ON, ");
    #endif
    #ifdef distanceDEBUG
    Serial.print(" Distance Debug verbose mode is ON, ");
    #endif
    #ifdef guageDEBUG
    Serial.print(" Gage Debug verbose mode is ON, ");
    #endif
    #ifdef EPO
    Serial.print(" Loaded as EPO Server, ");
    #endif
    #ifdef TackScore
    Serial.print(" Loaded as TackScore display, ");
    #endif
    #ifdef instNKE
    Serial.print(" NKE instrunent profile loaded, ");
    Serial2.println(" NKE profile loaded ");
    #endif
    #ifdef instBG
    Serial.print(" B&G instrunent profile loaded, ");
    Serial2.println(" B&G profile loaded ");
    #endif
    ///////Start the I2C Buss////
    Wire.begin(); // join i2c bus (address optional for master)
    startSensors();
    listHelp();
    Serial.println(" .....Initialization Complete. Initiating NMEA Processing");
    #ifdef CSVDEBUG
    Serial.println("Recnum,tackIndex,aDC,pressure,tws, twa,twaPrev,twaint,targetTWA,bspint,sogint,hdmint, cogmag,ktConv,duration,TAti,diArTemp,DAti,TAadc,av gDsttmp,avgdist,BSPadc,avgspeedtmp,DAadc,avgDist,a vgSpeed,twsint,twsintreduced,targetBSP,targetBSPav g,delimiter,TWA,TWAti,TWAadc,AWA,AWAti,AWAadc,avga ngle,deltaangle,SINda,templane,templanesign,LAti,L Aadc,prelanetot,predisttot,pretimetot,postcounter, currboard,finalforward,finalLane,tacktime,tackdist ,finalforward,tacklane,targetspeed,targetdist");
    #endif
    dotSplash();
    checkVoltage24();
    checkVoltage12();
    ReadExpPolarFile();
    ShowPolar();

    } //end of setup
    void loop() {
    if (serverON == 1) checkServer();

    while (Serial1.available() > 0) { //Port 1 Has Instruments
    char recieved = Serial1.read();
    charcount = charcount + 1;
    gps.encode(recieved);
    inData += recieved;
    if (recieved == '\n') // Process message when new line character is recieved
    { //begin by checking sentence for gross errors////
    //Serial.print(inData);
    String nmeaheader = inData.substring(1, 6);
    String checkchar = (inData.substring(charcount - 5, charcount - 4));
    if (checkchar != starcheck)
    {
    inData = "";
    }
    else
    {
    String checkhdr = (inData.substring(0, 3));
    if (checkhdr == "A")
    {
    inData = "";
    }
    ///////////passed error testing, proceed with processing /////
    else if (nmeaheader == "SDDPT" || nmeaheader == "IIDPT" || nmeaheader == "ECDPT")
    {
    if (Barometer == 1) readPressure();
    inData = "";
    }
    else if (nmeaheader == "IIPIX")
    {
    if (flightDetector == 1)
    {
    processPIX();
    checkFlight();
    }
    inData = "";
    }
    else if (nmeaheader == "SDROT" || nmeaheader == "IIROT" || nmeaheader == "ECROT")
    {
    if (PIXGenerate == 1); checkFlight();
    if (v24Record == 1)checkVoltage24();
    if (v12Record == 1)checkVoltage12();
    }
    else if (nmeaheader == "SDHDG" || nmeaheader == "IIHDG" || nmeaheader == "ECHDG") inData = "";
    else if (nmeaheader == "IIMTW" || nmeaheader == "IIMTW" || nmeaheader == "ECMTW") inData = "";
    else if (nmeaheader == "IIZDA" || nmeaheader == "IIZDA" || nmeaheader == "ECZDA") inData = "";
    else if (nmeaheader == "SDHDT" || nmeaheader == "IIHDT" || nmeaheader == "ECHDT")
    {
    if (tackScoreData == 1) XDRSend();
    if (polarSpeed == 1) getPolarBsp();
    }
    else if (nmeaheader == "GPVTG" || nmeaheader == "IIVTG" || nmeaheader == "ECVTG") processVTG();
    else if (nmeaheader == "IIVWT" || nmeaheader == "IIVWT" || nmeaheader == "ECVWT")
    {
    processVWT();
    if (PIXGenerate == 1); checkFlight();
    }
    else if (nmeaheader == "SDVHW" || nmeaheader == "IIVHW" || nmeaheader == "ECVHW")
    {
    processVHW();
    if (PIXGenerate == 1); checkFlight();
    if (tackScoreData == 1) TackScore(); //create score for every BSP
    }
    else if (nmeaheader == "GPGLL" || nmeaheader == "IIGLL" || nmeaheader == "ECGLL")
    {
    processGLL();
    ExpDelay = ExpDelay + 1;
    if (PIXGenerate == 1); checkFlight();
    if (ExpDelay >= 1) ExpReady = 1; //wait for enough data to fill records
    if (ExpReady = 1)
    {
    if (expCtr2 == expFreq)
    {
    LogExpeditionInfo();
    //Serial.println("Exp Record Written");
    }
    expCtr2 = expCtr2 + 1;
    }
    }
    else if (nmeaheader == "WIMWV" || nmeaheader == "IIMWV" || nmeaheader == "ECMWV")
    {
    processMWV();
    if (PIXGenerate == 1); checkFlight();
    }
    } //end sentence selection
    if (s1NMEAComm == 1) //Serial1.print(inData);
    if (NMEALog == 1)
    {
    digitalWrite(13, HIGH);
    myFile = SD.open("NMEALOG.txt", FILE_WRITE);
    myFile.print(inData);
    myFile.close();
    digitalWrite(13, LOW);
    }
    if (NMEAPlay == 1) Serial.print(inData);
    if (s3NMEAComm == 1) Serial3.print(inData);
    inData = "";
    charcount = 0;// end valid indata section
    NMEAin = NMEAin + 1;
    } // end \n (newline eval
    } // end while serial1 available
    ////////

    while (Serial3.available() > 0) {
    char recieved3 = Serial3.read();
    inData3 += recieved3;
    if (recieved3 == '\n') // Process message when new line character is recieved
    {
    if (statMsg == 1) Serial.print("s3 Message: ");
    if (statMsg == 1) Serial.print(inData3);
    myFile = SD.open("syslog.txt", FILE_WRITE);
    myFile.print("s3 message: ");
    myFile.print(inData3);
    myFile.close();
    inData3 = ""; // Clear recieved buffer
    } //end S3 input
    }
    ////////

    //console in port ///////////
    while (Serial.available() > 0) {
    char recieved2 = Serial.read();
    inData2 += recieved2;
    if (recieved2 == '\n') // Process message when new line character is received
    {
    if (statMsg == 1)
    {
    Serial.print("recieved a command input: ");
    Serial.println(inData2);
    }
    String hdrChk = inData2.substring(0, 5);
    //Serial.println(hdrChk);
    if (hdrChk == settingHeader) WriteSettings();
    else if (hdrChk == "setti") ReadSettings();

    else if (hdrChk == "$ECRT")
    {
    if (statMsg == 1) Serial.println("RTE Recieved");
    Serial1.print(inData2);
    }
    else if (hdrChk == "$ECWP")
    {
    if (statMsg == 1) Serial.println("WPL Recieved");
    Serial1.print(inData2);
    }
    else if (hdrChk == "$ECBW")
    //$ECBWC
    {
    Serial1.print(inData2);
    int commaloc = inData2.indexOf(',');
    int commaloc2 = inData2.indexOf(',', commaloc + 1);
    int commaloc3 = inData2.indexOf(',', commaloc2 + 1);
    int commaloc4 = inData2.indexOf(',', commaloc3 + 1);
    int commaloc5 = inData2.indexOf(',', commaloc4 + 1);
    int commaloc6 = inData2.indexOf(',', commaloc5 + 1);
    int commaloc7 = inData2.indexOf(',', commaloc6 + 1);
    int commaloc8 = inData2.indexOf(',', commaloc7 + 1);
    int commaloc9 = inData2.indexOf(',', commaloc8 + 1);
    int commaloc10 = inData2.indexOf(',', commaloc9 + 1);
    int commaloc11 = inData2.indexOf(',', commaloc10 + 1);
    markMag = inData2.substring(commaloc8 + 1, commaloc9);
    if (statMsg == 1) Serial.print ("Mark Dir Mag: "); Serial.print(markMag);
    markDist = inData2.substring(commaloc10 + 1, commaloc11);
    if (statMsg == 1) Serial.print (" Mark Dist NM: "); Serial.println(markDist);
    String markDistFloat = String(markDist.toFloat() * 100, 5);
    //markDistInt = mkFloat.toInt();
    String markFloat = String(markMag.toFloat(), 3);
    int markInt = markFloat.toInt();
    markDistInt = markDistFloat.toInt();
    }
    //
    else if (hdrChk == "sed-s") ReadSettings();
    else if (hdrChk == "sed-l") ReadLog();
    else if (hdrChk == "sed-f") ReadExpeditionLog();
    else if (hdrChk == "sed-p") ReadExpPolarFile();
    else if (hdrChk == "rdsdc") listSD();
    else if (hdrChk == "rmNME") rmNMEALog();
    else if (hdrChk == "ls -l") listSD();
    else if (hdrChk == "ls -p") ShowPolar();
    else if (hdrChk == "statu") sysStatus();
    else if (hdrChk == "echoo") NMEAPlay = 1;
    else if (hdrChk == "nmeao") NMEAPlay = 1;
    else if (hdrChk == "noisy") NMEAPlay = 1;
    else if (hdrChk == "nomsg") statMsg = 0;
    else if (hdrChk == "msgon") statMsg = 1;
    else if (hdrChk == "-help") listHelp();
    else if (hdrChk == "quiet") NMEAPlay = 0;
    else if (hdrChk == "nonme") NMEAPlay = 0;
    else if (hdrChk == "press") readPress();
    else if (hdrChk == "fligh") checkFlight();
    else if (hdrChk == "dimme") dotDim();
    else if (hdrChk == "toggl") dotToggle();
    else if (hdrChk == "brigh") dotBright();
    else if (hdrChk == "clear") dotClear();
    else if (hdrChk == "polar") getPolarBsp();
    else if (hdrChk == "dotpo") dotMode = 3;
    else if (hdrChk == "dotta") dotMode = 1;
    else if (hdrChk == "dottw") dotMode = 2;
    else if (hdrChk == "dotde") dotMode = 4;
    else if (hdrChk == "rdybs") isReadyMode = 1;
    else if (hdrChk == "rdytw") isReadyMode = 2;
    else if (hdrChk == "rdybo") isReadyMode = 3;
    else if (hdrChk == "rdyei") isReadyMode = 4;
    else if (hdrChk == "ifcon") ShowIpInfo();
    else if (hdrChk == "expre") ShowExpeditionInfo();
    //else Serial.println("Bad Command");
    inData2 = ""; // Clear recieved buffer
    } //end NL
    }///while serial inout string available
    } //end void loop

    ///////////
    // Expedition Record Write output ///
    ///////////
    void LogExpeditionInfo() {
    // digitalWrite(13, HIGH); //signal to show a write is taking place
    tmElements_t tm;
    RTC.read(tm);
    ColeTimeYear = ((((tm.Year) + 70) * 365) + ((tm.Month) * 30) + (tm.Day) + LeapDays);
    ColeTimeSecond = (((tm.Hour * 3600) + (tm.Minute * 60) + tm.Second) * 11.57407);
    fakeSecond = (long)ColeTimeSecond;
    if (Expedition == 1)
    {
    if (wiFly == 2)
    {
    s3expRecord();
    }
    }
    //digitalWrite(13, LOW);
    #ifdef ServerDEBUG
    Serial.print(" And Expedition Record ");
    Serial.print(ExpDelay);
    Serial.println(" Was Sent ");
    #endif

    if (directLog == 1)
    {
    int cTimeInt = fakeSecond * .0001;
    String timeCode;
    if (cTimeInt > 75) timeCode = "D";
    else if (cTimeInt > 50) timeCode = "C";
    else if (cTimeInt > 25) timeCode = "B";
    else timeCode = "A";
    String cDate = String(ColeTimeYear);
    logFileStringPrev = logFileString;
    logFileString = cDate + timeCode + logFileExt;
    if (logFileStringPrev != logFileString) {
    myFile = SD.open("syslog.txt", FILE_WRITE);
    myFile.print(" Expedition Log File ");
    myFile.print(logFileString);
    myFile.println(" now active ");
    myFile.close();
    }
    logFileString.toCharArray(logFile, 13);
    myFile = SD.open(logFile, FILE_WRITE);
    myFile.print(ColeTimeYear);
    myFile.print(".");
    if (fakeSecond > 1000000)
    {
    fakeSecond = 10;
    ColeTimeYear = ColeTimeYear + 1;
    } //backstop to an end of day miss
    if (fakeSecond < 100000) { //this set of statements backfills the second with leading zeros//
    if (fakeSecond < 10000) {
    if (fakeSecond < 1000) {
    if (fakeSecond < 100) {
    if (fakeSecond < 10) {
    myFile.print("0");
    }
    myFile.print("0");
    }
    myFile.print("0");
    }
    myFile.print("0");
    }
    myFile.print("0");
    }
    myFile.print(fakeSecond); //print the int second value
    myFile.print(F(","));
    myFile.print(bsp.value()); //boatspeed from II tiny
    myFile.print(F(","));
    myFile.print(RorL); //port is negative
    myFile.print(awaInt); //Apparent Wind Angle from II tiny
    myFile.print(F(","));
    myFile.print(awsInt); //Apparent Wind Speed from II tiny
    myFile.print(F(","));
    myFile.print(RorL); //port is negative
    myFile.print(twaInt); //Right or Left of bow (- or nothing), TWA from Tiny
    myFile.print(F(","));
    myFile.print(twsFloat2/100); //True Wind Speed from Tiny
    myFile.print(F(","));
    myFile.print(twd.value()); //True Wind Direction from II tiny
    myFile.print(F(",,,,")); //EXP COMMAS
    myFile.print(F(","));
    myFile.print(hdm.value()); //mag heading
    myFile.print(F(","));
    myFile.print((temperature)); //air temp
    myFile.print(F(","));
    myFile.print(mtw.value()); //water temp
    myFile.print(F(","));
    myFile.print(((pressure)*.01), 1); //Baro pressure
    myFile.print(F(","));
    myFile.print(dbt.value()); //depth
    myFile.print(F(","));
    myFile.print(roll, 1); // Heel
    myFile.print(F(","));
    myFile.print(pitch, 1); //trim
    myFile.print(F(","));
    myFile.print(rud.value()); //rudder
    myFile.print(F(",,,,,,,,,")); //9 EXP COMMAS
    myFile.print(F(","));
    myFile.print(volts); //voltage calculated from BMS
    myFile.print(F(","));
    myFile.print(rot.value()); //rate of turn
    myFile.print(F(",,,,,,,,")); //8 EXP COMMAS
    myFile.print(lat2, 6); //latitude
    //myFile.print(latDDTmp);
    //myFile.print(latMMfinal);
    myFile.print(F(",")); //corrected to make lng always negative, change if you go to the med or Japan!
    myFile.print(lng2, 6); //longitude
    myFile.print(F(","));
    myFile.print(cogMag); //Course over Ground
    myFile.print(F(","));
    myFile.print(sog.value()); //Speed over Ground
    myFile.print(F(",,,,,,"));
    myFile.print(travPos); //Traveler position (neg is to weather)
    myFile.print(F(",,,,,,,,"));
    //myFile.print(F(",,,,,,,,,,,,,,"));
    myFile.print(boardHeight); //Board Height
    myFile.print(F(",,,,,"));
    myFile.print(ColeTimeYear); // represnets days since 1900
    myFile.print(".");
    if (fakeSecond > 1000000) {
    fakeSecond = 10;
    ColeTimeYear = ColeTimeYear + 1;
    } //backstop to an end of day miss
    if (fakeSecond < 100000) { //this set of statements backfills the second with leading zeros//
    if (fakeSecond < 10000) {
    if (fakeSecond < 1000) {
    if (fakeSecond < 100) {
    if (fakeSecond < 10) {
    myFile.print("0");
    }
    myFile.print("0");
    }
    myFile.print("0");
    }
    myFile.print("0");
    }
    myFile.print("0");
    }
    myFile.print(fakeSecond); //print the int second value
    myFile.print(expRecord2); //17 additional commas //User1
    myFile.print(",,,,");
    myFile.print(activeSailCode); //active sail //User6
    myFile.print(",");
    myFile.print(polarBsp); //POLAR BSP //User7
    myFile.print(F(","));
    myFile.print(ExpDelay); //record number since starting //User8
    myFile.print(F(","));
    myFile.print(totlog.value()); //total miles in b&G log //User9
    myFile.print(F(","));
    myFile.print(currlog.value()); //current miles in B&G Log. //User10
    myFile.print(F(","));
    myFile.print(finalForward); //distance accumulated in the tack //user 11
    myFile.print(F(","));
    myFile.print(finalLane); //final Lane sag //user 12
    myFile.print(F(","));
    myFile.print(preDistTot / 100); //pre tack distance //user 13
    myFile.print(F(","));
    myFile.print(preLaneTot); //current guage +/- //user 14
    myFile.print(F(","));
    myFile.print(targetBSP / 10); //calculated target BSP, //user 15
    myFile.print(F(","));
    myFile.print(postCounter); //Duration counter for a tack //user 16
    myFile.print(F(","));
    myFile.print(targetTWA); //target TWA for a tack //user 17
    myFile.print(F(","));
    myFile.print(markDist); //mark distance //user 18
    myFile.print(F(","));
    myFile.print(markMag); //target bearing //user 19
    myFile.print(F(","));
    myFile.print(whichPixelR); //red target pixel //user 20
    myFile.print(F(","));
    myFile.print(whichPixelG); //green target pixel //user 21
    myFile.print(F(","));
    myFile.print(whichPixelB); //blue target pixel //user 22
    myFile.print(F(","));
    myFile.print(isReadyToFly); //flight conditions met //user 23
    myFile.print(F(","));
    myFile.print(isInFlight); //in flight //user 24
    myFile.print(F(","));
    myFile.print(v12Actual); //12v voltage //user 25
    myFile.print(F(","));
    myFile.print(v12Pct); //12v state of charge //user 26
    myFile.print(F(","));
    myFile.print(v24Actual); //24volt Voltage //user 27
    myFile.print(F(","));
    myFile.print(v24Pct); //24v Percent of Charge //user 28
    myFile.print(F(","));
    myFile.print(IsPolarRec); //is thia a polar eval record //user 29
    myFile.print(F(","));
    myFile.print(ValidPolarRecCtr); //number of sequential eval records //user 30
    myFile.print(F(",,,,,,,,,,,"));
    myFile.println((z - 119)); // z axis of accelerometer "motion" field
    myFile.close();
    expCtr2 = 0;
    }
    #ifdef ServerDEBUG
    Serial.print(" And Expedition Record ");
    Serial.print(ExpDelay);
    Serial.println(" Was Sent ");
    #endif
    }
    ///////////
    // HEEL, PITCH, SLAM BARO and temp sensor reads ///
    ///////////
    void readSensors() {
    uint8_t howManyBytesToRead = 6;
    readFrom( DATAX0, howManyBytesToRead, _buff); //read the acceleration data from the ADXL345
    // each axis reading comes in 10 bit resolution, ie 2 bytes. Least Significat Byte first!!
    // thus we are converting both bytes in to one int
    zold = z;
    x = (((int16_t)_buff[1]) << 8) | _buff[0];
    y = (((int16_t)_buff[3]) << 8) | _buff[2];
    z = (((int16_t)_buff[5]) << 8) | _buff[4];
    x = ((x + xold) / 2);
    y = ((y + yold) / 2);

    //Roll and Pitch to degree Equations
    roll = (atan2(-y, z) * 180.0) / M_PI;
    roll = roll + heelCorrector;
    pitch = (atan2(x, sqrt(y * y + z * z)) * 180.0) / M_PI;
    pitch = pitch + pitchCorrector;
    String PT1 = "$YXXDR,A,";
    String PT2 = ",D,HEEL,A,";
    String PT2P = ",D,HEEL,P,"; String PT3 = ",D,TRIM,*";
    String PT4 = ",D,SLAM,*";
    String PT5 = ",B,BARO,*";
    //Send to the output Stream
    if (XDRCounter == 2) XDRCounter = 0;
    if (XDRCounter == 0)
    {
    // heel and trim
    String XDRSTRING = PT1 + roll + PT2 + pitch + PT3;
    outputMsg(XDRSTRING); // print the entire message string, and append the CRC
    }
    else if (XDRCounter == 2)
    {
    // heel and slam
    String XDRSTRING = PT1 + roll + PT2 + z + PT4;
    outputMsg(XDRSTRING); // print the entire message string, and append the CRC
    }
    else if (XDRCounter == 1)
    {
    //heel and barometer
    float pressure4 = pressure * .01;
    String XDRSTRING = PT1 + roll + PT2P + pressure4 + PT5;
    outputMsg(XDRSTRING); // print the entire message string, and append the CRC
    }
    XDRCounter = XDRCounter + 1;
    xold = x; //averaging
    yold = y; //averaging
    }

    // -----------------------------------------------------------------------
    ///////////
    // Wire write routine for sensors ///
    ///////////
    void writeTo(byte address, byte val) {
    Wire.beginTransmission(DEVICE); // start transmission to device
    Wire.write(address); // send register address
    Wire.write(val); // send value to write
    Wire.endTransmission(); // end transmission
    }

    //////
    // Wire read routine for sensors ///
    //////
    // Reads num bytes starting from address register on device in to _buff array
    void readFrom(byte address, int num, byte _buff[]) {
    Wire.beginTransmission(DEVICE); // start transmission to device
    Wire.write(address); // sends address to read from
    Wire.endTransmission(); // end transmission
    Wire.beginTransmission(DEVICE); // start transmission to device
    Wire.requestFrom(DEVICE, num); // request 6 bytes from device
    int i = 0;
    while (Wire.available()) // device may send less than requested (abnormal)
    {
    _buff[i] = Wire.read(); // receive a byte
    i++;
    }
    Wire.endTransmission(); // end transmission
    }
    //////

    //////
    // Tackscore calcs and output //
    //////
    void TackScore() {
    } //end TackScore
    //////

    //////// XDR user variable sentence creation //
    void XDRSend() {
    String PT10 = "$YXXDR,G,";
    String PT20 = "$YXXDR,U,";
    String PT06 = ",,006,*";
    String PT07 = ",,007,*";
    String PT11 = ",,011,*";
    String PT12 = ",,012,*";
    String PT13 = ",,013,*";
    String PT14 = ",,014,*";
    String PT15 = ",,015,*";
    String PT16 = ",,016,*";
    String PT17 = ",,017,*";
    String PT18 = ",,018,*";
    String PT21 = ",V,025,*";
    String PT26 = ",,026,*";
    String PT24 = ",V,027,*";
    String PT28 = ",,028,*";
    String PT29 = ",,029,*";
    String PT30 = ",,030,*";
    if (XDRCounter2 == 3) XDRCounter2 = 0;
    if (XDRCounter2 == 0)
    {
    String XDRSTRING = PT10 + finalForward + PT11;
    outputMsg(XDRSTRING); // print the entire message string, and append the CRC
    ///user 12, finalane //
    XDRSTRING = PT10 + finalLane + PT12;
    outputMsg(XDRSTRING); // print the entire message string, and append the CRC
    }
    else if (XDRCounter2 == 1)
    {
    if (vctr >= 6) vctr = 0;
    String XDRSTRING = PT10 + postCounter + PT16;
    outputMsg(XDRSTRING); // print the entire message string, and append the CRC
    if ((v12Record == 1) && (vctr == 0)) {
    String XDRSTRING = PT10 + v12Actual + PT21;
    outputMsg(XDRSTRING); // print the entire message string, and append the CRC
    }
    if ((v24Record == 1) && (vctr == 1)) {
    String XDRSTRING = PT10 + v24Actual + PT24;
    outputMsg(XDRSTRING); // print the entire message string, and append the CRC
    }
    if ((v24Record == 1) && (vctr == 2)) {
    String XDRSTRING = PT10 + v24Pct + PT26;
    outputMsg(XDRSTRING); // print the entire message string, and append the CRC
    }
    if ((v12Record == 1) && (vctr == 3)) {
    String XDRSTRING = PT10 + v12Pct + PT28;
    outputMsg(XDRSTRING); // print the entire message string, and append the CRC
    }
    if (vctr == 4) {
    String XDRSTRING = PT10 + travPos + PT29;
    outputMsg(XDRSTRING); // print the entire message string, and append the CRC
    }
    if (vctr == 5) {
    String XDRSTRING = PT10 + activeSailCode + PT06;
    outputMsg(XDRSTRING); // print the entire message string, and append the CRC
    }
    vctr = vctr + 1;
    }
    else if (XDRCounter2 == 2)
    {
    if (sctr == 2)sctr = 0;
    if (sctr == 0) {
    ///user 15, targetBSP //
    float targetBSPFloat = targetBSP;
    targetBSPFloat = targetBSPFloat * .01;
    String XDRSTRING = PT10 + targetBSPFloat + PT15;
    outputMsg(XDRSTRING); // print the entire message string, and append the CRC
    //user 17, targetTWA //
    XDRSTRING = PT10 + targetTWA + PT17;
    outputMsg(XDRSTRING); // print the entire message string, and append the CRC
    }
    else if (sctr == 1) {
    String XDRSTRING = PT10 + polarBsp + PT07;
    outputMsg(XDRSTRING); // print the entire message string, and append the CRC
    //user 17, targetTWA //
    XDRSTRING = PT10 + boardHeight + PT30;
    outputMsg(XDRSTRING); // print the entire message string, and append the CRC
    }
    sctr = sctr + 1;
    }
    XDRCounter2 = XDRCounter2 + 1;
    }
    //////

    //Sends CRC Appended Message ////////////////
    void outputMsg(String msg) {
    msg.toCharArray(CRCbuffer, sizeof(CRCbuffer)); // put complete string into CRCbuffer
    int crc = convertToCRC(CRCbuffer);
    if (XDRMsg == 1) {
    if (s1XDRComm == 1) {
    Serial1.print(msg);
    if (crc < 16) Serial1.print("0");// add leading 0
    Serial1.println(crc, HEX); /////////there used to be serial3 here?????????????
    }
    if (s3XDRComm == 1) {
    Serial3.print(msg); /////////there used to be serial3 here?????????????
    if (crc < 16) Serial3.print("0");// add leading 0
    Serial3.println(crc, HEX);
    }
    if (s0XDRComm == 1) {
    Serial.print(msg);
    if (crc < 16) Serial.print("0");// add leading 0
    Serial.println(crc, HEX);
    }
    }
    }
    //////

    ///creates a CRC and appends to message//////
    byte convertToCRC(char *buff) {
    // NMEA CRC: XOR each byte with previous for all chars between '$' and '*'
    char c;
    byte i;
    byte start_with = 0;
    byte end_with = 0;
    byte CRC = 0;
    byte end_set = 0;
    for (i = 0; i < buff_len; i++) {
    c = buff[i];
    if (c == '$') {
    start_with = i;
    }
    if (c == '*') {

    if (end_set == 0) {
    end_with = i;
    end_set = 1;
    }
    }
    }
    if (end_with > start_with) {
    for (i = start_with + 1; i < end_with; i++) { // XOR every character between '$' and '*'
    CRC = CRC ^ buff[i] ; // compute CRC
    }
    }
    else { // print locations if error
    Serial.println("CRC ERROR");
    Serial.println("CRC ERROR");
    }
    return CRC;
    //based on code by Elimel├ƒ┬ęc L├ƒ┬│pez - July-19th-2013
    }
    //////
    void WriteSettings() {
    int commaloc = inData2.indexOf(',');
    int commaloc2 = inData2.indexOf(',', commaloc + 1);
    int commaloc3 = inData2.indexOf(',', commaloc2 + 1);
    int commaloc4 = inData2.indexOf(',', commaloc3 + 1);
    int commaloc5 = inData2.indexOf(',', commaloc4 + 1);
    int commaloc6 = inData2.indexOf(',', commaloc5 + 1);
    String settingType = inData2.substring(commaloc + 1, commaloc2);
    String settingVal = inData2.substring(commaloc2 + 1, commaloc3);
    myFile = SD.open("settings.txt", FILE_WRITE);
    myFile.print("[");
    myFile.print(settingType);
    myFile.print("=");
    myFile.print(settingVal);
    myFile.println("]");
    myFile.close();
    Serial.print("The settings File has been updated with: ");
    Serial.print(settingType);
    Serial.print(" = ");
    Serial.println(settingVal);
    myFile = SD.open("syslog.txt", FILE_WRITE);
    myFile.print("The settings File has been updated with: ");
    myFile.print(settingType);
    myFile.print("=");
    myFile.println(settingVal);
    myFile.close();
    applySetting(settingType, settingVal);
    }
    //////
    void ReadSettings() {
    Serial.println("Current Server Settings. to update type upstg,var,val, ");
    ShowIpInfo();
    Serial.print("startno: ");
    Serial.println(startNo);
    Serial.print("leapdays: ");
    Serial.println(LeapDays);
    Serial.print("targetspeedmultiplier: ");
    Serial.println(targetSpeedMultiplier);
    Serial.print("twscorrectorup: ");
    Serial.println(twsCorrectorUP);
    Serial.print("twscorrectordn: ");
    Serial.println(twsCorrectorDN);
    Serial.print("heelcorrector: ");
    Serial.println(heelCorrector);
    Serial.print("targetSpeedAVG: ");
    Serial.println(targetSpeedAVG);
    Serial.print("pitchcorrector: ");
    Serial.println(pitchCorrector);
    Serial.print("pressureoffset: ");
    Serial.println(baroffset);
    Serial.print("flightrange: ");
    Serial.println(isInFlightRange);
    Serial.print("flightspdmin: ");
    Serial.println(bspFlightMin);
    //Serial.print("flightpresscorrect ");
    //Serial.println(flightPressCorrector);
    //Serial.print("pressureoffset: ");
    //Serial.println(offset);
    Serial.println( );
    Serial.println("current soft switch settings");
    Serial.print("serveron: ");
    Serial.println(serverON);
    Serial.print("paddleselector: ");
    Serial.println(paddleSelector);
    Serial.print("tackscore: ");
    Serial.println(tackScore);
    Serial.print("wifly: ");
    Serial.println(wiFly);
    Serial.print("directlog: ");
    Serial.println(directLog);
    Serial.print("sensor: ");
    Serial.println(Sensor);
    Serial.print("barometet: ");
    Serial.println(Barometer);
    Serial.print("expedition: ");
    Serial.println(Expedition);
    Serial.print("NMEAPlay: ");
    Serial.println(NMEAPlay);
    Serial.print("expFreq: ");
    Serial.println(expFreq);
    Serial.println( );
    }
    //////

    ///Reads the System Logfile /////////////////
    void ReadLog() {
    String inData4;
    char recieved4;
    File myFile = SD.open("syslog.txt");
    if (myFile)
    {
    Serial.println(" SYSLOG.TXT file found. printing contents:");
    while (myFile.available())
    {
    recieved4 = myFile.read();
    inData4 += recieved4;
    if (recieved4 == '\n') // Process message when new line character is recieved
    {
    Serial.print(inData4);
    inData4 = "";
    }
    }
    }
    }
    //////

    ///Reads the Named Expedition Log File///////
    void ReadExpeditionLog() {
    String inData4;
    char recieved4;
    Serial.print("Looking for File ");
    int commaloc = inData2.indexOf(',');
    int commaloc2 = inData2.indexOf(',', commaloc + 1);
    int commaloc3 = inData2.indexOf(',', commaloc2 + 1);
    String ExpFileString1 = inData2.substring(commaloc + 1, commaloc2);
    String ExpFileString = inData2.substring(commaloc2 + 1, commaloc3);
    Serial.print(ExpFileString1);
    ExpFileString1.toCharArray(ExpFile, 13);
    File myFile = SD.open(ExpFile);
    if (myFile)
    {
    Serial.println("file found. printing contents:");
    while (myFile.available())
    {
    recieved4 = myFile.read();
    inData4 += recieved4;
    if (recieved4 == '\n') // Process message when new line character is recieved
    {
    Serial.print(inData4);
    inData4 = "";

    }
    }
    }
    }
    //////

    ///Lists the Contents of the SD Card/////////
    void ListSDC() {
    Sd2Card card;
    SdVolume volume;
    SdFile root;

    // print the type of card
    Serial.print("\nCard type: ");
    switch (card.type()) {
    case SD_CARD_TYPE_SD1:
    Serial.println("SD1");
    break;
    case SD_CARD_TYPE_SD2:
    Serial.println("SD2");
    break;
    case SD_CARD_TYPE_SDHC:
    Serial.println("SDHC");
    break;
    default:
    Serial.println("Unknown");
    }
    // Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32
    if (!volume.init(card)) {
    Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card");
    return;
    }
    Serial.println("\nFiles found on the card (name, date and size in bytes): ");
    root.openRoot(volume);
    // list all files in the card with date and size
    root.ls(LS_R | LS_DATE | LS_SIZE);
    }
    //////

    ///Removes the NMEA log from the SD card/////
    void rmNMEALog() {
    SD.remove("NMEALOG.txt");
    }
    //////

    ///Reads the Settings.txt file and sets variables/////////////////
    void readSDSettings() {
    char character;
    String settingName;
    String settingValue;

    File myFile = SD.open("settings.txt");
    if (myFile)
    {
    Serial.println(" SETTINGS.TXT file found: getting Configuration");
    while (myFile.available()) {
    character = myFile.read();
    while ((myFile.available()) && (character != '[')) {
    character = myFile.read();
    }
    character = myFile.read();
    while ((myFile.available()) && (character != '=')) {
    settingName = settingName + character;
    character = myFile.read();
    }
    character = myFile.read();
    while ((myFile.available()) && (character != ']')) {
    settingValue = settingValue + character;
    character = myFile.read();
    }
    if (character == ']') {
    //Debuuging Printing
    Serial.print("Name:");
    Serial.println(settingName);
    Serial.print("Value :");
    Serial.println(settingValue);
    // Apply the value to the parameter
    applySetting(settingName, settingValue);
    // Reset Strings
    settingName = "";
    settingValue = "";
    }
    }
    // close the file:
    myFile.close();
    } else {
    // if the file didn't open, print an error:
    Serial.println("error opening settings.txt");
    }
    }
    //////

    ///adds a line to settings.txt///////////////
    void writeSDSettings() {
    // Delete the old One
    SD.remove("settings.txt");
    // Create new one
    myFile = SD.open("settings.txt", FILE_WRITE);
    // writing in the file works just like regular print()/println() function
    myFile.print("[");
    myFile.print("exINT=");
    myFile.print(exINT);
    myFile.println("]");
    myFile.print("[");
    myFile.print("exFloat=");
    myFile.print(exFloat, 5);
    myFile.println("]");
    myFile.print("[");
    myFile.print("exBoolean=");
    myFile.print(exBoolean);
    myFile.println("]");
    myFile.print("[");
    myFile.print("exLong=");
    myFile.print(exLong);
    myFile.println("]");
    // close the file:
    myFile.close();
    //Serial.println("Writing done.");
    }
    //////

    //Ethernet - main process/////
    void checkServer() {
    EthernetClient client = server.available();
    if (client) {
    boolean currentLineIsBlank = true;
    boolean currentLineIsGet = true;
    int tCount = 0;
    char tBuf[254];
    int r, t;
    int parmValue;
    char *pch;
    char methodBuffer[8];
    char requestBuffer[48];
    char pageBuffer[48];
    char paramBuffer[48];
    char protocolBuffer[9];
    char fileName[32];
    char fileType[4];
    int clientCount = 0;
    requestNumber++;
    #ifdef ServerDEBUG
    Serial.print(F("\r\nClient request #"));
    Serial.print(requestNumber);
    Serial.print(F(": "));
    #endif
    // this controls the timeout
    int loopCount = 0;
    while (client.connected()) {
    while (client.available()) {
    // if packet, reset loopCount
    loopCount = 0;
    char c = client.read();

    if (currentLineIsGet && tCount < 63)
    {
    tBuf[tCount] = c;
    tCount++;
    tBuf[tCount] = 0;
    }

    if (c == '\n' && currentLineIsBlank) {
    #ifdef ServerDEBUG
    Serial.print(tBuf);
    #endif
    // Serial.print(F("POST data: "));
    while (client.available()) client.read();

    int scanCount = sscanf(tBuf, "%7s %47s %8s", methodBuffer, requestBuffer, protocolBuffer);

    if (scanCount != 3) {

    #ifdef ServerDEBUG
    Serial.println(F("bad request"));
    #endif
    sendBadRequest(client);
    return;
    }

    char* pch = strtok(requestBuffer, "?");
    if (pch != NULL) {
    strncpy(fileName, pch, 31);
    strncpy(tBuf, pch, 31);

    pch = strtok(NULL, "?");
    if (pch != NULL) {
    strcpy(paramBuffer, pch);
    }
    else paramBuffer[0] = 0;
    }

    strtoupper(requestBuffer);
    strtoupper(tBuf);

    for (int x = 0; x < strlen(requestBuffer); x++) {
    if (strchr(legalChars, requestBuffer[x]) == NULL) {
    Serial.println(F("bad character"));
    sendBadRequest(client);
    return;
    }
    }

    #ifdef ServerDEBUG
    Serial.print(F("file = "));
    Serial.println(requestBuffer);
    #endif
    pch = strtok(tBuf, ".");

    if (pch != NULL) {
    pch = strtok(NULL, ".");

    if (pch != NULL) strncpy(fileType, pch, 4);
    else fileType[0] = 0;

    //#ifdef ServerDEBUG
    if (statMsg == 1) Serial.print(F("file type = "));
    if (statMsg == 1) Serial.println(fileType);
    if (fileType == "LOG") {
    ExpReady = 0; //
    Serial.println("trapped LOG");
    }
    //#endif
    }

    #ifdef ServerDEBUG
    Serial.print(F("method = "));
    Serial.println(methodBuffer);
    #endif
    if (strcmp(methodBuffer, "GET") != 0 && strcmp(methodBuffer, "HEAD") != 0) {
    sendBadRequest(client);
    return;
    }

    #ifdef ServerDEBUG
    Serial.print(F("params = "));
    Serial.println(paramBuffer);

    Serial.print(F("protocol = "));
    Serial.println(protocolBuffer);
    #endif

    ////Ethernet Dynamic page type selector///////////////
    // if dynamic page name

    if (strcmp(requestBuffer, "/BSPTWA.PHP") == 0) {
    displayPageType = 1;
    //displayColorMode = 1;
    if (statMsg == 1) Serial.println("BSPTWA page requested");
    }
    else if (strcmp(requestBuffer, "/MYTEST.PHP") == 0) {
    displayPageType = 0;
    //displayColorMode = 1;
    if (statMsg == 1) Serial.println("mytest page requested");
    }
    else if (strcmp(requestBuffer, "/BSPHDG.PHP") == 0) {
    displayPageType = 2;
    //displayColorMode = 1;
    if (statMsg == 1) Serial.println("BSPHDG page requested");
    }
    else if (strcmp(requestBuffer, "/HDGTWA.PHP") == 0) {
    displayPageType = 3;
    //displayColorMode = 1;
    if (statMsg == 1) Serial.println("HDGTWA page requested");
    }
    else if (strcmp(requestBuffer, "/BSPTRG.PHP") == 0) {
    displayPageType = 4;
    //displayColorMode = 1;
    if (statMsg == 1) Serial.println("BSPTRG page requested");
    }
    else if (strcmp(requestBuffer, "/BSPTCT.PHP") == 0) {
    displayPageType = 5;
    //displayColorMode = 1;
    if (statMsg == 1) Serial.println("bsptct page requested");
    }
    else if (strcmp(requestBuffer, "/RNGBRG.PHP") == 0) {
    displayPageType = 6;
    //displayColorMode = 1;
    if (statMsg == 1) Serial.println("rngbrg page requested");
    }
    else if (strcmp(requestBuffer, "/SUMMARY.PHP") == 0) {
    displayPageType = 7;
    //displayColorMode = 1;
    if (statMsg == 1) Serial.println("summary page requested");
    }
    else if (strcmp(requestBuffer, "/FLIGHT.PHP") == 0) {
    displayPageType = 8;
    //displayColorMode = 1;
    if (statMsg == 1) Serial.println("flight page requested");
    }
    else if (strcmp(requestBuffer, "/TACKSCORE.PHP") == 0) {
    displayPageType = 9;
    //displayColorMode = 1;
    if (statMsg == 1) Serial.println("TACKSCORE page requested");
    }
    else if (strcmp(requestBuffer, "/LISTFILES.PHP") == 0) {
    displayPageType = 10;
    //displayColorMode = 1;
    if (statMsg == 1) Serial.println("listfiles page requested");
    }
    else if (strcmp(requestBuffer, "/SETTINGS.PHP") == 0) {
    displayPageType = 11;
    //displayColorMode = 1;
    if (statMsg == 1) Serial.println("settings page requested");
    }
    else if (strcmp(requestBuffer, "/BATT.PHP") == 0) {
    displayPageType = 12;
    //displayColorMode = 1;
    if (statMsg == 1) Serial.println("BATT page requested");
    }
    else if (strcmp(requestBuffer, "/DOT.PHP") == 0) {
    displayPageType = 13;
    //displayColorMode = 1;
    if (statMsg == 1) Serial.println("BSPTRG page requested");
    }
    else if (strcmp(requestBuffer, "/BSPPOL.PHP") == 0) {
    displayPageType = 14;
    //displayColorMode = 1;
    if (statMsg == 1) Serial.println("BSPTRG page requested");
    }
    else if (strcmp(requestBuffer, "/COMM.PHP") == 0) {
    displayPageType = 15;
    //displayColorMode = 1;
    if (statMsg == 1) Serial.println("COMM page requested");
    }
    else if (strcmp(requestBuffer, "/FEAT.PHP") == 0) {
    displayPageType = 16;
    //displayColorMode = 1;
    if (statMsg == 1) Serial.println("feature page requested");
    }
    else if (strcmp(requestBuffer, "/FEA2.PHP") == 0) {
    displayPageType = 17;
    //displayColorMode = 1;
    if (statMsg == 1) Serial.println("feature 2 page requested");
    }
    else if (strcmp(requestBuffer, "/SAIL.PHP") == 0) {
    displayPageType = 18;
    //displayColorMode = 1;
    if (statMsg == 1) Serial.println("sailelect page requested");
    }
    else if (strcmp(requestBuffer, "/MODE.PHP") == 0) {
    displayPageType = 19;
    //displayColorMode = 1;
    if (statMsg == 1) Serial.println("mytest page requested");
    }
    //
    ////Home Page From SD Card///////////////
    else {
    if (strcmp(fileName, "/") == 0) {
    strcpy(fileName, "/INDEX.HTM");
    strcpy(fileType, "HTM");
    includeDate = 0;

    #ifdef ServerDEBUG
    Serial.print(F("Home page "));
    #endif
    }

    #ifdef ServerDEBUG
    Serial.println(F("SD file"));
    #endif
    if (strlen(fileName) > 30) {
    #ifdef ServerDEBUG
    Serial.println(F("filename too long"));
    #endif
    sendBadRequest(client);

    return;
    }
    else if (strlen(fileType) > 3 || strlen(fileType) < 1) {

    #ifdef ServerDEBUG
    Serial.println(F("file type invalid size"));
    #endif
    sendBadRequest(client);
    return;
    }
    else {
    #ifdef ServerDEBUG
    Serial.println(F("filename format ok"));
    #endif
    if (SD.exists(fileName)) {
    #ifdef ServerDEBUG

    Serial.print(F("file found.."));
    #endif

    File myFile = SD.open(fileName);
    ExpReady = 2;

    if (!myFile) {
    #ifdef ServerDEBUG
    Serial.println(F("open error"));
    #endif
    sendFileNotFound(client);
    return;
    }
    #ifdef ServerDEBUG
    else Serial.print(F("opened.."));
    #endif

    strcpy_P(tBuf, PSTR("HTTP/1.0 200 OK\r\nContent-Type: "));
    // client.write(tBuf);
    // client.print(F("HTTP/1.0 200 OK\r\nContent-Type: "));

    // send Content-Type
    if (strcmp(fileType, "HTM") == 0) strcat_P(tBuf, PSTR("text/html"));
    else if (strcmp(fileType, "PHP") == 0) strcat_P(tBuf, PSTR("text/html"));
    else if (strcmp(fileType, "TXT") == 0) strcat_P(tBuf, PSTR("text/plain"));
    else if (strcmp(fileType, "CSS") == 0) strcat_P(tBuf, PSTR("text/css"));
    else if (strcmp(fileType, "GIF") == 0) strcat_P(tBuf, PSTR("image/gif"));
    else if (strcmp(fileType, "JPG") == 0) strcat_P(tBuf, PSTR("image/jpeg"));
    else if (strcmp(fileType, "JS") == 0) strcat_P(tBuf, PSTR("application/javascript"));
    else if (strcmp(fileType, "CSV") == 0) strcat_P(tBuf, PSTR("application/expedition"));
    else if (strcmp(fileType, "ICO") == 0) strcat_P(tBuf, PSTR("image/x-icon"));
    else if (strcmp(fileType, "PNG") == 0) strcat_P(tBuf, PSTR("image/png"));
    else if (strcmp(fileType, "PDF") == 0) strcat_P(tBuf, PSTR("application/pdf"));
    else if (strcmp(fileType, "ZIP") == 0) strcat_P(tBuf, PSTR("application/zip"));
    else strcat_P(tBuf, PSTR("text/plain"));

    strcat_P(tBuf, PSTR("\r\nConnection: close\r\n\r\n"));
    client.write(tBuf);

    if (strcmp(methodBuffer, "GET") == 0) {
    #ifdef ServerDEBUG
    Serial.print(F("send.."));
    #endif

    while (myFile.available()) {
    tBuf[clientCount] = myFile.read();
    clientCount++;
    tBuf[clientCount] = 0;

    if (clientCount > 63) {
    client.write((byte*)tBuf, 64);
    clientCount = 0;
    }

    }
    if (clientCount > 0) {
    client.write((byte*)tBuf, clientCount);
    }
    }


    // end this attempt

    myFile.close();
    #ifdef ServerDEBUG
    Serial.println(F("closed"));
    #endif
    if (includeDate == 0)
    {
    ////////conditional content appended to Index.htm///
    Serial.println("include the Date line");
    strcpy_P(tBuf, PSTR("<a href=\"HTTP://192.168.8.10/"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR(logFile));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("\"> <H2> Download active log file: "));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR(logFile));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</H2></a><p></p>"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("<a href=\"HTTP://192.168.8.10/settings.txt"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("\"> <H3> Server Settings "));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</H3></a><p></p>"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("<a href=\"HTTP://192.168.8.10/syslog.txt"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("\"> <H3> Startup Log "));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</H3></a><p></p>"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("<a href=\"HTTP://192.168.8.10/LISTFILES.PHP"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("\"> <H3> SD card File Listing"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</H3></a><p></p>"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("<a href=\"HTTP://192.168.8.10/BSPTWA.PHP"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("\"> <H3> Instrument Display"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</H3></a><p></p>"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("<a href=\"HTTP://192.168.8.10/SAIL.PHP"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("\"> <H3> System Tuning"));
    client.write(tBuf);
    includeDate = 1;
    }
    client.stop();
    #ifdef ServerDEBUG
    Serial.println(F("disconnected"));
    #endif
    return;
    }
    else {
    #ifdef ServerDEBUG
    Serial.println(F("File not found"));
    #endif
    sendFileNotFound(client);
    return;
    }
    }
    }
    pch = strtok(paramBuffer, "&");
    while (pch != NULL)

    {

    if (strncmp(pch, "a=", 2) == 0) ////////////////flight tws minimum
    {
    parmValue = atoi(pch + 2);
    if (parmValue >= 0 && parmValue < 8) twsFlightMin = parmValue;
    }
    if (strncmp(pch, "b=", 2) == 0) ///dot brightness
    {
    parmValue = atoi(pch + 2);
    if (parmValue >= 0 && parmValue < 8) dotBrightess = parmValue; // bounds check
    }
    if (strncmp(pch, "c=", 2) == 0) ////centerpixel
    {
    parmValue = atoi(pch + 2);
    if (parmValue == 0) centerPixel = centerPixel - 2;
    else if (parmValue == 1) centerPixel = centerPixel + 2;
    else if (parmValue == 2) centerPixel = centerPixel - 1;
    else if (parmValue == 3) centerPixel = centerPixel + 1;
    else if (parmValue == 4) centerPixel = centerPixel - 5;
    else if (parmValue == 5) centerPixel = centerPixel + 5;
    if (centerPixel <= 1) centerPixel = 1;
    if (centerPixel >= NUMPIXELS) centerPixel = NUMPIXELS - 2;
    }
    if (strncmp(pch, "d=", 2) == 0) //logging paramater
    {
    parmValue = atoi(pch + 2);
    if (parmValue == 0) {
    directLog = 0;
    NMEALog = 0;
    Expedition = 0;
    }
    else if (parmValue == 1) {
    directLog = 1;
    NMEALog = 0;
    Expedition = 1;
    }
    else if (parmValue == 2) {
    directLog = 0;
    NMEALog = 1;
    Expedition = 0;
    }
    }

    if (strncmp(pch, "e=", 2) == 0) ////board height
    {
    travPos = atof(pch + 2);
    }

    if (strncmp(pch, "f=", 2) == 0) //////////////neo min target floor
    {
    parmValue = atoi(pch + 2);
    if (parmValue >= 20 && parmValue < 100) neoMinTargetFloor = parmValue;
    }
    if (strncmp(pch, "g=", 2) == 0) //////////////flightspdmin
    {
    parmValue = atoi(pch + 2);
    if (parmValue == 0) bspFlightMin = bspFlightMin - 200;
    else if (parmValue == 1) bspFlightMin = bspFlightMin + 200;
    else if (parmValue == 2) bspFlightMin = bspFlightMin - 100;
    else if (parmValue == 3) bspFlightMin = bspFlightMin + 100;
    else if (parmValue == 4) bspFlightMin = bspFlightMin - 50;
    else if (parmValue == 5) bspFlightMin = bspFlightMin + 50;
    }
    if (strncmp(pch, "h=", 2) == 0) //caution roll
    {
    parmValue = atoi(pch + 2);
    if (parmValue == 0) cautionRoll = cautionRoll - 2;
    else if (parmValue == 1) cautionRoll = cautionRoll + 2;
    else if (parmValue == 2) cautionRoll = cautionRoll - 1;
    else if (parmValue == 3) cautionRoll = cautionRoll + 1;
    else if (parmValue == 4) cautionRoll = cautionRoll - 5;
    else if (parmValue == 5) cautionRoll = cautionRoll + 5;
    }
    if (strncmp(pch, "i=", 2) == 0) ///pitch corrector
    {
    parmValue = atoi(pch + 2);
    if (parmValue >= -20 && parmValue < 45) pitchCorrector = parmValue;
    }
    if (strncmp(pch, "j=", 2) == 0) //////////////flightspdmin
    {
    parmValue = atoi(pch + 2);
    if (parmValue == 0) twsFlightMin = twsFlightMin - 200;
    else if (parmValue == 1) twsFlightMin = twsFlightMin + 200;
    else if (parmValue == 2) twsFlightMin = twsFlightMin - 100;
    else if (parmValue == 3) twsFlightMin = twsFlightMin + 100;
    else if (parmValue == 4) twsFlightMin = twsFlightMin - 50;
    else if (parmValue == 5) twsFlightMin = twsFlightMin + 50;
    }
    if (strncmp(pch, "k=", 2) == 0) //////////////flightspdmin
    {
    parmValue = atoi(pch + 2);
    if (parmValue == 0) targetSpeedMultiplier = targetSpeedMultiplier - 2;
    else if (parmValue == 1) targetSpeedMultiplier = targetSpeedMultiplier + 2;
    else if (parmValue == 2) targetSpeedMultiplier = targetSpeedMultiplier - 1;
    else if (parmValue == 3) targetSpeedMultiplier = targetSpeedMultiplier + 1;
    else if (parmValue == 4) targetSpeedMultiplier = targetSpeedMultiplier - 5;
    else if (parmValue == 5) targetSpeedMultiplier = targetSpeedMultiplier + 5;
    }

    if (strncmp(pch, "l=", 2) == 0) ///pitch corrector
    {
    parmValue = atoi(pch + 2);
    if (parmValue >= -20 && parmValue < 45) pitchCorrector = parmValue;
    }
    if (strncmp(pch, "m=", 2) == 0) ///////dot mode
    {
    parmValue = atoi(pch + 2);
    if (parmValue > 0 && parmValue < 4) dotMode = parmValue;
    }
    if (strncmp(pch, "n=", 2) == 0) /////ready mode
    {
    parmValue = atoi(pch + 2);
    if (parmValue > 0 && parmValue < 5) isReadyMode = parmValue;
    }

    if (strncmp(pch, "o=", 2) == 0) /////ready mode
    {
    parmValue = atoi(pch + 2);
    if (parmValue == 1) WriteTune();
    }

    if (strncmp(pch, "p=", 2) == 0) //////////////trget speed multiplier
    {
    parmValue = atoi(pch + 2);
    if (parmValue > 1 && parmValue < 300) targetSpeedMultiplier = parmValue;
    }
    if (strncmp(pch, "q=", 2) == 0) //////////////trget speed multiplier
    {
    parmValue = atoi(pch + 2);
    if (parmValue == 0) warningRoll = warningRoll - 2;
    else if (parmValue == 1) warningRoll = warningRoll + 2;
    else if (parmValue == 2) warningRoll = warningRoll - 1;
    else if (parmValue == 3) warningRoll = warningRoll + 1;
    else if (parmValue == 4) warningRoll = warningRoll - 5;
    else if (parmValue == 5) warningRoll = warningRoll + 5;
    }
    if (strncmp(pch, "r=", 2) == 0) ////heel corrector
    {
    parmValue = atoi(pch + 2);
    if (parmValue > -5 && parmValue < 20) heelCorrector = parmValue;
    }
    if (strncmp(pch, "t=", 2) == 0) ///heel corrector
    {
    parmValue = atoi(pch + 2);
    displayColorMode = parmValue;
    }
    if (strncmp(pch, "v=", 2) == 0) ////////////minimum flight speed
    {
    parmValue = atoi(pch + 2);
    //if(parmValue >0 && parmValue<50000) bspFlightMin = parmValue;
    }
    if (strncmp(pch, "w=", 2) == 0) ///comm selector
    {
    parmValue = atoi(pch + 2);
    if (parmValue == 0) s0PIXComm = 0;
    else if (parmValue == 1) s0PIXComm = 1;
    else if (parmValue == 2) s1PIXComm = 0;
    else if (parmValue == 3) s1PIXComm = 1;
    else if (parmValue == 4) s3PIXComm = 0;
    else if (parmValue == 5) s3PIXComm = 1;
    else if (parmValue == 6) s0XDRComm = 0;
    else if (parmValue == 7) s0XDRComm = 1;
    else if (parmValue == 8) s1XDRComm = 0;
    else if (parmValue == 9) s1XDRComm = 1;
    else if (parmValue == 10) s3XDRComm = 0;
    else if (parmValue == 11) s3XDRComm = 1;
    else if (parmValue == 12) s1NMEAComm = 0;
    else if (parmValue == 13) s1NMEAComm = 1;
    else if (parmValue == 14) s3NMEAComm = 0;
    else if (parmValue == 15) s3NMEAComm = 1;
    else if (parmValue == 16) NMEAPlay = 0;
    else if (parmValue == 17) NMEAPlay = 1;
    }
    if (strncmp(pch, "x=", 2) == 0) ///sail selector
    {
    parmValue = atoi(pch + 2);
    if (parmValue == 0) activeSailCode = 400;
    else if (parmValue == 1) activeSailCode = 100;
    else if (parmValue == 2) activeSailCode = 200;
    else if (parmValue == 3) activeSailCode = 300;
    else if (parmValue == 4) activeSailCode = 500;
    else if (parmValue == 5) activeSailCode = activeSailCode + 50;
    else if (parmValue == 6) activeSailCode = activeSailCode + 25;
    else if (parmValue == 7) activeSailCode = activeSailCode + 12;
    }
    if (strncmp(pch, "y=", 2) == 0) ////board height
    {
    boardHeight = atof(pch + 2);
    }
    if (strncmp(pch, "z=", 2) == 0) ///sail selector
    {
    parmValue = atoi(pch + 2);
    if (parmValue == 0) tackScoreData = 0;
    else if (parmValue == 1) tackScoreData = 1;
    else if (parmValue == 10) serverON = 0;
    else if (parmValue == 11) serverON = 1;
    else if (parmValue == 20) wiFly = 0;
    else if (parmValue == 21) wiFly = 1;
    else if (parmValue == 30) v12Record = 0;
    else if (parmValue == 31) v12Record = 1;
    else if (parmValue == 32) v24Record = 0;
    else if (parmValue == 33) v24Record = 1;
    else if (parmValue == 34) {
    v12Record = 0;
    v24Record = 0;
    }
    else if (parmValue == 35) {
    v12Record = 1;
    v24Record = 1;
    }
    else if (parmValue == 40) Sensor = 0;
    else if (parmValue == 41) Sensor = 1;
    else if (parmValue == 42) Barometer = 0;
    else if (parmValue == 43) {
    Sensor = 0;
    Barometer = 0;
    }
    else if (parmValue == 44) {
    Sensor = 1;
    Barometer = 1;
    }
    else if (parmValue == 50) paddleSelector = 1;
    else if (parmValue == 51) paddleSelector = 2;
    else if (parmValue == 60) PIXGenerate = 0;
    else if (parmValue == 61) PIXGenerate = 1;
    else if (parmValue == 70) PIXGenerate = 0;
    else if (parmValue == 71) PIXGenerate = 1;
    else if (parmValue == 72) PIXGenerate = 2;
    else if (parmValue == 73) PIXGenerate = 3;
    else if (parmValue == 74) PIXGenerate = 4;
    else if (parmValue == 75) PIXGenerate = 5;
    else if (parmValue == 76) PIXGenerate = 6;
    else if (parmValue == 77) PIXGenerate = 7;
    else if (parmValue == 78) PIXGenerate = 8;
    else if (parmValue == 79) PIXGenerate = 9;
    }

    pch = strtok(NULL, "& ");
    }
    client.print(F("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n"));
    if (strcmp(methodBuffer, "GET") == 0) {
    /////////////////Dynamic Web Pages////
    //////////boaspeed - true wind angle //
    if (displayPageType == 1)
    {
    if (displayColorMode == 1) strcpy_P(tBuf, PSTR("<!DOCTYPE html><html><meta http-equiv=refresh content=1.5><body style=color:black;background-color:white;font-family:Verdana;font-weight:bold;><body><span style=font-size:28px;><center>Boatspeed"));
    else strcpy_P(tBuf, PSTR("<!DOCTYPE html><html><meta http-equiv=refresh content=1.5><body style=background-color:black;color:white;font-family:Verdana;font-weight:bold;><body><span style=font-size:28px;><center>Boatspeed"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</span></p><span style=font-size:200px;line-height:53%;><center>"));
    client.write(tBuf);
    float wBspFloat = bspInt * .01;
    dtostrf(wBspFloat, 5, 2, tBuf);
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</span></a><span style=font-size:10px;><hr></span><span style=font-size:28px;line-height:100%;><center>Wind Angle TRUE</span></p><span style=font-size:200px;line-height:53%;><center>"));
    client.write(tBuf);
    itoa (twaInt, tBuf, 10);
    client.write(tBuf);
    if (displayColorMode == 1) strcpy_P(tBuf, PSTR("<span style=font-size:20px;line-height:0%;><p align=left><a href=bsptwa.php?t=0>&lowast; <p align=right><a href=bsphdg.php?t=1>&rarr; </P></span></a></span></a></body></html>"));
    else strcpy_P(tBuf, PSTR("<span style=font-size:20px;line-height:0%;><p align=left><a href=bsptwa.php?t=1>&lowast; <p align=right><a href=bsphdg.php?t=0>&rarr; </P></span></a></span></a></body></html>"));
    client.write(tBuf);
    }
    //////////Boaspeed - Heading //////
    else if (displayPageType == 2)
    {
    if (displayColorMode == 1) strcpy_P(tBuf, PSTR("<!DOCTYPE html><html><meta http-equiv=refresh content=1.5><body style=color:black;background-color:white;font-family:Verdana;font-weight:bold;><body><span style=font-size:28px;><center>Boatspeed"));
    else strcpy_P(tBuf, PSTR("<!DOCTYPE html><html><meta http-equiv=refresh content=1.5><body style=background-color:black;color:white;font-family:Verdana;font-weight:bold;><body><span style=font-size:28px;><center>Boatspeed"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</span></p><span style=font-size:200px;line-height:53%;><center>"));
    client.write(tBuf);
    float wBspFloat = bspInt * .01;
    dtostrf(wBspFloat, 5, 2, tBuf);
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</span></a><span style=font-size:10px;><hr></span><span style=font-size:28px;line-height:100%;><center>Heading</span></p><span style=font-size:200px;line-height:53%;><center>"));
    client.write(tBuf);
    itoa (hdmInt, tBuf, 10);
    client.write(tBuf);
    if (displayColorMode == 1) strcpy_P(tBuf, PSTR("<span style=font-size:20px;line-height:0%;><p align=left><a href=bsphdg.php?t=0>&lowast; <p align=right><a href=hdgtwa.php?t=1>&rarr; </P></span></a></span></a></body></html>"));
    else strcpy_P(tBuf, PSTR("<span style=font-size:20px;line-height:0%;><p align=left><a href=bsphdg.php?t=1>&lowast; <p align=right><a href=hdgtwa.php?t=0>&rarr; </P></span></a></span></a></body></html>"));
    client.write(tBuf);
    }
    //////////Heading - True Wind Angle //////
    else if (displayPageType == 3) ///////////heading - true wind angle
    {
    if (displayColorMode == 1) strcpy_P(tBuf, PSTR("<!DOCTYPE html><html><meta http-equiv=refresh content=1.5><body style=color:black;background-color:white;font-family:Verdana;font-weight:bold;><body><span style=font-size:28px;><center>Heading"));
    else strcpy_P(tBuf, PSTR("<!DOCTYPE html><html><meta http-equiv=refresh content=1.5><body style=background-color:black;color:white;font-family:Verdana;font-weight:bold;><body><span style=font-size:28px;><center>Heading"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</span></p><span style=font-size:200px;line-height:53%;><center>"));
    client.write(tBuf);
    itoa (hdmInt, tBuf, 10);
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</span></a><span style=font-size:10px;><hr></span><span style=font-size:28px;line-height:100%;><center>Wing Angle TRUE</span></p><span style=font-size:200px;line-height:53%;><center>"));
    client.write(tBuf);
    itoa (twaInt, tBuf, 10);
    client.write(tBuf);
    if (displayColorMode == 1) strcpy_P(tBuf, PSTR("<span style=font-size:20px;line-height:0%;><p align=left><a href=hdgtwa.php?t=0>&lowast; <p align=right><a href=bsptrg.php?t=1>&rarr; </P></span></a></span></a></body></html>"));
    else strcpy_P(tBuf, PSTR("<span style=font-size:20px;line-height:0%;><p align=left><a href=hdgtwa.php?t=1>&lowast; <p align=right><a href=bsptrg.php?t=0>&rarr; </P></span></a></span></a></body></html>"));
    client.write(tBuf);
    }
    //////////Boaspeed - Target Speed //////
    else if (displayPageType == 4)
    {
    if (displayColorMode == 1) strcpy_P(tBuf, PSTR("<!DOCTYPE html><html><meta http-equiv=refresh content=1.5><body style=color:black;background-color:white;font-family:Verdana;font-weight:bold;><body><span style=font-size:28px;><center>Boatspeed"));
    else strcpy_P(tBuf, PSTR("<!DOCTYPE html><html><meta http-equiv=refresh content=1.5><body style=background-color:black;color:white;font-family:Verdana;font-weight:bold;><body><span style=font-size:28px;><center>Boatspeed"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</span></p><span style=font-size:200px;line-height:53%;><center>"));
    client.write(tBuf);
    float wBspFloat = bspInt * .01;
    dtostrf(wBspFloat, 5, 2, tBuf);
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</span></a><span style=font-size:10px;><hr></span><span style=font-size:28px;line-height:100%;><center>Target BSP</span></p><span style=font-size:200px;line-height:53%;><center>"));
    client.write(tBuf);
    float trgBspFloat = targetBSPAvg * .01;
    dtostrf(trgBspFloat, 5, 2, tBuf);
    client.write(tBuf);
    if (displayColorMode == 1) strcpy_P(tBuf, PSTR("<span style=font-size:20px;line-height:0%;><p align=left><a href=bsptrg.php?t=0>&lowast; <p align=right><a href=bsptct.php?t=1>&rarr; </P></span></a></span></a></body></html>"));
    else strcpy_P(tBuf, PSTR("<span style=font-size:20px;line-height:0%;><p align=left><a href=bsptrg.php?t=1>&lowast; <p align=right><a href=bsptct.php?t=0>&rarr; </P></span></a></span></a></body></html>"));
    client.write(tBuf);
    }
    //////////Boaspeed - Target Speed Percentage ///
    else if (displayPageType == 5)
    {
    if (displayColorMode == 1) strcpy_P(tBuf, PSTR("<!DOCTYPE html><html><meta http-equiv=refresh content=1.5><body style=color:black;background-color:white;font-family:Verdana;font-weight:bold;><body><span style=font-size:28px;><center>Boatspeed"));
    else strcpy_P(tBuf, PSTR("<!DOCTYPE html><html><meta http-equiv=refresh content=1.5><body style=background-color:black;color:white;font-family:Verdana;font-weight:bold;><body><span style=font-size:28px;><center>Boatspeed"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</span></p><span style=font-size:200px;line-height:53%;><center>"));
    client.write(tBuf);
    float wBspFloat = bspInt * .01;
    dtostrf(wBspFloat, 5, 2, tBuf);
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</span></a><span style=font-size:10px;><hr></span><span style=font-size:28px;line-height:100%;><center>Target PCT</span></p><span style=font-size:200px;line-height:53%;><center>"));
    client.write(tBuf);
    float trgBspFloat = targetBSPAvg * .01; /////////target
    float targetPctBsp = wBspFloat / trgBspFloat;
    float trgBspPctFloat = targetPctBsp * 100; //////////target avg
    dtostrf(trgBspPctFloat, 5, 1, tBuf);
    client.write(tBuf);
    if (displayColorMode == 1) strcpy_P(tBuf, PSTR("<span style=font-size:20px;line-height:0%;><p align=left><a href=bsptct.php?t=0>&lowast; <p align=right><a href=bsppol.php?t=1>&rarr; </P></span></a></span></a></body></html>"));
    else strcpy_P(tBuf, PSTR("<span style=font-size:20px;line-height:0%;><p align=left><a href=bsptct.php?t=1>&lowast; <p align=right><a href=bsppol.php?t=0>&rarr; </P></span></a></span></a></body></html>"));
    client.write(tBuf);
    }
    //////////Mark Distance and Bearing //////
    else if (displayPageType == 6)
    {
    if (displayColorMode == 1) strcpy_P(tBuf, PSTR("<!DOCTYPE html><html><meta http-equiv=refresh content=1.5><body style=color:black;background-color:white;font-family:Verdana;font-weight:bold;><body><span style=font-size:28px;><center>Mark Brg"));
    else strcpy_P(tBuf, PSTR("<!DOCTYPE html><html><meta http-equiv=refresh content=1.5><body style=background-color:black;color:white;font-family:Verdana;font-weight:bold;><body><span style=font-size:28px;><center>Mark Brg"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</span></p><span style=font-size:200px;line-height:53%;><center>"));
    client.write(tBuf);
    itoa (markInt, tBuf, 10);
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</span></a><span style=font-size:10px;><hr></span><span style=font-size:28px;line-height:100%;><center>Mark Range</span></p><span style=font-size:200px;line-height:53%;><center>"));
    client.write(tBuf);
    dtostrf(markDistFloat, 5, 2, tBuf);
    client.write(tBuf);
    if (displayColorMode == 1) strcpy_P(tBuf, PSTR("<span style=font-size:20px;line-height:0%;><p align=left><a href=rngbrg.php?t=0>&lowast; <p align=right><a href=flight.php?t=1>&rarr; </P></span></a></span></a></body></html>"));
    else strcpy_P(tBuf, PSTR("<span style=font-size:20px;line-height:0%;><p align=left><a href=rngbrg.php?t=1>&lowast; <p align=right><a href=flight.php?t=0>&rarr; </P></span></a></span></a></body></html>"));
    client.write(tBuf);
    }
    /////////Flight Status //
    else if (displayPageType == 8)
    {
    if (displayColorMode == 1) strcpy_P(tBuf, PSTR("<!DOCTYPE html><html><meta http-equiv=refresh content=1.5><body style=color:black;background-color:white;font-family:Verdana;font-weight:bold;><body><span style=font-size:28px;><center>Flight Conditions"));
    else strcpy_P(tBuf, PSTR("<!DOCTYPE html><html><meta http-equiv=refresh content=1.5><body style=background-color:black;color:white;font-family:Verdana;font-weight:bold;><body><span style=font-size:28px;><center>Flight Conditions"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</span></p><span style=font-size:150px;line-height:53%;><center>"));
    client.write(tBuf);
    if (isReadyToFly == 1) strcpy_P(tBuf, PSTR("YES"));
    else strcpy_P(tBuf, PSTR("NO"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</span></a><span style=font-size:10px;><hr></span><span style=font-size:28px;line-height:100%;><center>Flight Status</span></p><span style=font-size:200px;line-height:53%;><center>"));
    client.write(tBuf);
    if (isInFlight == 1) strcpy_P(tBuf, PSTR("YES"));
    else strcpy_P(tBuf, PSTR("NO"));
    client.write(tBuf);
    if (displayColorMode == 1) strcpy_P(tBuf, PSTR("<span style=font-size:20px;line-height:0%;><p align=left><a href=flight.php?t=0>&lowast; <p align=right><a href=tackscore.php?t=1>&rarr; </P></span></a></span></a></body></html>"));
    else strcpy_P(tBuf, PSTR("<span style=font-size:20px;line-height:0%;><p align=left><a href=flight.php?t=1>&lowast; <p align=right><a href=tackscore.php?t=0>&rarr; </P></span></a></span></a></body></html>"));
    client.write(tBuf);
    }
    //////////Tack Scoring Info //
    else if (displayPageType == 9) ///Tack Score Info
    {
    if (displayColorMode == 1) strcpy_P(tBuf, PSTR("<!DOCTYPE html><html><meta http-equiv=refresh content=1.5><body style=color:black;background-color:white;font-family:Verdana;font-weight:bold;><body><span style=font-size:28px;><center>Distance Lost"));
    else strcpy_P(tBuf, PSTR("<!DOCTYPE html><html><meta http-equiv=refresh content=1.5><body style=background-color:black;color:white;font-family:Verdana;font-weight:bold;><body><span style=font-size:28px;><center>Forward Distance Lost (ft)"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</span></p><span style=font-size:150px;line-height:53%;><center>"));
    client.write(tBuf);
    if (postCounter == -1 ) dtostrf(finalForward, 5, 2, tBuf);
    else strcpy_P(tBuf, PSTR("Processing"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</span></a><span style=font-size:10px;><hr></span><span style=font-size:28px;line-height:100%;><center>Lane Loss (ft)</span></p><span style=font-size:100px;line-height:53%;><center>"));
    client.write(tBuf);
    if (postCounter == -1) itoa (finalLane, tBuf, 10);
    else itoa (postCounter, tBuf, 10);
    client.write(tBuf);
    if (displayColorMode == 1) strcpy_P(tBuf, PSTR("<span style=font-size:20px;line-height:0%;><p align=left><a href=tackscore.php?t=0>&lowast; <p align=right><a href=summary.php?t=1>&rarr; </P></span></a></span></a></body></html>"));
    else strcpy_P(tBuf, PSTR("<span style=font-size:20px;line-height:0%;><p align=left><a href=tackscore.php?t=1>&lowast; <p align=right><a href=summary.php?t=0>&rarr; </P></span></a></span></a></body></html>"));
    client.write(tBuf);
    }
    //////////list files on the SD card to a web page ////////
    else if (displayPageType == 10) ///List Files on SD
    {
    delay(100);
    strcpy_P(tBuf, PSTR("</H3></a><p></p>"));
    client.write(tBuf);
    File root;
    root = SD.open("/");
    printDirectory(root);
    root.rewindDirectory(); // you need to rewind the the Directory
    while (true)
    {
    File entry = root.openNextFile();
    if (! entry)
    {
    break;
    }
    if (statMsg == 1)
    {
    Serial.print(entry.name());
    Serial.print(" ");
    Serial.println(entry.size());
    }
    strcpy_P(tBuf, PSTR("<a href=\"HTTP://192.168.8.10/"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR(entry.name()));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("\"> <H2> "));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR(entry.name()));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</H2></a><p></p>"));
    client.write(tBuf);
    }
    delay(100);
    }

    //////////batttery monitor //
    if (displayPageType == 12)
    {
    if (displayColorMode == 1) strcpy_P(tBuf, PSTR("<!DOCTYPE html><html><meta http-equiv=refresh content=1.5><body style=color:black;background-color:white;font-family:Verdana;font-weight:bold;><body><span style=font-size:28px;><center>24 V System"));
    else strcpy_P(tBuf, PSTR("<!DOCTYPE html><html><meta http-equiv=refresh content=1.5><body style=background-color:black;color:white;font-family:Verdana;font-weight:bold;><body><span style=font-size:28px;><center>24 V Battery"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</span></p><span style=font-size:150px;line-height:53%;><center>"));
    client.write(tBuf);
    dtostrf(v24Actual, 5, 1, tBuf);
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("v&nbsp;&nbsp;"));
    client.write(tBuf);
    itoa (v24Pct, tBuf, 10);
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("%</span></a><span style=font-size:10px;><hr></span><span style=font-size:28px;line-height:100%;><center>12 V System</span></p><span style=font-size:150px;line-height:53%;><center>"));
    client.write(tBuf);
    dtostrf(v12Actual, 5, 1, tBuf);
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("v&nbsp;&nbsp;"));
    client.write(tBuf);
    itoa (v12Pct, tBuf, 10);
    client.write(tBuf);
    if (displayColorMode == 1) strcpy_P(tBuf, PSTR("%<span style=font-size:20px;line-height:0%;><p align=left><a href=batt.php?t=0>&lowast; <p align=right><a href=bsptwa.php?t=1>&rarr; </P></span></a></span></a></body></html>"));
    else strcpy_P(tBuf, PSTR("%<span style=font-size:20px;line-height:0%;><p align=left><a href=batt.php?t=1>&lowast; <p align=right><a href=bsptwa.php?t=0>&rarr; </P></span></a></span></a></body></html>"));
    client.write(tBuf);
    }


    /////////dot speed thresholds//
    else if (displayPageType == 13)
    {
    if (displayColorMode == 1) strcpy_P(tBuf, PSTR("<!DOCTYPE html><html><body style=color:black;background-color:white;font-family:Verdana;font-weight:bold;><body><span style=font-size:28px;><center>Min DOT BSP<p/>"));
    else strcpy_P(tBuf, PSTR("<!DOCTYPE html><html><body style=background-color:black;color:white;font-family:Verdana;font-weight:bold;><body><span style=font-size:28px;><center>Min Dot BSP"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</span></p><span style=font-size:100px;line-height:53%;><center>"));
    client.write(tBuf);
    float wFlightBspFloat = bspFlightMin * .01;
    dtostrf(wFlightBspFloat, 5, 2, tBuf);
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("<span style=font-family:Verdana;font-size:30px;font-style:normal;font-weight:bold;line-height:53%;></p><center> Change To:</span></p><a href=DOT.PHP?g=0>-2kt&nbsp;&nbsp;</span></a><a href=DOT.PHP?g=2>-1kt&nbsp;&nbsp;"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</span></a><a href=DOT.PHP?g=4>-.5kt&nbsp;&nbsp;</span></a><a href=DOT.PHP?g=5>+.5kt&nbsp;&nbsp;</span></a><a href=DOT.PHP?g=3>+1kt&nbsp;&nbsp;</span></a><a href=DOT.PHP?g=1>+2kt&nbsp;&nbsp;</span></a>"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</span></a><span style=font-size:10px;><hr></span><span style=font-size:28px;line-height:100%;><center>Min DOT TWS</span></p><span style=font-size:100px;line-height:53%;><center>"));
    client.write(tBuf);
    float wFlightTwsFloat = twsFlightMin * .01;
    dtostrf(wFlightTwsFloat, 5, 2, tBuf);
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("<span style=font-family:Verdana;font-size:30px;font-style:normal;font-weight:bold;line-height:53%;></p><center> Change To:</span></p><a href=DOT.PHP?j=0>-2kt&nbsp;&nbsp;</span></a><a href=DOT.PHP?j=2>-1kt&nbsp;&nbsp;"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</span></a><a href=DOT.PHP?j=4>-.5kt&nbsp;&nbsp;</span></a><a href=DOT.PHP?j=5>+.5kt&nbsp;&nbsp;</span></a><a href=DOT.PHP?j=3>+1kt&nbsp;&nbsp;</span></a><a href=DOT.PHP?j=1>+2kt&nbsp;&nbsp;</span></a>"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</span></a><span style=font-size:10px;><hr></span><span style=font-size:28px;line-height:100%;><center>Target / Polar Gain</span></p><span style=font-size:100px;line-height:53%;><center>"));
    client.write(tBuf);
    itoa (targetSpeedMultiplier, tBuf, 10);
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("<span style=font-family:Verdana;font-size:30px;font-style:normal;font-weight:bold;line-height:53%;></p><center> Change To:</span></p><a href=DOT.PHP?k=4>-5&nbsp;&nbsp;</span></a><a href=DOT.PHP?k=0>-2&nbsp;&nbsp;</span></a>"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("<a href=DOT.PHP?k=2>-1&nbsp;&nbsp;</span></a></span></a><a href=DOT.PHP?k=3>+1&nbsp;&nbsp;</span></a><a href=DOT.PHP?k=1>+2&nbsp;&nbsp;</span></a><a href=DOT.PHP?k=5>+5&nbsp;&nbsp;"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</span></a><span style=font-size:10px;><hr></span><span style=font-size:28px;line-height:100%;><center>Caution Heel Angle</span></p><span style=font-size:100px;line-height:53%;><center>"));
    client.write(tBuf);
    itoa (cautionRoll, tBuf, 10);
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("<span style=font-family:Verdana;font-size:30px;font-style:normal;font-weight:bold;line-height:53%;></p><center> Change To:</span></p><a href=DOT.PHP?h=0>-2&nbsp;&nbsp;</span></a><a href=DOT.PHP?h=2>-1&nbsp;&nbsp;"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</span></a><a href=DOT.PHP?h=3>+1&nbsp;&nbsp;</span></a><a href=DOT.PHP?h=1>+2&nbsp;&nbsp;</span></a>"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</span></a><span style=font-size:10px;><hr></span><span style=font-size:28px;line-height:100%;><center>Warning Heel Angle (RED)</span></p><span style=font-size:100px;line-height:53%;><center>"));
    client.write(tBuf);
    itoa (warningRoll, tBuf, 10);
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("<span style=font-family:Verdana;font-size:30px;font-style:normal;font-weight:bold;line-height:53%;></p><center> Change To:</span></p><a href=DOT.PHP?q=0>-2&nbsp;&nbsp;</span></a><a href=DOT.PHP?q=2>-1&nbsp;&nbsp;"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</span></a><a href=DOT.PHP?q=3>+1&nbsp;&nbsp;</span></a><a href=DOT.PHP?q=1>+2&nbsp;&nbsp;</span></a>"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</span></a><span style=font-size:10px;><hr></span><span style=font-size:28px;line-height:100%;><center>CenterPixel</span></p><span style=font-size:100px;line-height:53%;><center>"));
    client.write(tBuf);
    itoa (centerPixel, tBuf, 10);
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("<span style=font-family:Verdana;font-size:30px;font-style:normal;font-weight:bold;line-height:53%;></p><center> Change To:</span></p><a href=DOT.PHP?c=0>-2&nbsp;&nbsp;</span></a><a href=DOT.PHP?c=2>-1&nbsp;&nbsp;"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</span></a><a href=DOT.PHP?c=3>+1&nbsp;&nbsp;</span></a><a href=DOT.PHP?c=1>+2&nbsp;&nbsp;</span></a>"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</span></a><span style=font-size:10px;><hr></span><span style=font-size:28px;line-height:100%;><center>Update Settings File</span></p><span style=font-size:100px;line-height:53%;><center>"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("<span style=font-family:Verdana;font-size:30px;font-style:normal;font-weight:bold;line-height:53%;></p><center> </span></p><a href=DOT.PHP?o=1>PRESS TO UPDATE</span></a>"));
    client.write(tBuf);
    if (displayColorMode == 1) strcpy_P(tBuf, PSTR("<span style=font-size:20px;line-height:0%;><p align=left><a href=dot.php?t=0>&lowast; <p align=right><a href=sail.php?t=1>&rarr; </P></span></a></span></a></body></html>"));
    else strcpy_P(tBuf, PSTR("<span style=font-size:20px;line-height:0%;><p align=left><a href=dot.php?t=1>&lowast; <p align=right><a href=sail.php?t=0>&rarr; </P></span></a></span></a></body></html>"));
    client.write(tBuf);
    }
    //////////Boaspeed - Polar Speed //////
    else if (displayPageType == 14)
    {
    if (displayColorMode == 1) strcpy_P(tBuf, PSTR("<!DOCTYPE html><html><meta http-equiv=refresh content=1.5><body style=color:black;background-color:white;font-family:Verdana;font-weight:bold;><body><span style=font-size:28px;><center>Boatspeed"));
    else strcpy_P(tBuf, PSTR("<!DOCTYPE html><html><meta http-equiv=refresh content=1.5><body style=background-color:black;color:white;font-family:Verdana;font-weight:bold;><body><span style=font-size:28px;><center>Boatspeed"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</span></p><span style=font-size:200px;line-height:53%;><center>"));
    client.write(tBuf);
    float wBspFloat = bspInt * .01;
    dtostrf(wBspFloat, 5, 2, tBuf);
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</span></a><span style=font-size:10px;><hr></span><span style=font-size:28px;line-height:100%;><center>Polar BSP</span></p><span style=font-size:200px;line-height:53%;><center>"));
    client.write(tBuf);
    dtostrf(polarBsp, 5, 2, tBuf);
    client.write(tBuf);
    if (displayColorMode == 1) strcpy_P(tBuf, PSTR("<span style=font-size:20px;line-height:0%;><p align=left><a href=bsppol.php?t=0>&lowast; <p align=right><a href=rngbrg.php?t=1>&rarr; </P></span></a></span></a></body></html>"));
    else strcpy_P(tBuf, PSTR("<span style=font-size:20px;line-height:0%;><p align=left><a href=bsppol.php?t=1>&lowast; <p align=right><a href=rngbrg.php?t=0>&rarr; </P></span></a></span></a></body></html>"));
    client.write(tBuf);
    }
    /////////System Features //
    else if (displayPageType == 15)
    {
    if (displayColorMode == 1) strcpy_P(tBuf, PSTR("<!DOCTYPE html><html><body style=color:black;background-color:white;font-family:Verdana;font-weight:bold;><body><span style=font-size:28px;><center>Standard NMEA Outputs<p/>"));
    else strcpy_P(tBuf, PSTR("<!DOCTYPE html><html><body style=background-color:black;color:white;font-family:Verdana;font-weight:bold;><body><span style=font-size:28px;><center>Standard NMEA Outputs"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</span></p><span style=font-size:100px;line-height:53%;><center>"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("S0: "));
    client.write(tBuf);
    itoa (NMEAPlay, tBuf, 10);
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("&nbsp;&nbsp;S1: "));
    client.write(tBuf);
    itoa (s1NMEAComm, tBuf, 10);
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("&nbsp;&nbsp;S3: "));
    client.write(tBuf);
    itoa (s3NMEAComm, tBuf, 10);
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("<span style=font-family:Verdana;font-size:30px;font-style:normal;font-weight:bold;line-height:53%;></p><center> Change To:</span></p><a href=COMM.PHP?w=16>S0 OFF&nbsp;&nbsp;</span></a><a href=COMM.PHP?w=17>S0 ON&nbsp;&nbsp;&nbsp;&nbsp; </span></a>"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("<a href=COMM.PHP?w=12>S1 OFF&nbsp;&nbsp;</span></a><a href=COMM.PHP?w=13>S1 ON&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></a><a href=COMM.PHP?w=14>S3 OFF&nbsp;&nbsp;</span></a><a href=COMM.PHP?w=15>S3 ON&nbsp;&nbsp;</span></a>"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("<span style=font-size:10px;><hr></span><span style=font-size:28px;line-height:100%;><center>Special NMEA XDR Sentences</span></p><span style=font-size:100px;line-height:53%;><center>"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("S0: "));
    client.write(tBuf);
    itoa (s0XDRComm, tBuf, 10);
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("&nbsp;&nbsp;S1: "));
    client.write(tBuf);
    itoa (s1XDRComm, tBuf, 10);
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("&nbsp;&nbsp;S3: "));
    client.write(tBuf);
    itoa (s3XDRComm, tBuf, 10);
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("<span style=font-family:Verdana;font-size:30px;font-style:normal;font-weight:bold;line-height:53%;></p><center> Change To:</span></p><a href=COMM.PHP?w=6>S0 OFF&nbsp;&nbsp;</span></a><a href=COMM.PHP?w=7>S0 ON&nbsp;&nbsp;&nbsp;&nbsp; </span></a>"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("<a href=COMM.PHP?w=8>S1 OFF&nbsp;&nbsp;</span></a><a href=COMM.PHP?w=9>S1 ON&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></a><a href=COMM.PHP?w=10>S3 OFF&nbsp;&nbsp;</span></a><a href=COMM.PHP?w=11>S3 ON&nbsp;&nbsp;</span></a>"));
    client.write(tBuf);

    strcpy_P(tBuf, PSTR("<span style=font-size:10px;><hr></span><span style=font-size:28px;line-height:100%;><center>PIX Sentences</span></p><span style=font-size:100px;line-height:53%;><center>"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("S0: "));
    client.write(tBuf);
    itoa (s0PIXComm, tBuf, 10);
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("&nbsp;&nbsp;S1: "));
    client.write(tBuf);
    itoa (s1PIXComm, tBuf, 10);
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("&nbsp;&nbsp;S3: "));
    client.write(tBuf);
    itoa (s3PIXComm, tBuf, 10);
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("<span style=font-family:Verdana;font-size:30px;font-style:normal;font-weight:bold;line-height:53%;></p><center> Change To:</span></p><a href=COMM.PHP?w=0>S0 OFF&nbsp;&nbsp;</span></a><a href=COMM.PHP?w=1>S0 ON&nbsp;&nbsp;&nbsp;&nbsp; </span></a>"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("<a href=COMM.PHP?w=2>S1 OFF&nbsp;&nbsp;</span></a><a href=COMM.PHP?w=3>S1 ON&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></a><a href=COMM.PHP?w=4>S3 OFF&nbsp;&nbsp;</span></a><a href=COMM.PHP?w=5>S3 ON&nbsp;&nbsp;</span></a>"));
    client.write(tBuf);
    if (displayColorMode == 1) strcpy_P(tBuf, PSTR("<span style=font-size:20px;line-height:0%;><p align=left><a href=COMM.php?t=0>&lowast; <p align=right><a href=dot.php?t=1>&rarr; </P></span></a></span></a></body></html>"));
    else strcpy_P(tBuf, PSTR("<span style=font-size:20px;line-height:0%;><p align=left><a href=COMM.php?t=1>&lowast; <p align=right><a href=dot.php>&rarr; </P></span></a></span></a></body></html>"));
    client.write(tBuf);
    }
    /////////System Features //
    else if (displayPageType == 16)
    {
    if (displayColorMode == 1) strcpy_P(tBuf, PSTR("<!DOCTYPE html><html><body style=color:black;background-color:white;font-family:Verdana;font-weight:bold;><body><span style=font-size:28px;><center>Heel/Pitch/Barometer<p/>"));
    else strcpy_P(tBuf, PSTR("<!DOCTYPE html><html><body style=background-color:black;color:white;font-family:Verdana;font-weight:bold;><body><span style=font-size:28px;><center>Heel/Pitch/Barometer"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</span></p><span style=font-size:100px;line-height:53%;><center>"));
    client.write(tBuf);
    if (Sensor == 0 && Barometer == 0) strcpy_P(tBuf, PSTR("All OFF"));
    else if (Sensor == 1 && Barometer == 1) strcpy_P(tBuf, PSTR("ON"));
    else if (Sensor == 0 && Barometer == 1) strcpy_P(tBuf, PSTR(" Sensor OFF"));
    else if (Sensor == 1 && Barometer == 0) strcpy_P(tBuf, PSTR("Barometer OFF"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("<span style=font-family:Verdana;font-size:30px;font-style:normal;font-weight:bold;line-height:53%;></p><center> Change To:</span></p><a href=FEAT.PHP?z=43>OFF &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></a><a href=FEAT.PHP?z=44>ON&nbsp;&nbsp; </span></a>"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</span></a><span style=font-size:10px;><hr></span><span style=font-size:28px;line-height:100%;><center>Flight Sentences</span></p><span style=font-size:100px;line-height:53%;><center>"));
    client.write(tBuf);
    if (PIXGenerate == 1) strcpy_P(tBuf, PSTR("ON"));
    else if (PIXGenerate == 0) strcpy_P(tBuf, PSTR("OFF"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("<span style=font-family:Verdana;font-size:30px;font-style:normal;font-weight:bold;line-height:53%;></p><center> Change To:</span></p><a href=FEAT.PHP?z=60>OFF&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;</span></a><a href=FEAT.PHP?z=61>ON&nbsp;&nbsp;</span></a>"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</span></a><span style=font-size:10px;><hr></span><span style=font-size:28px;line-height:100%;><center>Tack Scoring</span></p><span style=font-size:100px;line-height:53%;><center>"));
    client.write(tBuf);
    if (tackScoreData == 0) strcpy_P(tBuf, PSTR("OFF"));
    else if (tackScoreData == 1) strcpy_P(tBuf, PSTR("ON"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("<span style=font-family:Verdana;font-size:30px;font-style:normal;font-weight:bold;line-height:53%;></p><center> Change To:</span></p><a href=FEAT.PHP?z=0>OFF&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ; </span></a><a href=FEAT.PHP?z=1>ON&nbsp;&nbsp;</span></a>"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</span></a><span style=font-size:10px;><hr></span><span style=font-size:28px;line-height:100%;><center>Voltage Monitoring</span></p><span style=font-size:100px;line-height:53%;><center>"));
    client.write(tBuf);
    if (v12Record == 0 && v24Record == 0) strcpy_P(tBuf, PSTR("All OFF"));
    else if (v12Record == 1 && v24Record == 1) strcpy_P(tBuf, PSTR("ALL ON"));
    else if (v12Record == 0 && v24Record == 1) strcpy_P(tBuf, PSTR("24v ON 12v OFF"));
    else if (v12Record == 1 && v24Record == 0) strcpy_P(tBuf, PSTR("12v ON 24v OFF"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("<span style=font-family:Verdana;font-size:30px;font-style:normal;font-weight:bold;line-height:53%;></p><center> Change To:</span></p><a href=FEAT.PHP?z=34> ALL OFF&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></a><a href=FEAT.PHP?z=35>ALL ON&nbsp;&nbsp;</span></a>"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</span></a><span style=font-size:10px;><hr></span><span style=font-size:28px;line-height:100%;><center>SD Logging Type</span></p><span style=font-size:100px;line-height:53%;><center>"));
    client.write(tBuf);
    if (directLog == 1) strcpy_P(tBuf, PSTR("Expedition"));
    else if (NMEALog == 1) strcpy_P(tBuf, PSTR("NMEA0183"));
    else if (directLog == 0 && NMEALog == 0) strcpy_P(tBuf, PSTR("OFF"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("<span style=font-family:Verdana;font-size:30px;font-style:normal;font-weight:bold;line-height:53%;></p><center> Change To:</span></p><a href=FEAT.PHP?d=0> ALL OFF&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></a><a href=FEAT.PHP?d=1>Expedition&nbsp;&nbsp;</span></a>"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("<a href=FEAT.PHP?d=2>NMEA0183&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;</span></a>"));
    client.write(tBuf);
    if (displayColorMode == 1) strcpy_P(tBuf, PSTR("<span style=font-size:20px;line-height:0%;><p align=left><a href=feat.php?t=0>&lowast; <p align=right><a href=comm.php?t=1>&rarr; </P></span></a></span></a></body></html>"));
    else strcpy_P(tBuf, PSTR("<span style=font-size:20px;line-height:0%;><p align=left><a href=feat.php?t=1>&lowast; <p align=right><a href=comm.php>&rarr; </P></span></a></span></a></body></html>"));
    client.write(tBuf);
    }

    /////////system switches FEA2//
    else if (displayPageType == 17)
    {
    if (displayColorMode == 1) strcpy_P(tBuf, PSTR("<!DOCTYPE html><html><body style=color:black;background-color:white;font-family:Verdana;font-weight:bold;><body><span style=font-size:28px;><center>Logging<p/>"));
    else strcpy_P(tBuf, PSTR("<!DOCTYPE html><html><body style=background-color:black;color:white;font-family:Verdana;font-weight:bold;><body><span style=font-size:28px;><center>zzLogging"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</span></p><span style=font-size:100px;line-height:53%;><center>"));
    client.write(tBuf);
    if (directLog == 1) strcpy_P(tBuf, PSTR("Expedition"));
    else if (NMEALog == 1) strcpy_P(tBuf, PSTR("NMEA0183"));
    else if (directLog == 0 && NMEALog == 0) strcpy_P(tBuf, PSTR("OFF"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("<span style=font-family:Verdana;font-size:30px;font-style:normal;font-weight:bold;line-height:53%;></p><center> Change To:</span></p><a href=PICK.PHP?b=0>0&nbsp;&nbsp;</span></a><a href=PICK.PHP?b=1>1&nbsp;&nbsp;"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</span></a><a href=FEA2.PHP?b=2>2&nbsp;&nbsp;</span></a><a href=FEA2.PHP?b=3>3&nbsp;&nbsp;</span></a><a href=FEA2.PHP?b=4>4&nbsp;&nbsp;</span></a><a href=FEA2.PHP?b=5>5&nbsp;&nbsp;</span></a>"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</span></a><a href=FEA2.PHP?b=6>6&nbsp;&nbsp;</span></a><a href=FEA2.PHP?b=7>7&nbsp;</span></a></p>"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</span></a><span style=font-size:10px;><hr></span><span style=font-size:28px;line-height:100%;><center>DOT Display Mode</span></p><span style=font-size:100px;line-height:53%;><center>"));
    client.write(tBuf);
    if (dotMode == 1) strcpy_P(tBuf, PSTR("Target Speed"));
    else if (dotMode == 2) strcpy_P(tBuf, PSTR("TWA"));
    else if (dotMode == 3) strcpy_P(tBuf, PSTR("Polar Speed"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("<span style=font-family:Verdana;font-size:30px;font-style:normal;font-weight:bold;line-height:53%;></p><center> Change To:</span></p><a href=FEA2.PHP?m=1>Target Speed&nbsp;&nbsp;"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</span></a><a href=FEA2.PHP?m=2>TWA&nbsp;&nbsp;</span></a><a href=FEA2.PHP?m=3>Polar Speed&nbsp;&nbsp;</span></a></p>"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</span></a><span style=font-size:10px;><hr></span><span style=font-size:28px;line-height:100%;><center>Flight Ready Mode</span></p><span style=font-size:100px;line-height:53%;><center>"));
    client.write(tBuf);
    if (isReadyMode == 1) strcpy_P(tBuf, PSTR("BSP"));
    else if (isReadyMode == 2) strcpy_P(tBuf, PSTR("TWS"));
    else if (isReadyMode == 3) strcpy_P(tBuf, PSTR("BSP and TWS"));
    else if (isReadyMode == 4) strcpy_P(tBuf, PSTR("BSP or TWS"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("<span style=font-family:Verdana;font-size:30px;font-style:normal;font-weight:bold;line-height:53%;></p><center> Change To:</span></p><a href=FEA2.PHP?n=1>BSP&nbsp;&nbsp; </span></a><a href=FEA2.PHP?n=2>TWS&nbsp;&nbsp;"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</span></a><a href=FEA2.PHP?n=3>BOTH&nbsp;&nbsp;</span></a><a href=FEA2.PHP?n=4>EITHER&nbsp;&nbsp;</span></a></p>"));
    client.write(tBuf);
    if (displayColorMode == 1) strcpy_P(tBuf, PSTR("<span style=font-size:20px;line-height:0%;><p align=left><a href=FEA2.php?t=0>&lowast; <p align=right><a href=mytest.php?t=1>&rarr; </P></span></a></span></a></body></html>"));
    else strcpy_P(tBuf, PSTR("<span style=font-size:20px;line-height:0%;><p align=left><a href=FEA2.php?t=1>&lowast; <p align=right><a href=mytest.php>&rarr; </P></span></a></span></a></body></html>"));
    client.write(tBuf);
    }
    /////////Sail Selection //
    else if (displayPageType == 18)
    {
    if (displayColorMode == 1) strcpy_P(tBuf, PSTR("<!DOCTYPE html><html><body style=color:black;background-color:white;font-family:Verdana;font-weight:bold;><body><span style=font-size:28px;><center>Active Headsail<p/>"));
    else strcpy_P(tBuf, PSTR("<!DOCTYPE html><html><body style=background-color:black;color:white;font-family:Verdana;font-weight:bold;><body><span style=font-size:28px;><center>Active Headsail"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</span></p><span style=font-size:100px;line-height:53%;><center>"));
    client.write(tBuf);
    if (activeSailCode == 400) strcpy_P(tBuf, PSTR("C0"));
    else if (activeSailCode == 100) strcpy_P(tBuf, PSTR("A1"));
    else if (activeSailCode == 200) strcpy_P(tBuf, PSTR("A2"));
    else if (activeSailCode == 300) strcpy_P(tBuf, PSTR("A3"));
    else if (activeSailCode == 500) strcpy_P(tBuf, PSTR("SOLENT"));
    else if (activeSailCode % 100 == 50) strcpy_P(tBuf, PSTR("Stysl"));
    else if (activeSailCode % 100 == 25) strcpy_P(tBuf, PSTR("1 Reef"));
    else if (activeSailCode % 100 == 12) strcpy_P(tBuf, PSTR("2 Reef"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</span><span style=font-family:Verdana;font-size:30px;font-style:normal;font-weight:bold;line-height:53%;><center></p> Change To: </p><a href=SAIL.PHP?x=0>A0&nbsp; </span></a></p> <a href=SAIL.PHP?x=1>A1&nbsp;"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</span></a></p><a href=SAIL.PHP?x=2>A2&nbsp;</span></a></p><a href=SAIL.PHP?x=3>A3&nbsp;</span></a></p><a href=SAIL.PHP?x=4>Solent&nbsp;</span></a></p><a href=SAIL.PHP?x=5>Staysail&nbsp;</span></a></p>"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</span></a><span style=font-size:10px;><hr></span><span style=font-size:28px;line-height:100%;><center>Board Height</span></p><span style=font-size:100px;line-height:53%;><center>"));
    client.write(tBuf);
    dtostrf(boardHeight, 5, 2, tBuf);
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("<span style=font-family:Verdana;font-size:30px;font-style:normal;font-weight:bold;line-height:53%;></p><center> Change To:</span></p><a href=SAIL.PHP?y=0>0&nbsp; </span></a></p> <a href=SAIL.PHP?y=0.5>.5&nbsp;"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</span></a></p><a href=SAIL.PHP?y=1.0>1&nbsp;</span></a></p><a href=SAIL.PHP?y=1.5>1.5&nbsp;</span></a></p><a href=SAIL.PHP?y=2>2&nbsp;</span></a></p><a href=SAIL.PHP?y=2.5>2.5&nbsp;</span></a></p>"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</span></a></p><a href=SAIL.PHP?y=3>3&nbsp;</span></a></p><a href=SAIL.PHP?y=3.5>3.5&nbsp;</span></a></p><a href=SAIL.PHP?y=4>4&nbsp;</span></a></p><a href=SAIL.PHP?y=4.5>4.5&nbsp;</span></a></p><a href=SAIL.PHP?y=5>5&nbsp;</span></a></p>"));
    client.write(tBuf);

    strcpy_P(tBuf, PSTR("</span></a><span style=font-size:10px;><hr></span><span style=font-size:28px;line-height:100%;><center>Traveler Position</span></p><span style=font-size:100px;line-height:53%;><center>"));
    client.write(tBuf);
    dtostrf(travPos, 5, 2, tBuf);
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("<span style=font-family:Verdana;font-size:30px;font-style:normal;font-weight:bold;line-height:53%;></p><center> Change To:</span></p><a href=SAIL.PHP?e=-1>-1&nbsp;</span></a></p><a href=SAIL.PHP?e=0>0&nbsp;</span></a></p><a href=SAIL.PHP?e=0.5>.5&nbsp;"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</span></a></p><a href=SAIL.PHP?e=1.0>1&nbsp;</span></a></p><a href=SAIL.PHP?e=1.5>1.5&nbsp;</span></a></p><a href=SAIL.PHP?e=2>2&nbsp;</span></a></p><a href=SAIL.PHP?e=2.5>2.5&nbsp;</span></a></p>"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</span></a></p><a href=SAIL.PHP?e=3>3&nbsp;</span></a></p><a href=SAIL.PHP?e=3.5>3.5&nbsp;</span></a></p><a href=SAIL.PHP?e=4>4&nbsp;</span></a></p><a href=SAIL.PHP?e=4.5>4.5&nbsp;</span></a></p><a href=SAIL.PHP?e=5>5&nbsp;</span></a></p>"));
    client.write(tBuf);

    if (displayColorMode == 1) strcpy_P(tBuf, PSTR("<span style=font-size:20px;line-height:0%;><p align=left><a href=sail.php?t=0>&lowast; <p align=right><a href=mode.php?t=1>&rarr; </P></span></a></span></a></body></html>"));
    else strcpy_P(tBuf, PSTR("<span style=font-size:20px;line-height:0%;><p align=left><a href=sail.php?t=1>&lowast; <p align=right><a href=mode.php>&rarr; </P></span></a></span></a></body></html>"));
    client.write(tBuf);
    }
    /////////dot Brightness & Mode //
    else if (displayPageType == 19)
    {
    if (displayColorMode == 1) strcpy_P(tBuf, PSTR("<!DOCTYPE html><html><body style=color:black;background-color:white;font-family:Verdana;font-weight:bold;><body><span style=font-size:28px;><center>Dot Brightness<p/>"));
    else strcpy_P(tBuf, PSTR("<!DOCTYPE html><html><body style=background-color:black;color:white;font-family:Verdana;font-weight:bold;><body><span style=font-size:28px;><center>Dot Brightness"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</span></p><span style=font-size:100px;line-height:53%;><center>"));
    client.write(tBuf);
    itoa (dotBrightess, tBuf, 10);
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("<span style=font-family:Verdana;font-size:30px;font-style:normal;font-weight:bold;line-height:53%;></p><center> Change To:</span></p><a href=MODE.PHP?b=0>0&nbsp;&nbsp;</span></a><a href=MODE.PHP?b=1>1&nbsp;&nbsp;"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</span></a><a href=MODE.PHP?b=2>2&nbsp;&nbsp;</span></a><a href=MODE.PHP?b=3>3&nbsp;&nbsp;</span></a><a href=mode.PHP?b=4>4&nbsp;&nbsp;</span></a><a href=MODE.PHP?b=5>5&nbsp;&nbsp;</span></a>"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</span></a><a href=MODE.PHP?b=6>6&nbsp;&nbsp;</span></a><a href=MODE.PHP?b=7>7&nbsp;</span></a></p>"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</span></a><span style=font-size:10px;><hr></span><span style=font-size:28px;line-height:100%;><center>DOT Display Mode</span></p><span style=font-size:100px;line-height:53%;><center>"));
    client.write(tBuf);
    if (dotMode == 1) strcpy_P(tBuf, PSTR("Target Speed"));
    else if (dotMode == 2) strcpy_P(tBuf, PSTR("TWA"));
    else if (dotMode == 3) strcpy_P(tBuf, PSTR("Polar Speed"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("<span style=font-family:Verdana;font-size:30px;font-style:normal;font-weight:bold;line-height:53%;></p><center> Change To:</span></p><a href=MODE.PHP?m=1>Target Speed&nbsp;&nbsp;"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</span></a><a href=MODE.PHP?m=2>TWA&nbsp;&nbsp;</span></a><a href=MODE.PHP?m=3>Polar Speed&nbsp;&nbsp;</span></a></p>"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</span></a><span style=font-size:10px;><hr></span><span style=font-size:28px;line-height:100%;><center>Flight Ready Mode</span></p><span style=font-size:100px;line-height:53%;><center>"));
    client.write(tBuf);
    if (isReadyMode == 1) strcpy_P(tBuf, PSTR("BSP"));
    else if (isReadyMode == 2) strcpy_P(tBuf, PSTR("TWS"));
    else if (isReadyMode == 3) strcpy_P(tBuf, PSTR("BSP and TWS"));
    else if (isReadyMode == 4) strcpy_P(tBuf, PSTR("BSP or TWS"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("<span style=font-family:Verdana;font-size:30px;font-style:normal;font-weight:bold;line-height:53%;></p><center> Change To:</span></p><a href=MODE.PHP?n=1>BSP&nbsp;&nbsp; </span></a><a href=MODE.PHP?n=2>TWS&nbsp;&nbsp;"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</span></a><a href=MODE.PHP?n=3>BOTH&nbsp;&nbsp;</span></a><a href=MODE.PHP?n=4>EITHER&nbsp;&nbsp;</span></a></p>"));
    client.write(tBuf);

    strcpy_P(tBuf, PSTR("</span></a><span style=font-size:10px;><hr></span><span style=font-size:28px;line-height:100%;><center>Mood Lighting</span></p><span style=font-size:100px;line-height:53%;><center>"));
    client.write(tBuf);
    if (dotReset == 3) strcpy_P(tBuf, PSTR("Blue"));
    if (dotReset == 4) strcpy_P(tBuf, PSTR("White"));
    if (dotReset == 5) strcpy_P(tBuf, PSTR("Red"));
    if (dotReset == 6) strcpy_P(tBuf, PSTR("Yellow"));
    if (dotReset == 7) strcpy_P(tBuf, PSTR("Purple"));
    if (dotReset == 8) strcpy_P(tBuf, PSTR("Clear All"));
    if (dotReset == 1) strcpy_P(tBuf, PSTR("Sailing Mode"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("<span style=font-family:Verdana;font-size:30px;font-style:normal;font-weight:bold;line-height:53%;></p><center> Change To:</span></p><a href=MODE.PHP?z=71>Sailing Mode&nbsp;&nbsp; </span></a><a href=MODE.PHP?z=73>Blue&nbsp;&nbsp;"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</span></a><a href=MODE.PHP?z=74>White&nbsp;&nbsp;</span></a><a href=MODE.PHP?z=75>Red&nbsp;&nbsp;</span></a></p></span></a><a href=MODE.PHP?z=75>Red&nbsp;&nbsp;</span></a></span></a><a href=MODE.PHP?z=76>Yellow&nbsp;&nbsp;</span></a>"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</span></a><a href=MODE.PHP?z=77>Purple&nbsp;&nbsp;</span></a><a href=MODE.PHP?z=78>Wipe&nbsp;&nbsp;</span></a>"));
    client.write(tBuf);


    if (displayColorMode == 1) strcpy_P(tBuf, PSTR("<span style=font-size:20px;line-height:0%;><p align=left><a href=mode.php?t=0>&lowast; <p align=right><a href=feat.php?t=1>&rarr; </P></span></a></span></a></body></html>"));
    else strcpy_P(tBuf, PSTR("<span style=font-size:20px;line-height:0%;><p align=left><a href=mode.php?t=1>&lowast; <p align=right><a href=feat.php>&rarr; </P></span></a></span></a></body></html>"));
    client.write(tBuf);
    }
    ///////////default mytest.php page//////
    else if (strcmp(requestBuffer, "/MYTEST.PHP") == 0)
    {
    strcpy_P(tBuf, PSTR("<html><head><script type=\"text/javascript\">"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("function show_alert() {alert(\"Are You Sure?\");}"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</script></head><body><H1>Configuration and Tuning Paramaters</H1><form method=GET onSubmit=\"show_alert()\">"));
    client.write(tBuf);
    //brightnessw////////////////
    strcpy_P(tBuf, PSTR("DOT Brightness...................range 0 to 8..... <input type=text name=b><input type=submit></form></body></html>"));
    client.write(tBuf);

    ///minimum BSP for flight////////////////
    strcpy_P(tBuf, PSTR("<form method=GET onSubmit=\"show_alert()\">Min BSP for flight........in 1/100 of a kt...... <input type=text name=v><input type=submit></form></body></html>"));
    client.write(tBuf);

    ///minimum TWS for flight////////////////
    strcpy_P(tBuf, PSTR("<form method=GET onSubmit=\"show_alert()\">Min TWS for flight.........in 1/10 of a kt...... <input type=text name=a><input type=submit></form></body></html>"));
    client.write(tBuf);

    ///minimum HEEL for caution/////////////
    strcpy_P(tBuf, PSTR("<form method=GET onSubmit=\"show_alert()\">Caution (purple) HEEL angle...20 to 30... <input type=text name=h><input type=submit></form></body></html>"));
    client.write(tBuf);

    ///minimum HEEL WARNING////////////////
    strcpy_P(tBuf, PSTR("<form method=GET onSubmit=\"show_alert()\">WARNING (RED) HEEL angle... 30 to 50.. <input type=text name=w><input type=submit></form></body></html>"));
    client.write(tBuf);

    ///minimum %////
    strcpy_P(tBuf, PSTR("<form method=GET onSubmit=\"show_alert()\">Display Range. set to 80 for a 20% range <input type=text name=p><input type=submit></form></body></html>"));
    client.write(tBuf);

    ///minimum target %///
    strcpy_P(tBuf, PSTR("<form method=GET onSubmit=\"show_alert()\">TARGET BSP Percentage........Typ 100...... <input type=text name=p><input type=submit></form></body></html>"));
    client.write(tBuf);

    //centerpixel %/////
    strcpy_P(tBuf, PSTR("<form method=GET onSubmit=\"show_alert()\">TARGET Pixel (Blue Dot).......Typ 11........ <input type=text name=c><input type=submit></form></body></html>"));
    client.write(tBuf);

    ///mode////////////////
    strcpy_P(tBuf, PSTR("<form method=GET onSubmit=\"show_alert()\"> Flight Target MODE...............1 to 4........... <input type=text name=m><input type=submit></form></body></html>"));
    client.write(tBuf);

    ///mode////////////////
    strcpy_P(tBuf, PSTR("<form method=GET onSubmit=\"show_alert()\">Flight Ready MODE ............1 to 3.............. <input type=text name=n><input type=submit></form></body></html></p>"));
    client.write(tBuf);

    if (displayColorMode == 1)strcpy_P(tBuf, PSTR("<span style=font-size:20px;line-height:0%;><p align=left><a href=mytest.php?t=0>&lowast; <p align=right><a href=sail.php?t=1>&rarr; </P></span></a></span></a></body></html>"));
    else strcpy_P(tBuf, PSTR("<span style=font-size:20px;line-height:0%;><p align=left><a href=mytest.php?t=1>&lowast; <p align=right><a href=sail.php?t=0>&rarr; </P></span></a></span></a></body></html>"));
    client.write(tBuf);
    }
    /////////// 9 up detail page/////////////
    else if (displayPageType == 7) ///////////nine up page
    {
    if (displayColorMode == 1)
    {
    strcpy_P(tBuf, PSTR("<!DOCTYPE html><html><meta http-equiv=refresh content=3><body style=color:black;background-color:white;font-family:Verdana;font-weight:bold;>"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("<body><span style=font-size:28px;><center>BSP----------------Target----------------Pct</span></p><span style=font-size:48px;line-height:100%;><center>"));
    client.write(tBuf);
    }
    else
    {
    strcpy_P(tBuf, PSTR("<!DOCTYPE html><html><meta http-equiv=refresh content=5><body style=background-color:black;color:white;font-family:Verdana;font-weight:bold;>;"));
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("<body><span style=font-size:28px;><center>BSP----------------Target----------------Pct</span></p><span style=font-size:48px;line-height:100%;><center>"));
    client.write(tBuf);
    }
    float wBspFloat = bspInt * .01; ////////speed
    dtostrf(wBspFloat, 5, 2, tBuf);
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("......."));
    client.write(tBuf);
    float trgBspFloat = targetBSPAvg * .01; /////////target
    dtostrf(trgBspFloat, 5, 2, tBuf);
    client.write(tBuf);
    strcpy_P(tBuf, PSTR(".........."));
    client.write(tBuf);
    float targetPctBsp = wBspFloat / trgBspFloat;
    float trgBspPctFloat = targetPctBsp * 100; //////////target avg
    dtostrf(trgBspPctFloat, 5, 1, tBuf);
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</span></a><span style=font-size:10px;><hr></span><span style=font-size:28px;line-height:100%;><center>TWA----------------Target----------------Dif")); //////make a rule and move to the next line
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</p><span style=font-size:48px;line-height:53%;><center>")); //////make a rule and move to the next line
    client.write(tBuf);
    itoa (twaInt, tBuf, 10); ///////twa
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("..........."));
    client.write(tBuf);
    itoa (targetTWA, tBuf, 10); /////////target twa
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("............"));
    client.write(tBuf);
    int twaTargDiff = twaInt - targetTWA; ////////target vs actual twa diffeence
    itoa (twaTargDiff, tBuf, 10);
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</span></a><span style=font-size:10px;><hr></span><span style=font-size:28px;line-height:100%;><center>HDG--------------Dist / Brg---------Opp Tack")); //////make a rule and move to the next line
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</span></p><span style=font-size:48px;line-height:53%;><center>")); //////make a rule and move to the next line
    client.write(tBuf);
    itoa (hdmInt, tBuf, 10); /////////heading
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("..........."));
    client.write(tBuf);
    dtostrf(markDistFloat, 5, 2, tBuf);
    client.write(tBuf);
    strcpy_P(tBuf, PSTR(" / "));
    client.write(tBuf);
    itoa (markInt, tBuf, 10);
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("..........."));
    client.write(tBuf);
    int tackAngle = 0;
    int oppTack = 0;
    if (twaInt > 90) /////sets the tacking angles
    {
    tackAngle = 180 - twaInt;
    tackAngle = tackAngle * 2;
    }
    else
    {
    tackAngle = twaInt;
    tackAngle = tackAngle * 2;
    }
    if (RorL == "-")
    {
    if (twaInt > 90) oppTack = hdmInt + tackAngle;
    else oppTack = hdmInt - tackAngle;
    }
    else {
    if (twaInt > 90) oppTack = hdmInt - tackAngle;
    else oppTack = hdmInt + tackAngle;
    }
    if (oppTack < 0) oppTack = oppTack + 360;
    else if (oppTack > 359) oppTack = oppTack - 360;
    itoa (oppTack, tBuf, 10); /////////opp tack
    client.write(tBuf);
    strcpy_P(tBuf, PSTR("</span></a></body></html>"));
    client.write(tBuf);
    if (displayColorMode == 1) strcpy_P(tBuf, PSTR("<span style=font-size:20px;line-height:0%;><p align=left><a href=summary.php?t=0>&lowast; <p align=right><a href=bsptwa.php?t=1>&rarr; </P></span></a></span></a></body></html>"));
    else strcpy_P(tBuf, PSTR("<span style=font-size:20px;line-height:0%;><p align=left><a href=summary.php?t=1>&lowast; <p align=right><a href=bsptwa.php?t=0>&rarr; </P></span></a></span></a></body></html>"));
    client.write(tBuf);
    }
    else
    {

    }
    }
    client.stop();
    }
    else if (c == '\n') {
    currentLineIsBlank = true;
    currentLineIsGet = false;
    }
    else if (c != '\r') {
    currentLineIsBlank = false;
    }
    }

    loopCount++;

    // if 1000ms has passed since last packet
    if (loopCount > 1000) {
    // close connection
    client.stop();
    #ifdef ServerDEBUG
    Serial.println("\r\nTimeout");
    #endif
    }

    // delay 1ms for timeout timing
    delay(1);
    }
    #ifdef ServerDEBUG
    Serial.println(F("disconnected"));
    #endif
    }
    }
    /////////responds to a Bad file Request/////
    void sendFileNotFound(EthernetClient thisClient) {
    char tBuf[64];
    strcpy_P(tBuf, PSTR("HTTP/1.0 404 File Not Found\r\n"));
    thisClient.write(tBuf);
    strcpy_P(tBuf, PSTR("Content-Type: text/html\r\nConnection: close\r\n\r\n"));
    thisClient.write(tBuf);
    strcpy_P(tBuf, PSTR("<html><body><H1>FILE NOT FOUND</H1></body></html>"));
    thisClient.write(tBuf);
    thisClient.stop();
    #ifdef ServerDEBUG
    Serial.println(F("disconnected"));
    #endif
    }

    /////////responds to an HTTP 400: Bad Request///
    void sendBadRequest(EthernetClient thisClient) {
    char tBuf[64];
    strcpy_P(tBuf, PSTR("HTTP/1.0 400 Bad Request\r\n"));
    thisClient.write(tBuf);
    strcpy_P(tBuf, PSTR("Content-Type: text/html\r\nConnection: close\r\n\r\n"));
    thisClient.write(tBuf);
    strcpy_P(tBuf, PSTR("<html><body><H1>BAD REQUEST</H1></body></html>"));
    thisClient.write(tBuf);
    thisClient.stop();
    #ifdef ServerDEBUG
    Serial.println(F("disconnected"));
    #endif
    }
    //////
    void strtoupper(char* aBuf) {

    for (int x = 0; x < strlen(aBuf); x++) {
    aBuf[x] = toupper(aBuf[x]);
    }
    }
    byte socketStat[MAX_SOCK_NUM];
    ////////////////Lists a directory////////////
    void printDirectory(File dir) {
    //------------------------------------------------------------
    dir.rewindDirectory(); // you need to rewind the the Directory
    //------------------------------------------------------------
    while (true) {
    File entry = dir.openNextFile();
    if (! entry) {
    break;
    }
    Serial.print(entry.name());
    Serial.print(" ");
    Serial.println(entry.size());

    }
    }
    //////

    ///SD File Listing Routine ///
    void listSD() {
    File root;
    root = SD.open("/");
    printDirectory(root);
    }
    //////


    void logStart() {
    ////Update Configuration////////////////
    startNo = startNo + 1; //updates restart counter and writes to log.
    myFile = SD.open("settings.txt", FILE_WRITE);
    myFile.print("[");
    myFile.print("startno=");
    myFile.print(startNo);
    myFile.println("]");
    myFile.close();
    delay(1000);
    ////Initialize System Log ////////////////
    myFile = SD.open("syslog.txt", FILE_WRITE);
    myFile.println("");
    myFile.print("--------------------- SYSTEM START NUMBER ");
    myFile.print(startNo);
    myFile.print(" OF ");
    myFile.print(verstring);
    myFile.println("--------------------");
    myFile.println("Reading Paramaters from Settings.txt");
    myFile.close();
    }
    //////


    ////write settings to system log/////////////
    void logConfig() {
    myFile = SD.open("syslog.txt", FILE_WRITE);
    myFile.print("System Configured with the following paramaters: ");
    myFile.print(" Leapdays=");
    myFile.print(LeapDays);
    myFile.print(" Sensor=");
    myFile.print(Sensor);
    myFile.print(" Barometer=");
    myFile.print(Barometer);
    myFile.print(" NMEAPlay=");
    myFile.print(NMEAPlay);
    myFile.print(" barometer offset=");
    myFile.print(baroffset);
    myFile.print(" Expedition=");
    myFile.print(Expedition);
    myFile.print(" targetspeedmultiplier=");
    myFile.print(targetSpeedMultiplier);
    myFile.print(" twsCorrectorUP=");
    myFile.print(twsCorrectorUP);
    myFile.print(" twsCorrectorDN=");
    myFile.print(twsCorrectorDN);
    myFile.print(" pitchCorrector=");
    myFile.print(pitchCorrector);
    myFile.print(" heelCorrector=");
    myFile.print(heelCorrector);
    myFile.print(" directlog=");
    myFile.println(directLog);
    myFile.close();
    }
    //

    ///Start the I2C Sensors ///
    void startSensors() {
    Serial.println(" Configuration Complete. Initialization begins.....NMEA Processor logic 1.1.5 Tackscore 2.1.0 Initializing...Sensor Setup Begins....");
    bmp.begin(); //start the pressure sensor
    Serial.print(" BMP085 Pressure Sensor Online...");
    Serial1.print(" BMP085 Pressure Sensor Online...");
    writeTo(DATA_FORMAT, 0x01); //Put the ADXL345 into Measurement Mode by writing 0x08 to the POWER_CTL register.
    writeTo(POWER_CTL, 0x08); //set ADXL to 4g
    Serial.print("ADXL Online...");
    Serial1.print("ADXL Online.4G mode..");
    if (Sensor == 1) {
    readSensors();
    if (Barometer == 1) {
    readPressure();
    readPressure();
    readPressure();
    readPressure();
    Serial.print(" Pressure Sensor is ON. Reading: ");
    readPressure();
    Serial.println((pressure)*.01, 1);
    }
    Serial.print("pitch: ");
    Serial.print( pitch );
    Serial.print(" heel: ");
    Serial.print( roll );
    Serial.print(" slam ");
    Serial.print((z - 117), DEC);
    Serial.print(" Barometric Pressure ");
    Serial.print(((pressure)*.01), DEC ); ///changed from .1
    Serial.print(" Air Temprature ");
    Serial.print((temperature), DEC);
    Serial.println(" degrees C ");
    Serial.print(" Sensor Init Complete....Getting The Time...");
    Serial1.print(" Sensor Init Complete...Getting The Time....");

    myFile = SD.open("syslog.txt", FILE_WRITE);
    myFile.print("Pressure and Orientation Sensor Enabled: ");
    myFile.print("pitch=");
    myFile.print(pitch);
    myFile.print(" Heel=");
    myFile.print(roll);
    myFile.print(" Temperature=");
    myFile.print(temperature);
    myFile.print(" C, Pressure=");
    myFile.println(pressure + baroffset);
    myFile.close();
    }
    ////setting up the time for expedition///////////
    tmElements_t tm;
    RTC.read(tm);
    ColeTimeYear = ((((tm.Year) + 70) * 365) + ((tm.Month) * 30) + (tm.Day) + LeapDays);
    ColeTimeSecond = (((tm.Hour * 3600) + (tm.Minute * 60) + tm.Second) * 11.57407);
    fakeSecond = (long)ColeTimeSecond; //remove the decimal from the second
    Serial.print("The dateTime is: ");
    Serial.print(ColeTimeYear);
    Serial.print(".");
    Serial.println(fakeSecond);
    Serial3.print("The dateTime is: ");
    Serial3.print(ColeTimeYear);
    Serial3.print(".");
    Serial3.println(fakeSecond);

    myFile = SD.open("syslog.txt", FILE_WRITE);
    myFile.print("Time Enabled: ");
    myFile.print("Day = ");
    myFile.print(ColeTimeYear);
    myFile.print(" Fraction =");
    myFile.println(fakeSecond);
    myFile.close();
    }
    //

    ///Interactive Systems Status ////////////////
    void sysStatus() {
    Serial.print(verstring);
    Serial.print(" System Start Number: ");
    Serial.println(startNo); //record number since starting //User8
    ShowIpInfo();
    Serial.print(". NMEA Records Processed: ");
    Serial.print(NMEAin); //record number since starting
    Serial.print(" Time in MS since last rec cycle: ");
    Serial.println(duration); //record number since starting //User8
    HumanTime();
    Serial.print(" Active Log File: ");
    Serial.print(logFileString);
    Serial.print(" Exp. Recs written: ");
    Serial.print(ExpDelay); //record number since starting //User8
    Serial.print(" Date and Time: ");
    Serial.print(ColeTimeYear); // represnets days since 1900
    Serial.print(".");
    if (fakeSecond > 1000000) {
    fakeSecond = 10;
    ColeTimeYear = ColeTimeYear + 1;
    } //backstop to an end of day miss
    if (fakeSecond < 100000) { //this set of statements backfills the second with leading zeros//
    if (fakeSecond < 10000) {
    if (fakeSecond < 1000) {
    if (fakeSecond < 100) {
    if (fakeSecond < 10) {
    Serial.print("0");
    }
    Serial.print("0");
    }
    Serial.print("0");
    }
    Serial.print("0");
    }
    Serial.print("0");
    }
    Serial.println(fakeSecond); //print the int second value
    Serial.println("");
    Serial.print(" BSP: ");
    Serial.print(bsp.value()); //boatspeed from II tiny
    Serial.print(" SOG: ");
    Serial.print(sog.value());
    Serial.print(" DBSP: ");
    Serial.print(dbspInt); //diff of bsp and sog
    Serial.print(" TRGT: ");
    Serial.println(targetBSP); //calculated target BSP,
    Serial.print(" AWS: ");
    Serial.print(awsInt); //Apparent Wind Speed from II tiny
    Serial.print(" TWS: ");
    Serial.print(twsInt); //True Wind Speed from Tiny
    Serial.print(" AWA: ");
    Serial.print(RorL);
    Serial.print(awaInt); //Apparent Wind Angle from II tiny
    Serial.print(" TWA: ");
    Serial.print(RorL);
    Serial.print(twaInt); //Right or Left of bow (- or nothing), TWA from Tiny
    Serial.print(" TWD: ");
    Serial.println(twd.value()); //True Wind Direction from II tiny
    Serial.print(" HDM: ");
    Serial.print(hdm.value()); //mag heading
    Serial.print(" COG: ");
    Serial.print(cogMag); //Course over Ground
    Serial.print(" dHDM: ");
    Serial.println(dhdmInt); //diff of hdm and cog //user 18
    Serial.print(" MTA: ");
    Serial.print((temperature)); //air temp
    Serial.print(" MTW: ");
    Serial.print(mtw.value()); //water temp
    Serial.print(" MBAR: ");
    Serial.println(((pressure)*.01), 1); ////from .01 //Baro pressure
    Serial.print(" DBT: ");
    Serial.print(dbt.value()); //depth
    Serial.print(" HEEL: ");
    Serial.print(roll, 1); // Heel
    Serial.print(" PITCH: ");
    Serial.println(pitch, 1); //trim
    Serial.print(" Mark Brg: "); //
    Serial.print(markMag); //mark bearing
    Serial.print(" Mark Rng: "); //corrected to make lng always negative
    Serial.println(markDist); //mark Range
    Serial.print(" LNG: "); //corrected to make lng always negative
    Serial.print(lng2, 6); //longitude
    Serial.print(" LAT: ");
    Serial.println(lat2, 6); //latitude
    Serial.print(" VOLTS: ");
    Serial.println(volts);
    Serial.print(" isInFlight ");
    Serial.print(isInFlight);
    //Serial.print(" fltdrv: ");
    //Serial.print(flightPressDrive);
    //Serial.print(" fltdif: ");
    //Serial.print(flightPressDiff);
    Serial.print(" fltange: ");
    Serial.print(isInFlightRange);
    Serial.print(" fltrdy: ");
    Serial.print(isReadyToFly);
    Serial.print(" fltspdmin: ");
    Serial.println(bspFlightMin);
    Serial.print(" TOTLOG: ");
    Serial.print(totlog.value()); //total miles in b&G log //User9
    Serial.print(" CURLOG: ");
    Serial.println(currlog.value()); //current miles in B&G Log. //User10
    Serial.print(" FWD: ");
    Serial.print(finalForward); //distance accumulated in the tack //user 11
    Serial.print(" GUAGE: ");
    Serial.println(finalLane); //final Lane sag //user 12
    ReadSettings();
    }
    //

    ///SD File Listing///////
    void listFileHTML(File dir) {
    dir.rewindDirectory(); // you need to rewind the the Directory
    while (true)
    {
    File entry = dir.openNextFile();
    if (! entry) {
    break;
    }
    Serial.print(entry.name());
    Serial.print(" ");
    Serial.println(entry.size());
    /*strcpy_P(tBuf,PSTR("<a href=\"HTTP://192.168.8.10/"));
    client.write(tBuf);
    strcpy_P(tBuf,PSTR(entry.name()));
    client.write(tBuf);
    strcpy_P(tBuf,PSTR("\"> <H2> "));
    client.write(tBuf);
    strcpy_P(tBuf,PSTR(entry.name()));
    client.write(tBuf);
    strcpy_P(tBuf,PSTR("</H2></a><p></p>"));
    client.write(tBuf);*/
    }
    }
    //

    ///NMEA INBOUND SENTENCE PROCESSING //////////
    ///Process VTG Sentence ////
    void processVTG() {
    //$IIVTG,097.,T,102.,M,6.9,N,,K*75
    //$ECVTG,169.7,T,184.0,M,0.9,N,1.7,K*54
    //$GPVTG,129.3,T,143.6,M,5.2,N,9.7,K,A*23

    int commaloc = inData.indexOf(',');
    int commaloc2 = inData.indexOf(',', commaloc + 1);
    int commaloc3 = inData.indexOf(',', commaloc2 + 1);
    int commaloc4 = inData.indexOf(',', commaloc3 + 1);
    int commaloc5 = inData.indexOf(',', commaloc4 + 1);
    int commaloc6 = inData.indexOf(',', commaloc5 + 1);
    sogTmp = inData.substring(commaloc5 + 1, commaloc6);
    String cogTmp = inData.substring(commaloc3 + 1, commaloc4);
    String sogFloat = String(sogTmp.toFloat() * 100, 2);
    sogInt = sogFloat.toInt();
    dbspInt = bspInt - sogInt;
    String cogFloat = String(cogTmp.toFloat(), 0);
    cogInt = cogFloat.toInt();
    dhdmInt = hdmInt - cogInt;
    if (dhdmInt > 90) dhdmInt = dhdmInt - 359;
    if (dhdmInt < -90) dhdmInt = dhdmInt + 359;
    long cogTru = 0;
    cogTru = atol(cog.value());
    cogMag = cogTru + magVar;
    if (cogMag > 359) cogMag = cogMag - 359;
    else if (cogMag < 0) cogMag = cogMag + 359;
    /*
    Serial.println("");
    Serial.print(",sogint:");
    Serial.print(sogInt);
    Serial.print(", dbspInt:");
    Serial.print(dbspInt);
    Serial.print(", cogTru:");
    Serial.print(cogTru);
    Serial.print(", cogmag:");
    Serial.print(cogMag);
    Serial.print(", dhnmint:");
    Serial.println(dhdmInt);
    */
    #ifdef instNKE
    Serial1.print("$IIVTG,,,");
    Serial1.print(cogMag);
    Serial1.print(",M,");
    Serial1.print(sog.value());
    Serial1.println(",N,,,A*23");
    inData = ""; //eliminate VTG Sentence - NKE specific
    #endif
    } //end VTG
    //

    ///Process VWT Sentence ////
    void processVWT() {
    // created bspInt, hdmInt
    //$IIVWT,038,R,017.1,N,008.8,M,,K*73 Velocity Wind True VWT,true wind angle, Right or Left of bow, true wind speed, ,units,
    //not in H5000
    int commaloc = inData.indexOf(',');
    int commaloc2 = inData.indexOf(',', commaloc + 1);
    int commaloc3 = inData.indexOf(',', commaloc2 + 1);
    int commaloc4 = inData.indexOf(',', commaloc3 + 1);
    int commaloc5 = inData.indexOf(',', commaloc4 + 1);
    int commaloc6 = inData.indexOf(',', commaloc5 + 1);
    String twsTmp = inData.substring(commaloc3 + 1, commaloc4);
    String twsFloat = String(twsTmp.toFloat() * 100, 4); //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    twsInt = twsFloat.toInt();
    twsFloat2 = twsFloat.toFloat() , 4;
    twsFloat2 = twsFloat2 /100;
    //Serial.print("TWS:"); Serial.println(twsInt);
    //Serial.print("FWS:"); Serial.println(twsFlightMin);
    twsInt = twsInt * twsCorrectorUP;
    twsInt = twsInt / 10000;
    targetBSPOld = targetBSPAvg;
    if (awaInt > 50) targetBSP = targetBSPArrayDN[twsInt] * targetSpeedMultiplier;
    else targetBSP = targetBSPArrayUP[twsInt] * targetSpeedMultiplier;
    targetBSP = targetBSP / 100;
    targetBSPAvg = (targetBSP + targetBSPOld) / 2;
    String twaTmp = inData.substring(commaloc + 1, commaloc2);
    float latDDFloat1 = (twaTmp.toFloat() * 100, 4);
    String twaFloat = String(twaTmp.toFloat() * 100, 4);
    twaPrev = twaInt;
    twaInt = twaFloat.toInt();
    twaInt = twaInt / 100;
    twaArray[tackIndex] = twaInt;
    //twaInt = twaInt /100;
    if (twaInt > 60) targetTWA = targetTWAArrayDN[twsInt];
    else targetTWA = targetTWAArrayUP[twsInt];
    if (Sensor == 1) readSensors(); //inData = ""; //get the heel and add to the stream
    }
    //

    ///Process VHW Sentence ////
    void processVHW() {
    // creates bspInt, hdmInt
    //$WIMWV,13.3,R,3.9,N,A*18
    //$WIMWV,145.8,T,1.5,N,A*29
    //$IIVHW, ,T,130 ,M,07.78,N,,K*41 (Boatspeed and heading) , direction ,True or Magnetic, Heading, Magnetic, BoatspeedSpeed, Knots
    //$ECVHW,164.7,T,179.0,M,0.0 ,N,0.0,K*52
    int commaloc = inData.indexOf(',');
    int commaloc2 = inData.indexOf(',', commaloc + 1);
    int commaloc3 = inData.indexOf(',', commaloc2 + 1);
    int commaloc4 = inData.indexOf(',', commaloc3 + 1);
    int commaloc5 = inData.indexOf(',', commaloc4 + 1);
    int commaloc6 = inData.indexOf(',', commaloc5 + 1);
    bspTmp = inData.substring(commaloc5 + 1, commaloc6);
    String hdmTmp = inData.substring(commaloc3 + 1, commaloc4);
    String bspFloat = String(bspTmp.toFloat() * 100, 4);
    bspInt = bspFloat.toInt();
    // Serial.print(bspInt);
    // Serial.print(", hdmInt");
    String hdmFloat = String(hdmTmp.toFloat(), 3);
    hdmInt = hdmFloat.toInt();
    // Serial.println(hdmInt);

    } //end VHW
    //

    ///Process GLL Sentence ////
    void processGLL() {
    // creates lat2, lng2,
    //$IIGLL,2430.525,N,08150.750,W,171852,A*2E //GLL,Lat,N/S,LON,E/W . GPS LAT/LON
    //$GPGLL,1802.1975,N,06307.4095,W,142741,A,A*5B//h5000
    //$ECGLL,1938.143,N,06313.569,W,005450,A*25
    int commaloc = inData.indexOf(',');
    int commaloc2 = inData.indexOf(',', commaloc + 1);
    int commaloc3 = inData.indexOf(',', commaloc2 + 1);
    int commaloc4 = inData.indexOf(',', commaloc3 + 1);
    int commaloc5 = inData.indexOf(',', commaloc4 + 1);
    String gllChk = inData.substring(commaloc4 + 1, commaloc4 + 2);
    if (gllChk == "W" or gllChk == "E")
    {
    String NOrS = inData.substring(commaloc2 + 1, commaloc2 + 2);
    String latDDTmp = inData.substring(commaloc + 1, commaloc + 3);
    float latDDFloat1 = latDDTmp.toFloat();
    String latMMTmp = inData.substring(commaloc + 3, commaloc + 10);
    float mmssFloat1 = latMMTmp.toFloat();
    mmssFloat1 = (mmssFloat1 / 60);
    lat2 = latDDFloat1 + mmssFloat1;
    String lngDDTmp = inData.substring(commaloc3 + 1, commaloc3 + 4);
    float lngDDFloat1 = lngDDTmp.toFloat();
    String lngMMTmp = inData.substring(commaloc3 + 4, commaloc3 + 11);
    float lngmmssFloat1 = lngMMTmp.toFloat();
    lngmmssFloat1 = (lngmmssFloat1 / 60);
    lng2 = lngDDFloat1 + lngmmssFloat1;
    if (gllChk == "W") lng2 = lng2 * -1;
    }
    } //end GLL
    //

    ///Process MWV Sentence ////
    void processMWV() {
    //$WIMWV,13.3,R,3.9,N,A*18 ///apparent wind
    //$WIMWV,145.8,T,1.5,N,A*29 ///true wind
    //$WIMWV,145.8,T,1.5,N,A*29 //h5000
    //$ECMWV,293.0,T,12.0,N,A*06
    //$ECMWV,319.0,R,16.8,N,A*0F
    //creates awaInt,RorL, sets p/s relay
    int commaloc = inData.indexOf(',');
    int commaloc2 = inData.indexOf(',', commaloc + 1);
    int commaloc3 = inData.indexOf(',', commaloc2 + 1);
    int commaloc4 = inData.indexOf(',', commaloc3 + 1);
    int commaloc5 = inData.indexOf(',', commaloc4 + 1);
    int commaloc6 = inData.indexOf(',', commaloc5 + 1);
    String typeTmp = inData.substring(commaloc2 + 1, commaloc3);
    // Serial.print(", type:");
    // Serial.println(typeTmp);
    if (typeTmp == "R")
    {
    String awaTmp = inData.substring(commaloc + 1, commaloc2);
    String awaFloat = String(awaTmp.toFloat(), 3);
    // Serial.print(", awa:");
    // Serial.print(awaFloat);
    awaPrev = awaInt;
    awaInt = awaFloat.toInt();
    RorL = "";
    RorLArray[tackIndex] = 1;
    if (awaInt > 180)
    {
    awaInt = 360 - awaInt;
    RorL = "-";
    RorLArray[tackIndex] = 0;
    // Serial.print(", awaIntCorr:");
    // Serial.print(awaInt);
    }
    awaArray[tackIndex] = awaInt;
    String awsTmp = inData.substring(commaloc3 + 1, commaloc4);
    // Serial.print(", awaInt:");
    // Serial.print(awaInt);
    //new aws calcs
    //aws = awsTmp;
    String awsFloat = String(awsTmp.toFloat(), 3);
    // Serial.print(", awsfloat:");
    // Serial.println(awsFloat);
    //awsPrev = awaInt;
    awsInt = awsFloat.toInt();
    // Serial.print(", awsInt:");//
    // Serial.println(awsInt);
    //awaArray[tackIndex] = awaInt;
    } //awaTemp is OK, not "M"
    else if (typeTmp == "T")
    {
    String twsTmp = inData.substring(commaloc3 + 1, commaloc4);
    String twsFloat = String(twsTmp.toFloat() * 100, 4);
    twsInt = twsFloat.toInt();
    twsFloat2 = twsFloat.toFloat() , 4;
    //Serial.print(", TWSInt:"); Serial.print(twsInt);
    //Serial.print("FWS:"); Serial.println(twsFlightMin);
    twsInt = twsInt * twsCorrectorUP;
    twsInt = twsInt / 10000;
    targetBSPOld = targetBSPAvg;
    if (awaInt > 50) targetBSP = targetBSPArrayDN[twsInt] * targetSpeedMultiplier;
    else targetBSP = targetBSPArrayUP[twsInt] * targetSpeedMultiplier;
    targetBSP = targetBSP / 100;
    targetBSPAvg = (targetBSP + targetBSPOld) / 2;
    String twaTmp = inData.substring(commaloc + 1, commaloc2);
    String twaFloat = String(twaTmp.toFloat() * 100, 4);
    twaPrev = twaInt;
    twaInt = twaFloat.toInt();
    twaInt = twaInt / 100;
    // Serial.print(", twaInt:");//
    // Serial.println(twaInt);
    if (twaInt > 180)
    {
    twaInt = 360 - twaInt;
    //RorL = "-";
    // Serial.print(", twaIntCorr:");
    // Serial.println(twaInt);
    }
    twaArray[tackIndex] = twaInt;
    //twaInt = twaInt /100;
    if (twaInt > 60) targetTWA = targetTWAArrayDN[twsInt];
    else targetTWA = targetTWAArrayUP[twsInt];
    if (Sensor == 1) readSensors(); //inData = ""; //get the heel and add to the stream
    polarRecordCheck();
    }
    }
    //

    ///Process VWR Sentence ////
    void processVWR() {
    // Serial.println("VWR Processing");
    //not in h5000
    //creates awaInt,RorL, sets p/s relay
    int commaloc = inData.indexOf(',');
    int commaloc2 = inData.indexOf(',', commaloc + 1);
    int commaloc3 = inData.indexOf(',', commaloc2 + 1);
    String awaTmp = inData.substring(commaloc + 1, commaloc2);
    if (awaTmp == "M") inData = ""; //checks for a bad VWR sentence read and throwss it away
    else {
    awa = awaTmp;
    String awaFloat = String(awaTmp.toFloat(), 3);
    awaPrev = awaInt;
    awaInt = awaFloat.toInt();
    awaArray[tackIndex] = awaInt;
    String RorLTmp = inData.substring(commaloc2 + 1, commaloc3);
    if (RorLTmp == "M") inData = ""; //checks for a bad VWR sentence read and throwss it away
    else if (RorLTmp == "L")
    {
    RorL = "-";
    if (paddleSelector == 1) digitalWrite(22, LOW);
    RorLArray[tackIndex] = 0;
    }
    else
    {
    RorL = "";
    RorLArray[tackIndex] = 1;
    if (paddleSelector == 1) digitalWrite(22, HIGH);
    }
    } //awaTemp is OK, not "M"
    } //end VWR
    //

    ////Process PIX Sentence ///
    void processPIX() {
    }
    //

    /////END OF INBOUND SENTENCES/////////////////

    ////Checks 2 BMP's and gives difference //////
    void checkDrive() {
    digitalWrite(BMPSelector, HIGH);
    flightPressDrive = (bmp.readPressure());
    flightPressDrive = flightPressDrive - flightPressCorrector;
    digitalWrite(BMPSelector, LOW);
    delay(15);
    flightPressAtmos = (bmp.readPressure());
    flightPressDiff = flightPressDrive - flightPressAtmos + flightGain;
    if (flightPressDiff >= 0) isInFlight = 1;
    if (statMsg == 1)
    {
    Serial.print("Flight pressure Corrector: ");
    Serial.print(flightPressCorrector);
    Serial.print(" Corrected SailDrive Pressure: ");
    Serial.print(flightPressDrive);
    Serial.print(" Flight pressure Atmos: ");
    Serial.print(flightPressAtmos);
    Serial.print(" Gain Value: ");
    Serial.print(flightGain);
    Serial.print(" Difference with gain ");
    Serial.print(flightPressDiff);
    Serial.print(" isInFlight: ");
    Serial.println(isInFlight);
    }
    }
    //

    //Interactive non-averaged Barometer//////////
    void readPress() {
    pressure = (bmp.readPressure());
    pressure = pressure + baroffset;
    Serial.println("The barometric pressure in mb is: ");
    Serial.println((pressure)*.01, 1);
    }
    //

    ///standard baro pressure read////////////////
    void readPressure() {
    temperature = (bmp.readTemperature());
    pressure = (bmp.readPressure());
    //Serial.println(pressure);
    pressure = pressure + baroffset;
    //Serial.println(pressure);
    pressure = ((pressure + pressureold) / 2);
    //Serial.println(pressure);
    temperature = ((temperature + tempold) / 2);
    tempold = temperature; //averaging
    pressureold = pressure; //averaging
    }
    //

    //checks the 12v voltage////
    void checkVoltage12() {
    float v12Actual1 = analogRead(v12Signal);
    }
    //

    ///checkks 24 volt levels///
    void checkVoltage24() {
    float v24Actual1 = analogRead(v24Signal);
    float v24Actual2 = analogRead(v24Signal);
    float v24Actual3 = analogRead(v24Signal);
    v24Actual = v24Actual1 + v24Actual2 + v24Actual3;
    v24Actual = v24Actual * v24Multiplier;
    v24Pct = 0;
    if (v24Actual >= v2490Threshold) v24Pct = 90;
    else if (v24Actual >= v2480Threshold) v24Pct = 80;
    else if (v24Actual >= v2470Threshold) v24Pct = 70;
    else if (v24Actual >= v2460Threshold) v24Pct = 60;
    else if (v24Actual >= v2450Threshold) v24Pct = 50;
    else if (v24Actual >= v2440Threshold) v24Pct = 40;
    else if (v24Actual >= v2430Threshold) v24Pct = 30;
    else if (v24Actual >= v2420Threshold) v24Pct = 20;
    else if (v24Actual >= v2410Threshold) v24Pct = 10;
    else if (v24Actual >= v240Threshold) v24Pct = 0;
    if (statMsg == 1)
    {
    Serial.print(" 24 volt level:");
    Serial.print(v24Actual);
    Serial.print(" , ");
    Serial.println(v24Pct);
    }
    }

    //

    /// checks flight status and sets pixels/////////
    void checkFlight() {
    isReadyToFlyFlag = 0;
    }
    //

    //////prints the flight signals //////////////
    void checkFlightStat() {
    Serial.print(" Boatspeed is ");
    Serial.print(bspInt);
    Serial.print(", isReadyToFly is ");
    Serial.print(isReadyToFly);
    Serial.print(", isInFlightSignal is: ");
    Serial.print(isInFlightSignal);
    Serial.print(", isInFlight is ");
    Serial.println(isInFlight);
    }
    //

    ///fills a row of dots//////
    void dotFill(char clr) {
    if (statMsg == 1) {
    Serial.print(" dot fill color character:");
    Serial.println(clr);
    }
    int clrR = 0;
    int clrG = 0;
    int clrB = 0;
    if (clr == 'd')
    {
    int i;
    for (i = 0; i < NUMPIXELS - 1; i++)
    {
    PixelArrayR[i] = 255;
    }
    }
    else if (clr == 'r')
    {
    int i;
    for (i = 0; i < NUMPIXELS - 1; i++)
    {
    PixelArrayG[i] = 255;
    }
    }
    else if (clr == 'l')
    {
    int i;
    for (i = 0; i < NUMPIXELS - 1; i++)
    {
    PixelArrayB[i] = 255;
    }
    }
    else if (clr == 'k')
    {
    int i;
    for (i = 0; i < NUMPIXELS - 1; i++)
    {
    PixelArrayR[i] = 0;
    PixelArrayG[i] = 0;
    PixelArrayB[i] = 0;
    }
    }
    else if (clr == 'h')
    {
    int i;
    for (i = 0; i < NUMPIXELS - 1; i++)
    {
    PixelArrayG[i] = 255;
    PixelArrayR[i] = 255;
    PixelArrayB[i] = 255;
    }
    }
    }
    //

    ///wipes a row of dots//////
    void dotWipe(char clr) {
    //if (statMsg == 1) {
    // Serial.print(" dot wipe color character:");
    // Serial.println(clr);
    // }
    int clrR = 0;
    int clrG = 0;
    int clrB = 0;
    if (clr == 'd')
    {
    int i;
    for (i = 0; i < NUMPIXELS - 1; i++)
    {
    PixelArrayR[i] = 0;
    }
    }
    else if (clr == 'r')
    {
    int i;
    for (i = 0; i < NUMPIXELS - 1; i++)
    {
    PixelArrayG[i] = 0;
    }
    }
    else if (clr == 'l')
    {
    int i;
    for (i = 0; i < NUMPIXELS - 1; i++)
    {
    PixelArrayB[i] = 0;
    }
    }
    else if (clr == 'k')
    {
    int i;
    for (i = 0; i < NUMPIXELS - 1; i++)
    {
    PixelArrayR[i] = 0;
    PixelArrayG[i] = 0;
    PixelArrayB[i] = 0;
    }
    }
    else if (clr == 'h')
    {
    int i;
    for (i = 0; i < NUMPIXELS - 1; i++)
    {
    PixelArrayG[i] = 0;
    PixelArrayR[i] = 0;
    PixelArrayB[i] = 0;
    }
    }
    }
    //

    //dotBright - sets a higher brightness level///////
    void dotBright() {
    if (dotBrightess >= 7) dotBrightess = 7;
    else dotBrightess = dotBrightess + 1;
    if (statMsg == 1)
    {
    Serial.print(dotBrightess);
    Serial.println("brightness level up by one");
    }
    }
    //

    ///dotDim - sets a lower dimming level/////////////
    void dotToggle() {
    if (dotBrightess <= 0) dotBrightess = 3;
    else dotBrightess = 0;
    if (statMsg == 1)
    {
    Serial.print(dotBrightess);
    Serial.println(" dots toggled ");
    }
    }
    //

    ///dotDim - sets a lower dimming level/////////////
    void dotDim() {
    if (dotBrightess <= 0) dotBrightess = 0;
    else dotBrightess = dotBrightess - 1;
    if (statMsg == 1)
    {
    Serial.print(dotBrightess);
    Serial.println("brightness level down by one");
    }
    }
    //

    ///wipes a row of dots//////
    void dotClear() {
    if (statMsg == 1) {
    Serial.println(" dot array cleared ");
    }
    int i;
    for (i = 0; i < NUMPIXELS - 1; i++)
    {
    PixelArrayG[i] = 0;
    PixelArrayR[i] = 0;
    PixelArrayB[i] = 0;
    }
    dotDisplay();
    dotReset = 1;
    if (statMsg == 1)Serial.println("Dot Reset");
    }
    //

    ////////////////sets the DOT String brightness///
    void dotBrightness() {
    if (dotBrightess == 0) strip.setBrightness(000);
    if (dotBrightess == 1) strip.setBrightness(002);
    if (dotBrightess == 2) strip.setBrightness(003);
    if (dotBrightess == 3) strip.setBrightness(010);
    if (dotBrightess == 4) strip.setBrightness(035);
    if (dotBrightess == 5) strip.setBrightness(075);
    if (dotBrightess == 6) strip.setBrightness(150);
    if (dotBrightess == 7) strip.setBrightness(255);
    if (statMsg == 1) Serial.println("brightness sent to strip");
    }
    //

    ///Moves the array to the DOT String and shows/////
    void verDisplay() {
    dotBrightness();
    int i = 0;
    for (i = 0; i < NUMPIXELS - 1; i++)
    {
    strip.setPixelColor(i, strip.Color(000, 000, versionArray[i]));
    strip.show();
    }
    }
    //

    ///Moves the array to the DOT String and shows/////
    void dotDisplay() {
    dotBrightness();
    int i = 0;
    for (i = 0; i < NUMPIXELS - 1; i++)
    {
    strip.setPixelColor(i, strip.Color(PixelArrayG[i], PixelArrayR[i], PixelArrayB[i]));
    strip.show();
    dotReset = 0;
    }
    }
    //

    ///Help Commands/////////
    void getPolarBsp() {
    if (twaInt < 0) twaInt = 0;
    if (twaInt > 180) twaInt = 180;
    int twsTrunc = twsInt;
    if (twsTrunc > 30) twsTrunc = 30;
    if (twsTrunc < 0) twsTrunc = 0;
    //polarBspOld = polarBspAvg;
    polarBsp = polarArray[twsTrunc][twaInt];
    polarBspAvg = polarBsp + polarBspAvg;
    polarBspAvg = polarBspAvg * .5;
    //polarBsp = polarBsp*.01;
    if (statMsg == 1) {
    Serial.print("polar speeds ");
    Serial.print(", TWS Int ,"); Serial.print(twsInt);
    Serial.print(", TWA Int "); Serial.print(twaInt);
    Serial.print(", PolarBspAvg "); Serial.print(polarBspAvg);
    Serial.print(",Polar Spd "); Serial.print(polarBsp); Serial.println(",");
    }
    }
    //

    ////////////////sets target on red string/////
    void dotTarget() {
    float targetPctBsp2 = 0;
    float bspFloat2 = bspInt;
    float targetBSPAvg2 = targetBSPAvg;
    float numpixelsFloat = NUMPIXELS;
    float centerPixelFloat = centerPixel;
    pickPixelMult = centerPixelFloat / numpixelsFloat; //calculate percentage for each pixel
    targetPctBsp2 = bspFloat2 / targetBSPAvg2; //temp target percentage value
    targetPctBsp2 = targetPctBsp2 * 100; //make ready for int conversion
    prevPixelT = whichPixelT; //save the reentrant value
    whichPixelT = targetPctBsp2 - neoMinTargetFloor; //figure where we are in the range
    whichPixelT = pickPixelMult * whichPixelT; //set the range to the pixels
    if (statMsg == 1)
    {
    Serial.print("dotTarget,");
    Serial.print(",pickpixelmult," ); Serial.print(pickPixelMult);
    Serial.print(",targetpctbsp," ); Serial.print(targetPctBsp2);
    Serial.print(",neomintargetfloor," ); Serial.println(neoMinTargetFloor);
    }
    pixelXDR();
    }
    //

    ////////////////uses Polars instead of targets///
    void dotPolar() {
    float polarPctBsp2 = 0;
    float bspFloat2 = bspInt;
    float polarBSPAvg2 = polarBspAvg;
    float numpixelsFloat = NUMPIXELS;
    float centerPixelFloat = centerPixel;
    bspFloat2 = bspFloat2 * .01;
    pickPixelMult = centerPixelFloat / numpixelsFloat; //calculate percentage for each pixel
    polarPctBsp2 = bspFloat2 / polarBSPAvg2; //temp target percentage value
    polarPctBsp2 = polarPctBsp2 * 100; //make ready for int conversion
    prevPixelT = whichPixelT; //save the reentrant value
    whichPixelT = polarPctBsp2 - neoMinTargetFloor; //figure where we are in the range
    whichPixelT = pickPixelMult * whichPixelT; //set the range to the pixels
    if (statMsg == 1)
    {
    Serial.print("dotPolar,");
    Serial.print(",pickpixelmult," ); Serial.print(pickPixelMult);
    Serial.print(",polarpctbsp," ); Serial.print(polarPctBsp2);
    Serial.print(",neomintargetfloor," ); Serial.println(neoMinTargetFloor);
    }
    pixelXDR();
    }
    //

    ////////////////displays TWA only downwind////
    void dotTWA() {
    float targetPctBsp2 = 0;
    float bspFloat2 = bspInt;
    float targetBSPAvg2 = targetBSPAvg;
    float numpixelsFloat = NUMPIXELS;
    float centerPixelFloat = centerPixel;
    pickPixelMult = centerPixelFloat / numpixelsFloat; //calculate percentage for each pixel
    targetPctBsp2 = bspFloat2 / targetBSPAvg2; //temp target percentage value
    targetPctBsp2 = targetPctBsp2 * 100; //make ready for int conversion
    prevPixelT = whichPixelT; //save the reentrant value
    whichPixelT = targetPctBsp2 - neoMinTargetFloor; //figure where we are in the range
    whichPixelT = pickPixelMult * whichPixelT; //set the range to the pixels
    pixelXDR();
    }
    //

    ////////////////sets the driver pixel and sends the XDR////////////
    void pixelXDR() {

    }
    //

    ///Dot Splash Lights /////////
    void dotSplash() {
    verDisplay();
    delay(2000);
    int splashDelay = 200;
    dotBrightness();
    dotFill('Rd');
    dotDisplay();
    delay(splashDelay);
    dotWipe('Rd');
    dotDisplay();
    dotFill('Gr');
    dotDisplay();
    delay(splashDelay);
    dotWipe('Gr');
    dotDisplay();
    dotFill('Bl');
    dotDisplay();
    delay(splashDelay);
    dotWipe('Bl');
    dotDisplay();
    dotFill('Wh');
    dotDisplay();
    delay(splashDelay / 2);
    int i;
    for (i = 150; i > 0; i--)
    {
    strip.setBrightness(i);
    //Serial.println(i);
    strip.show();
    delay(3);
    }
    dotWipe('Bk');
    dotDisplay();
    }
    //

    ///updates a setting read from a file read or console//////////////
    void applySetting(String settingName, String settingValue) {
    if ((settingName == "pressureoffset") || (settingName == "baroffset")) {
    Serial.print("the existing value of ");
    Serial.print(baroffset);
    baroffset = settingValue.toInt();
    Serial.print(" has been replaced with ");
    Serial.println(baroffset);
    }
    else if (settingName == "startno") {
    Serial.print("the existing value of ");
    Serial.print(startNo);
    Serial.print(" has been replaced with ");
    startNo = settingValue.toInt(); //set the leapdays to correct coledatetime
    Serial.println(startNo);
    }
    }
    //

    ///Help Commands/////
    void listHelp() {
    Serial.println(" Available Console Commands:");
    Serial.println(" sed-l - reads the system log file and plays it to console");
    Serial.println(" sed-s - reads the settings file and plays it to the console. can also type SETTINGS ");
    Serial.println(" sed-p - reads the polar file and enumerates the polar array and target array ");
    Serial.println(" rdsdc - lists he contents of the SD card and plays it to console. can also type ls -l ");
    Serial.println(" sed-f - reads the file named and plays it to console, must be preceded and followed by a comma. example: sed-f,123456.csv, ");
    Serial.println(" upstg - updates contents of the settings file with the paramater and value specified in the command. example: upstg,parmater,value, ");
    Serial.println(" ");
    Serial.println(" setti - reads the settings file and plays it to console");
    Serial.println(" quiet - turns off NMEA data to console");
    Serial.println(" nomsg - turns off system messages to serial");
    Serial.println(" msgon - turns off system messages to serial");
    Serial.println(" nonmea - turns off NMEA messages to serial");
    Serial.println(" nmeaon - turns ON NMEA data to console");
    Serial.println(" echoo - turns ON NMEA data to console");
    Serial.println(" noisy - turns ON NMEA data to console");
    Serial.println(" statu - shows system and data status");
    Serial.println(" press - shows current barometric pressure");
    Serial.println(" -help - shows the command help file");
    Serial.println(" ls -l - lists the contents of the SD card and plays it to console");
    Serial.println(" ls -p - lists the contents of the target and polar arrays and plays them to console");
    Serial.println(" DOT COMMANDS");
    Serial.println(" dimmer - dims the driver lights");
    Serial.println(" bright - brightens the driver lights");
    Serial.println(" clear - clears the dot display");
    Serial.println(" dotpol - sets the dot mode to polar boatspeed mode");
    Serial.println(" dottarg - sets the dot mode to target boatspeed mode");
    Serial.println(" dottwa - sets the dot mode to target TWA display");
    Serial.println(" rdybsp - sets dot ready mode to Boatspeed only");
    Serial.println(" rdytwa - sets dot ready mode to TWA only");
    Serial.println(" rdyboth - sets dot ready mode to both BSP & TWA ");
    Serial.println(" rdyei - sets dot ready mode to either BSP or TWA ");
    Serial.println(" toggle - toggles the dot display between on and off");
    Serial.println(" ifcon - displays the IP interface settings");
    }
    //

    ////////////////writes expedition record to S3 /////////////
    void s3expRecord() {
    Serial3.print("$MEXP1#");

    Serial3.println("#23");
    }
    //

    ////////////////reads the heel angle /////
    void readRoll() {
    uint8_t howManyBytesToRead = 6;
    readFrom( DATAX0, howManyBytesToRead, _buff); //read the acceleration data from the ADXL345
    // each axis reading comes in 10 bit resolution, ie 2 bytes. Least Significat Byte first!!
    // thus we are converting both bytes in to one int
    zold = z;
    x = (((int16_t)_buff[1]) << 8) | _buff[0];
    y = (((int16_t)_buff[3]) << 8) | _buff[2];
    z = (((int16_t)_buff[5]) << 8) | _buff[4];
    //x = ((x + xold) / 2);
    //y = ((y + yold) / 2);
    //Roll and Pitch to degree Equations
    roll = (atan2(-y, z) * 180.0) / M_PI;
    roll = roll + heelCorrector;
    }
    //

    //show the polar array////
    void ShowPolar() {
    Serial.println("Polar File!");

    for ( int c = 0; c < 180; c++) {
    Serial.print(c);
    Serial.print(",");
    }

    for ( int r = 0; r < 36; r++) {
    for ( int c = 0; c < 180; c++) {
    Serial.print( polarArray[r][c]);
    Serial.print(",");
    }
    Serial.println();
    }
    Serial.println();
    Serial.println("Upwind Targets!");
    for ( int c = 0; c < 35; c++) {
    Serial.print(c);
    Serial.print(",");
    Serial.print(targetTWAArrayUP[c]);
    Serial.print(",");
    Serial.print(targetBSPArrayUP[c]);
    Serial.println("");
    }
    Serial.println("Downwind Targets!");
    for ( int c = 0; c < 35; c++) {
    Serial.print(c);
    Serial.print(",");
    Serial.print( targetTWAArrayDN[c]);
    Serial.print(",");
    Serial.print( targetBSPArrayDN[c]);
    Serial.println("");
    }
    }
    //

    //////polar file read and enumerate routine/////////////////
    //polar file must have 0 row, be CSV named txt and have a 0 tws row//////////////
    void ReadExpPolarFile() {
    String inData5 = "";
    String inData6 = "";
    char recieved5;
    int colTyp = 0;
    int pcommaloc = 0;
    int pcommalocprev = 0;
    int endLoc = 0;
    int ididx = 0;
    String valFloat = 0;
    String valTmp = "";
    int valRow = 0;
    int polTws = 0;
    int EOL = 0;
    int firstCol = 1;
    int polBsp = 0;
    int polTwa = 0;
    int lowTwa = 0;
    int highTwa = 0;
    int lowBsp = 0;
    int highBsp = 0;
    int lowerPair = 0;
    float diffBsp = 0;
    float lowBspF = 0;
    int diffTwa = 0;
    float addBsp = 0;
    File myFile = SD.open("polarfil.txt");
    if (myFile)
    {
    Serial.println(" fil.txt file found. processing contents: ");
    while (myFile.available())
    {
    recieved5 = myFile.read();
    inData5 += recieved5;
    ididx = 0;
    if (recieved5 == '\n') // Process message when new line character is received
    {
    inData6 = inData5;
    inData5 = "";
    endLoc = inData6.indexOf('\n'); //right end bound
    //Serial.print("endloc "); Serial.print(endLoc); Serial.print(" ididx "); Serial.print(ididx);
    Serial.print(" Processing Record:");
    Serial.print(inData6);
    pcommalocprev = 0;
    firstCol = 1;

    while (EOL == 0) //we're not at the end of a record so get more
    {
    if (firstCol == 1)
    {
    firstCol = 0;
    pcommaloc = inData6.indexOf(',', pcommalocprev);
    valTmp = inData6.substring(pcommalocprev, pcommaloc);
    valFloat = String(valTmp.toFloat());
    polTws = valFloat.toInt();
    if (pcommaloc < ididx) EOL = 1;
    ididx = pcommaloc + 1; //////////////sets us to the data row
    pcommalocprev = pcommaloc + 1;
    }
    if (colTyp == 0) colTyp = 1; ////flops the column type values
    else colTyp = 0;
    pcommaloc = inData6.indexOf(',', pcommalocprev);
    valTmp = inData6.substring(pcommalocprev, pcommaloc);

    if (colTyp == 0) //speed
    {
    valFloat = String(valTmp.toFloat() * 100 , 4);
    valRow = valFloat.toInt();
    polBsp = valRow;
    if (lowerPair == 0)
    {
    lowTwa = polTwa;
    lowBsp = polBsp;
    lowerPair = 1;
    //Serial.println(" were slotted into lower vals ");
    }
    else
    {
    highTwa = polTwa;
    highBsp = polBsp;
    //build the diffs///////////
    diffBsp = highBsp - lowBsp;
    diffTwa = highTwa - lowTwa;
    addBsp = diffBsp / diffTwa;
    addBsp = addBsp * .01;
    lowBspF = lowBsp * .01;
    for (int co = lowTwa; co <= highTwa; co++)
    {
    int lowBspFInt = lowBspF * 100; //this line ghcanges to an int...
    polarArray[polTws][co] = lowBspF;
    lowBspF = lowBspF + addBsp;
    }
    Serial.print("+");
    /////////////finishing up for the next loop
    lowTwa = highTwa;
    lowBsp = highBsp;
    }
    }
    else //coltype must equal 1
    {
    valFloat = String(valTmp.toFloat());
    valRow = valFloat.toInt();
    polTwa = valRow;
    }
    if (pcommaloc < ididx) EOL = 1;
    ididx = pcommaloc + 1; //////////////sets us to the data row
    pcommalocprev = pcommaloc + 1;
    }
    Serial.println(" Record Sucessfully Processed ");
    EOL = 0;
    lowerPair = 0;
    inData5 = "";
    }
    }
    }
    ///fill in the columns
    int r = 0;
    int c = 0;
    float lowB = 0;
    float highB = 0;
    int gotLow = 0;
    int gotHigh = 0;
    int rowCounter = 1;
    int lowRow = 0;
    float val = 0;
    float valDiff = 0;
    float valAdd = 0 ;
    int highRow = 0;

    while (c < 180)
    {
    while (r < 36)
    {
    val = polarArray[r][c];
    if (val != 0 && gotLow == 0) {
    gotLow = 1;
    rowCounter = 0;
    lowB = val;
    lowRow = r;
    }
    else if (val != 0 && gotLow == 1 && gotHigh == 0)
    {
    gotHigh = 1;
    highB = val;
    valDiff = highB - lowB;
    valAdd = valDiff / rowCounter;
    highRow = lowRow + rowCounter;
    for (int i = lowRow; i < highRow; i++)
    {
    Serial.print(".");
    polarArray[lowRow][c] = lowB;
    lowB = lowB + valAdd;
    lowRow++;
    }
    gotLow = 1;
    gotHigh = 0;
    rowCounter = 0;
    lowB = highB;
    lowRow = r;
    highB = 0;
    highRow = 0;
    }
    r++;
    if (gotLow == 1) rowCounter ++;
    }
    r = 0;
    gotLow = 0;
    gotHigh = 0;
    c++;
    }
    //ShowPolar();
    BuildTargets();
    }
    //

    //Target array refresh from polars////////
    void BuildTargets() {
    float topVal = 0;
    int topValInt = 0;
    int angleT = 0;
    float val = 0;
    int c = 0;
    int r = 0;
    float cosTmp = 0;
    int cCos = 0;

    while (r < 36)
    {
    while (c < 180)
    {
    if (c > 90) cCos = 180 - c;
    else cCos = c;
    cosTmp = cosArray[cCos] * .0001;
    val = polarArray[r][c] * cosTmp;
    if (val > topVal) {
    topVal = val;
    angleT = c;
    }
    if (c > 90)
    {
    targetTWAArrayDN[r] = angleT;
    topValInt = topVal * 100;
    targetBSPArrayDN[r] = topValInt;
    }
    else
    {
    targetTWAArrayUP[r] = angleT;
    topValInt = topVal * 100;
    targetBSPArrayUP[r] = topValInt;
    }
    c++;
    }
    c = 0;
    angleT = 0;
    topVal = 0;
    topValInt = 0;
    r++;
    }
    }
    //

    ///writes updateable settings to SD////
    void WriteTune() {
    myFile = SD.open("settings.txt", FILE_WRITE);
    myFile.print("["); myFile.print("centerPixel"); myFile.print("="); myFile.print(centerPixel); myFile.println("]");
    myFile.print("["); myFile.print("bspFlightMin"); myFile.print("="); myFile.print(bspFlightMin); myFile.println("]");
    myFile.print("["); myFile.print("dotBrightess"); myFile.print("="); myFile.print(dotBrightess); myFile.println("]");
    myFile.print("["); myFile.print("warningRoll"); myFile.print("="); myFile.print(warningRoll); myFile.println("]");
    myFile.print("["); myFile.print("cautionRoll"); myFile.print("="); myFile.print(cautionRoll); myFile.println("]");
    myFile.print("["); myFile.print("dotMode"); myFile.print("="); myFile.print(dotMode); myFile.println("]");
    myFile.print("["); myFile.print("NMEALog"); myFile.print("="); myFile.print(NMEALog); myFile.println("]");
    //myFile.print("["); myFile.print("boardHeight"); myFile.print("="); myFile.print(boardHeight); myFile.println("]");
    //myFile.print("["); myFile.print("activeSail"); myFile.print("="); myFile.print(activeSail); myFile.println("]");
    myFile.print("["); myFile.print("s3PIXComm"); myFile.print("="); myFile.print(s3PIXComm); myFile.println("]");
    myFile.print("["); myFile.print("s1PIXComm"); myFile.print("="); myFile.print(s1PIXComm); myFile.println("]");
    myFile.print("["); myFile.print("s0PIXComm"); myFile.print("="); myFile.print(s0PIXComm); myFile.println("]");
    myFile.print("["); myFile.print("s1NMEAComm"); myFile.print("="); myFile.print(s1NMEAComm); myFile.println("]");
    myFile.print("["); myFile.print("s3NMEAComm"); myFile.print("="); myFile.print(s3NMEAComm); myFile.println("]");
    myFile.print("["); myFile.print("PIXGenerate"); myFile.print("="); myFile.print(PIXGenerate); myFile.println("]");
    myFile.print("["); myFile.print("s0XDRComm"); myFile.print("="); myFile.print(s0XDRComm); myFile.println("]");
    myFile.print("["); myFile.print("s1XDRComm"); myFile.print("="); myFile.print(s1XDRComm); myFile.println("]");
    myFile.print("["); myFile.print("s3XDRComm"); myFile.print("="); myFile.print(s3XDRComm); myFile.println("]");
    myFile.print("["); myFile.print("neoMinTargetFloor"); myFile.print("="); myFile.print(neoMinTargetFloor); myFile.println("]");
    myFile.print("["); myFile.print("baroffset"); myFile.print("="); myFile.print(baroffset); myFile.println("]");
    myFile.print("["); myFile.print("NMEAPlay"); myFile.print("="); myFile.print(NMEAPlay); myFile.println("]");
    myFile.print("["); myFile.print("Expedition"); myFile.print("="); myFile.print(Expedition); myFile.println("]");
    myFile.print("["); myFile.print("Sensor"); myFile.print("="); myFile.print(Sensor); myFile.println("]");
    myFile.print("["); myFile.print("Barometer"); myFile.print("="); myFile.print(Barometer); myFile.println("]");
    myFile.print("["); myFile.print("paddleSelector"); myFile.print("="); myFile.print(paddleSelector); myFile.println("]");
    myFile.print("["); myFile.print("directLog"); myFile.print("="); myFile.print(directLog); myFile.println("]");
    myFile.print("["); myFile.print("tackScoreData"); myFile.print("="); myFile.print(tackScoreData); myFile.println("]");
    myFile.print("["); myFile.print("v24Record"); myFile.print("="); myFile.print(v24Record); myFile.println("]");
    myFile.print("["); myFile.print("v12Record"); myFile.print("="); myFile.print(v12Record); myFile.println("]");
    myFile.print("["); myFile.print("LeapDays"); myFile.print("="); myFile.print(LeapDays); myFile.println("]");
    myFile.print("["); myFile.print("isReadyMode"); myFile.print("="); myFile.print(isReadyMode); myFile.println("]");
    myFile.print("["); myFile.print("twsFlightMin"); myFile.print("="); myFile.print(twsFlightMin); myFile.println("]");
    //myFile.print("["); myFile.print(""); myFile.print("="); myFile.print(); myFile.println("]");
    myFile.close();
    Serial.println("The settings File has been updated with a web request");
    myFile = SD.open("syslog.txt", FILE_WRITE);
    myFile.println("The settings File has been updated from a web request: ");
    myFile.close();
    }
    /////

    /////////////shows time in standard format//

    void HumanTime() {
    }
    //////

    //////
    void print2digits(int number) {
    if (number >= 0 && number < 10) {
    Serial.write('0');
    }
    Serial.print(number);
    }
    //////

    ////sends a single expedition record to Serial//
    void ShowExpeditionInfo() {

    Serial.println((z - 119)); // z axis of accelerometer "motion" field
    }
    //////

    ////checks wind and sets polar field ////////////
    void polarRecordCheck() {
    }
    /////

    ////displays ip settings ////
    void ShowIpInfo()
    {
    Serial.println("")
    ;Serial.print("IP: ");
    Serial.print(Ethernet.localIP());
    Serial.print(" Gateway: ");
    Serial.print(Ethernet.gatewayIP());
    Serial.print(" Subnet Mask: ");
    Serial.println(Ethernet.subnetMask());
    }
    /////




Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •