Advertisement
Guest User

Untitled

a guest
Oct 3rd, 2016
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 24.49 KB | None | 0 0
  1. Here is the current code, that I am having the issue.
  2.  
  3. [code]/*  ==============================================================================================================================================================================================
  4.     IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
  5.                         INCLUDE
  6.     IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
  7.     ==============================================================================================================================================================================================
  8. */
  9.  
  10. /* IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
  11.      INCLUDE - SD CARD
  12.    IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
  13. */
  14. // ========== SD Card  ======================================================
  15.  
  16. #include <SD.h>         // Needed to read/write to the SD Card
  17. const int chipSelect = 4;
  18.  
  19. File myFile;                     // to handle to temperature tp160110.txt files
  20. File webFile;                    // to handle to Extron Output00.htm files
  21.  
  22.  
  23. /* IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
  24.      INCLUDE - Ethernet
  25.    IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
  26. */
  27. // ========== Ethernet Card  ======================================================
  28.  
  29. #include <SPI.h>        // Needed to us the 6 special pins for the eithernet card
  30. #include <Ethernet.h>   // Needed to use the eithernet card
  31.  
  32. // ========== Ethernet Parameters  ======================================================
  33.  
  34. // comment out next line to write to SD from FTP server
  35. #define FTPWRITE
  36. #define error(s) error_P(PSTR(s))     // Make sure this is below #include <SD.h> or else there will be an error.
  37.  
  38. // this must be unique
  39. byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0xC1, 0xDE };
  40.  
  41. // change to your network settings
  42. byte ip[] = { 10, 0, 0, 88 };
  43. byte gateway[] = { 10, 0, 0, 1 };
  44. byte subnet[] = { 255, 255, 255, 0  };
  45. byte dnsserver[] = { 10, 0, 0, 1 };
  46.  
  47. // change fileName to your file (8.3 format!)
  48. //char fileName[13] = "day00.txt";
  49. //char fileName[13] = "TP150826.TXT";        // Capital letters need to match. or else it will upload as written. eqrunner is finicky about capitals vs lower case // not needed as we already have templog_filename
  50. char ftpserver[] = "XXXXXXXXXXXX.com";            // url of the server
  51. char ftpuserName[] = "USER XXXXXXXX";    // Make sure it includes the USER lead in:  "USER admin"
  52. char ftppassWord[] = "PASS XXXXXXXXX";        // Make sure it has the PASS lead also:     "PASS kittykat"
  53. char file_name[13];          // For startFTP. To define the file that will be uploaded
  54. char *file_folder;             // For startFTP. To define the folder that the file_name will be uploaded to
  55.  
  56.  
  57.  
  58. char outBuf[128];
  59. char outCount;
  60.  
  61. EthernetServer server(80);        // allows the arduino to be a server. to 'host' a file
  62. EthernetClient client;            // the basic ground work to allow the arduino to be a client 'user'
  63. EthernetClient dclient;           // needed for the doFTP stuff
  64.  
  65. // ========== EMAIL  ======================================================
  66.  
  67. char email_server[] = "www.eqrunner.com";       // Setup for server to email me.
  68. boolean email_ip_run = 0;                       // True/False statement to only run the "email ip address" once.
  69.  
  70.  
  71.  
  72. /* IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
  73.      INCLUDE - RTC Real Time Clock
  74.    IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
  75. */
  76.  
  77.  
  78. #include "Wire.h"       // Needed for RTC Chip
  79.  
  80. #define DS1307_ADDRESS 0x68     // RTC Address.
  81. // char timestamp[27];             // Sets up the 28 char count for the write to SD card line. EX: char timestamp[27] = ("2015-07-01 WED 12:31 </br>");
  82. // [new Date(2015,08,25,00,01,58), 78.61 , 82.02 , -95.94 , 95.81 , -5.34 , 76.20 ],
  83. // [[00,00,22], 8.56 , 7.16 , 6.60 , 43.38 , 58.65 , 0.00 ],
  84. // Do you think this is nessassary? just print each item individualy. line by line. Takes up less ram to do.
  85.  
  86. // ========== Temperature Sensor  ======================================================
  87. char time_format [9];         // This is the character string for current time ( HH,mm,SS)
  88. char date_format [9];         // This is the character string for current date ( YY,MM,DD)
  89. char templog_filename [13];    // This is the character string for the file name tpYYMMDD.txt
  90.  
  91. // ========== Mail Box  ======================================================
  92. char timestamp[27];             // Sets up the 28 char count for the write to SD card line. EX: char timestamp[27] = ("2015-07-01 WED 12:31 </br>");
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99. /*  ==============================================================================================================================================================================================
  100.     SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
  101.                         SETUP
  102.     SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
  103.     ==============================================================================================================================================================================================
  104. */
  105.  
  106. void setup() {
  107.   // put your setup code here, to run once:
  108.   /* SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
  109.      SETUP - Serial Port
  110.     SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
  111.   */
  112.  
  113.   // Open serial communications and wait for port to open:
  114.   Serial.begin(9600);
  115.   while (!Serial) {
  116.     ; // wait for serial port to connect. Needed for Leonardo only
  117.   }
  118.  
  119.  
  120.   /* SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
  121.        SETUP - SD Card
  122.      SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
  123.   */
  124.  
  125.   Serial.print("Initializing SD card...");
  126.  
  127.   // see if the card is present and can be initialized:
  128.   if (!SD.begin(chipSelect)) {
  129.     Serial.println("Card failed, or not present");
  130.     //LED_power_loop(0);
  131.     //LED_sdcard_loop(0);
  132.     // don't do anything more:
  133.     return;
  134.   }
  135.   Serial.println("card initialized.");
  136.  
  137.   /* SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
  138.        SETUP - Ethernet
  139.      SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
  140.   */
  141.  
  142.   // == SETUP ============ ETHERNET  ============
  143.   // Ethernet.begin(mac, ip);
  144.   Ethernet.begin(mac, ip, dnsserver, gateway, subnet);
  145.  
  146.   /*
  147.     if (Ethernet.begin(mac) == 0) {
  148.       Serial.println("Failed to configure Ethernet using DHCP");
  149.       LEDethernetStatus = 3;  // IF it can not, it will show as as failed.
  150.       // no point in carrying on, so do nothing forevermore:
  151.       // try to congifure using IP address instead of DHCP:
  152.       Ethernet.begin(mac, ip, dnsserver, gateway, subnet);
  153.     }
  154.   */
  155.  
  156.   Serial.print("IP Address:  ");
  157.   for (byte thisByte = 0; thisByte < 4; thisByte++) {
  158.     // print the value of each byte of the IP address:
  159.     Serial.print(Ethernet.localIP()[thisByte], DEC);
  160.     Serial.print(".");
  161.   }
  162.   Serial.println();
  163.   Serial.print("SubnetMask:  ");
  164.   for (byte thisByte = 0; thisByte < 4; thisByte++) {
  165.     // print the value of each byte of the IP address:
  166.     Serial.print(Ethernet.subnetMask()[thisByte], DEC);
  167.     Serial.print(".");
  168.   }
  169.   Serial.println();
  170.   Serial.print("Gateway:  ");
  171.   for (byte thisByte = 0; thisByte < 4; thisByte++) {
  172.     // print the value of each byte of the IP address:
  173.     Serial.print(Ethernet.gatewayIP()[thisByte], DEC);
  174.     Serial.print(".");
  175.   }
  176.   Serial.println();
  177.   Serial.print("DNS:  ");
  178.   for (byte thisByte = 0; thisByte < 4; thisByte++) {
  179.     // print the value of each byte of the IP address:
  180.     Serial.print(Ethernet.dnsServerIP()[thisByte], DEC);
  181.     Serial.print(".");
  182.   }
  183.   Serial.println();
  184.   server.begin();
  185.  
  186.   //printDate();  // Parses the Current date and time once.  // Commented out since This does not need to run so soon.
  187.   // ButtonUpload_count = 0;         // Resets Button Upload count to 0, cause printDate() counts to 53.
  188.   //email_ip();   // Runs email_ip to send me an email of its current ip  // Commented out since I don't need it as it is home now. Not on some site.
  189.  
  190.   /* SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
  191.        SETUP - RTC - Real Time Clock
  192.      SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
  193.   */
  194.  
  195.   Wire.begin();  // sets up the 'wire' code to be able to read the RTC
  196. }
  197.  
  198.  
  199.  
  200. /*  ==============================================================================================================================================================================================
  201.     LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
  202.                         LOOP
  203.     LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
  204.     ==============================================================================================================================================================================================
  205. */
  206. void loop() {
  207.   // put your main code here, to run repeatedly:
  208.  
  209.   /* LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
  210.      LOOP - SERIAL activated Actions
  211.     LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
  212.   */
  213.   // == LOOP ============ SERIAL INPUT ====================================
  214.   // TESTING: If F is entered into the serial widow, then it will execute an ftp upload
  215.   byte inChar;
  216.   inChar = Serial.read();
  217.   if (inChar == 't')
  218.   {
  219.     // Testing Character
  220.     startFTP("templog_action");
  221.   }
  222.  
  223.  
  224. }
  225. /*  ==============================================================================================================================================================================================
  226.     ==============================================================================================================================================================================================
  227.                         SERVER
  228.     ==============================================================================================================================================================================================
  229.     ==============================================================================================================================================================================================
  230. */
  231. // =====================================================================================================================
  232. // ============ FTP UPLOAD =============================================================================================
  233. // =====================================================================================================================
  234.  
  235. // ========== STEP 1 - Define which file  ======================================================
  236. void startFTP(char which_action[]) {
  237.   Serial.println("startFTP activated. ");
  238.   int startFTP_ready = 0;
  239.  
  240.   // ========== STEP 2 - Setup variables for specified file type  ======================================================
  241.   if (which_action == "templog_action") {
  242.     Serial.println("Temp Log Action Activated");
  243.     sprintf(file_name, templog_filename);         // have to build it as a sprintf for some stuipd reason. Other than templog_filename is a sprintf
  244.     // sprintf(file_folder ,"cwd temperature");  
  245.     //startFTP_ready = 1;
  246.   }
  247.   if (which_action == "phpdaily_action") {
  248.     Serial.println("PHP Daily Action Activated");
  249.  
  250.   }
  251.   if (which_action == "maillog_action") {
  252.     Serial.println("Mail Log Action Activated");
  253.  
  254.   }
  255.  
  256.   if (which_action == "comcastlog") {
  257.     Serial.println("Mail Log Action Activated");
  258.  
  259.   }
  260.  
  261.  
  262.   if (startFTP_ready == 1) {
  263.     if (doFTP()) {
  264.       Serial.println(F("FTP OK"));  // executes the doFTP code to upload on the Ethernet tab. Will return FTP OK if it worked
  265.       //wdt_enable(WDTO_4S);
  266.       //LED_ethernet_loop(1);
  267.     }
  268.     else {
  269.       //wdt_enable(WDTO_4S);
  270.       //LED_ethernet_loop(3);
  271.     }
  272.   }
  273.  
  274.   Serial.println(file_name);
  275.   Serial.println(file_folder);   // This wont render correctly???
  276.   Serial.println("startFTP END");
  277.  
  278.  
  279.  
  280.  
  281.  
  282.  
  283.  
  284.   // Activate the FTP upload -> Step 3
  285.  
  286.  
  287. }
  288.  
  289. // ========== STEP 3 - Upload Said file  ======================================================
  290.  
  291.  
  292. byte doFTP()       // Is a byte. If below completes successfully, it returns with a 1. if it fails, it returns with a 0
  293. {
  294.  
  295.   Serial.print("FTP Started....");
  296.  
  297.   //digitalWrite(LEDethernetRed, HIGH);
  298.   //wdt_disable();                                   // Stops the watchdog as this may take more than 4 seconds
  299.  
  300.   myFile = SD.open(file_name, FILE_READ);  // Opens up the file for reading (1st of 2 connections open)
  301.  
  302.   if (!myFile)
  303.   {
  304.     Serial.println(F("SD open fail"));
  305.     return 0;
  306.   }
  307.  
  308.   if (client.connect(ftpserver, 21)) {          // Opens up FTP server (2nd of 2 connections open)  Just like FTP> open eqrunner
  309.     //Serial.println(F("Command connected"));
  310.   }
  311.   else {                                        // If there is a fail, it returns with a 0 = fail
  312.     client.stop();
  313.     myFile.close();
  314.     Serial.println(F("Command connection failed"));
  315.     return 0;
  316.   }
  317.   if (!eRcv()) return 0;                        // Waits for server to finish sending me all of it's welcome text. User (eqrunner.com:(none)): When it is completed then...
  318.   client.println(ftpuserName);                  // Sends preset user name.Example:  FTP> USER admin
  319.   if (!eRcv()) return 0;                        // Waits for server to finish sending back info Example: 331 User admin OK. Password required.  Password:
  320.   client.println(ftppassWord);                  // Sends preset password .Example:  FTP> PASS kittykat
  321.   if (!eRcv()) return 0;
  322.   client.println(F("SYST"));                    // Asks server for System identification type. Example UNIX Type: L8.
  323.   if (!eRcv()) return 0;
  324.   client.println(F("Type I"));                  // Sets the type of file to be transferred. Type I = image (binary data)
  325.   if (!eRcv()) return 0;
  326.   client.println(F("PASV"));                    // Tells the server to enter 'passive mode'
  327.   if (!eRcv()) return 0;
  328.  
  329.  
  330.   char *tStr = strtok(outBuf, "(,");            // have no clue?
  331.   int array_pasv[6];
  332.   for ( int i = 0; i < 6; i++) {
  333.     tStr = strtok(NULL, "(,");
  334.     array_pasv[i] = atoi(tStr);
  335.     if (tStr == NULL)
  336.     {
  337.       Serial.println(F("Bad PASV Answer"));
  338.     }
  339.   }
  340.   unsigned int hiPort, loPort;
  341.   hiPort = array_pasv[4] << 8;
  342.   loPort = array_pasv[5] & 255;
  343.   //Serial.print(F("Data port: "));
  344.   hiPort = hiPort | loPort;
  345.   //Serial.println(hiPort);
  346.   //if (dclient.connect(server, hiPort)) {
  347.   if (dclient.connect(ftpserver, hiPort)) {
  348.     //Serial.println(F("Data connected"));
  349.   }
  350.   else {
  351.     Serial.println(F("Data connection failed"));
  352.     client.stop();
  353.     myFile.close();
  354.     return 0;
  355.   }
  356.  
  357.  
  358.   // IF it got this far, then All is well and ready to upload
  359.   client.println(F("cwd temperature"));           // Change Directory to /temperature/      cwd acts the same as cd in ftp>
  360.   //client.println(file_folder);           // Change Directory to /temperature/      cwd acts the same as cd in ftp>
  361.   if (!eRcv()) return 0;                          // wait for the responce back.
  362.   client.print(F("STOR "));                       // Buildng the client.println to do the following: ftp> STOR tp20150826.txt
  363.   client.println(file_name);                // STOR is the raw version of 'put' in ftp> language
  364.  
  365.   if (!eRcv())
  366.   {
  367.     dclient.stop();
  368.     return 0;
  369.   }
  370.  
  371.  
  372.   //Serial.println(F("Writing"));                  // Begins writing the file to the server, one byte at a time
  373.   byte clientBuf[64];
  374.   int clientCount = 0;
  375.   while (myFile.available())
  376.   {
  377.     clientBuf[clientCount] = myFile.read();
  378.     clientCount++;
  379.  
  380.     if (clientCount > 63)
  381.     {
  382.       dclient.write(clientBuf, 64);
  383.       clientCount = 0;
  384.     }
  385.   }
  386.  
  387.   if (clientCount > 0) dclient.write(clientBuf, clientCount);
  388.  
  389.   dclient.stop();
  390.   //Serial.println(F("Data disconnected"));
  391.   // END of writing the file to the server.
  392.   if (!eRcv()) return 0;                          // wait for the responce back.
  393.   // Okey We are complete with the upload. Lets end this ftp>
  394.   client.println(F("QUIT"));                      // Send quit command to quit to log off and end ftp connection
  395.   if (!eRcv()) return 0;                          // wait for the responce back.
  396.   client.stop();                                  // Close ethernet connection that was opened at the start of this.
  397.   //Serial.println(F("Command disconnected"));
  398.   myFile.close();                                 // Close the SD card connection that was opened at the start of this.
  399.   //Serial.println(F("SD closed"));
  400.   return 1;
  401. }
  402.  
  403. // ---------------------------------------------------------------------------------------------------------------------------------
  404. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  405. // - - - - - - - - - - e Recieve.  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  406. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  407. // Reads each byte sent from the server.
  408. // Checks byte from server Makes sure it is ok if so, returns with a 1 saying all is well.
  409.  
  410. byte eRcv()
  411. {
  412.   byte respCode;
  413.   byte thisByte;
  414.   int timeout = 0;                              // Creates a time out interger. Should there be a issue and it cant connect.
  415.   //wdt_reset();
  416.  
  417.   while (!client.available())  {                // Asking, While client is NOT availible (Say outside internet is down) ....
  418.     //Serial.print(".");
  419.     delay(5);                                   // Waits 5 miliseconds. tries again
  420.     timeout++;                                  // increases the timeout count every time.
  421.     if (timeout > 1000) {                       // If the timeout count gets to 10000 Then...
  422.       Serial.print("INFINITE LOOP BREAK!");     // Serial Prints out that the client could not connect. and...
  423.       return 0;                                 // returns the eRec(0) thus ending the connection and exiting out and returning back to the void loop.
  424.     }
  425.   }
  426.  
  427.   respCode = client.peek();
  428.  
  429.   outCount = 0;
  430.  
  431.   while (client.available())
  432.   {
  433.     thisByte = client.read();
  434.     // - - - - - - - - - - - - - - -
  435.     // Serial.write(thisByte);                // Spits out each responce back from godaddy.
  436.     // - - - - - - - - - - - - - - -
  437.     if (outCount < 127)
  438.     {
  439.       outBuf[outCount] = thisByte;
  440.       outCount++;
  441.       outBuf[outCount] = 0;
  442.     }
  443.   }
  444.  
  445.   if (respCode >= '4')
  446.   {
  447.     efail();
  448.     return 0;
  449.   }
  450.  
  451.   return 1;
  452. }
  453.  
  454.  
  455. // ---------------------------------------------------------------------------------------------------------------------------------
  456. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  457. // - - - - - - - - - - eFAILED - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  458. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  459.  
  460. void efail()
  461. {
  462.   byte thisByte = 0;
  463.  
  464.   client.println(F("QUIT"));
  465.   while (!client.available()) delay(1);
  466.  
  467.   while (client.available())
  468.   {
  469.     thisByte = client.read();
  470.     Serial.write(thisByte);
  471.   }
  472.  
  473.   client.stop();
  474.   Serial.println(F("Command disconnected"));
  475.   myFile.close();
  476.   Serial.println(F("SD closed"));
  477. }
  478. // ---------------------------------------------------------------------------------------------------------------------------------
  479. /*  ==============================================================================================================================================================================================
  480.     ==============================================================================================================================================================================================
  481.                         RTC - Real Time Clock Get Time
  482.     ==============================================================================================================================================================================================
  483.     ==============================================================================================================================================================================================
  484. */
  485.  
  486. // - - - - - - - - - - RTC - Real Time Clock Get time - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  487.  
  488. byte bcdToDec(byte val)  {
  489.   // Convert binary coded decimal to normal decimal numbers
  490.   return ( (val / 16 * 10) + (val % 16) );
  491. }
  492.  
  493. void printDate() {
  494.   // Reset the register pointer
  495.   Wire.beginTransmission(DS1307_ADDRESS);
  496.  
  497.   byte zero = 0x00;
  498.   Wire.write(zero);
  499.   Wire.endTransmission();
  500.  
  501.   Wire.requestFrom(DS1307_ADDRESS, 7);
  502.  
  503.   int second = bcdToDec(Wire.read());
  504.   int minute = bcdToDec(Wire.read());
  505.   int hour = bcdToDec(Wire.read() & 0b111111); //24 hour time
  506.   int weekDay = bcdToDec(Wire.read()); //0-6 -> sunday - Saturday
  507.   int monthDay = bcdToDec(Wire.read());
  508.   int month = bcdToDec(Wire.read());
  509.   int year = bcdToDec(Wire.read());
  510.   char * DayOfWeek[8] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" , "SUN"};
  511.   /*
  512.     //print the date EG   3/1/11 23:59:59
  513.     Serial.print(month);
  514.     Serial.print("/");
  515.     Serial.print(monthDay);
  516.     Serial.print("/");
  517.     Serial.print(year);
  518.     Serial.print("-");
  519.     char * DayOfWeek[8] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" , "SUN"};
  520.     //Serial.print(weekDay);
  521.     Serial.print(DayOfWeek[weekDay]);
  522.  
  523.     Serial.print(" ");
  524.     Serial.print(hour);
  525.     Serial.print(":");
  526.     Serial.print(minute);
  527.     Serial.print(":");
  528.     Serial.println(second);
  529.   */
  530.  
  531.   //char date_format [9];
  532.   sprintf(date_format, "%02d-%02d-%02d", year, month, monthDay );  // builds up the date format
  533.   // char time_format [9];
  534.   sprintf(time_format, "%02d,%02d,%02d", hour, minute, second );  // builds up the time format
  535.   sprintf(templog_filename, "tp%02d%02d%02d.txt", year, month, monthDay );
  536.  
  537.   /*
  538.     Serial.print("FILE: ");
  539.     Serial.print(filename_format);
  540.     Serial.print(" DATE: ");
  541.     Serial.print(date_format);
  542.     Serial.print(" ");
  543.     Serial.print(DayOfWeek[weekDay]);
  544.     Serial.print(" ");
  545.     Serial.println(time_format);
  546.   */
  547.   //Serial.println(time_format);
  548.   //Serial.println(time_format[7]);    // Even thou it is buffered at 9, only 7 values are used starting with 0. HH is 0 and 1, MM is 3 and 4. SS is 6 and 7)
  549.  
  550.   //char * DayOfWeek[8] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" , "SUN"};                                                 // Setup so you can convert the 'weekDay' to a alpha value
  551.   //sprintf(timestamp,  "20%d-%02d-%02d %s %02d:%02d </br>", year, month, monthDay, DayOfWeek[weekDay], hour, minute);        // Lays out the sprintf( define the char string, "the format and types of values" , each value)
  552.   //Serial.println( F("TIME: ") );
  553.   //Serial.println( timestamp );
  554.  
  555. }
  556.  
  557. // - - - - - - - - - - RTC - Real Time Clock Get time - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  558. [/code]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement