Hello,
I'm using the clock (DS1307) and in the serial it's working just fine - I can see the date+hour+day . all good
but when I try to see it in the webpage I get
0/0/0 0:0:0
the webpage is working and I can see all other data
this is the code:
void printDate(){
// Reset the register pointer
Wire.beginTransmission(DS1307_ADDRESS);
byte zero = 0x00;
Wire.write(zero);
Wire.endTransmission();
Wire.requestFrom(DS1307_ADDRESS, 7);
int second = bcdToDec(Wire.read());
int minute = bcdToDec(Wire.read());
int hour = bcdToDec(Wire.read() & 0b111111); //24 hour time
int weekDay = bcdToDec(Wire.read()); //0-6 ->
int monthDay = bcdToDec(Wire.read());
int month = bcdToDec(Wire.read());
int year = bcdToDec(Wire.read());
int tempDay=weekDay;
switch(tempDay)
{//start of switch
case 1:
Serial.println("Sunday ");
break;
case 2:
Serial.println("Monday ");
break;
case 3:
Serial.println("Tuesday ");
break;
case 4:
Serial.println("Wednesday ");
break;
case 5:
Serial.println("Thursday ");
break;
case 6:
Serial.println("Friday ");
break;
case 7:
Serial.println("Saturday ");
break;
}//end of switch
Serial.print(monthDay);
Serial.print("/");
Serial.print(month);
Serial.print("/");
Serial.print(year);
Serial.print(" ");
Serial.print(hour);
Serial.print(":");
Serial.print(minute);
Serial.print(":");
if(second<10)
{
Serial.print("0");
}
Serial.println(second);
}//end of print date
byte bcdToDec(byte val) // Convert binary coded decimal to normal decimal numbers
{
return ( (val/16*10) + (val%16) );
}
and this is what I have in the main code as HTML:
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
//meta-refresh page every 1 seconds
client.println("<HTML>");
client.print("<HEAD>");
client.print("<meta http-equiv=\"refresh\" content=\"1\">");
client.print("<TITLE /> Test</title>");
client.print("</head>");
client.println("<BODY>");
client.print("autorefresh test ");
client.println("
");
int temp_volt=Battary();
client.print(" Status of the Power is - ");
client.println(temp_volt);
client.print("
");
///print date+hour
///*****************************
printDate();
client.print("
");
client.print(monthDay);
client.print("/");
client.print(month);
client.print("/");
client.print(year);
client.print(" ");
client.print(hour);
client.print(":");
client.print(minute);
client.print(":");
if(second<10)
{
client.print("0");
}
client.println(second);
//****************************
OC=Operation_cheak();
client.println("The value of OC is - ");
client.println(OC);
I'm sure my mistake is simple - but I just can't see it
Thanks ,
Your variables are out of scope.
// Move these to global
int second, minute, hour, weekDay, monthDay, month, year;
// then set them in printDate()
second = bcdToDec(Wire.read());
minute = bcdToDec(Wire.read());
hour = bcdToDec(Wire.read() & 0b111111); //24 hour time
weekDay = bcdToDec(Wire.read()); //0-6 ->
monthDay = bcdToDec(Wire.read());
month = bcdToDec(Wire.read());
year = bcdToDec(Wire.read());
edit: Are you the david1234 from the MikroTik forum?
Thanks.
I have done what you have said , but not now I can't see the Day
I get the date+hour ,without the day(Sunday....)
#include <Ethernet.h>
#include <SPI.h>
#include "Wire.h"
#define DS1307_ADDRESS 0x68
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // MAC address of the device
IPAddress ip(10,0,0,25); // IP addres
IPAddress gateway(10,0,0,1); // gateway of device
EthernetServer server(80); //server is using port 80
int y,x,i,d,m,OC,ML;
unsigned long updateTime;
int t=0;
int monthDay,month,year,hour,minute,second,weekDay;
void printDate(){
// Reset the register pointer
Wire.beginTransmission(DS1307_ADDRESS);
byte zero = 0x00;
Wire.write(zero);
Wire.endTransmission();
Wire.requestFrom(DS1307_ADDRESS, 7);
second = bcdToDec(Wire.read());
minute = bcdToDec(Wire.read());
hour = bcdToDec(Wire.read() & 0b111111); //24 hour time
weekDay = bcdToDec(Wire.read()); //0-6 ->
monthDay = bcdToDec(Wire.read());
month = bcdToDec(Wire.read());
year = bcdToDec(Wire.read());
int tempDay=weekDay;
switch(tempDay)
{//start of switch
case 1:
Serial.println("Sunday ");
break;
case 2:
Serial.println("Monday ");
break;
case 3:
Serial.println("Tuesday ");
break;
case 4:
Serial.println("Wednesday ");
break;
case 5:
Serial.println("Thursday ");
break;
case 6:
Serial.println("Friday ");
break;
case 7:
Serial.println("Saturday ");
break;
}//end of switch
Serial.print(monthDay);
Serial.print("/");
Serial.print(month);
Serial.print("/");
Serial.print(year);
Serial.print(" ");
Serial.print(hour);
Serial.print(":");
Serial.print(minute);
Serial.print(":");
if(second<10)
{
Serial.print("0");
}
Serial.println(second);
}//end of print date
what else need to be change?
Thanks ,
Remember, spaces are an illegal character in a url. The string must be url encoded. You can't send "Sunday ". You must use "Sunday%20".
edit: I think you have the same problem with tempDay. It should be global.
Post all your code.
I think my problem is that I'm trying to "send" a word and not a value 0\1 , I have try to use "byte" -
am I right?
I understand where is my mistake -
when I do switch\case I only print in serial, and doesn't save it in tempDay or something
so how can I save it in the tempDay?
void printDate(){
// Reset the register pointer
Wire.beginTransmission(DS1307_ADDRESS);
byte zero = 0x00;
Wire.write(zero);
Wire.endTransmission();
Wire.requestFrom(DS1307_ADDRESS, 7);
second = bcdToDec(Wire.read());
minute = bcdToDec(Wire.read());
hour = bcdToDec(Wire.read() & 0b111111); //24 hour time
weekDay = bcdToDec(Wire.read()); //0-6 ->
monthDay = bcdToDec(Wire.read());
month = bcdToDec(Wire.read());
year = bcdToDec(Wire.read());
tempDay=weekDay;
switch(tempDay)
{//start of switch
case 1:
Serial.println("Sunday ");
////// ****** here I'm guessing need to put ----- tempDay=("sunday"); or something ... right?, so when I print in the the main code as client.print(tempDay) it will be correct
////////////////////
break;
case 2:
Serial.println("Monday ");
break;
case 3:
Serial.println("Tuesday ");
break;
case 4:
Serial.println("Wednesday ");
break;
case 5:
Serial.println("Thursday ");
break;
case 6:
Serial.println("Friday ");
break;
case 7:
Serial.println("Saturday ");
break;
}//end of switch
Serial.print(monthDay);
Serial.print("/");
Serial.print(month);
Serial.print("/");
Serial.print(year);
Serial.print(" ");
Serial.print(hour);
Serial.print(":");
if (minute<10)
{
Serial.print("0");
}
Serial.print(minute);
Serial.print(":");
if(second<10)
{
Serial.print("0");
}
Serial.println(second);
}//end of print date
byte bcdToDec(byte val) // Convert binary coded decimal to normal decimal numbers
{
return ( (val/16*10) + (val%16) );
}
Thanks ,
I use a character array.
char weekday[7][4] = {"THU","FRI","SAT","SUN","MON","TUE","WED"};
Serial.print(weekday[tempDay]);
Are you on the MikroTik forum also? There is a David1234 there also.
I will try it - but before I just want to see I understand
when I use char like you did
char weekday[7][4] = {"THU","FRI","SAT","SUN","MON","TUE","WED"};
the first number [7] - is telling me how many "words" are ,and can be use ,right?
the second number [4] - what does it mean ?
also I don't see how from weekDay it will know which "day" to bring me and print from me (after he read it from the clock_
Thanks,
char weekday[7][4] = {"THU","FRI","SAT","SUN","MON","TUE","WED"};
the first number [7] - is telling me how many "words" are ,and can be use ,right?
the second number [4] - what does it mean ?
The second number is the size of each of the 7 character arrays. There are 7 character arrays with 4 characters each. There must be one more than the length of the text to allow for the terminating zero.
1 JAN 1970 was a Thursday. So that is where we start.
weekday[tempDay] is the string you want to display.
Serial.print(weekday[tempDay]);
O.K
but how does it connect with the clock?
I still don't understand where\ how to put it
Thanks ,
Wire.requestFrom(DS1307_ADDRESS, 7);
second = bcdToDec(Wire.read());
minute = bcdToDec(Wire.read());
hour = bcdToDec(Wire.read() & 0b111111); //24 hour time
// here is where it comes from the clock. This is the index to the weekday array
weekDay = bcdToDec(Wire.read()); //0-6 ->
monthDay = bcdToDec(Wire.read());
month = bcdToDec(Wire.read());
year = bcdToDec(Wire.read());
// then use that to print that string. Those variable names are a bit too close for me tho.
Serial.println(weekday[weekDay]);
until here I understand
but the printDate is a program inside the main code (in the main code I "read" printDate).
so how do I return the day outside to the main?
I don't need it to print it here (I do it only for "debug")
can I do something like this:
byte printDate()
{
.
.
weekDay = bcdToDec(Wire.read()); //0-6 ->
.Serial.println(weekday[weekDay]);
temp=weekday[weekDay]
return temp;
}
?
I understand what to do - and how to use the char array with the client.print
Thanks ,